Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 帮助允许其他开发人员自定义类_Vb.net_Class_Interface_Methods_Overriding - Fatal编程技术网

Vb.net 帮助允许其他开发人员自定义类

Vb.net 帮助允许其他开发人员自定义类,vb.net,class,interface,methods,overriding,Vb.net,Class,Interface,Methods,Overriding,更新:添加了一些示例代码以帮助澄清 嗨,我觉得这应该没那么复杂,但我想我只是不知道我要做什么的正确名称。我正在处理一个ASP.net项目 这个概念非常简单: 我有一个提供一些ecomm函数的库。 库中的一个类包含计算税收的函数。 库中的一个类围绕购物车标题旋转。 此类由web项目使用 将有一个类似于:carthead.SaveCart的方法。 在SaveCart中,它需要调用tax.CalculateTax 我需要做的是找到一种方法,允许carthead.SavCart始终能够访问特定函数,例如

更新:添加了一些示例代码以帮助澄清

嗨,我觉得这应该没那么复杂,但我想我只是不知道我要做什么的正确名称。我正在处理一个ASP.net项目

这个概念非常简单: 我有一个提供一些ecomm函数的库。 库中的一个类包含计算税收的函数。 库中的一个类围绕购物车标题旋转。 此类由web项目使用

将有一个类似于:carthead.SaveCart的方法。 在SaveCart中,它需要调用tax.CalculateTax

我需要做的是找到一种方法,允许carthead.SavCart始终能够访问特定函数,例如tax.CalculateTax(例如,该函数必须始终对库可用)

但是,我希望允许任何人创建tax.CalculateTax方法的不同版本

我尝试过使用可重写的基类做一些事情,但我发现,即使在web项目中重写tax基类,它也只在我从web项目调用时调用tax类的重写版本。 我无法将tax类设置为接口,因为当我这样做时,我无法将tax.CalculateTax的结果定义为的列表(因为在本例中t是一个接口,而不是实际的类)-此列表必须由carthead.SaveCart方法使用

因此,当您逐步浏览代码时,您会发现,当web项目调用carthead.SaveCart方法时,carthead.SaveCart方法无法从web项目中访问重写的代码。。。并导致调用tax.CalculateTax方法的非重写版本

我肯定我遗漏了一些东西,但我甚至不确定我应该研究什么,或者我想要完成的事情的确切名称是什么

简而言之,我需要能够重写一个方法,并从库中不可重写的方法调用该方法的重写版本

谁能告诉我我把什么搞砸了,或者我应该看什么

更新: 添加了一些代码片段以帮助澄清:

下面是讨论中的CartHeader类的一部分: "其他课堂内容略去,

