📄 customer.vb
字号:
Imports System.Data
Imports System.Data.SqlClient
Namespace Common
Public Class Customer
Public ConnString As String = "Data Source=localhost;Initial Catalog=Shop;user id=sa;pwd=sa"
Public Enum CustomerTypesEnum
CustomerType_临时 = 0
CustomerType_消费客户 = 1
CustomerType_商务 = 2
End Enum
Public Enum AccountStatusEnum
AccountStatus_启用 = 1
AccountStatus_禁用 = 2
End Enum
Public CustomerID As String
Public CustomerName As String
Public EmailAddress As String
Public Password As String
Public CreateDate As DateTime
Public AccountStatus As AccountStatusEnum
Public CustomerType As CustomerTypesEnum
Public objItems As Item
Public Addresses As Address
'Public Function AddCustomer(ByVal CustomerID As String, _
'ByVal CustomerName As String, _
'ByVal CustomerType As Customer.CustomerTypesEnum, _
'ByVal EmailAddress As String, _
'ByVal Password As String, _
'ByVal TrueName As String, _
'ByVal AccountStatus As Customer.AccountStatusEnum _
') As Customer
'Dim objCustomer As New Customer()
'objCustomer.CustomerID = CustomerID
'objCustomer.CustomerName = CustomerName
'objCustomer.CustomerType = CustomerType
'objCustomer.EmailAddress = EmailAddress
'objCustomer.Password = Password
'objCustomer.AccountStatus = AccountStatus
'Return objCustomer
'End Function
Public Function AuthenticateCustomer(ByVal strEmailAddress As String, _
ByVal strPassword As String) As Customer
Dim dsCustomers As dsCustomers = GetCustomerByEmail(strEmailAddress)
If dsCustomers.Customers.Rows.Count = 0 Then
Return Nothing
Exit Function
End If
Dim strCustomerPassword As String = dsCustomers.Customers(0).Password
If System.String.Compare(strPassword, strCustomerPassword, False) = 0 Then
Dim objCustomer As New Customer()
With dsCustomers.Customers(0)
objCustomer.EmailAddress = .EmailAddress
objCustomer.CustomerName = .CustomerName
objCustomer.CustomerID = .CustomerID.ToString()
objCustomer.AccountStatus = .AccountStatus
objCustomer.CustomerType = .CustomerType
objCustomer.CreateDate = .DateCreated
End With
Return objCustomer
Else
Return Nothing
End If
End Function
Public Function GetCustomerByEmail(ByVal strEmailAddress As String) As dsCustomers
Dim sqlcmdGetCustomerByEmail As New SqlCommand("sp_Customers_SEL_byEmail")
With sqlcmdGetCustomerByEmail
.CommandType = CommandType.StoredProcedure
With .Parameters
.Add("@nvchrEmailAddress", SqlDbType.NVarChar, 50)
.Item("@nvchrEmailAddress").Value = strEmailAddress
End With
End With
Dim dsCustomers As New dsCustomers()
Dim sqlconIBuyAdventure As New SqlConnection(Connstring)
sqlcmdGetCustomerByEmail.Connection = sqlconIBuyAdventure
Dim sqladpCustomers As New SqlDataAdapter(sqlcmdGetCustomerByEmail)
sqladpCustomers.Fill(dsCustomers, "Customers")
Return dsCustomers
End Function
Public Function InsertAddress(ByVal objCustomer As Customer) As Address
Try
Dim objAddress As Address
Dim sqlcmdInsertCustomerAddress As New SqlCommand("sp_Addresses_INS")
With sqlcmdInsertCustomerAddress
.CommandType = CommandType.StoredProcedure
With .Parameters
.Add("@chrAddressID", SqlDbType.Char, 38)
.Add("@chrCustomerID", SqlDbType.Char, 38)
.Add("@nvchrAddress1", SqlDbType.NVarChar, 50)
.Add("@nvchrAddress2", SqlDbType.NVarChar, 30)
.Add("@nvchrCity", SqlDbType.NVarChar, 30)
.Add("@nvchrRegion", SqlDbType.NVarChar, 30)
.Add("@nvchrPostalCode", SqlDbType.NVarChar, 20)
.Add("@nvchrCountry", SqlDbType.NVarChar, 30)
.Add("@nchrPhoneNumber", SqlDbType.NChar, 15)
End With
End With
Dim sqlconShop As New SqlConnection(ConnString)
sqlconShop.Open()
sqlcmdInsertCustomerAddress.Connection = sqlconShop
If objAddress.AddressID.Length = 0 Then
objAddress.AddressID = System.Guid.NewGuid.ToString()
End If
With sqlcmdInsertCustomerAddress.Parameters
.Item("@chrAddressID").Value = objAddress.AddressID
.Item("@nvchrAddress1").Value = objAddress.Address1
.Item("@nvchrAddress2").Value = objAddress.Address2
.Item("@nvchrCity").Value = objAddress.City
.Item("@nvchrCountry").Value = objAddress.Country
.Item("@nchrPhoneNumber").Value = objAddress.Telphone
.Item("@nvchrPostalCode").Value = objAddress.PostalCode
.Item("@nvchrRegion").Value = objAddress.Region
.Item("@chrCustomerID").Value = objCustomer.CustomerID
End With
sqlcmdInsertCustomerAddress.ExecuteNonQuery()
sqlconShop.Close()
Return objAddress
Catch excp As System.Exception
Throw excp
End Try
End Function
Public Function InsertOrderAddresses(ByVal objOrder As Order) As Order
Try
Dim objAddress As Address
Dim sqlcmdInsertOrderAddress As New SqlCommand("sp_OrderAddresses_INS")
With sqlcmdInsertOrderAddress
.CommandType = CommandType.StoredProcedure
With .Parameters
.Add("@chrOrderAddressID", SqlDbType.Char, 38)
.Add("@nvchrAddress1", SqlDbType.NVarChar, 50)
.Add("@nvchrAddress2", SqlDbType.NVarChar, 30)
.Add("@nvchrCity", SqlDbType.NVarChar, 30)
.Add("@nvchrRegion", SqlDbType.NVarChar, 30)
.Add("@nvchrPostalCode", SqlDbType.NVarChar, 20)
.Add("@nvchrCountry", SqlDbType.NVarChar, 50)
.Add("@nchrPhoneNumber", SqlDbType.NChar, 15)
End With
End With
Dim sqlconIBuyAdventure As New SqlConnection(ConnString)
sqlconIBuyAdventure.Open()
sqlcmdInsertOrderAddress.Connection = sqlconIBuyAdventure
With sqlcmdInsertOrderAddress.Parameters
.Item("@chrOrderAddressID").Value = objAddress.AddressID
.Item("@nvchrAddress1").Value = objAddress.Address1
.Item("@nvchrAddress2").Value = objAddress.Address2
.Item("@nvchrCity").Value = objAddress.City
.Item("@nvchrRegion").Value = objAddress.Region
.Item("@nvchrPostalCode").Value = objAddress.PostalCode
.Item("@nvchrCountry").Value = objAddress.Country
.Item("@nchrPhoneNumber").Value = objAddress.Telphone
End With
sqlcmdInsertOrderAddress.ExecuteNonQuery()
'
sqlconIBuyAdventure.Close()
Return objOrder
Catch excp As System.Exception
Throw excp
End Try
End Function
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -