mydr(1)=row.ProductName
mydr(2)=row.ReferencePrice
mydr(3)=cookie.Values(i)
mydr(4)=row.unit
mydr(5)=(CType(mydr(2),Single)*CInt(mydr(3))).ToString
mydt.Rows.Add(mydr)
End If
Next
End If
’设置DataGrid数据源
dg_Cart.DataSource=mydt.DefaultView
’DataGrid绑定
dg_Cart.DataBind()
End Sub
’DataGrid编辑事件
Private Sub dg_Cart_EditCommand(ByVal source As Object,ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)Handles dg_Cart.EditCommand dg_Cart.EditItemIndex=e.Item.ItemIndex
BindGrid()
End Sub
’DataGrid取消事件
Private Sub dg_Cart_CancelCommand(ByVal source As Object,ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)Handles dg_Cart.CancelCommand dg_Cart.EditItemIndex=—1
BindGrid()
End Sub
’DataGrid更新事件
Private Sub dg_Cart_UpdateCommand(ByVal source As Object,ByVal e As System.Web.UI. Web—Controls.DataGridCommandEventArgs)Handles dg_Cart.UpdateCommand
Dim Number As String
Number=(CType(e.Item.Cells(4).Controls(0),TextBox)).Text
Dim cookie As HttpCookie=New HttpCookie(”ProductCart”)
Dim i As Integer
For i=0 To dg_Cart.Items.Count
Dim id As String
Dim count As String
id=dg_Cart.Items(i).Cells(0).Text
If e.Item.ItemIndex=i Then
count=Number
Else
count=dg_Cart.Items(i).Cells(4).Text
End If
If count.Trim()=””Then
count=”0”
End If
cookie.Values.Add(id,count)
Next
Dim ts As TimeSpan=New TimeSpan(0,0,10,0)
cookie.Expires=DateTime.Now.Add(ts)
Response.AppendCookie(cookie)
dg_Cart.EditItemIndex=—1
Response.Redirect(”ShowCart.aspx”)
End Sub
’清除购物车中商品
Private Sub btnCleanCart_Click(ByVal sender As System.Object,ByVal e As System.
EventArgs) Handles btnCleanCart.Click
Dim tempCB As System.Web.UI.WebControls.CheckBox
Dim cookie As HttpCookie=New HttpCookie(”ProductCart”)
Dim i As Integer
For i=0 To dg_Cart.Items.Count— 1
tempCB=CType(dg_Cart.Items(i).FindControl(”ckb_Select”),_
System.Web.UI.WebControls.CheckBox)
If Not tempCB Is Nothing Then
If Not tempCB.Checked Then
Dim id As String
Dim count As String
id=dg_Cart.Items(i).Cells(0).Text
count=dg_Cart.Items(i).Cells(5).Text
If count.Trim()=””Then
count=”0”
End If
cookie.Values.Add(id,count)
End If
End If
Next
Dim ts As TimeSpan=New TimeSpan(0,0,10,0)
cookie.Expires=DateTime.Now.Add(ts)
Response.AppendCookie(cookie)
’重新定位到当前页面
Response.Redirect(”ShowCart.aspx”)
End Sub
’提交购物车中的商品
Private Sub btnPutOrder_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btnPutOrder.Click
’提交购物车中的商品时,服务器端要把客户的信息保存到数据库中用户预定表中
Try
Dim cookie As HttpCookie=New HttpCookie(”ProductCart”)
Dim i As Integer
For i=0 To dg_Cart.Items.Count—1
Dim id As String
Dim count As String
id=dg_Cart.Items(i).Cells(0).Text
count=dg_Cart.Items(i).Cells(4).Text
If count.Trim()=””Then
count=”1”
End If
With row_orderDetail
.PreOrderID=preorderid
.Number=CInt(cookie.Values(i))
.ProductId=CInt(cookie.Values.AllKeys(i))
End With
Next
’向数据库预定表中插入数据
MyNearFar.T_OrderDetailCollection.Insert(row_orderDetail)
Catch ex As Exception
End Try
End Sub
思考题
1.如何理解对象、类的概念,对象和类的关系?
2.如何理解封装、继承、多态的概念?
3.继承有哪些优点和缺点?
4.继承与组合有哪些异同?
5.方法覆盖必须满足哪些规则?
6.软件重用的好处是什么?
7.如何在页面间传递参数?
8.如何使用页面缓存?
9.web.config的作用?
10.什么情况使用全局变量?