Public Function UpdateCartStep2(ByVal CartNo As Long, ByVal Username As String, _
ByVal PmtMethod As String, ByVal ShipMethod As String, _
ByVal ShipComplete As Boolean, ByVal ShipCost As Double, _
ByVal ShipInstr As String, Optional ByVal TaxGroup As String = "", _
Optional ByVal PickupLoc As String = "", _
Optional ByVal FuelSurcharge As Double = 0, _
Optional ByVal Misc As String = "", _
    Optional ByVal TaxThisSomeTaxOrder As Boolean = False, _
    Optional ByVal ShipToID As Long = 0, _
    Optional ByVal ShipToZip As String = "", _
    Optional ByVal mCustCode As String = "", _
    Optional ByVal CustTax As Tax = Nothing) As Integer
    '=================>
    'note that the last parameter is new which is what we're currently using to pass in the customtax class so that we can consume it inside this method
    '==================>


    If IsNothing(CustTax) Then
        CustTax = New Tax
    End If

    '6-29-08 this stored proc was updated to allow for fuel surcharge
    'added fuel surcharge parameter

    Dim Resultval As Integer
    Dim strConnect As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
    Dim SqlCommand As New SqlCommand("sp_UpdateCartStep2", strConnect)

    Try

        Dim SubTotalAmt As Double
        SubTotalAmt = GetCartSubTotal(CartNo)

        GetCartHeader(CartNo)

        Dim CartTax As Double

        Dim SystemTypeID As Integer = CInt(ConfigurationManager.AppSettings("SystemTypeID").ToString)

        Select Case SystemTypeID
            Case 1

                If profile.AllowTerms = False Then
                    CartTax = CalcTax(SubTotalAmt, ShipCost, FuelSurcharge, m_Ship_State_Province)
                Else
                    CartTax = 0
                End If
            Case 2
                '6-29-08 added to figure fuel surcharge
                'Dim CustTax As New Tax
                'Dim CustCode As String = System.Web.HttpContext.Current.Profile("CustCode")
                Dim lCustTax As New List(Of Tax)

                '=========================>
                'note that this part of the header must always call into the calctax method.
                'it should be able to call the custom method if it has been defined.
                lCustTax = CustTax.wa_cc_CalcTax(mCustCode, ShipToID, SubTotalAmt, ShipCost, FuelSurcharge, CStr(m_Ship_State_Province), CStr(ShipToZip))
                '==========================>


                For Each ct As Tax In lCustTax
                    CartTax += ct.Tax
                Next
                'CartTax = CalcTax(SubTotalAmt, ShipCost, FuelSurcharge, m_Ship_State_Province, TaxGroup)

        End Select

        SqlCommand.CommandType = CommandType.StoredProcedure
        strConnect.Open()

        SqlCommand.Parameters.AddWithValue("@CartNo", SqlDbType.BigInt).Value = CartNo
        SqlCommand.Parameters.AddWithValue("@Username", SqlDbType.VarChar).Value = Username
        SqlCommand.Parameters.AddWithValue("@PmtMethod", SqlDbType.VarChar).Value = PmtMethod
        SqlCommand.Parameters.AddWithValue("@ShipMethod", SqlDbType.VarChar).Value = ShipMethod
        SqlCommand.Parameters.AddWithValue("@ShipCompleteFlag", SqlDbType.Bit).Value = ShipComplete
        SqlCommand.Parameters.AddWithValue("@ShipCost", SqlDbType.Money).Value = ShipCost
        SqlCommand.Parameters.AddWithValue("@Tax", SqlDbType.Money).Value = CartTax
        SqlCommand.Parameters.AddWithValue("@ShipInstr", SqlDbType.VarChar).Value = ShipInstr
        SqlCommand.Parameters.AddWithValue("@PickupLoc", SqlDbType.VarChar).Value = PickupLoc
        SqlCommand.Parameters.AddWithValue("@FuelSurcharge", SqlDbType.Float).Value = FuelSurcharge

        '1-30-08 Changed to accomodate holding the carrier number when selecting collect freight
        'required modification of the sp_UpdateCartStep2 stored procedure.
        SqlCommand.Parameters.AddWithValue("@Misc3", SqlDbType.VarChar).Value = Misc3

        SqlCommand.ExecuteNonQuery()
        Resultval = 0
    Catch ex As Exception
        Resultval = -1
        System.Web.HttpContext.Current.Trace.Write(ex.Message)
    Finally
        strConnect.Close()
    End Try

    Return Resultval
End Function
末级


这是我们用作基类的类。。。如果基本函数calcs不适用,它将覆盖wa_cc_calctax

Public Class Tax


Private _Tax As Double
Public Property Tax() As Double
    Get
        Return _Tax
    End Get
    Set(ByVal value As Double)
        _Tax = value
    End Set
End Property

Private _TaxRate As Double
Public Property TaxRate() As Double
    Get
        Return _TaxRate
    End Get
    Set(ByVal value As Double)
        _TaxRate = value
    End Set
End Property


Private _TaxDesc As String
Public Property TaxDesc() As String
    Get
        Return _TaxDesc
    End Get
    Set(ByVal value As String)
        _TaxDesc = value
    End Set
End Property


Private _TaxGroupID As String
Public Property TaxGroupID() As String
    Get
        Return _TaxGroupID
    End Get
    Set(ByVal value As String)
        _TaxGroupID = value
    End Set
End Property


Private _TaxJurisdictionID As String
Public Property TaxJurisdictionID() As String
    Get
        Return _TaxJurisdictionID
    End Get
    Set(ByVal value As String)
        _TaxJurisdictionID = value
    End Set
End Property



Private _TaxCustCode As String
Public Property TaxCustCode() As String
    Get
        Return _TaxCustCode
    End Get
    Set(ByVal value As String)
        _TaxCustCode = value
    End Set
End Property


Private _TaxFreight As Boolean
Public Property taxFreight() As Boolean
    Get
        Return _TaxFreight
    End Get
    Set(ByVal value As Boolean)
        _TaxFreight = value
    End Set
End Property




Public Enum TaxableStatus
    All
    None
    some
End Enum


''' <summary>
''' It will first try to figure out if we're shipping to the same zip as the ship to
''' if it is the same, then we'll use the ship-tos tax group
''' if it is different, then we'll go to manual tax.
''' in manual tax, the customer record is reviewed and the class_1id field is interogated.
''' The code selected tells us what states the customer is taxable for.
''' If we are in those states, then the customer tax group is chosed based on the state.
''' </summary>
''' <param name="mCustCode"></param>
''' <param name="mShipToID"></param>
''' <param name="SubTotalAmt"></param>
''' <param name="FreightCost"></param>
''' <param name="FuelSurcharge"></param>
''' <param name="m_Ship_State_Province"></param>
''' <param name="m_Zip"></param>
''' <param name="TaxGroup"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Overridable Function wa_cc_CalcTax(ByVal mCustCode As String, _
                       ByVal mShipToID As String, _
                       ByVal SubTotalAmt As Double, _
                     ByVal FreightCost As Double, _
                    ByVal FuelSurcharge As Double, _
                    ByVal m_Ship_State_Province As String, _
                    ByVal m_Zip As String, _
                     Optional ByVal TaxGroup As String = "") As List(Of Tax)

    'do some 'normal' tax calcs.


    Return New List(Of Tax)

End Function
公共类税
个人所得税加倍
公共财产税(双倍)
得到
报税表
结束
设置(ByVal值为双精度)
_税=价值
端集
端属性
私人(单位)税率为双倍
公共财产税率()为双倍
得到
收益率
结束
设置(ByVal值为双精度)
_税率=价值
端集
端属性
Private\u TaxDesc作为字符串
公共属性TaxDesc()作为字符串
得到
报税表
结束
设置(ByVal值作为字符串)
_TaxDesc=值
端集
端属性
Private\u TaxGroupID作为字符串
公共属性TaxGroupID()作为字符串
得到
Return\u TaxGroupID
结束
设置(ByVal值作为字符串)
_TaxGroupID=值
端集
端属性
Private\u taxjustictionId为字符串
公共属性TaxJudictionId()作为字符串
得到
Return\u taxjustictionid
结束
设置(ByVal值作为字符串)
_TaxJudictionId=值
端集
端属性
Private\u TaxCustCode作为字符串
公共属性TaxCustCode()作为字符串
得到
返回\u TaxCustCode
结束
设置(ByVal值作为字符串)
_TaxCustCode=值
端集
端属性
Private\u作为布尔值
公共属性TaxCargo()为布尔值
得到
退运税
结束
设置(ByVal值为布尔值)
_税运费=价值
端集
端属性
公共枚举可征税状态
全部的
没有一个
一些
结束枚举
''' 
''它将首先试图弄清楚我们的发货地址是否与发货地址相同
''如果是相同的,那么我们将使用ship tos税务组
''如果是不同的,那么我们就去手动纳税。
''在手动税务中,审查客户记录,并对class_1id字段进行互选。
''所选代码告诉我们客户应纳税的州。
''如果我们在这些州,则根据州选择客户税组。
''' 
''' 
''' 
''' 
''' 
''' 
''' 
''' 
''' 
''' 
''' 
公共可重写函数wa_cc_CalcTax(ByVal mCustCode作为字符串_
ByVal mShipToID作为字符串_
ByVal小计金额为双倍_
比瓦尔运费加倍_
比瓦尔燃油附加费为双倍_
ByVal m_Ship_State_Province作为字符串_
ByVal m_Zip作为字符串_
可选ByVal TaxGroup作为字符串=”)作为列表(税)
'进行一些“正常”税务计算。
报税表(税单)
端函数
末级


这是覆盖wa_cc_calctax函数的CustomTax类:

Public Class CustomTax

Inherits Tax


''' <summary>
''' It will first try to figure out if we're shipping to the same zip as the ship to
''' if it is the same, then we'll use the ship-tos tax group
''' if it is different, then we'll go to manual tax.
''' in manual tax, the customer record is reviewed and the class_1id field is interogated.
''' The code selected tells us what states the customer is taxable for.
''' If we are in those states, then the customer tax group is chosed based on the state.
''' </summary>
''' <param name="mCustCode"></param>
''' <param name="mShipToID"></param>
''' <param name="SubTotalAmt"></param>
''' <param name="FreightCost"></param>
''' <param name="FuelSurcharge"></param>
''' <param name="m_Ship_State_Province"></param>
''' <param name="m_Zip"></param>
''' <param name="TaxGroup"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Overrides Function wa_cc_CalcTax(ByVal mCustCode As String, _
                       ByVal mShipToID As String, _
                       ByVal SubTotalAmt As Double, _
                     ByVal FreightCost As Double, _
                    ByVal FuelSurcharge As Double, _
                    ByVal m_Ship_State_Province As String, _
                    ByVal m_Zip As String, _
                     Optional ByVal TaxGroup As String = "") As List(Of Tax)
    Dim lTX As New List(Of Tax)

    Dim mUseP21Tax As Boolean = True
    If mShipToID <= 0 Then
        mUseP21Tax = False
    End If

    If FreightCost <= 0 Then
        FreightCost = 0
    End If

    Dim tx As New CustomTax
    Dim ZipMatch As Boolean
    If mShipToID > 0 Then
        'we're dealing with a selected ship to so we should see if it all still matches
        ZipMatch = CheckZipAgainstShipTo(m_Zip, mCustCode, mShipToID)
    Else
        'this item is not a selected ship-to so no need to look for a match
        ZipMatch = False
    End If

    If ZipMatch = True Then

        lTX = LookupTaxForShipTo(mCustCode, mShipToID, SubTotalAmt, FreightCost)
    Else
        lTX = LookupManualTax(mCustCode, m_Ship_State_Province, SubTotalAmt, FreightCost, , m_Zip)


    End If


    Return lTX
公共类海关税
遗产税
''' 
''它将首先试图弄清楚我们的发货地址是否与发货地址相同
''如果是相同的,那么我们将使用ship tos税务组
''如果是不同的,那么我们就去手动纳税。
''在手动税务中,审查客户记录,并对class_1id字段进行互选。
''所选代码告诉我们客户应纳税的州。
''如果我们在这些州,则根据州选择客户税组。
''' 
''' 
''' 
''' 
''' 
''' 
''' 
''' 
''' 
''' 
''' 
公共重写函数wa_cc_CalcTax(ByVal mCustCode作为字符串_
ByVal mShipToID作为字符串_
ByVal小计金额为双倍_
比瓦尔运费加倍_
比瓦尔燃油附加费为双倍_
拜瓦尔木船_
Public Class CustomTax

Inherits Tax


''' <summary>
''' It will first try to figure out if we're shipping to the same zip as the ship to
''' if it is the same, then we'll use the ship-tos tax group
''' if it is different, then we'll go to manual tax.
''' in manual tax, the customer record is reviewed and the class_1id field is interogated.
''' The code selected tells us what states the customer is taxable for.
''' If we are in those states, then the customer tax group is chosed based on the state.
''' </summary>
''' <param name="mCustCode"></param>
''' <param name="mShipToID"></param>
''' <param name="SubTotalAmt"></param>
''' <param name="FreightCost"></param>
''' <param name="FuelSurcharge"></param>
''' <param name="m_Ship_State_Province"></param>
''' <param name="m_Zip"></param>
''' <param name="TaxGroup"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Overrides Function wa_cc_CalcTax(ByVal mCustCode As String, _
                       ByVal mShipToID As String, _
                       ByVal SubTotalAmt As Double, _
                     ByVal FreightCost As Double, _
                    ByVal FuelSurcharge As Double, _
                    ByVal m_Ship_State_Province As String, _
                    ByVal m_Zip As String, _
                     Optional ByVal TaxGroup As String = "") As List(Of Tax)
    Dim lTX As New List(Of Tax)

    Dim mUseP21Tax As Boolean = True
    If mShipToID <= 0 Then
        mUseP21Tax = False
    End If

    If FreightCost <= 0 Then
        FreightCost = 0
    End If

    Dim tx As New CustomTax
    Dim ZipMatch As Boolean
    If mShipToID > 0 Then
        'we're dealing with a selected ship to so we should see if it all still matches
        ZipMatch = CheckZipAgainstShipTo(m_Zip, mCustCode, mShipToID)
    Else
        'this item is not a selected ship-to so no need to look for a match
        ZipMatch = False
    End If

    If ZipMatch = True Then

        lTX = LookupTaxForShipTo(mCustCode, mShipToID, SubTotalAmt, FreightCost)
    Else
        lTX = LookupManualTax(mCustCode, m_Ship_State_Province, SubTotalAmt, FreightCost, , m_Zip)


    End If


    Return lTX
abstract class BaseCartOperations
{
    public void SaveCart ()
    {

        // ...

        CalculateTax();
    }


    protected void CalculateTax ()
    {
        // Base Tax Stuff
        CalculateTaxInternal();
    }


    // Force implementation
    protected abstract void CalculateTaxInternal ();
}