Tuesday, February 2, 2010

VB Classes

Here is what we did with the form. We created a table with text fields and a button. We will use this eventually to insert data and populate the People and Donation classes:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Enter your information</p>
<asp:Table ID="Table1" runat="server" Width="248px">
<asp:TableRow>
<asp:TableCell>Last Name</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>First Name</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Address</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>City</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>State</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtState" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Zip code</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtZipcode" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>Home Phone</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtHomePhone" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>Email</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>Donation Amount</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtDonation" runat="server"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell> </asp:TableCell>
<asp:TableCell>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</asp:TableCell>
</asp:TableRow>

</asp:Table>
</div>
</form>
</body>
</html>

Now here is the Person class. It consists soley of private fields and public properties. Its purpose it to store the data for a new person:

Imports Microsoft.VisualBasic

Public Class Person

Private firstName As String
Private lastName As String
Private address As String
Private city As String
Private state As String
Private zipcode As String
Private homePhone As String
Private email As String
Private PKey As Integer



Public Property PersonFirstName() As String
Get
Return FirstName
End Get
Set(ByVal value As String)
FirstName = value
End Set
End Property

Public Property PersonLastName() As String
Get
Return LastName
End Get
Set(ByVal value As String)
LastName = value
End Set
End Property

Public Property PersonAddress() As String
Get
Return address
End Get
Set(ByVal value As String)
address = value
End Set
End Property

Public Property PersonCity() As String
Get
Return city
End Get
Set(ByVal value As String)
city = value
End Set
End Property

Public Property PersonState() As String
Get
Return state
End Get
Set(ByVal value As String)
If value.Length > 2 Then
Dim ex As New Exception("use two letters for a state")
Throw ex
Else
state = value
End If
End Set
End Property

Public Property PersonZipcode() As String
Get
Return zipcode
End Get
Set(ByVal value As String)
zipcode = value
End Set
End Property

Public Property PersonHomePhone() As String
Get
Return homePhone
End Get
Set(ByVal value As String)
homePhone = value
End Set
End Property

Public Property PersonEmail() As String
Get
Return email
End Get
Set(ByVal value As String)
email = value
End Set
End Property

Public Property PersonKey() As Integer
Get
Return PKey
End Get
Set(ByVal value As Integer)
PKey = value
End Set
End Property


End Class


Now we have the Donation Class:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

Public Class Donation

Private amount As Double
Private donDate As Date
Private Pkey As Integer

Public Property DonationAmount() As Double
Get
Return amount
End Get
Set(ByVal value As Double)
amount = value
End Set
End Property

Public Property DonationDate() As Date
Get
Return donDate
End Get
Set(ByVal value As Date)
donDate = value
End Set
End Property

Public Property DonationPersonKey() As Integer
Get
Return Pkey
End Get
Set(ByVal value As Integer)
Pkey = value
End Set
End Property
End Class

Finally we have just the beginnings of the DataLayer Class. All we have done so far is import the Data and Data.SqlClient namespaces, added to object fields to recieve a person and a donation, and created a constructor with which to pass them to the class

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient

Public Class DataLayer

Private pers As Object
Private don As Object


Public Sub New(ByRef p As Person, ByRef d As Donation)
pers = p
don = d

End Sub



End Class

1 comment:

  1. I'm so confused. I can't find any ASP blog posts for last week. There are SQL posts instead. Will you be posting soon?

    ReplyDelete