1 / 26

Visual Basic.NET Programming March 3, 2004

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.

norm
Télécharger la présentation

Visual Basic.NET Programming March 3, 2004

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic.NET ProgrammingMarch 3, 2004

  2. Agenda • Questions / Discussion • Cookies • Project Work (Ends Around 9:00 PM) • Demo's (15 minutes per team)

  3. 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.

  4. Cookies

  5. 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.

  6. 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.

  7. 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)

  8. 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

  9. 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.

  10. Topics Covered in the Visual Basic.NET ProgrammingCourse

  11. Console Application Command Window Console Application

  12. Windows Form Application Input Screen Windows Form Class

  13. Windows Form with Class DLL Input Screen Class Constructors Fields Windows Form Class Get Set Properties Methods

  14. Windows Form, Class DLL, and ADO Class Input Screen Constructors Fields Get Set Properties Windows Form Class Methods Database

  15. WebForm Application Browser (IE6) WebForm Class Code Behind File

  16. WebForm, Class DLL, and ADO Class Browser (IE6) Constructors Fields Get Set Properties WebForm Class Methods Database Code Behind File

  17. Web Services using localhost Class Browser (IE6) Constructors Fields Get Set Properties SOAP WebForm Class Web Service Proxy Methods Database Code Behind File

  18. 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

  19. 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

  20. 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

  21. 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

  22. 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

  23. 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

  24. 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

More Related