Shopping basket.


73 views
Uploaded on:
Description
Shopping basket. Pursuit and presentation item data. Add thing to truck. Perspective truck substance ... Response.Write(
Transcripts
Slide 1

Shopping basket

Slide 2

ASP.NET State Management Session: User state Application: Application state Cache Static variables: Public Shared interestRate as Single Demo:StateTest2.aspx

Slide 3

faint msg1, msg2, msg3 as string open shared msg4 as string sub Page_Load() if not page.ispostBack then msg1="hi one" msg2="hi two" msg3="hi three" msg4="hi four" response.write("First time stacking page. the message one is:" + msg1 + "<br>") response.write("First time stacking page. the message two is:" + msg2 + "<br>") response.write("First time stacking page. the message three is:" + msg3 + "<br>") response.write("First time stacking page. the message four is:" + msg4 + "<br>") session("myMsg1")=msg1 application("myMsg2")=msg2 cache("myMsg3")=msg3 else msg1=session("myMsg1") msg2=application("myMsg2") msg3=cache("myMsg3") response.write("After the clench hand page stacking, the message one is:" + msg1 + "<br>") response.write("After the clench hand page stacking, the message two is:" + msg2 + "<br>") response.write("After the clench hand page stacking, the message three is:" + msg3 + "<br>") response.write("After the clench hand page stacking, the message four is:" + msg4 + "<br>") end if end sub

Slide 4

Shopping Cart Search and show item data Add thing to truck View truck substance Check out

Slide 5

Shopping Cart Example Database: WebCustomer: CustID, CustName, Addr, Phone WebOrder: OrderID, CustID, OrderDate, CreditCardType, CreditCardNo WebLine: OrderID, PID, Qty WebProduct: Pid, Pname, Price, UnitsInStock Session ID is utilized for OrderID Other decisions? Guest Counter? Login client utilizing treat Each thing is displayed as a class, and things are gathered in an accumulation before added to the database.

Slide 6

Implementing Shopping Cart as Class Shopping Cart Properties: Public oid As String Public cid As String Public ODate As DateTime Public CreditCardType As String Public CreditCardNo as String Public CollCartLine As New ArrayList() Methods: AddItem, DeleteItem, ViewCart, CheckOut DetailLine Properties: OID PID Pname Price Qty Amount = Qty * Price

Slide 7

Adding Buttons to a Bound DataGrid Use DataGrid/Columns editorial manager Bound sections, Button segments, Template segments Button occasion methodology CodeWIndow/DataGrid DeleteCommand EditCommand CancelCommand UpdateCommand e As System.Web.UI.WebControls.DataGridCommandEventArgs

Slide 8

Edit/Delete Customer Record Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then OleDbDataAdapter1.Fill(DataSet31, "customer") DataGrid1.DataBind() Session("MyDs") = DataSet31 Else DataSet31 = Session("MyDs") End If End Sub Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand DataGrid1.EditItemIndex = e.Item.ItemIndex DataGrid1.DataBind() End Sub

Slide 9

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand DataSet31.Tables("Customer").Rows(e.Item.ItemIndex).Item("rating") = CType(e.Item.Cells(4).Controls(0), TextBox).Text DataGrid1.EditItemIndex = - 1 DataGrid1.DataBind() Session("MyDs") = DataSet31 End Sub Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand DataGrid1.EditItemIndex = - 1 DataGrid1.DataBind() End Sub

Slide 10

Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand DataSet31.Tables("customer").Rows.RemoveAt(e.Item.ItemIndex) DataGrid1.DataBind() Session("MyDs") = DataSet31 End Sub

Slide 11

DataGrid Button Commands Examples DeleteCommand: DataSet31.Tables("customer").Rows.RemoveAt(e.Item.ItemIndex) Edit Command: DataGrid1.EditItemIndex = e.Item.ItemIndex Cancel summon: DataGrid1.EditItemIndex = - 1 Update charge: DataSet31.Tables("Customer").Rows(e.Item.ItemIndex).Item("rating") = CType(e.Item.Cells(4).Controls(0), TextBox).Text DataGrid1.EditItemIndex = - 1 Note: CType(e.Item.Cells(4).Controls(0), TextBox)

Slide 12

Dim objDataSet As New DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load \'Put client code to instate the page here If Not Page.IsPostBack Then Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" Dim objConn As New OleDbConnection(strConn) Dim strSQL As String = "select pid,description,price from product;" Dim objAdapter As New OleDbDataAdapter(strSQL, objConn) objAdapter.Fill(objDataSet, "Product") DataGrid1.DataSource = objDataSet DataGrid1.DataMember = "Product" DataGrid1.DataBind() Session("MyDs") = objDataSet Else objDataSet = Session("MyDs") End If End Sub Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand DataGrid1.EditItemIndex = e.Item.ItemIndex DataGrid1.DataSource = objDataSet DataGrid1.DataMember = "Product" DataGrid1.DataBind() End Sub DataGrid Button Commands Example

Slide 13

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand objDataSet.Tables("Product").Rows(e.Item.ItemIndex).Item("Price") = CDbl(CType(e.Item.Cells(4).Controls(0), TextBox).Text) DataGrid1.EditItemIndex = - 1 DataGrid1.DataSource = objDataSet DataGrid1.DataMember = "Product" DataGrid1.DataBind() Session("MyDs") = objDataSet End Sub Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand DataGrid1.EditItemIndex = - 1 DataGrid1.DataSource = objDataSet DataGrid1.DataMember = "Product" DataGrid1.DataBind() End Sub Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand objDataSet.Tables("Product").Rows.RemoveAt(e.Item.ItemIndex) DataGrid1.DataSource = objDataSet DataGrid1.DataMember = "Product" DataGrid1.DataBind() Session("MyDs") = objDataSet End Sub

Slide 14

Adding Textbox and Button and to a Bound DataGrid Properties/Columns supervisor: Template segment: HeaderText: This content will be utilized as segment name Web Page\'s HTML view: Add ItemTemplate to the Template segment label Add Control\'s label Event: ItemCommand

Slide 15

Example <asp:TemplateColumn HeaderText="Quantity"> <ItemTemplate> <asp:TextBox id="txtQty" Width="70" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="AddToCart"> <ItemTemplate> <asp:Button Text="AddToCart" Runat="server"></asp:Button> </ItemTemplate> </asp:TemplateColumn>

Slide 16

How to recover information from a phone in the chose line? Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand Response.Write(CType(e.Item.Cells(4).Controls(1), TextBox).Text) Response.Write(CType(e.Item.Cells(4).FindControl("txtQty"), TextBox).Text) End Sub Note: Cells(4).Controls(1) Controls(0) is the cell itself, Controls(1) is the 2 nd control in the cell.

Slide 17

If there are two catches made by ItemTemplate, how to tell which catch is clicked? Utilize the ItemCommand technique Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand If e.CommandSource.text = "View" Then Response.Write("You click View button") End If e.CommandSource.text = "Add" Then Response.Write("You click Add button") End If End Sub

Slide 18

ShopCart Class Public Class ShopCart Public oid As String Public cid As String Public ODate As DateTime Public CreditCardType As String Public CreditCardNo As String Public CollCartLine As New ArrayList() Public ReadOnly Property CartTotal() As Double Get Dim thing As New CartLine Dim aggregate As Double Dim itemIndex As Integer For Each thing In CollCartLine absolute = complete + item.price * item.qty Next CartTotal = all out End Get End Property

Slide 19

AddItem Method Public Sub AddItem(ByVal line As CartLine) Dim thing As New CartLine() Dim incart As New Boolean() incart = False If CollCar

Recommended
View more...