an object named EmployeeBroker.vb contains this code:
>
On behalves of Dboy and BeauGeek
*************Referencing the Employee collection
> <Serializable()> _
> Public Class Employees : Inherits CollectionBase ‘ *************"Inherits a
> collection"
> Default Public ReadOnly Property Item(ByVal index As Integer) As
> Employee
> Get
> Return CType(List.Item(index), Employee) ‘*************Converting
> the indexed list Item to an employee or visa versa
> End Get
> End Property
>
**If this function is call and either of the methods’ conditions are
true than the methods will throw exceptions. Ie. If emp.SSN =
String.Empty, first name= empty **string, is the ssn# =! 9 chars,
last name =empty string and etc. Then an error message will be thrown.
‘‘
> Public Function CreateEmployee(ByVal emp As Employee, ByVal dept
> As String, ByVal UserName As String, ByVal UserPassword As String,
> ByVal DataSourceName As String) As Employee
>
> Dim db As DBinterface
> Dim rowsAffected As Integer
>
> 'validate input
> If emp.SSN = String.Empty Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgDataMissing,
> "Employee, Employee SSN."))
> ElseIf emp.FirstName = String.Empty Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgDataMissing,
> "Employee, Employee Fisrt Name."))
> ElseIf emp.SSN.Length > Employee.MaxLength.ssn Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgTooLong,
> "SSN", Employee.MaxLength.ssn.ToString("d")))
> ElseIf emp.FirstName.Length > Employee.MaxLength.firstname
> Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgTooLong,
> "First Name", Employee.MaxLength.firstname.ToString("d")))
> ElseIf emp.LastName.Length > Employee.MaxLength.lastname Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgTooLong,
> "Last Name", Employee.MaxLength.lastname.ToString("d")))
>
>
'insert the data
> Try
> db = New DBinterface(UserName, UserPassword,
> DataSourceName) **********************************‘Trying to see if the
> UserName, Password,and Datae source name is valid”
> rowsAffected = db.InsertEmployee(emp)’**********************db is
> an object that has a method that inserting the employee and return the rows
> affected’
‘*************************Pretty much if it didn’t work this will
throw error messages
> Catch ex As OracleException
> Select Case CType(ex.Code, Global.OracleError)
> Case Global.OracleError.UniqueContraint
> Throw New
> WarningApplicationException(String.Format(Global.MsgInsertFailedNotUnique,
> "Employee", "ID"), ex)
> Case Global.OracleError.NullConstraint
> Throw New
> InformationalApplicationException(String.Format(Global.MsgInsertFailedReqFieldMissing,
> "Employee"), ex)
> Case Global.OracleError.ValueTooLargeForColumn
> Throw New
> InformationalApplicationException(String.Format(Global.MsgInsertFailedValueTooLong,
> "Employee"), ex)
> Case Else
> Global.NotifyException(ex, "CreateEmployee")
> Throw New
> CriticalApplicationException(Global.MsgDatabaseError & ex.Message, ex)
> End Select
> Catch ex As Exception
> Global.NotifyException(ex, "CreateEmployee")
> Throw ex
> End Try
>
************* needs general exception to caught any ex that do not
fall in to the area stated above
***************If there are no row affected then throw an exceptions
> ************** 'verify that insert really happened
> If rowsAffected = 0 Then
> Throw New
> CriticalApplicationException(String.Format(Global.MsgInsertFailed,
> "Employee"))
> End If
>
> 'set return value
> Return emp
> End Function 'CreateEmployee
>
> End Class
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _
>
>****an object named DBinterface.vb contains this code:
> ****** using both Data Source client oracle and SQL pretty much you are
> connection to both database
> Imports System.Data.OracleClient
> Imports System.Data.SqlClient
>
> 'database connection string (set in
> New())**************************exactly as commented
> Private m_Connect As String
> Private m_SchemaName As String
>
> Private Const sqlInsertEmployee As String =
> "{0}.Employee.EmployeeAdd" ‘the array for employees’
>
“**************************************************Connecting strings
to the test ,Dev, and production database.”
> Public Sub New(ByVal UserName As String, ByVal UserPassword As
> String, ByVal DataSourceName As String)
> If DataSourceName = "TEST" Then”*************TEst”
> m_Connect = String.Format("User
> ID={0};Password={1};Server={2}", UserName, UserPassword,
> System.Configuration.ConfigurationSettings.AppSettings.Get("dbTestServer"))
> m_SchemaName = "dbTestSchema*************Hard coded name of the
> test database schema”
> ElseIf DataSourceName = "DEVELOPMENT" Then “******8dev”
> m_Connect = String.Format("User
> ID={0};Password={1};Server={2}", UserName, UserPassword,
> System.Configuration.ConfigurationSettings.AppSettings.Get("dbDevServer"))
> m_SchemaName = "dbDevSchema*****8Hard coded name of the dev
> database schema”
> Else’Prod”
> m_Connect = String.Format("User
> ID={0};Password={1};Server={2}", UserName, UserPassword,
> System.Configuration.ConfigurationSettings.AppSettings.Get("dbServer"))
> m_SchemaName = "dbSchema" “******************Hard coded name of
> the prod database schema”
> End If
> End Sub 'New
>
*************“inserting”
> Public Function InsertEmployee(ByVal emp As Employee) As Integer
> “*************Initializing and Instantiating the connection”
> Dim cn As OracleConnection = New OracleConnection(m_Connect)
> cn.Open()”open the connection”
>
> Try
*************m_SchemaName is being used to find the connection string
in the app settings file
*********sqlInsertEmployeeis sql statement or stroed procedure, cn is
the connection
> Dim cm As OracleCommand = New
> OracleCommand(String.Format(sqlInsertEmployee,
>************* Here the application is putting the all the data in the
>corresponding fields, with their appropriate data Type.“
Configuration.ConfigurationSettings.AppSettings(m_SchemaName)), cn)
> cm.CommandType = CommandType.StoredProcedure
> cm.Parameters.Add("pE_ssn", OracleType.VarChar).Value =
> ToOraValue(emp.SSN)
> cm.Parameters.Add("pE_firstname",
> OracleType.VarChar).Value = ToOraValue(emp.FirstName)
> cm.Parameters.Add("pE_lastname", OracleType.VarChar).Value
> = ToOraValue(emp.LastName)
> cm.Parameters.Add("pE_dob", OracleType.DateTime).Value =
> ToOraValue(emp.DOB)
> checking the rows affected
> Dim rowsAffected As Integer = cm.ExecuteNonQuery()
>
> 'get primary key and rows affected output parameter values”self
> explanatory”
> emp.Key = CType(cm.Parameters("pE_id").Value, Integer)
> If rowsAffected < 0 Then rowsAffected =
> CType(cm.Parameters("pRowsAffected").Value, Integer)
> *************self explanatory
> Return rowsAffected
> Finally
*************self explanatory
> cn.Close()
> End Try
>
> End Function 'InsertEmployee
> End Class
On Sep 24, 11:49 am, Brock <[EMAIL PROTECTED]> wrote:
> I'm reviewing an desktop application that uses an architecture that
> I'm not familiar with and hope someone has seen this type before. I'm
> looking for someone to explain what is going on in each layer and what
> is the reasoning for using this model. I'm using vb.net as my front-
> end and stored procedures from Oracle as the back-end. My confusion is
> the tiers (layers) of the front-end vb.net application with this
> structure and I hope someone can explain the reason this logic model
> was used:
>
> 1) Presentation Layer (all the user forms, no need to elaborate here,
> except that no sql or data connections are defined in the code. This
> is done in the server layer: DBinterface.vb)
> _________________________________________________________________
>
> 2) Entity Layer (this is where I'm stumped by the logic - there are
> two objects (what is each doing?):
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _
>
> an object named Employee.vb contains this code:
>
> <Serializable()> _
> Public Class Employee : Implements IComparable
>
> Private m_Key As Integer
> Private m_FirstName As String
> Private m_LastName As String
> Private m_DOB As Date
>
> Public Enum MaxLength
> e_id = 10
> firstname = 20
> lastname = 20
> End Enum
>
> Public Property Key() As Integer
> Get
> Return m_Key
> End Get
> Set(ByVal Value As Integer)
> m_Key = Value
> End Set
> End Property
>
> Public Property FirstName() As String
> Get
> Return m_FirstName
> End Get
> Set(ByVal Value As String)
> m_FirstName = Value
> End Set
> End Property
>
> Public Property LastName() As String
> Get
> Return m_LastName
> End Get
> Set(ByVal Value As String)
> m_LastName = Value
> End Set
> End Property
>
> Public Property DOB() As Date
> Get
> Return m_DOB
> End Get
> Set(ByVal Value As Date)
> m_DOB = Value
> End Set
> End Property
>
> Public ReadOnly Property DOBString() As String
> Get
> If m_DOB <> Date.MinValue Then
> Return m_DOB.ToShortDateString
> Else
> Return String.Empty
> End If
> End Get
> End Property
>
> Public Sub New()
>
> m_Key = Integer.MinValue
> m_FirstName = String.Empty
> m_LastName = String.Empty
> m_DOB = Date.MinValue
> End Sub 'New
>
> End Class
> _________________________________________________________________
>
> 3) Server Layer (this is where I'm stumped by the logic - there are
> two objects (what is each doing?):
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _
>
> an object named EmployeeBroker.vb contains this code:
>
> <Serializable()> _
> Public Class Employees : Inherits CollectionBase
> Default Public ReadOnly Property Item(ByVal index As Integer) As
> Employee
> Get
> Return CType(List.Item(index), Employee)
> End Get
> End Property
>
> Public Function CreateEmployee(ByVal emp As Employee, ByVal dept
> As String, ByVal UserName As String, ByVal UserPassword As String,
> ByVal DataSourceName As String) As Employee
>
> Dim db As DBinterface
> Dim rowsAffected As Integer
>
> 'validate input
> If emp.SSN = String.Empty Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgDataMissing,
> "Employee, Employee SSN."))
> ElseIf emp.FirstName = String.Empty Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgDataMissing,
> "Employee, Employee Fisrt Name."))
> ElseIf emp.SSN.Length > Employee.MaxLength.ssn Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgTooLong,
> "SSN", Employee.MaxLength.ssn.ToString("d")))
> ElseIf emp.FirstName.Length > Employee.MaxLength.firstname
> Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgTooLong,
> "First Name", Employee.MaxLength.firstname.ToString("d")))
> ElseIf emp.LastName.Length > Employee.MaxLength.lastname Then
> Throw New
> InformationalApplicationException(String.Format(Global.MsgTooLong,
> "Last Name", Employee.MaxLength.lastname.ToString("d")))
>
> 'insert the data
> Try
> db = New DBinterface(UserName, UserPassword,
> DataSourceName)
> rowsAffected = db.InsertEmployee(emp)
> Catch ex As OracleException
> Select Case CType(ex.Code, Global.OracleError)
> Case Global.OracleError.UniqueContraint
> Throw New
> WarningApplicationException(String.Format(Global.MsgInsertFailedNotUnique,
> "Employee", "ID"), ex)
> Case Global.OracleError.NullConstraint
> Throw New
> InformationalApplicationException(String.Format(Global.MsgInsertFailedReqFieldMissing,
> "Employee"), ex)
> Case Global.OracleError.ValueTooLargeForColumn
> Throw New
> InformationalApplicationException(String.Format(Global.MsgInsertFailedValueTooLong,
> "Employee"), ex)
> Case Else
> Global.NotifyException(ex, "CreateEmployee")
> Throw New
> CriticalApplicationException(Global.MsgDatabaseError & ex.Message, ex)
> End Select
> Catch ex As Exception
> Global.NotifyException(ex, "CreateEmployee")
> Throw ex
> End Try
>
> 'verify that insert really happened
> If rowsAffected = 0 Then
> Throw New
> CriticalApplicationException(String.Format(Global.MsgInsertFailed,
> "Employee"))
> End If
>
> 'set return value
> Return emp
> End Function 'CreateEmployee
>
> End Class
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _
>
> an object named DBinterface.vb contains this code:
>
> Imports System.Data.OracleClient
> Imports System.Data.SqlClient
>
> 'database connection string (set in New())
> Private m_Connect As String
> Private m_SchemaName As String
>
> Private Const sqlInsertEmployee As String =
> "{0}.Employee.EmployeeAdd"
>
> Public Sub New(ByVal UserName As String, ByVal UserPassword As
> String, ByVal DataSourceName As String)
> If DataSourceName = "TEST" Then
> m_Connect = String.Format("User
> ID={0};Password={1};Server={2}", UserName, UserPassword,
> System.Configuration.ConfigurationSettings.AppSettings.Get("dbTestServer"))
> m_SchemaName = "dbTestSchema"
> ElseIf DataSourceName = "DEVELOPMENT" Then
> m_Connect = String.Format("User
> ID={0};Password={1};Server={2}", UserName, UserPassword,
> System.Configuration.ConfigurationSettings.AppSettings.Get("dbDevServer"))
> m_SchemaName = "dbDevSchema"
> Else
> m_Connect = String.Format("User
> ID={0};Password={1};Server={2}", UserName, UserPassword,
> System.Configuration.ConfigurationSettings.AppSettings.Get("dbServer"))
> m_SchemaName = "dbSchema"
> End If
> End Sub 'New
>
> Public Function InsertEmployee(ByVal emp As Employee) As Integer
>
> Dim cn As OracleConnection = New OracleConnection(m_Connect)
> cn.Open()
>
> Try
> Dim cm As OracleCommand = New
> OracleCommand(String.Format(sqlInsertEmployee,
> Configuration.ConfigurationSettings.AppSettings(m_SchemaName)), cn)
> cm.CommandType = CommandType.StoredProcedure
> cm.Parameters.Add("pE_ssn", OracleType.VarChar).Value =
> ToOraValue(emp.SSN)
> cm.Parameters.Add("pE_firstname",
> OracleType.VarChar).Value = ToOraValue(emp.FirstName)
> cm.Parameters.Add("pE_lastname", OracleType.VarChar).Value
> = ToOraValue(emp.LastName)
> cm.Parameters.Add("pE_dob", OracleType.DateTime).Value =
> ToOraValue(emp.DOB)
>
> Dim rowsAffected As Integer = cm.ExecuteNonQuery()
>
> 'get primary key and rows affected output parameter values
> emp.Key = CType(cm.Parameters("pE_id").Value, Integer)
> If rowsAffected < 0 Then rowsAffected =
> CType(cm.Parameters("pRowsAffected").Value, Integer)
>
> Return rowsAffected
> Finally
> cn.Close()
> End Try
>
> End Function 'InsertEmployee
> End Class
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---