260 likes | 384 Views
Visual Basic.NET Programming March 3, 2004. Agenda. Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team). Questions. All homework homework due by Friday. Web Site will remain available for awhile, if not, contact me, I'll have the material.
E N D
Agenda • Questions / Discussion • Cookies • Project Work (Ends Around 9:00 PM) • Demo's (15 minutes per team)
Questions • All homework homework due by Friday. • Web Site will remain available for awhile, if not, contact me, I'll have the material. • a tip... use the Microsoft Web Site Advanced Search to look up errors. I think it works half of the time.
Cookies • Cookies are a way to save information on the client machine between web page requests. • A cookie is a name/value pair that the browser saves on behalf of the application. • Cookies are keyed to the domain of the application. • When a browser requests a page it automatically transmits the cookies that belong to that domain as part of the request. • The application then reads the cookies and takes appropriate action.
Cookies Cookies are generally used in two ways. • To save some sort of user identifying information about the user, so that when the returns to a given site, the application knows who the user is. • The other is to save information indicating the application's state between web page requests within a single session. Although any information can be saved in a cookie, best practice is to use some sort of key to look up the actual information of the server.
Cookies Cookies are created by adding items to the Cookies collection of the ASP.NET Response object (available through the Response property of the Page Class). Example Dim cookie as HttpCookie cookie = New HttpCookie("MyCookie","MyCookieValue") Response.Cookies.Add(cookie)
Cookies Cookies are read from the Cookies collection of the ASP.NET Request object (available through the Request property of the Page Class). Example Dim cookie as HttpCookie cookie = Request.Cookies("MyCookie") Label1.Text = cookie.Value
HttpCookie Properties • Domain – the domain associated with the cookie (string). • Expires – date and time the cookie expires (datetime). • HasKeys – whether the cookie as subkeys (boolean). • Item – old ASP way of accessing subkeys, indexed by subkey name. • Name – the name of the cookie (string). • Path – the path associated with the cookie (string). • Secure – does the cookies require a secure transmission (boolean). • Value – the value of the cookie (string). • Values – if the cookie as subkeys, Values represents an instance of a NameValuesCollection.
Console Application Command Window Console Application
Windows Form Application Input Screen Windows Form Class
Windows Form with Class DLL Input Screen Class Constructors Fields Windows Form Class Get Set Properties Methods
Windows Form, Class DLL, and ADO Class Input Screen Constructors Fields Get Set Properties Windows Form Class Methods Database
WebForm Application Browser (IE6) WebForm Class Code Behind File
WebForm, Class DLL, and ADO Class Browser (IE6) Constructors Fields Get Set Properties WebForm Class Methods Database Code Behind File
Web Services using localhost Class Browser (IE6) Constructors Fields Get Set Properties SOAP WebForm Class Web Service Proxy Methods Database Code Behind File
Web Services using Remote Host Client Server Class Browser (IE6) Constructors Fields Get Set Properties SOAP WebForm Class Web Service Proxy Methods Database Code Behind File
Web Form Client Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.text = "" Try Dim obj As New Service1 Dim ds As New DataSet Dim str As String = "Select * from NameAddress" ds = obj.ServiceGetDataSet(str) DataGrid1.DataSource = ds DataGrid1.DataBind() Catch ex As Exception Label1.text = ex.Message End Try End Sub
Web Service <WebMethod()> _ Public Function ServiceGetDataSet(ByVal SQLStmt As String) As DataSet Try Dim obj As New CDatabase Dim ds As New DataSet obj.SQLString = SQLStmt If obj.GetDataSet(ds) Then Return ds End If Catch ex As Exception Dim se As New SoapException("Fault occurred - " + ex.Message, SoapException.ClientFaultCode) Throw se End Try End Function
Database Class Notes • Don't name everything DatabaseClass • Name the Project DatabaseClass • Name the .vb module DBClass • Name the class Cdatabase • Check the project properties to determine the imports name to use in the application
Database Class Private cn As New OleDbConnection() Private adpt As New OleDbDataAdapter() Private m_SQLString As String Public Sub New() End Sub Public Property SQLString() Get Return m_SQLString End Get Set(ByVal Value) m_SQLString = Value End Set End Property
Database Class Public Function GetDataSet(ByVal ds As DataSet) As Boolean Try If Not OpenConnection() Then Throw New ApplicationException("Connection Open Failure") End If adpt = New OleDbDataAdapter(m_SQLString, cn) adpt.Fill(ds, "Messages") adpt.Dispose() Catch ex As Exception Throw New ApplicationException("Database Error - " + ex.Message) Finally cn.Close() cn = Nothing End Try Return True End Function
Database Class Private Function OpenConnection() As Boolean Try If cn.State <> ConnectionState.Open Then cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\...\Guestbook.mdb" cn.Open() Return True End If Catch ex As Exception Throw New ApplicationException("Connection Failure - " + ex.Message) End Try End Function