이 내 코드입니다. 특정 항목을 찾거나 항목을 추가하기 전에 특정 항목을 찾으려고합니다. 우리는 동일한 아이템 콜렉션에있을 수없는 두 개의 패치 제품 코드를 가지고 있습니다.아이템 컬렉션에있는 기존 아이템 찾기 아래 코드
하나는 "% CNBG의 %"처럼
다른 하나는 "% CN- %의"
이 두 제품 코드와 별도의 거래의 이유로 같은 컬렉션에 추가 할 수 없습니다 같다. CNBG 제품에 CN 제품을 입력 할 수 없다는 오류를 표시하기 만하면됩니다.
내 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
이 내 장바구니 클래스 프레임 워크 2.0
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
추가 참고 사항 : 체크는 s.ItemCD에 있습니다.이 카트에는 CNBG 제품을 추가 할 수 없습니다. CN-BIC001을 입력하면 CNBG-BIC007 항목 코드를 입력 할 수 없습니다. – user1636949
어떤 Framework 버전을 사용하고 있습니까? 보다 구체적으로 LINQ를 사용할 수 있습니까? 솔루션은 코드 작성이 쉽고 신속하게 수행해야합니까 (아니면 둘 다 필요합니까?)? ItemCollection이 정의 된 방식을 보여줄 수 있습니까? 컬렉션의 유형은 기본적으로 무엇입니까? – eol
Framework 2.0이지만 최대 3.5 개까지 가능합니다. 위의 항목을 장바구니 항목 컬렉션의 클래스로 편집했습니다. – user1636949