Shopping Cart. ASP.NET State Management Session: User state Application: Application state Cache Static variables: –Public Shared interestRate as Single.

Slides:



Advertisements
Similar presentations
Cookies. Data in Cookies Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One or more pieces of data Keys Define.
Advertisements

VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Cookies. Data in Cookies Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One or more pieces of data Keys Define.
Authenticating Users in an ASP.NET Application. Web Site Administration Tool From VS 2008, click Website/ ASP.Net Configuration to open Web Site Administration.
Introduction to ADO.NET Programming. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB)
Shopping Cart Demo. Shopping Cart Search and display product information Add item to cart View cart contents Check out Note: WebsiteCart.
ASP.NET and ADO.NET. ASP.NET Server Controls Intrinsic Controls: These controls correspond to their HTML counterparts. –Ex. Textbox, listbox, button,
VB.NET Database Tools ISYS Net Applications OLE DB Provider OLE DB Data Source OLE DB Provider ODBC Data Source SQL Server Data Source SQL Server.Net.
Coding ADO.NET Objects: Connection, Command, DataReader.
Website Security ISYS 512. Authentication Authentication is the process that determines the identity of a user. Web.config file – node Options: –Windows.
ASP.Net AJAX. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net, etc.
Shopping Cart. ASP.NET State Management Session: User state Application: Application state Cache Static variables: –Public Shared interestRate as Single.
ASP.NET and ADO.NET. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB) Database.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
Web Site Security ISYS 512/812. Authentication Authentication is the process that determines the identity of a user. Web.config file – node Options: –Windows:
Coding ADO.NET Objects: Connection, Command, DataReader.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Working with Session and Application Objects. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Coding ADO.Net DataSet Objects. DataSet Object A DataSet object can hold several tables and relationships between tables. A DataSet is a set of disconnedted.
VB.NET Database Tools ISYS 573. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Introduction to Web Application Development with.Net and Web Service ISYS 350.
ASP.NET and ADO.NET. Bind the DataReader to a DataGrid Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" Dim objConn.
Introduction to ADO.NET. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB) Database.
Updating Database. Two Approaches to Update Database 1. Using the DataSet object, the updates are first applied to the DataSet then applied to the database.
Coding ADO.NET Objects: Connection, Command, DataReader.
Working with Session. Postback and Variables Variables declared in a web page including ADO.Net objects may be reinitialized and lose their values.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Introduction to VB.Net Internet Tools. Web Server Default directory –C:\InetPub\wwwroot –Computer lab: Zip drive dchao Default home page –Default.aspx,
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Website Security ISYS 512. Cookies Data in Cookies System.Web Which web site set the cookie Expiration date –DateTime data type –TimeSpan data type One.
Shopping Cart. Search and display product information Add item to cart View cart contents Check out.
Introduction to Web Service ISYS 512. Web Service XML Web Service Web services are classes that are stored on the web which can instantiate and use in.
Introduction to ADO.NET. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB) Database.
ASP and HTML. Anchor Tag testAnchorTag Demo: ASPNet/ASPNETProdListSelf.ASPX.
Introduction to VB.Net Internet Tools. Downloading Internet Resources Download the HTML from a web page and display it in a text box. –System.URI A class.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Introduction to XML and Web Service ISYS 464. HTML vs XML HTML is a language specifically designed for displaying information in browser. It doesn’t carry.
ASP.NET Event Handlers Database -> Browser ->Shopping Basket Validators.
DEV305 Presenting Data with the ASP.NET DataGrid Control Ken Getz Senior Consultant MCW Technologies, LLC.
Working with GridView Control: Adding Columns. Adding Buttons to a Bound GridView: 1. Drag the WebProduct table from Data connection to a page 2. Demo.
ASP.NET - accessing the database - datareader vs dataset - datagrid vs datalist - brief look at web matrix.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Unit 3: Adding Code to a Microsoft ASP.NET Web Form.
Introduction to Web Service ISYS 512. Web Service XML Web Service Web services are classes that are stored on the web which can instantiate and use in.
ASP.Net and HTML. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data.
Command Object’s ExecuteNonQuery Method ISYS 512.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Introduction to XML and Web Service ISYS 512/812.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
Coding ADO.NET Objects: Connection, Command, DataReader.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
C# Classes ISYS 512. Introduction to Classes A class is the blueprint for an object. –It describes a particular type of object. –It specifies the properties.
C# Classes ISYS 512. Introduction to Classes A class is the blueprint for an object. –It describes a particular type of object. –It specifies the properties.
PLACING ORDERS- SHOPPPING CARTS. Introduction There are several stages to the order process, starting with an order page, which allows customers to add.
Shopping Cart Demo. Shopping Cart Search and display product information Add item to cart View cart contents Check out.
Coding ADO.NET Objects: Connection, Command, DataReader.
Coding ADO.NET Objects: Connection, Command, DataReader
ASP.NET and ADO.NET.
Web Services Introduction
Coding ADO.NET Objects: Connection, Command, DataReader
Database Handling Class and Service
ASP.NET and ADO.NET.
VB Classes ISYS 512.
Working with Session and Application Objects
Introduction to ADO.NET
Shopping Cart Demo.
Command Object’s ExecuteNonQuery Method
Presentation transcript:

Shopping Cart

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

dim msg1, msg2, msg3 as string public 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 loading page. the message one is:" + msg1 + " ") response.write("First time loading page. the message two is:" + msg2 + " ") response.write("First time loading page. the message three is:" + msg3 + " ") response.write("First time loading page. the message four is:" + msg4 + " ") session("myMsg1")=msg1 application("myMsg2")=msg2 cache("myMsg3")=msg3 else msg1=session("myMsg1") msg2=application("myMsg2") msg3=cache("myMsg3") response.write("After the fist page loading, the message one is:" + msg1 + " ") response.write("After the fist page loading, the message two is:" + msg2 + " ") response.write("After the fist page loading, the message three is:" + msg3 + " ") response.write("After the fist page loading, the message four is:" + msg4 + " ") end if end sub

Shopping Cart Product information Add item to cart View cart contents Check out

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 used for OrderID –Other choices? Visitor Counter? Login user using cookie Each item is modeled as a class, and items are collected in a collection before added to the database.

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

Adding Buttons to a Bound DataGrid Use DataGrid/Columns editor –Bound columns, Button columns, Template columns Button event procedures –CodeWIndow/DataGrid DeleteCommand EditCommand CancelCommand UpdateCommand –e As System.Web.UI.WebControls.DataGridCommandEventArgs

DeleteCommand: –emps.RemoveAt(e.Item.ItemIndex) Edit Command: –DataGrid1.EditItemIndex = e.Item.ItemIndex Cancel command: –DataGrid1.EditItemIndex = -1 Update command: –emps.Item(e.Item.ItemIndex).salary = CDbl(CType(e.Item.Cells(4).Controls(0), TextBox).Text) – DataGrid1.EditItemIndex = -1 – DataGrid1.DataSource = emps – DataGrid1.DataBind() DataGrid Button Commands Examples

DataGrid Button Commands Example Dim objDataSet As New DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize 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

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

Adding Controls to a Bound DataGrid DataGrid Properties/Columns editor: –Template column: HeaderText Web Page’s HTML view: –Add ItemTemplate to the Template column tag –Add Control’s tag Example: – Event: ItemCommand

How to retrieve data from a cell in the selected row? Response.Write(CType(e.Item.Cells(0).FindControl("tbox "), TextBox).Text) Response.Write(CType(e.Item.Cells(5).Controls(0), TextBox).Text)

