Shopping Cart Demo. Shopping Cart Search and display product information Add item to cart View cart contents Check out.

Slides:



Advertisements
Similar presentations
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
Advertisements

Authenticating Users in an ASP.NET Application. Web Site Administration Tool From VS 2008, click Website/ ASP.Net Configuration to open Web Site Administration.
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.
Introduction to Data Adapter. A Simplified View of ADO.Net Objects Ado.Net Data Provider Connection Adapter Command Reader Dataset Data Consumer WinForm.
ASP.NET and ADO.NET. ADO.NET Objects Data Set.NET Applications Data Reader Command Object Connection Object Managed Data Provider (OLEDB) Database.
Shopping Cart. ASP.NET State Management Session: User state Application: Application state Cache Static variables: –Public Shared interestRate as Single.
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.
Concurrency Control. R/RR/W W/W User 2 ReadWrite User 1 Read Write R/W: Inconsistent Read problem. W/W: Lost Update problem.
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.
Coding ADO.NET Objects: Connection, Command, DataReader.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
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 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.
ASP and HTML. Anchor Tag testAnchorTag Demo: ASPNet/ASPNETProdListSelf.ASPX.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS546.
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.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
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.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
VB Procedures. Procedures. Sub procedure: Private/Public Sub SubName(Arguments) … End Sub Private: Can only be accessed by procedures in the same form.
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.
Working with the Application Object. Session VS Application Object The Session object helps to preserve data on a per user basis. What if we want to initialize.
Website Security ISYS 512. Authentication Authentication is the process that determines the identity of a user.
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.
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
1 CS 3870/CS 5870: Note05 Prog3 Web Application with Database.
TRAINING SESSIONS.NET Controls.  Standard Controls  Label  Textbox  Checkbox  Button, Image Button, Image control  Radio Button  Literal  Hyperlink.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
1 CS387/CS587: Note04 Lab 3. 2 Master Page All Web pages will be similar Should be created before other web pages Add New Items Controls on the Master.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
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.
The Windows Forms DataGrid A Complex-Bound.NET GUI Control Mike FITZSIMON SYSTEMSARCHITECT F ITZSIMON IT C ONSULTING PTY LTD.
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.
Coding ADO.NET Objects: Connection, Command, DataReader
ASP.NET and ADO.NET.
Coding ADO.NET Objects: Connection, Command, DataReader
ASP.NET Relationships between tables
Database Handling Class and Service
ASP.NET and ADO.NET.
VB Classes ISYS 512.
Working with Session and Application Objects
Shopping Cart Demo.
Command Object’s ExecuteNonQuery Method
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Shopping Cart Demo

Shopping Cart Search and display 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, Pname, Price, Qty –WebProduct: Pid, Pname, Price, UnitsInStock OrderID 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 a Class to a Website Website project: –Class files must save in App_Code folder –Right click Solution explorer and Choose Add ASP.Net Folder

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 item As New CartLine Dim total As Double Dim itemIndex As Integer For Each item In CollCartLine total = total + item.price * item.qty Next CartTotal = total End Get End Property

AddItem Method 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

Shopping Cart Detail Line Public Class CartLine Private hiddenoid As String Private hiddenpid As String Private hiddenpname As String Private hiddenprice As Double Private hiddenqty As Integer Public Property oid() As String Get oid = hiddenoid End Get Set(ByVal Value As String) hiddenoid = Value End Set End Property Public Property pid() As String Get pid = hiddenpid End Get Set(ByVal Value As String) hiddenpid = Value End Set End Property

Public Property pname() As String Get pname = hiddenpname End Get Set(ByVal Value As String) hiddenpname = Value End Set End Property Public Property price() As Double Get price = hiddenprice End Get Set(ByVal Value As Double) hiddenprice = Value End Set End Property Public Property qty() As Integer Get qty = hiddenqty End Get Set(ByVal Value As Integer) hiddenqty = Value End Set End Property Public ReadOnly Property amount() As Double Get amount = qty * price End Get End Property End Class

AddToCart Button Event Procedure Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged MyCart = Session("MyCart") Dim objLine As New CartLine() objLine.oid = Session.SessionID objLine.pid = GridView1.SelectedRow.Cells(0).Text objLine.pname = GridView1.SelectedRow.Cells(1).Text objLine.price = CDbl(GridView1.SelectedRow.Cells(2).Text) objLine.qty = CInt(CType(GridView1.SelectedRow.Cells(4).Controls(1), TextBox).Text) MyCart.AddItem(objLine) Response.Write("number of items in cart:" & CStr(MyCart.CollCartLine.Count)) Session("MyCart") = MyCart End Sub

Delete Button Procedure Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting MyCart.deleteItem(e.RowIndex) Session("MyShopCart") = MyCart GridView1.DataSource = MyCart.CollCartLine GridView1.DataBind() TextBox1.Text = MyCart.CartTotal.ToString 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

Working with GridView Control Murach’s ASP.Net Chap. 14

Adding Buttons to a Bound GridView Use GridView smart tag: –Edit Columns –Bound Fields, Command Fields, Template Fields Example: –Drag a table from Server Explorer to create a bound gridView. –Use smart tag to choose Edit Columns –Add command field: Edit –Update, Cancel –ASP.Net will execute the command automatically. Delete Select

Adding Command Fields to a Bound GridView Created by Code

Rearrange the Fields Order Cancel the “ Auto-Generate Fields ” option Then add bound fields: –For each bound field properties: Appearance: –Header Text: This text will be used as column name Data: –Data Field: for data binding Arrange fields order

Adding Edit/Update/Cancel and Delete Buttons –Use smart tag to choose Edit Columns –Add command field: Edit –Update, Cancel Delete

Adding Events for Edit/Update/Cance and Delete Buttons Dim objDataSet As New DataSet 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 Source = c:\salesDB.mdb" Dim objConn As New OleDbConnection(strConn) Dim strSQL As String If Not Page.IsPostBack Then strSQL = "select * from customer;" Dim objAdapter As New OleDbDataAdapter(strSQL, objConn) objAdapter.Fill(objDataSet, "customer") GridView1.DataSource = objDataSet GridView1.DataMember = "customer" GridView1.DataBind() Session("MyDs") = objDataSet objConn.Close() Else objDataSet = Session("MyDs") End If End Sub Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit GridView1.EditIndex = -1 GridView1.DataSource = objDataSet GridView1.DataMember = "customer" GridView1.DataBind() End Sub

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting objDataSet.Tables("customer").Rows.RemoveAt(e.RowIndex) GridView1.DataSource = objDataSet GridView1.DataMember = "customer" GridView1.DataBind() End Sub Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing Response.Write(e.NewEditIndex) GridView1.EditIndex = e.NewEditIndex GridView1.DataSource = objDataSet GridView1.DataMember = "customer" GridView1.DataBind() End Sub Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating GridView1.EditIndex = -1 objDataSet.Tables("Customer").Rows(e.RowIndex).Item("Rating") = CType(GridView1.Rows(e.RowIndex).Cells(3).Controls(0), TextBox).Text GridView1.DataSource = objDataSet GridView1.DataMember = "customer" GridView1.DataBind() End Sub

Adding Textbox and Button and to a Bound DataGrid GridView smart tag/Edit Columns: –Template fields: HeaderText: This text will be used as column name From the design view, click GridView’s smart tag and select Edit Template Drag a textbox to the template window.

Example

Command Field: Select Select a row Trigger events: –SelectedIndexChanged Retrieve the selected row: –GridView1.SelectedRow Retrieve cells of the selected row: –GridView1.SelectedRow.Cells(1).Text Retrieve data entered in the textbox: –CType(GridView1.SelectedRow.Cells(4).Controls(1), TextBox).Text