熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET入門教程 13.4.5 計劃結賬[6]

2022-06-13   來源: .NET編程 

    如果此時實際上正在登錄階段這個步驟才會起作用檢查以查看是否己經驗證用戶如果沒有驗證則顯示適當的錯誤消息通知用戶他們這一次沒有能夠登錄否則驗證用戶

 

Sub Wizard_NextButtonClick(ByVal sender As Object ByVal e As SystemWebUIWebControlsWizardNavigationEventArgs)

 

        If eCurrentStepIndex = Then

 

            Dim l As SystemWebUIWebControlsLogin = CType(WizardFindControl(Login) Login)

 

            If MembershipValidateUser(lUserName lPassword) Then

                FormsAuthenticationSetAuthCookie(lUserName lRememberMeSet)

 

                eCancel = False

            Else

                TraceWrite(lUserName lPassword)

                lInstructionText = Your login attempt was not successful Please try again

                lInstructionTextStyleForeColor = SystemDrawingColorRed

 

                eCancel = True

            End If

        End If

 

    End Sub

    FinishButtonClick包含或許是最長的代碼集但它並不像看起來那麼復雜在此處將用戶的訂單寫入到數據庫必須能夠在發生錯誤時回滾這一點首先創建連接字符串並且創建事務然後將結賬過程中提供的所有詳情讀入到參數中有許多參數!具有成員名遞送地址信用卡詳情和整個購物車總價

 

Sub Wizard_FinishButtonClick(ByVal sender As Object ByVal e As SystemWebUIWebControlsWizardNavigationEventArgs)

 

        TODO: Move to component

        Insert the order and order lines into the database

        Dim conn As New SqlConnection(ConfigurationManagerConnectionStrings(WroxUnited)ConnectionString)

        Dim trans As SqlTransaction = Nothing

        Dim cmd As New SqlCommand()

        Dim OrderID As Integer

 

 

        Try

            connOpen()

            trans = connBeginTransaction

            cmdConnection = conn

            cmdTransaction = trans

            cmdCommandType = DataCommandTypeStoredProcedure

 

            set the order details

            cmdCommandText = usp_OrderAdd

            TODO: by default in beta creating a stored proc doesnt give execute perms

            cmdCommandText = INSERT INTO Orders(MemberName OrderDate Name Address County PostCode Country SubTotal Discount Total) & _

                             VALUES (@MemberName @OrderDate @Name @Address @County @PostCode @Country @SubTotal @Discount @Total)

            cmdParametersAdd(@MemberName DataSqlDbTypeVarChar )

            cmdParametersAdd(@OrderDate DataSqlDbTypeDateTime)

            cmdParametersAdd(@Name DataSqlDbTypeVarChar )

            cmdParametersAdd(@Address DataSqlDbTypeVarChar )

            cmdParametersAdd(@County DataSqlDbTypeVarChar )

            cmdParametersAdd(@PostCode DataSqlDbTypeVarChar )

            cmdParametersAdd(@Country DataSqlDbTypeVarChar )

            cmdParametersAdd(@SubTotal DataSqlDbTypeMoney)

            cmdParametersAdd(@Discount DataSqlDbTypeMoney)

            cmdParametersAdd(@Total DataSqlDbTypeMoney)

 

            cmdParameters(@MemberName)Value = UserIdentityName

            cmdParameters(@OrderDate)Value = DateTimeNow()

            cmdParameters(@Name)Value = CType(WizardFindControl(txtName) TextBox)Text

            cmdParameters(@Address)Value = CType(WizardFindControl(txtAddress) TextBox)Text

            cmdParameters(@County)Value = CType(WizardFindControl(txtCounty) TextBox)Text

            cmdParameters(@PostCode)Value = CType(WizardFindControl(txtPostCode) TextBox)Text

            cmdParameters(@Country)Value = CType(WizardFindControl(txtCountry) TextBox)Text

           

            cmdParameters(@Total)Value = ProfileCartTotal

 

            OrderID = ConvertToInt(cmdExecuteScalar())

[]  []  []  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15649.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.