Vb.net 在项目集合中查找现有项目

Vb.net 在项目集合中查找现有项目,vb.net,itemcollection,Vb.net,Itemcollection,下面是我的代码。我正在尝试在项目之后或添加项目之前查找特定项目。我们有两个特定的产品代码,不能在同一个项目集合中 一个类似于“%CNBG%” 另一个类似于“%CN-%” 这两个产品代码不能由于单独的交易而添加到同一集合中。我只想显示一个错误,CN-products不能与CNBG products一起输入 这是我的AddStormItem,它在收藏中做广告,我想我的支票应该在这里。如何在我要添加到下面的集合中找到现有项目?这样我就可以检查一下了 Private Sub AddStoreItem(B

下面是我的代码。我正在尝试在项目之后或添加项目之前查找特定项目。我们有两个特定的产品代码,不能在同一个项目集合中

一个类似于“%CNBG%”

另一个类似于“%CN-%”

这两个产品代码不能由于单独的交易而添加到同一集合中。我只想显示一个错误,CN-products不能与CNBG products一起输入

这是我的AddStormItem,它在收藏中做广告,我想我的支票应该在这里。如何在我要添加到下面的集合中找到现有项目?这样我就可以检查一下了

Private Sub AddStoreItem(ByVal ProductCd As String, ByVal ddlSearchField As String, ByVal tbSearchValue As String)

    Dim cartitems As Cart = OnsiteCart

    Dim s As New dB.Product
    Dim dt As DataTable = Store.GetProductbyCd(ProductCd)
    Dim ds As New DataSet
    Dim er As New Visitor

    ds = Common.GetCustomerByParam(OnsiteCart.CustomerCD, "", "", "", "", "")

    er.IsMemberFlg = nullCStr(ds.Tables(0).Rows(0)("IsMemberFlg"))

    VisitorData = er

    Try

        If VisitorData.IsMemberFlg <> "N" Then

            s.Amount = Format(dt.Rows(0)("UDEF2AMT"), "0.00")
            s.Description = dt.Rows(0)("PRODUCTNAME")
            s.ItemCD = dt.Rows(0)("PRODUCTCD")
            s.Quantity = 1

        Else
            s.Amount = Format(dt.Rows(0)("UNITPRICE"), "0.00")
            s.Description = dt.Rows(0)("PRODUCTNAME")
            s.ItemCD = dt.Rows(0)("PRODUCTCD")
            s.Quantity = 1

        End If

    Catch ex As Exception
        lblProductError.Text = "Product not found"
        lblProductError.Visible = True
    End Try

    If s.Amount <> 0 Then
        cartitems.ItemCollection.Add(s)
        lblProductError.Visible = False
    End If

End Sub
Private子AddStoreItem(ByVal ProductCd作为字符串,ByVal ddlSearchField作为字符串,ByVal tbSearchValue作为字符串)
Dim cartitems As Cart=OnsiteCart
Dim s作为新的数据库产品
作为DataTable的Dim dt=Store.GetProductbyCd(ProductCd)
Dim ds作为新数据集
新来的客人
ds=Common.GetCustomerByParam(OnsiteCart.CustomerCD,“”,“”,“”,“”,“”,“”)
er.IsMemberFlg=nullCStr(ds.表(0).行(0)(“IsMemberFlg”))
VisitorData=er
尝试
如果VisitorData.IsMemberFlg为“N”,则
s、 金额=格式(数据行(0)(“UDEF2AMT”),“0.00”)
s、 Description=dt.行(0)(“产品名称”)
s、 ItemCD=dt.行(0)(“PRODUCTCD”)
s、 数量=1
其他的
s、 金额=格式(dt.行(0)(“单价”),“0.00”)
s、 Description=dt.行(0)(“产品名称”)
s、 ItemCD=dt.行(0)(“PRODUCTCD”)
s、 数量=1
如果结束
特例
lblProductError.Text=“未找到产品”
lblProductError.Visible=True
结束尝试
如果美国的金额为0,那么
cartitems.ItemCollection.Add(s)
lblProductError.Visible=False
如果结束
端接头
这是我的购物车课

Imports system
Imports System.Configuration
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Collections.ObjectModel

<Serializable()> _
Public Class Cart

#Region " Private Variables "

    Private strenterusercd As String
    Private strinvoicenum As String
    Private strinvoicenumreused As Boolean
    Private strpayeecd As String
    Private strpayeetypecd As String
    Private strcustomercd As String

    Private strpaymenttype As enPaymentType
    Private dblcashamount As Double
    Private dblcheckamount As Double
    Private strchecknumber As String
    Private strponumber As String

    Private strCCType As String
    Private strCCNumber As String
    Private strCCNumberEncrypted As String
    Private strCCExp As String
    Private strCCZip As String
    Private strCCCVV As String

    Private strCCVerificationcd As String
    Private strCCResponsecd As String
    Private strCCRejectioncd As String
    Private strCCTransactioncd As String

    Private intmaxID As Int32

    Private dblCCAmount As Double

#End Region

    Public ItemCollection As New CartItems(Of iInvoiceItem)

    Enum enPaymentType
        CreditCard
        Cash
        Check
        PO
    End Enum

#Region " Public Properties "

    Public Property EnterUserCd() As String
        Get
            Return strenterusercd
        End Get
        Set(ByVal value As String)
            strenterusercd = value
        End Set
    End Property

    Public Property InvoiceNumReUsed() As Boolean
        Get
            Return strinvoicenumreused
        End Get
        Set(ByVal value As Boolean)
            strinvoicenumreused = value
        End Set
    End Property

    Public Property InvoiceNum() As String
        Get
            Return strinvoicenum
        End Get
        Set(ByVal value As String)
            strinvoicenum = value
        End Set
    End Property

    Public Property PayeeCd() As String
        Get
            Return strpayeecd
        End Get
        Set(ByVal value As String)
            strpayeecd = value
        End Set
    End Property

    Public Property PayeeTypeCd() As String
        Get
            Return strpayeetypecd
        End Get
        Set(ByVal value As String)
            strpayeetypecd = value
        End Set
    End Property

    Public Property CustomerCD() As String
        Get
            Return strcustomercd
        End Get
        Set(ByVal value As String)
            strcustomercd = value
        End Set
    End Property

    Public Property PaymentType() As enPaymentType
        Get
            Return strpaymenttype
        End Get
        Set(ByVal value As enPaymentType)
            strpaymenttype = value
        End Set
    End Property

    Public Property CashAmount() As Double
        Get
            Return dblcashamount
        End Get
        Set(ByVal value As Double)
            dblcashamount = value
        End Set
    End Property

    Public Property CheckAmount() As Double
        Get
            Return dblcheckamount
        End Get
        Set(ByVal value As Double)
            dblcheckamount = value
        End Set
    End Property

    Public Property CheckNumber() As String
        Get
            Return strchecknumber
        End Get
        Set(ByVal value As String)
            strchecknumber = value
        End Set
    End Property

    Public Property PONumber() As String
        Get
            Return strponumber
        End Get
        Set(ByVal value As String)
            strponumber = value
        End Set
    End Property

    Public Property CCType() As String
        Get
            Return strCCType
        End Get
        Set(ByVal value As String)
            strCCType = value
        End Set
    End Property

    Public Property CCNumber() As String
        Get
            Return strCCNumber
        End Get
        Set(ByVal value As String)
            strCCNumber = value
        End Set
    End Property

    Public ReadOnly Property CCNumberEncrypted() As String
        Get
            If CCNumber Is Nothing Then
                Return ""
            ElseIf CCNumber.Length = 16 Then
                Return "************" & Right(CCNumber, 4)
            Else
                Return "***********" & Right(CCNumber, 4)
            End If
        End Get
    End Property

    Public Property CCExp() As String
        Get
            Return strCCExp
        End Get
        Set(ByVal value As String)
            strCCExp = value
        End Set
    End Property

    Public Property CCZip() As String
        Get
            Return strCCZip
        End Get
        Set(ByVal value As String)
            strCCZip = value
        End Set
    End Property

    Public Property CCCVV() As String
        Get
            Return strCCCVV
        End Get
        Set(ByVal value As String)
            strCCCVV = value
        End Set
    End Property

    Public Property CCAmount() As Double
        Get
            Return dblCCAmount
        End Get
        Set(ByVal value As Double)
            dblCCAmount = value
        End Set
    End Property

    Public Property CCVerificationcd() As String
        Get
            Return strCCVerificationcd
        End Get
        Set(ByVal value As String)
            strCCVerificationcd = value
        End Set
    End Property

    Public Property CCResponsecd() As String
        Get
            Return strCCResponsecd
        End Get
        Set(ByVal value As String)
            strCCResponsecd = value
        End Set
    End Property

    Public Property CCRejectioncd() As String
        Get
            Return strCCRejectioncd
        End Get
        Set(ByVal value As String)
            strCCRejectioncd = value
        End Set
    End Property

    Public Property CCTransactioncd() As String
        Get
            Return strCCTransactioncd
        End Get
        Set(ByVal value As String)
            strCCTransactioncd = value
        End Set
    End Property

    Public Property MaxID() As Int32
        Get
            Return intmaxID
        End Get
        Set(ByVal value As Int32)
            intmaxID = value
        End Set
    End Property

#End Region

    <Serializable()> _
    Public Class CartItems(Of itemType As iInvoiceItem)
        Inherits Collection(Of iInvoiceItem)
    End Class

    Public Sub New()
        Me.EnterUserCd = HttpContext.Current.User.Identity.Name
        Me.InvoiceNumReUsed = False
        Me.InvoiceNum = Nothing 'Common.getAutonumber("INVOICE")
        Me.MaxID = 0
    End Sub

    Public Sub New(ByVal invoicenum As String)
        Me.EnterUserCd = HttpContext.Current.User.Identity.Name
        Me.InvoiceNumReUsed = True
        Me.InvoiceNum = invoicenum
        Me.MaxID = 0
    End Sub

    Public Sub New(ByVal payeecd As String, ByVal payeetypecd As String)
        Me.EnterUserCd = HttpContext.Current.User.Identity.Name
        Me.InvoiceNum = Nothing 'Common.getAutonumber("INVOICE")
        Me.InvoiceNumReUsed = False
        Me.PayeeCd = payeecd
        Me.PayeeTypeCd = payeetypecd
        Me.MaxID = 0
    End Sub

    Public Sub New(ByVal invoicenum As String, ByVal payeecd As String, ByVal payeetypecd As String)
        Me.EnterUserCd = HttpContext.Current.User.Identity.Name
        Me.InvoiceNum = invoicenum
        Me.InvoiceNumReUsed = True
        Me.PayeeCd = payeecd
        Me.PayeeTypeCd = payeetypecd
        Me.MaxID = 0
    End Sub

    Public Function CartTotal()
        Dim total As Double = 0

        For Each item As iInvoiceItem In Me.ItemCollection
            total += item.getPrice
            'total += item.Amount * item.Quantity
        Next

        Return total
    End Function

    Public Function getNewCartItemID() As Int32
        Dim ID As Int32 = 0

        Me.MaxID += 1
        ID = Me.MaxID

        Return ID
    End Function

    Public Function getParentIndSession(ByVal assignedsessioncd As String) As IndSession
        Dim S As New IndSession

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type = "Session" Then
                If CType(item, dB.IndSession).Assignedsessioncd = assignedsessioncd Then
                    S = CType(item, dB.IndSession)
                End If
            End If
        Next
        Return S
    End Function

    Public Function getChildIndfunctions(ByVal assignedsessioncd As String) As CartItems(Of iInvoiceItem)
        Dim tempcart As New CartItems(Of iInvoiceItem)

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type = "Function" Then
                If CType(item, dB.IndFunction).Assignedsessioncd = assignedsessioncd Then
                    tempcart.Add(CType(item, dB.IndFunction))
                End If
            End If
        Next
        Return tempcart
    End Function

    Public Sub DeleteByAssignedsessioncd(ByVal assignedsessioncd As String)
        Dim tempcart As New CartItems(Of iInvoiceItem)

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type = "Session" Then
                If CType(item, dB.IndSession).Assignedsessioncd = assignedsessioncd Then
                    tempcart.Add(item)
                End If
            ElseIf item.Type = "Function" Then
                If CType(item, dB.IndFunction).Assignedsessioncd = assignedsessioncd Then
                    tempcart.Add(item)
                End If
            End If
        Next

        For Each deleteditem As iInvoiceItem In tempcart
            Me.ItemCollection.Remove(deleteditem)
        Next
    End Sub

    Public Function getCompCodes() As ArrayList
        Dim arrCompCodes As New ArrayList

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type = "Function" Then
                If Not CType(item, dB.IndFunction).Compcd Is Nothing Then
                    arrCompCodes.Add(CType(item, dB.IndFunction).Compcd)
                End If
            End If
        Next
        Return arrCompCodes
    End Function

    Public Function getUsedFreeFullRegistrations() As Int32
        Dim count As Int32 = 0

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type = "Session" Then
                If CType(item, dB.IndSession).ItemCD = "EXHIB_XC" Then
                    count += 1
                End If
            End If
        Next
        Return count
    End Function

    Public Function getUsedFreeExhibitOnlyRegistrations() As Int32
        Dim count As Int32 = 0

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type = "Session" Then
                If CType(item, dB.IndSession).ItemCD = "EXHIB_XD" Then
                    count += 1
                End If
            End If
        Next
        Return count
    End Function

    Public Function getUsedFreeExhibitDailyRegistrations() As Int32
        Dim count As Int32 = 0

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type = "Session" Then
                If CType(item, dB.IndSession).ItemCD = "EXHIB_XE" Then
                    count += 1
                End If
            End If
        Next
        Return count
    End Function

    Public Sub Checkout()
        If Me.CartTotal > 0 Then
            System.Web.HttpContext.Current.Response.Redirect("payment.aspx")
        Else
            System.Web.HttpContext.Current.Response.Redirect("confirm.aspx")
        End If
    End Sub

    Public Sub Clear()
        Me.CashAmount = Nothing
        Me.CCAmount = Nothing
        Me.CCCVV = Nothing
        Me.CCExp = Nothing
        Me.CCNumber = Nothing
        Me.CCRejectioncd = Nothing
        Me.CCResponsecd = Nothing
        Me.CCType = Nothing
        Me.CCVerificationcd = Nothing
        Me.CCZip = Nothing
        Me.CheckAmount = Nothing
        Me.CheckNumber = Nothing
        Me.CustomerCD = Nothing
        Me.EnterUserCd = Nothing
        Me.InvoiceNum = Nothing 'Common.getAutonumber("INVOICE")
        Me.InvoiceNumReUsed = Nothing
        Me.ItemCollection = New CartItems(Of iInvoiceItem)
        Me.MaxID = Nothing
        Me.PayeeCd = Nothing
        Me.PayeeTypeCd = Nothing
        Me.PaymentType = Nothing
        Me.PONumber = Nothing
    End Sub

    Public Sub ClearItems()
        Me.CashAmount = Nothing
        Me.CCAmount = Nothing
        Me.CCCVV = Nothing
        Me.CCExp = Nothing
        Me.CCNumber = Nothing
        Me.CCRejectioncd = Nothing
        Me.CCResponsecd = Nothing
        Me.CCType = Nothing
        Me.CCVerificationcd = Nothing
        Me.CCZip = Nothing
        Me.CheckAmount = Nothing
        Me.CheckNumber = Nothing
        Me.InvoiceNumReUsed = Nothing
        Me.ItemCollection = New CartItems(Of iInvoiceItem)
        Me.MaxID = Nothing
        Me.PaymentType = Nothing
        Me.PONumber = Nothing
    End Sub

    Public Function getCartContents() As ArrayList
        Dim arrCartItems As New ArrayList

        For Each item As iInvoiceItem In Me.ItemCollection
            arrCartItems.Add(item)
        Next
        Return arrCartItems
    End Function

    Public Function getSingleUserCartAssignedsessioncd() As String
        Dim retval As String = ""

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type = "Session" Then
                retval = CType(item, dB.IndSession).Assignedsessioncd
            End If
        Next
        Return retval
    End Function

    Public Function getParentItems() As DataTable
        Dim dt As New DataTable

        For Each item As iInvoiceItem In Me.ItemCollection
            If item.Type <> "Function" Then
                If Not CType(item, dB.IndFunction).Compcd Is Nothing Then
                    dt.Rows.Add(CType(item, dB.IndFunction).Compcd)
                End If
            End If
        Next
        Return dt
    End Function

End Class
导入系统
导入系统配置
导入System.Web.Configuration
导入系统数据
导入System.Data.SqlClient
导入系统.Web
导入System.Web.UI
导入System.Collections.ObjectModel
_
公共类购物车
#区域“私有变量”
私有StrengterUserCD作为字符串
私有的strinvoicenum作为字符串
私有strinvoicenum重用为布尔值
私有strPayeCD作为字符串
私有strPayeTypecD作为字符串
私有strucstomercd作为字符串
私有strpaymenttype作为enPaymentType
私有dblcashamount为双精度
私有dblcheckamount作为双
私有strchecknumber作为字符串
作为字符串的专用strponumber
私有strCCType作为字符串
私有strCCNumber作为字符串
私有strccnumbers加密为字符串
私有strCCExp作为字符串
私有strCCZip作为字符串
专用strccvv作为字符串
私有strCCVerificationcd作为字符串
私有strcResponseCD作为字符串
私有strCCRejectioncd作为字符串
私有strCCTransactioncd作为字符串
私有intmaxID为Int32
专用dblCCAmount为双精度
#末端区域
作为新CartItems的公共ItemCollection(属于iInvoiceItem)
枚举支付类型
信用卡
现金
检查
人事军官
结束枚举
#区域“公共财产”
公共属性EnterUserCd()作为字符串
得到
返回强度用户CD
结束
设置(ByVal值作为字符串)
strengterusercd=值
端集
端属性
公共属性InvoiceNumReUsed()为布尔值
得到
返回序列号
结束
设置(ByVal值为布尔值)
strinvoicenumreused=值
端集
端属性
公共属性InvoiceNum()作为字符串
得到
回程斯特林沃森
结束
设置(ByVal值作为字符串)
strinvoicenum=值
端集
端属性
公共属性payecd()作为字符串
得到
返回strpayecd
结束
设置(ByVal值作为字符串)
strpayecd=值
端集
端属性
公共属性payetypecd()作为字符串
得到
返回strpayetypecd
结束
设置(ByVal值作为字符串)
strPayeTypecd=值
端集
端属性
公共属性CustomerCD()作为字符串
得到
返回strucstomercd
结束
设置(ByVal值作为字符串)
STRCSTOMERCD=值
端集
端属性
公共属性PaymentType()作为enPaymentType
得到
返回strpaymenttype
结束
设置(作为enPaymentType的ByVal值)
strpaymenttype=值
端集
端属性
公共财产现金金额()为双倍
得到
返回dblcashamount
结束
设置(ByVal值为双精度)
dblcashamount=值
端集
端属性
公共属性CheckAmount()为双精度
得到
返回dblcheckamount
结束
设置(ByVal值为双精度)
dblcheckamount=值
端集
端属性
公共属性CheckNumber()作为字符串
得到
返回strchecknumber
结束
设置(ByVal值作为字符串)
strchecknumber=值
端集
端属性
作为字符串的公共属性PONumber()
得到
返回strponumber
结束
设置(ByVal值作为字符串)
strponumber=值
端集
端属性
公共属性CCType()作为字符串
得到
返回strCCType
结束
设置(ByVal值作为字符串)
strCCType=值
端集
端属性
公共属性CCNumber()作为字符串
得到
返回strCCNumber
结束
设置(ByVal值作为字符串)
strCCNumber=值
端集
端属性
作为字符串的公共只读属性CCnumberCrypted()
得到
如果CCN编号不正确
If s.ItemCd.Contains("CNBG") Then
    If (From i In cartitems.ItemCollection Where i.ItemCd.Contains("CN-") Select i).Any() Then
        'Error message         
        Return
    End If
ElseIf s.ItemCd.Contains("CN-") Then
    If (From i In cartitems.ItemCollection Where i.ItemCd.Contains("CNBG") Select i).Any() Then
        'Error message                
        Return
    End If
End If

'Ok if we got here
cartitems.ItemCollection.Add(s)