You are on page 1of 13

Option Strict On Imports CanineSecurity.Types Imports CanineSecurity.SqlLayer Namespace CanineSecurity.BOL ''' <summary> ''' Public Class "Client".

''' Implements the "IClient" Interface. ''' </summary> Public Class Client Implements IClient #Region "Variables" ''' <summary> ''' Public variable used to designate that the data used to create a "Cl ient" object is trusted to be clean. ''' Such is the case when the data used is from the database. ''' </summary> Public blnTrustedSource As Boolean ''' <summary> ''' Private variable used to store a Client's ID. ''' </summary> Private mClientId As Integer ''' <summary> ''' Private variable used to store a Client's company name. ''' </summary> Private mName As String ''' <summary> ''' Private variable used to store a Client's business address. ''' </summary> Private mAddress As String ''' <summary> ''' Private variable used to store the city of a Client's address. ''' </summary> Private mCity As String ''' <summary> ''' Private variable used to store the province of a Client's address. ''' </summary> Private mProvince As String ''' <summary> ''' Private variable used to store the postal code of a Client's address . ''' </summary> Private mPostal As String ''' <summary> ''' Private variable used to store a Client's business telephone number. ''' </summary> Private mPhone As String ''' <summary> ''' Private variable used to store a Client's business fax number. ''' </summary> Private mFax As String ''' <summary> ''' Private variable used to store a contact name for a Client. ''' </summary> Private mContactName As String ''' <summary> ''' Private variable used to store a contact email address for a Client. ''' </summary> Private mEmail As String

#End Region #Region "Properties" ''' <summary> ''' Public Read Only property for the ClientId. ''' </summary> ''' <value>Integer value representing the ClientsId</value> ''' <remarks> ''' <example>This sample shows how to get the Client's ClientId. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim intClientId As Integer ''' intClientId = objClient.ClientId ''' </code> ''' </example> ''' </remarks> Public ReadOnly Property ClientId As Integer Implements IClient.ClientId Get Return mClientId End Get End Property ''' <summary> ''' Public property for the Client's company name. ''' </summary> ''' <value>String value representing the Client's Company name.</value> ''' <remarks>Cannot be empty ''' <seealso cref="validate.stringValues"/> ''' and must be less than 51 characters in length. ''' <seealso cref="Validate.fieldLength"/> ''' <example>This sample shows how to set the Client's Name. ''' <code> ''' Dim objClient As Client = Client.Create() ''' objClient.Name = "ACME Inc." ''' </code> ''' <example>This sample shows how to get the Client's Name. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim strClientName As String ''' strClientName = objClient.Name ''' </code> ''' </example> ''' </example></remarks> Public Property Name As String Implements IClient.Name Get Return mName End Get Set(ByVal value As String) If blnTrustedSource = True Then mName = value Exit Property End If Validate.stringValues(value, CheckStringValue.MustNotBeNullorEmp ty, "Name") If mName <> value Then Validate.fieldLength(value, 50, "Name", SizeOperator.CanBeLe ssThan) End If mName = value End Set End Property

''' <summary> ''' Public property for the Client's busines address. ''' </summary> ''' <value>String value representing the Client's Street address of the Client</value> ''' <remarks>Cannot be empty ''' <seealso cref="validate.stringValues"/> ''' and must be less than 51 characters in length. ''' <seealso cref="Validate.fieldLength"/> ''' <example>This sample shows how to set the Client's Address. ''' <code> ''' Dim objClient As Client = Client.Create() ''' objClient.Address = "1234 This Street" ''' </code> ''' </example> ''' <example>This sample shows how to get the Client's Address. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim strAddress As String ''' strAdress = objClient.Address ''' </code> ''' </example></remarks> Public Property Address As String Implements IClient.Address Get Return mAddress End Get Set(ByVal value As String) If blnTrustedSource = True Then mAddress = value Exit Property End If Validate.stringValues(value, CheckStringValue.MustNotBeNullorEmp ty, "Street Address") If mAddress <> value Then Validate.fieldLength(value, 50, "Street Address", SizeOperat or.CanBeLessThan) End If mAddress = value End Set End Property ''' <summary> ''' Public property for the city of the Client's adress. ''' </summary> ''' <value>String value representing the city of the Client's address</v alue> ''' <remarks>Cannot be empty ''' <seealso cref="validate.stringValues"/> ''' and must be less than 21 characters in length. ''' <seealso cref="Validate.fieldLength"/> ''' <example>This sample shows how to set the Client's City. ''' <code> ''' Dim objClient As Client = Client.Create() ''' objClient.City = "That City" ''' </code> ''' </example> ''' <example>This sample shows how to get the Client's City. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim strCity As String ''' strCity = objClient.City

