⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbcustomer.vb

📁 .net 编写的电子商务系统 使用方便 超做简单 好用
💻 VB
字号:
Imports System
Imports System.Data
Imports System.Data.SqlClient

Namespace Services

    Public Class DBCustomer

        Private Connstring As String = _
        "Data Source=localhost;Initial Catalog=Store;user id=sa;pwd=sa"

        Public Function AuthenticateCustomer( _
        ByVal strEmailAddress As String, _
        ByVal strPassword As String) As String

            Dim sqlcmdSelectCustomers As New SqlCommand _
            ("sp_Customers_Login")
            With sqlcmdSelectCustomers
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .Add("@strEmailAddress", SqlDbType.NVarChar, 50)
                    .Add("@strPassword", SqlDbType.NVarChar, 10)
                    .Add("@intCustomerID", SqlDbType.Int, 4)
                End With
            End With
            Dim CustomerID As Integer
            Dim sqlconCustomers As New SqlConnection(Connstring)
            sqlcmdSelectCustomers.Connection = sqlconCustomers
            With sqlcmdSelectCustomers.Parameters
                .Item("@strEmailAddress").Value = strEmailAddress
                .Item("@strPassword").Value = strPassword
                .Item("@intCustomerID").Direction = _
                ParameterDirection.Output
            End With
            sqlconCustomers.Open()
            sqlcmdSelectCustomers.ExecuteNonQuery()
            sqlconCustomers.Close()
            CustomerID = sqlcmdSelectCustomers.Parameters.Item _
            ("@intCustomerID").Value
            If CustomerID = 0 Then
                Return Nothing
            Else
                Return CustomerID.ToString
            End If
        End Function

        Public Function InsertCustomer( _
        ByVal objCustomer As Customer) As String
            Dim sqlcmdInsertCustomer As New SqlCommand _
            ("sp_Customers_INS")
            With sqlcmdInsertCustomer
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .Add("@intCustomerID", SqlDbType.Int, 4)
                    .Add("@nvchrCustomerName", SqlDbType.NVarChar, 50)
                    .Add("@nvchrEmailAddress", SqlDbType.NVarChar, 50)
                    .Add("@nvchrPassword", SqlDbType.NVarChar, 10)
                    .Item("@intCustomerID").Direction = ParameterDirection.Output
                    .Item("@nvchrCustomerName").Value = objCustomer.CustomerName
                    .Item("@nvchrEmailAddress").Value = objCustomer.EmailAddress
                    .Item("@nvchrPassword").Value = objCustomer.Password
                End With
            End With
            Dim sqlconCustomers As New SqlConnection(Connstring)
            sqlconCustomers.Open()
            sqlcmdInsertCustomer.Connection = sqlconCustomers
            sqlcmdInsertCustomer.ExecuteNonQuery()
            sqlconCustomers.Close()
            Dim intCustomerID As Integer
            intCustomerID = sqlcmdInsertCustomer.Parameters.Item("@intCustomerID").Value
            Return intCustomerID.ToString
        End Function

        Public Function GetCustomerDetails(ByVal strCustomerID As String) As Customer
            Dim objCustomer As New Customer()
            Dim sqlcmdInsertCustomer As New SqlCommand("sp_Customers_Details")
            With sqlcmdInsertCustomer
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .Add("@intCustomerID", SqlDbType.Int, 4)
                    .Add("@nvchrCustomerName", SqlDbType.NVarChar, 50)
                    .Add("@nvchrEmailAddress", SqlDbType.NVarChar, 50)
                    .Add("@nvchrPassword", SqlDbType.NVarChar, 10)
                    .Item("@intCustomerID").Value = strCustomerID
                    .Item("@nvchrCustomerName").Direction = ParameterDirection.Output
                    .Item("@nvchrEmailAddress").Direction = ParameterDirection.Output
                    .Item("@nvchrPassword").Direction = ParameterDirection.Output
                End With
            End With
            Dim sqlconCustomers As New SqlConnection(Connstring)
            sqlconCustomers.Open()
            sqlcmdInsertCustomer.Connection = sqlconCustomers
            sqlcmdInsertCustomer.ExecuteNonQuery()
            sqlconCustomers.Close()
            With sqlcmdInsertCustomer.Parameters
                objCustomer.CustomerName = CStr(.Item("@nvchrCustomerName").Value)
                objCustomer.EmailAddress = CStr(.Item("@nvchrEmailAddress").Value)
                objCustomer.Password = CStr(.Item("@nvchrPassword").Value)
            End With
            Return objCustomer
        End Function

    End Class

    Public Class Customer

        Public CustomerName As String
        Public EmailAddress As String
        Public Password As String
    End Class

End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -