知识大全 ASP.NET入门教程 13.4.5 计划结账[3]
Posted 知
篇首语:学习是为了完善人生,追求卓越自我,成功就会出其不意的找上门来。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 ASP.NET入门教程 13.4.5 计划结账[3]相关的知识,希望对你有一定的参考价值。
ASP.NET入门教程 13.4.5 计划结账[3] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
( )在这个代码上添加如下代码 <%@ Import Namespace= System Data SqlClient %> <%@ Import Namespace= Wrox Commerce %>
( )保存该设计
( )转到Solution Explorer 选择checkout aspx vb
( )添加如下后台代码 取代已经位于其中的代码
Imports System
Imports System Data SqlClient
Imports Wrox Commerce
Partial Class Checkout
Inherits System Web UI Page
Sub Page_Load(ByVal sender As Object ByVal e As System EventArgs) Handles Me Load
Trace Write( In Page_Load )
If Not Page IsPostBack Then
If Profile Cart Is Nothing Then
NoCartlabel Visible = True
Wizard Visible = False
End If
Trace Write( In Page_Load User Identity IsAuthenticated ToString())
If User Identity IsAuthenticated Then
Wizard ActiveStepIndex =
Else
Wizard ActiveStepIndex =
End If
End If
End Sub
Sub cUseProfileAddress_CheckedChanged(ByVal sender As Object ByVal e As System EventArgs)
fill the delivery address from the profile but only if it s empty
we don t want to overwrite the values
If cUseProfileAddress Checked AndAlso txtName Text Trim() = Then
txtName Text = Profile Name
txtAddress Text = Profile Address
txtCity Text = Profile City
txtCounty Text = Profile County
txtPostCode Text = Profile PostCode
txtCountry Text = Profile Country
End If
End Sub
Sub Wizard _FinishButtonClick(ByVal sender As Object ByVal e As System Web UI WebControls WizardNavigationEventArgs)
Insert the order and order lines into the database
Dim conn As SqlConnection = Nothing
Dim trans As SqlTransaction = Nothing
Dim cmd As SqlCommand
Try
conn = New SqlConnection(ConfigurationManager ConnectionStrings( WroxUnited ) ConnectionString)
conn Open()
trans = conn BeginTransaction
cmd = New SqlCommand()
cmd Connection = conn
cmd Transaction = trans
set the order details
cmd CommandText = INSERT INTO Orders(MemberName OrderDate Name Address County PostCode Country SubTotal Discount Total) & _
VALUES (@MemberName @OrderDate @Name @Address @County @PostCode @Country @SubTotal @Discount @Total)
cmd Parameters Add( @MemberName Data SqlDbType VarChar )
cmd Parameters Add( @OrderDate Data SqlDbType DateTime)
cmd Parameters Add( @Name Data SqlDbType VarChar )
cmd Parameters Add( @Address Data SqlDbType VarChar )
cmd Parameters Add( @County Data SqlDbType VarChar )
cmd Parameters Add( @PostCode Data SqlDbType VarChar )
cmd Parameters Add( @Country Data SqlDbType VarChar )
cmd Parameters Add( @SubTotal Data SqlDbType Money)
cmd Parameters Add( @Discount Data SqlDbType Money)
cmd Parameters Add( @Total Data SqlDbType Money)
cmd Parameters( @MemberName ) Value = User Identity Name
cmd Parameters( @OrderDate ) Value = DateTime Now()
cmd Parameters( @Name ) Value = CType(Wizard FindControl( txtName ) TextBox) Text
cmd Parameters( @Address ) Value = CType(Wizard FindControl( txtAddress ) TextBox) Text
cmd Parameters( @County ) Value = CType(Wizard FindControl( txtCounty ) TextBox) Text
cmd Parameters( @PostCode ) Value = CType(Wizard FindControl( txtPostCode ) TextBox) Text
cmd Parameters( @Country ) Value = CType(Wizard FindControl( txtCountry ) TextBox) Text
cmd Parameters( @SubTotal ) Value = Profile Cart SubTotal
cmd Parameters( @Discount ) Value = Profile Cart MemberDiscount
cmd Parameters( @Total ) Value = Profile Cart Total
Dim OrderID As Integer
OrderID = Convert ToInt (cmd ExecuteScalar())
change the query and parameters for the order lines
cmd CommandText = INSERT INTO OrderLines(OrderID ProductID Quantity Price) & _
VALUES (@OrderID @ProductID @Quantity @Price)
cmd Parameters Clear()
cmd Parameters Add( @OrderID Data SqlDbType Int)
cmd Parameters Add( @ProductID Data SqlDbType Int)
cmd Parameters Add( @Quantity Data SqlDbType Int)
cmd Parameters Add( @Price Data SqlDbType Money)
cmd Parameters( @OrderID ) Value = OrderID
For Each item As CartItem In Profile Cart Items
cmd Parameters( @ProductID ) Value = item ProductID
cmd Parameters( @Quantity ) Value = item Quantity
cmd Parameters( @Price ) Value = item Price
cmd ExecuteNonQuery()
Next
mit the transaction
trans Commit()
Catch SqlEx As SqlException
some form of error rollback the transaction
and rethrow the exception
If trans IsNot Nothing Then
trans Rollback()
End If
Log the exception
Tools log( An error occurred while creating the order SqlEx)
Throw New Exception( An error occurred while creating the order SqlEx)
CreateOrderErrorLabel Visible = True
Return
Finally
If conn IsNot Nothing Then
conn Close()
End If
End Try
we will only reach here if the order has been created sucessfully
so clear the cart
Profile Cart Items Clear()
End Sub
Sub Wizard _NextButtonClick(ByVal sender As Object ByVal e As System Web UI WebControls WizardNavigationEventArgs)
Trace Write( next: CurrentStep e CurrentStepIndex ToString())
If e CurrentStepIndex = Then
Dim l As System Web UI WebControls Login = CType(Wizard FindControl( Login ) Login)
If Membership ValidateUser(l UserName l Password) Then
FormsAuthentication SetAuthCookie(l UserName l RememberMeSet)
e Cancel = False
Else
Trace Write(l UserName l Password)
l InstructionText = Your login attempt was not successful Please try again
l InstructionTextStyle ForeColor = System Drawing Color Red
e Cancel = True
End If
Else
If Not User Identity IsAuthenticated Then
e Cancel = True
Wizard ActiveStepIndex =
End If
End If
End Sub
Protected Sub Wizard _ActiveStepChanged(ByVal sender As Object ByVal e As System EventArgs) Handles Wizard ActiveStepChanged
If Not User Identity IsAuthenticated Then
Trace Write( step changed not authenticated returning to step )
Wizard ActiveStepIndex =
End If
End Sub
End Class
cha138/Article/program/net/201311/15651相关参考
知识大全 ASP.NET入门教程 13.4.5 计划结账[5]
ASP.NET入门教程13.4.5计划结账[5] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&n
知识大全 ASP.NET入门教程 13.4.5 计划结账[1]
ASP.NET入门教程13.4.5计划结账[1] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&n
知识大全 ASP.NET入门教程 13.4.5 计划结账[8]
ASP.NET入门教程13.4.5计划结账[8] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&n
知识大全 ASP.NET入门教程 13.4.5 计划结账[6]
ASP.NET入门教程13.4.5计划结账[6] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&n
知识大全 ASP.NET入门教程 13.4.5 计划结账[7]
ASP.NET入门教程13.4.5计划结账[7] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&n
知识大全 ASP.NET入门教程 13.4.5 计划结账[2]
ASP.NET入门教程13.4.5计划结账[2] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!&n
ASP.NET入门教程13.4结账 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! &nb
知识大全 ASP.NET入门教程 10.5.3 ASP.NET 2.0的新特性[2]
ASP.NET入门教程10.5.3ASP.NET2.0的新特性[2] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快
知识大全 ASP.NET入门教程 10.5.3 ASP.NET 2.0的新特性[1]
ASP.NET入门教程10.5.3ASP.NET2.0的新特性[1] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快
ASP.NET入门教程9.2.3循环[3] 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!