''' </code> ''' </example></remarks> Public Property City As String Implements IClient.City Get Return mCity End Get Set(ByVal value As String) If blnTrustedSource = True Then mCity = value Exit Property End If Validate.stringValues(value, CheckStringValue.MustNotBeNullorEmp ty, "City") If mCity <> value Then Validate.fieldLength(value, 20, "City", SizeOperator.CanBeLe ssThan) End If mCity = value End Set End Property ''' <summary> ''' Public property for the province of the Client's adress. ''' </summary> ''' <value>String value representing the province of the Client's addres s</value> ''' <remarks>Cannot be empty ''' <seealso cref="validate.stringValues"/> ''' and must a valid Canadian province. ''' <seealso cref="validate.validateProvince" /> ''' <example>This sample shows how to set the Client's Province. ''' <code> ''' Dim objClient As Client = Client.Create() ''' objClient.Province = "AB" ''' </code> ''' OR ''' <code> ''' objClient.Province = cmbProvince.SelectedItem ''' </code> ''' </example> ''' <example>This sample shows how to get the Client's Province. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim strProvince As String ''' strProvince = objClient.Province ''' </code> ''' </example></remarks> Public Property Province As String Implements IClient.Province Get Return mProvince End Get Set(ByVal value As String) If blnTrustedSource = True Then mProvince = value Exit Property End If Validate.stringValues(value, CheckStringValue.MustNotBeNullorEmp ty, "Province") If mProvince <> value Then Validate.validateProvince(value) mProvince = value

End ''' ''' ''' ''' ress</value> ''' <remarks>Cannot be empty and must be a valid canadian postal code. ''' <seealso cref="Validate.validatePostalCode"/> ''' <example>This sample shows how to set the Client's PostalCode. ''' <code> ''' Dim objClient As Client = Client.Create() ''' objClient.PostalCode = "E4R5T6" ''' </code> ''' OR ''' <code> ''' objClient.PostalCode = cmbPostalCode.SelectedItem ''' </code> ''' </example> ''' <example>This sample shows how to get the Client's PostalCode. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim strPostalCode As String ''' strPostalCode = objClient.PostalCode ''' </code> ''' </example></remarks> Public Property PostalCode As String Implements IClient.PostalCode Get Return mPostal End Get Set(ByVal value As String) If blnTrustedSource = True Then mPostal = value Exit Property End If If mPostal <> value Then Validate.validatePostalCode(value) mPostal = value End If End Set End Property ''' <summary> ''' Public property for the Client's telephone number. ''' </summary> ''' <value>String value representing the Client's telephone number.</val ue> ''' <remarks>Cannot be empty,must be numeric. ''' <seealso cref="validate.stringValues"/> ''' and must be 10 characters in length ''' <seealso cref="validate.fieldLength" /> ''' <example>This sample shows how to set the Client's Phone Number. ''' <code> ''' Dim objClient As Client = Client.Create() ''' objClient.Phone = "3215551234" ''' </code> ''' </example> ''' <example>This sample shows how to get the Client's Phone number. ''' <code> ''' Dim objClient As Client = Client.Create(1234)

End If End Set Property <summary> Public property for the postal code of the Client's adress. </summary> <value>String value representing the postal code of the Client's add

''' Dim strPhone As String ''' strPhone = objClient.Phone ''' </code> ''' </example></remarks> Public Property Phone As String Implements IClient.Phone Get Return mPhone End Get Set(value As String) If blnTrustedSource = True Then mPhone = value End If Validate.stringValues(value, CheckStringValue.MustNotBeNullorEmp ty, "Phone Number") If mPhone <> value Then Validate.fieldLength(value, 10, "Phone Number", SizeOperator .MustBeEqualTo) Validate.stringValues(value, CheckStringValue.MustBeNumeric, "Phone Number") mPhone = value End If End Set End Property ''' <summary> ''' Public property for the Client's fax number. ''' </summary> ''' <value>String value representing the Client's fax number.</value> ''' <remarks>Cannot be empty, must be numeric. ''' <seealso cref="validate.stringValues"/> ''' and must be 10 characters in length ''' <seealso cref="validate.fieldLength" /> ''' <example>This sample shows how to set the Client's Fax Number. ''' <code> ''' Dim objClient As Client = Client.Create() ''' objClient.Fax = "3215553456" ''' </code> ''' </example> ''' <example>This sample shows how to get the Client's Fax number. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim strFax As String ''' strFax = objClient.Fax ''' </code> ''' </example></remarks> Public Property Fax As String Implements IClient.Fax Get Return mFax End Get Set(value As String) If blnTrustedSource = True Then mFax = value End If Validate.stringValues(value, CheckStringValue.MustNotBeNullorEmp ty, "Fax Number") If mFax <> value Then Validate.fieldLength(value, 10, "Fax Number", SizeOperator.M ustBeEqualTo) Validate.stringValues(value, CheckStringValue.MustBeNumeric, "Fax Number") mFax = value

End If End Set End Property ''' <summary> ''' Public property for contact name for the Client. ''' </summary> ''' <value>String value representing a contact name for the Client. May be empty.</value> ''' <remarks> If not left empty, it must be less than 51 characters in l ength. ''' <seealso cref="Validate.fieldLength"/> ''' <example>This sample shows how to set the Client's ContactName. ''' <code> ''' Dim objClient As Client = Client.Create() ''' objClient.ContactName = "John Smith" ''' </code> ''' </example> ''' <example>This sample shows how to get the Client's ContactName. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim strContactName As String ''' strConactName = objClient.ContactName ''' </code> ''' </example></remarks> Public Property ContactName As String Implements IClient.ContactName Get Return mContactName End Get Set(value As String) If blnTrustedSource = True Then mContactName = value Exit Property End If If mContactName = String.Empty Then If value <> String.Empty Then Validate.fieldLength(value, 50, "Contact Name", SizeOper ator.CanBeLessThan) End If Else If mContactName <> value Then Validate.fieldLength(value, 50, "Contact Name", SizeOper ator.CanBeLessThan) End If End If mContactName = value End Set End Property ''' <summary> ''' Public property for contact email address for the Client. ''' </summary> ''' <value>String value representing a contact email address for the Cli ent. May be empty.</value> ''' <remarks> If not left empty, it must be less than 51 characters in l ength. ''' <seealso cref="Validate.fieldLength"/> ''' and must be a valid email address. ''' <seealso cref="Validate.validateEmail"/> ''' <example>This sample shows how to set the Client's Email Address. ''' <code> ''' Dim objClient As Client = Client.Create()

''' ''' ''' ''' ress.

objClient.Email = "acmeinc@acme.com" </code> </example> <example>This sample shows how to get the Client's contact Email add

''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim strEmail As String ''' strEail = objClient.Email ''' </code> ''' </example></remarks> Public Property Email As String Implements IClient.Email Get Return mEmail End Get Set(value As String) If blnTrustedSource = True Then mEmail = value Exit Property End If If mEmail = String.Empty Then If value <> String.Empty Then Validate.fieldLength(value, 50, "Email", SizeOperator.Ca nBeLessThan) Validate.validateEmail(value) End If Else If mEmail <> value Then Validate.fieldLength(value, 50, "Email", SizeOperator.Ca nBeLessThan) Validate.validateEmail(value) End If End If mEmail = value End Set End Property ''' <summary> ''' Public Read Only property for locations belonging to the Client. ''' </summary> ''' <value>A list of <c>Location</c> object belonging to the Client</val ue> ''' <remarks>Calls the <c>GetClientLocations</c> of the <c>LocationSQL</ c> class, passing it the ClientId. ''' <see cref="BOL.Location"/> ''' <example>This sample shows how to get the Client's Locations. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' Dim lstLocation As List(Of Location) ''' lstLocation = objClient.ClientLocations ''' </code> ''' </example></remarks> Public ReadOnly Property ClientLocations As List(Of Location) Get If mClientId = 0 Then Throw New DataException("A ClientId must be set before a Job 's Assignments can be returned.") End If Return Location.Repackager(LocationSQL.GetClientLocations(mClien tId)) End Get

End Property #End Region #Region "Client isComplete" ''' <summary> ''' Friend Read Only property checking if this instance of a Client has all the required properties filled. ''' </summary> ''' <value>Returns <c>True</c> if this instance is complete; <c>False</c > otherwise.</value> Friend ReadOnly Property isComplete As Boolean Implements IClient.isComp lete Get If String.IsNullOrEmpty(Name) OrElse String.IsNullOrEmpty(Address) OrElse String.IsNullOrEmpty(City) OrElse String.IsNullOrEmpty(Province) OrElse String.IsNullOrEmpty(PostalCode) OrElse String.IsNullOrEmpty(Phone) OrElse String.IsNullOrEmpty(Fax) Then Return False End If Return True End Get End Property #End Region #Region "Constructors" ''' <summary> ''' Private Constructor. ''' Prevents a default instance of the Client class from being created. ''' </summary> Private Sub New() End Sub #End Region #Region "Client Factory" ''' ''' ''' ''' ''' ject. ''' <code> ''' Dim objClient As Client = Client.Create() ''' </code> ''' </example></remarks> Public Overloads Shared Function Create() As Client Dim tmpClient As New Client Return tmpClient End Function ''' ''' ''' ''' ''' <summary> Creates the specified client ID. </summary> <param name="ClientID">The ClientId of the desired Client.</param> <returns>A Client object with properties loaded from the DataBase da <summary> Public Shared Function that creates an empty instance of a Client. </summary> <returns>Returns an empty Client Object.</returns> <remarks><example>This sample shows how to create an empty Client ob

ta.</returns> ''' <remarks>This Function calls the Client.Repackager function to packa ge the Clients properties. ''' <see cref="Client.Repackager"/> ''' <example>This sample shows how to retieve a particular Client from t he DataBase. ''' <code> ''' Dim objClient As Client = Client.Create(1234) ''' </code> ''' </example></remarks> Public Overloads Shared Function Create(ByVal ClientID As Integer) As Cl ient If ClientID = 0 Then Throw New ArgumentException("Client ID is invalid") End If Dim tmpTable As DataTable = ClientSQL.retrieveClient(ClientID) If tmpTable.Rows.Count = 0 Then Throw New DataException("This client does not exist in the datat able") End If Return Repackager(tmpTable).Item(0) End Function #End Region #Region "Client Repackager" ''' <include file="CommentFile.xml" path="Clients/Members[@name='Repacka ger']/*"/> Public Shared Function Repackager(ByVal dt As DataTable, Optional ByVal type As RetrieveType = RetrieveType.EntireFile) As List(Of Client) Dim tmpListClient As New List(Of Client) If type = RetrieveType.LookupTable Then For i = 0 To (dt.Rows.Count - 1) Dim tmpClient As New Client tmpClient.blnTrustedSource = True tmpClient.mClientId = CInt(dt.Rows(i).Item("ClientID")) tmpClient.Name = dt.Rows(i).Item("LastName").ToString tmpClient.blnTrustedSource = False tmpListClient.Add(tmpClient) Next Else For i = 0 To (dt.Rows.Count - 1) Dim tmpClient As New Client tmpClient.blnTrustedSource = True tmpClient.mClientId = CInt(dt.Rows(i).Item("ClientID")) tmpClient.Name = dt.Rows(i).Item("Name").ToString tmpClient.Address = dt.Rows(i).Item("StreetAddress").ToStrin g tmpClient.City = dt.Rows(i).Item("City").ToString tmpClient.Province = dt.Rows(i).Item("Province").ToString tmpClient.PostalCode = dt.Rows(i).Item("PostalCode").ToStrin g

tmpClient.Phone = dt.Rows(i).Item("Phone").ToString tmpClient.Fax = dt.Rows(i).Item("Fax").ToString tmpClient.ContactName = (IIf(dt.Rows(i).Item("ContactName") Is DBNull.Value, String.Empty, dt.Rows(i).Item("ContactName"))).ToString tmpClient.Email = (IIf(dt.Rows(i).Item("ContactEmail") Is DB Null.Value, String.Empty, dt.Rows(i).Item("ContactEmail"))).ToString tmpClient.blnTrustedSource = False tmpListClient.Add(tmpClient) Next End If Return tmpListClient End Function #End Region #Region "Methods" ''' <summary> ''' Public Shared Function the searches for clients. ''' </summary> ''' <param name="type">The RetrieveType.</param> ''' <param name="name">Optional. The name of a company.</param> ''' <remarks> ''' <example>This sample shows how to use this function form teh front e nd. ''' <code> ''' Dim lstClient As List(Of Client) ''' lstClients = Repackager(SearchClient(RetrieveType.EntireFile)) ''' </code> ''' OR ''' <code> ''' Dim dtClients As DataTable ''' dtClients = SearchClient(RetrieveType.LookupTable) ''' </code> ''' </example> ''' </remarks> ''' <returns>A <c>DataTable</c> containing the data for the search resul ts.</returns> Public Shared Function SearchClient(ByVal type As RetrieveType, Optional ByVal name As String = "") As DataTable Return ClientSQL.SearchClient(type, name) End Function ''' <summary> ''' Public Shared Function that Inserts the specified Client into the da tabase. ''' </summary> ''' <param name="Client">The client.</param> ''' <remarks> ''' <example>This sample shows how to load a Client and Insert it into t he database. ''' Dim client As Client = Client.Create() ''' client.Name = "ACME Inc." ''' client.Address = "123 This Street" ''' client.City = "That City" ''' client.Province = "AB" ''' client.Phone = "3215551234" ''' client.Fax = "3215554321" ''' client.Contact = "John Smith"

''' client.Email = acmeinc@acme.com" ''' ''' Dim blnInsert As Boolean = Insert(client) ''' </example> ''' </remarks> Public Shared Sub Insert(ByVal Client As Client) Client.mClientId = ClientCUD.Insert(Client) End Sub ''' <summary> ''' Updates the specified client. ''' </summary> ''' <param name="Client">A complete Client object.</param> ''' <returns> ''' Returns <c>True</c> if the Update is successful, <c>False</c> otherw ise. ''' </returns> ''' <remarks> ''' <example>This sample shows how to get a Client, edit its properties and Update it in the database. ''' Dim client As Client = Client.Create(1234) ''' client.Email = johnSmith@acme.com" ''' ''' Dim blnInsert As Boolean = Update(client) ''' </example> ''' </remarks> Public Shared Function Update(ByVal Client As Client) As Boolean Return ClientCUD.Update(Client) End Function ''' <summary> ''' Deletes the specified client id. ''' </summary> ''' <param name="ClientId">The client id.</param><returns> ''' Returns <c>True</c> if the Delete is successful, <c>False</c> otherw ise. ''' </returns> ''' <remarks> ''' <example>This sample shows how to Delete a Client on the front end. ''' <code> ''' Dim client As Client = Client.Create(1234) ''' Dim intCLientId As Integer = client.ClientId ''' Dim blnDelete As Boolean = Delete(intClientId) ''' </code> ''' </example></remarks> Public Shared Function Delete(ByVal ClientId As Integer) As Boolean Return ClientCUD.Delete(ClientId) End Function ''' <summary> ''' Retrieves the client. ''' </summary> ''' <param name="ClientID">The client ID.</param> ''' <returns>A <c>DataTable</c> containing the data for the requested Cl ientId.</returns> ''' <remarks> ''' <example>This sample shows how to Retieve a Client on the front end. ''' <code> ''' Dim dtClient As DataTable = Client.Create(1234) ''' </code> ''' </example> ''' </remarks> Public Shared Function retrieveClient(ByVal ClientID As Integer) As Data

Table Return ClientSQL.retrieveClient(ClientID) End Function #End Region End Class End Namespace

You might also like