If there are two buttons created by ItemTemplate, how to tell which button is clicked? Use the ItemCommand procedure Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommand EventArgs) Handles DataGrid1.ItemCommand If e.CommandSource.text = "View" Then Response.Write("You click View button") End If If e.CommandSource.text = "Add" Then Response.Write("You click Add button") End If End Sub

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 Sub AddItem(ByVal line As CartLine) Dim item As New CartLine() Dim incart As New Boolean() incart = False If CollCartLine.Count > 0 Then For Each item In CollCartLine If item.pid = line.pid Then item.qty = line.qty incart = True Exit For End If Next End If If incart = False Then CollCartLine.Add(line) End If End Sub

Public Sub deleteItem(ByVal deleteIndex As Integer) CollCartLine.RemoveAt(deleteIndex) End Sub Public Sub checkOut() Dim objLine As New CartLine() Dim strSQL As String Dim strConn As String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" Dim objConn As New OleDbConnection() objConn.ConnectionString = strConn Dim objComm As New OleDbCommand() objConn.Open() objComm.Connection = objConn objComm.CommandType = CommandType.Text strSQL = "insert into weborder values ('" & oid & "', '" & cid & "', #" & ODate.ToString & "#, '" & CreditCardType & "','" & CreditCardNo & "')" objComm.CommandText = strSQL objComm.ExecuteNonQuery() For Each objLine In CollCartLine strSQL = "insert into webline values ('" & objLine.oid & "', '" & objLine.pid & "', " & CStr(objLine.qty) & ")" objComm.CommandText = strSQL objComm.ExecuteNonQuery() Next End Sub End Class

AddToCart Button Event Procedure Private Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.ItemCommand MyCart = Session("MyShopCart") Dim objLine As New CartLine() objLine.oid = Session.SessionID objLine.pid = e.Item.Cells(0).Text objLine.pname = e.Item.Cells(1).Text objLine.price = CDbl(e.Item.Cells(2).Text) objLine.qty = CInt(CType(e.Item.Cells(1).FindControl("tbox"), TextBox).Text) MyCart.AddItem(objLine) Response.Write("number of items in cart:" & CStr(MyCart.CollCartLine.Count)) End Sub

Delete Button Procedure Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand myCart.deleteItem(e.Item.ItemIndex) Session("MyShopCart") = myCart DataGrid1.DataSource = myCart.CollCartLine DataGrid1.DataBind() End Sub

CheckOut Procedure Dim MyCart As New ShopCart() Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here MyCart = Session("MyShopCart") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MyCart.oid = Session.SessionID MyCart.cid = Session("cid") MyCart.ODate = DateTime.Now() MyCart.CreditCardType = RadioButtonList1.SelectedItem.Text MyCart.CreditCardNo = TextBox1.Text MyCart.checkOut() Response.Write(" Thank you for shopping at My.Com ") Session.Abandon() End Sub

Web Service XML Web Service Web services are classes that are stored on the web which can instantiate and use in both Windows and Web applications.

A Web Service Example ASPET/TestWebService.ASMX imports System.Web.Services imports System imports System.Data imports System.Data.Oledb Public Class CustomerInfo public Function GetCname(ByVal CID as String) as String 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 * from customer where CID = '" & CID & "';" dim objComm as new OledbCommand(strSQL,objConn) dim Results as string objConn.open() dim objDataReader as oledbDataReader objDataReader=objComm.executeReader() objDataReader.read() return objDataReader("Cname") end function

Creating a Web Service Using VS New Project/ASP.Net Web Service

Web Service Description Language (WSDL) A WSDL file is an XML document containing a complete description of the web service. It shows a web service’s name, methods, and parameter types. Help page: After entering web service’s URL, a help page is displayed. You can click the Service Description link to see the WSDL file.

Consuming Web Services from a Windows Application Add a web reference to the web service. Declare a web service class variable. –Dim myWebService As New dchaolaptop.CustomerInfo() Demo: UseWebService

Universal Description, Discovery, and Integration (UDDI) A directory service for web services. –