Option Strict On
Option Explicit On

Imports MicroFour.StrataFrame.Business
Imports MicroFour.StrataFrame.Security
Imports MicroFour.StrataFrame.UI.Windows.Forms
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.IO

Partial Public Class OrdersBO

#Region " Component Implementation "

    <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If (disposing _
           AndAlso (Not (Me.components) Is Nothing)) Then
            Me.components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerNonUserCodeAttribute()> _
    Private Sub InitializeComponent()
        Dim BusinessParentRelationship1 As MicroFour.StrataFrame.Business.BusinessParentRelationship = New MicroFour.StrataFrame.Business.BusinessParentRelationship
        '
        'OrdersBO
        '
        BusinessParentRelationship1.ForeignKeyField = New String() {"or_cust_pk"}
        BusinessParentRelationship1.ParentBusinessObjectType = "SFLib.CustomersBO"
        BusinessParentRelationship1.ParentPrimaryKeyField = New String() {"cust_pk"}
        Me.ParentRelationship = BusinessParentRelationship1

    End Sub

#End Region

#Region " BusinessLayer Overriden Methods & Properties "

    ''' <summary>
    ''' The collection of required fields for the business object.
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Overrides Property RequiredFields() As RequiredFieldsCollection
        Get
            Return MyBase.RequiredFields
        End Get
        Set(ByVal value As RequiredFieldsCollection)
            MyBase.RequiredFields = value
        End Set
    End Property

    ''' <summary>
    ''' Defines the constraint that defines the parent-child relationship between this business object type and another business object type.
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Overrides Property ParentRelationship() As IBusinessParentRelationship
        Get
            Return MyBase.ParentRelationship
        End Get
        Set(ByVal value As IBusinessParentRelationship)
            MyBase.ParentRelationship = value
        End Set
    End Property

    ''' <summary>
    ''' Returns all of the field names in a single string in the form of [field1],[field2],...  This must be used in the place of '*' in select statements if Query Notifications are to be registered.
    ''' </summary>
    ''' <remarks></remarks>
    Protected Overrides ReadOnly Property AllFieldNames() As String
        Get
            Return "[or_pk],[or_cust_pk],[or_ponumber],[or_Created],[or_Version]"
        End Get
    End Property

    ''' <summary>
    ''' The name of the database that contains the table to which this business object is mapped.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property Database() As String
        Get
            Return "StrataFrameSample"
        End Get
    End Property

    Private Shared _PrimaryKeyFields As String() = New String() {"or_pk"}
    ''' <summary>
    ''' Gets the field or fields that comprise the primary key for the business object.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property PrimaryKeyFields() As String()
        Get
            Return _PrimaryKeyFields
        End Get
    End Property

    ''' <summary>
    ''' The name of the table in the database to which this business object is mapped.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property TableName() As String
        Get
            Return "Orders"
        End Get
    End Property

    ''' <summary>
    ''' The schema of the table in the database to which this business object is mapped.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property TableSchema() As String
        Get
            Return "dbo"
        End Get
    End Property

    ''' <summary>
    ''' Creates and returns an array of DataColumns that contains the schema for the table.  This is used to prevent a round trip to the server to aquire the initial schema for the internal DataTable.
    ''' </summary>
    ''' <remarks></remarks>
    Protected Overrides Function CreateTableSchema() As DataColumn()
        Return New DataColumn() { _
        New DataColumn("or_pk", GetType(System.Int32)), _
        New DataColumn("or_cust_pk", GetType(System.Int32)), _
        New DataColumn("or_ponumber", GetType(System.String)), _
        New DataColumn("or_Created", GetType(System.DateTime)), _
        New DataColumn("or_Version", GetType(System.Int32))}
    End Function

    ''' <summary>
    ''' Adds a broken rule to the business object's collection
    ''' </summary>
    ''' <remarks></remarks>
    Protected Shadows Sub AddBrokenRule(ByVal Field As OrdersBOFieldNames, ByVal ErrorMessage As String)
        MyBase.AddBrokenRule(Field, ErrorMessage)
    End Sub

    ''' <summary>
    ''' Adds a broken rule to the business object's collection
    ''' </summary>
    ''' <remarks></remarks>
    Protected Shadows Sub AddBrokenRule(ByVal FieldName As String, ByVal ErrorMessage As String)
        MyBase.AddBrokenRule(FieldName, ErrorMessage)
    End Sub

    ''' <summary>
    ''' Adds a broken rules to the business object's collection using the given message key to pull the error message from the localization database
    ''' </summary>
    ''' <remarks></remarks>
    Protected Shadows Sub AddBrokenRuleByKey(ByVal Field As OrdersBOFieldNames, ByVal ErrorMessageKey As String)
        MyBase.AddBrokenRuleByKey(Field, ErrorMessageKey)
    End Sub

    ''' <summary>
    ''' Adds a broken rules to the business object's collection using the given message key to pull the error message from the localization database
    ''' </summary>
    ''' <remarks></remarks>
    Protected Shadows Sub AddBrokenRuleByKey(ByVal FieldName As String, ByVal ErrorMessageKey As String)
        MyBase.AddBrokenRuleByKey(FieldName, ErrorMessageKey)
    End Sub

    ''' <summary>
    ''' Gets a collection of the names for all fields that belong to this business object and map to the database.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property AllFieldsList() As List(Of String)
        Get
            Return _AllFieldsList
        End Get
    End Property

    ''' <summary>
    ''' Gets a dictionary of the DbTypes for all fields that belong to this business object and map to the database.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property FieldDbTypes() As Dictionary(Of String, DbType)
        Get
            Return _FieldDbTypes
        End Get
    End Property

    ''' <summary>
    ''' Gets a dictionary of all fields within this business object that map to the FieldNames enumeration for this business object.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property FieldEnums() As BusinessLayerFieldEnumDictionary
        Get
            Return _FieldEnums
        End Get
    End Property

    ''' <summary>
    ''' Gets a dictionary of all of the lengths for all fields within this business object that map to a field in the database.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property FieldLengths() As Dictionary(Of String, Integer)
        Get
            Return _FieldLengths
        End Get
    End Property

    ''' <summary>
    ''' Gets a dictionary of the native DbType (SqlDbType, OracleType, OleDbType, etc.) for all fields within this buisness object that map to a field in the database.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property FieldNativeDbTypes() As Dictionary(Of String, Integer)
        Get
            Return _FieldNativeDbTypes
        End Get
    End Property

    ''' <summary>
    ''' Gets a dictionary of the security permission keys for each field in the business object.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides ReadOnly Property FieldPermissionKeys() As Dictionary(Of String, String)
        Get
            Return _FieldPermissionKeys
        End Get
    End Property

#End Region

#Region " Field Properties "

    ''' <summary>
    ''' or_pk
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("or_pk"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Property [or_pk]() As System.Int32
        Get
            Return CType(Me.CurrentRow.Item("or_pk"), System.Int32)
        End Get
        Set(ByVal value As System.Int32)
            Me.CurrentRow.Item("or_pk") = value
        End Set
    End Property

    ''' <summary>
    ''' or_cust_pk
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("or_cust_pk"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Property [or_cust_pk]() As System.Int32
        Get
            Return CType(Me.CurrentRow.Item("or_cust_pk"), System.Int32)
        End Get
        Set(ByVal value As System.Int32)
            Me.CurrentRow.Item("or_cust_pk") = value
        End Set
    End Property

    ''' <summary>
    ''' or_ponumber
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("or_ponumber"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Property [or_ponumber]() As System.String
        Get
            Return CType(Me.CurrentRow.Item("or_ponumber"), System.String)
        End Get
        Set(ByVal value As System.String)
            Me.CurrentRow.Item("or_ponumber") = value
        End Set
    End Property

    ''' <summary>
    ''' or_Created
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("or_Created"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Property [or_Created]() As System.DateTime
        Get
            Return CType(Me.CurrentRow.Item("or_Created"), System.DateTime)
        End Get
        Set(ByVal value As System.DateTime)
            Me.CurrentRow.Item("or_Created") = value
        End Set
    End Property

    ''' <summary>
    ''' or_Version
    ''' </summary>
    ''' <remarks></remarks>
    <Browsable(False), _
     BusinessFieldDisplayInEditor(), _
     Description("or_Version"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
    Public Property [or_Version]() As System.Int32
        Get
            Return CType(Me.CurrentRow.Item("or_Version"), System.Int32)
        End Get
        Set(ByVal value As System.Int32)
            Me.CurrentRow.Item("or_Version") = value
        End Set
    End Property

#End Region

#Region " Field Property Events  "

#End Region

#Region " Nested Types & Field Security "

    ''' <summary>
    ''' Contains all of the field names that belong to the business object.
    ''' </summary>
    ''' <remarks></remarks>
    Public Enum OrdersBOFieldNames As Integer
        [or_pk]
        [or_cust_pk]
        [or_ponumber]
        [or_Created]
        [or_Version]
        CUSTOM_FIELD
    End Enum

    ''' <summary>
    ''' Gets the System.Type of the enumeration that contains the field names for the business object.
    ''' </summary>
    ''' <remarks></remarks>
    Public Overrides Function GetFieldEnumType() As System.Type
        Return GetType(OrdersBOFieldNames)
    End Function

    ''' <summary>
    ''' Creates a new CheckFieldSecurityEventArgs object that can be used with this business object type.
    ''' </summary>
    ''' <remarks></remarks>
    Protected Overrides Function CreateNewFieldSecurityEventArgs(ByVal Field As System.Enum, ByVal CustomField As String, ByVal PermissionKey As String, ByVal Perm As PermissionInfo) As CheckFieldSecurityEventArgsBase
        Return New CheckFieldSecurityEventArgs(Of OrdersBOFieldNames)(Field, CustomField, PermissionKey, Perm)
    End Function

    ''' <summary>
    ''' Describes a method that will handle the CheckFieldScurity event.
    ''' </summary>
    ''' <remarks></remarks>
    Public Delegate Sub CheckFieldSecurityEventHandler(ByVal sender As Object, ByVal e As CheckFieldSecurityEventArgs(Of OrdersBOFieldNames))

    ''' <summary>
    ''' Occurs when the business objects needs to check the security on a field.
    ''' </summary>
    ''' <remarks></remarks>
    Public Event CheckFieldSecurity As CheckFieldSecurityEventHandler

    ''' <summary>
    ''' Raises the CheckFieldSecurity event.
    ''' </summary>
    ''' <remarks></remarks>
    Protected Overrides Sub OnCheckFieldSecurity(ByVal e As CheckFieldSecurityEventArgsBase)
        RaiseEvent CheckFieldSecurity(Me, CType(e, CheckFieldSecurityEventArgs(Of OrdersBOFieldNames)))
    End Sub

#End Region

#Region " Item Property Implementation "


    Private Shared _AllFieldsList As List(Of String)
    Private Shared _FieldDbTypes As Dictionary(Of String, DbType)
    Private Shared _FieldEnums As BusinessLayerFieldEnumDictionary
    Private Shared _FieldLengths As Dictionary(Of String, Integer)
    Private Shared _FieldNativeDbTypes As Dictionary(Of String, Integer)
    Private Shared _FieldPermissionKeys As Dictionary(Of String, String)

    ''' <summary>
    ''' Initializes the shared members of the OrdersBO class.
    ''' </summary>
    ''' <remarks></remarks>
    Shared Sub New()
        '-- Create the new shared dictionary and populate it with an 
        '   instance of each property descriptor
        _PropertyDescriptors = New PropertyDescriptorDictionary(10)
        _PropertyDescriptors.Add("or_pk", New Field_or_pk_Descriptor())
        _PropertyDescriptors.Add("or_cust_pk", New Field_or_cust_pk_Descriptor())
        _PropertyDescriptors.Add("or_ponumber", New Field_or_ponumber_Descriptor())
        _PropertyDescriptors.Add("or_Created", New Field_or_Created_Descriptor())
        _PropertyDescriptors.Add("or_Version", New Field_or_Version_Descriptor())

        _AllFieldsList = New List(Of String)(5)
        _AllFieldsList.Add("or_pk")
        _AllFieldsList.Add("or_cust_pk")
        _AllFieldsList.Add("or_ponumber")
        _AllFieldsList.Add("or_Created")
        _AllFieldsList.Add("or_Version")

        _FieldDbTypes = New Dictionary(Of String, DbType)(5)
        _FieldDbTypes.Add("or_pk", DbType.Int32)
        _FieldDbTypes.Add("or_cust_pk", DbType.Int32)
        _FieldDbTypes.Add("or_ponumber", DbType.String)
        _FieldDbTypes.Add("or_Created", DbType.DateTime)
        _FieldDbTypes.Add("or_Version", DbType.Int32)

        _FieldEnums = New BusinessLayerFieldEnumDictionary(6)
        _FieldEnums.Add("or_pk", OrdersBOFieldNames.or_pk)
        _FieldEnums.Add("or_cust_pk", OrdersBOFieldNames.or_cust_pk)
        _FieldEnums.Add("or_ponumber", OrdersBOFieldNames.or_ponumber)
        _FieldEnums.Add("or_Created", OrdersBOFieldNames.or_Created)
        _FieldEnums.Add("or_Version", OrdersBOFieldNames.or_Version)
        _FieldEnums.Add("CUSTOM_FIELD", OrdersBOFieldNames.CUSTOM_FIELD)

        _FieldLengths = New Dictionary(Of String, Integer)(5)
        _FieldLengths.Add("or_pk", 0)
        _FieldLengths.Add("or_cust_pk", 0)
        _FieldLengths.Add("or_ponumber", 25)
        _FieldLengths.Add("or_Created", 0)
        _FieldLengths.Add("or_Version", 0)

        _FieldNativeDbTypes = New Dictionary(Of String, Integer)(5)
        _FieldNativeDbTypes.Add("or_pk", System.Data.SqlDbType.Int)
        _FieldNativeDbTypes.Add("or_cust_pk", System.Data.SqlDbType.Int)
        _FieldNativeDbTypes.Add("or_ponumber", System.Data.SqlDbType.NVarChar)
        _FieldNativeDbTypes.Add("or_Created", System.Data.SqlDbType.DateTime)
        _FieldNativeDbTypes.Add("or_Version", System.Data.SqlDbType.Int)

        _FieldPermissionKeys = New Dictionary(Of String, String)(5)

    End Sub

    Private Shared _AreCustomDescriptorsEvaluated As Boolean = False
    Protected Overrides ReadOnly Property AreCustomDescriptorsEvaluated() As Boolean
        Get
            Dim llReturn As Boolean = _AreCustomDescriptorsEvaluated
            _AreCustomDescriptorsEvaluated = True
            Return llReturn
        End Get
    End Property

    Private Shared _PropertyDescriptors As PropertyDescriptorDictionary
    Protected Overrides ReadOnly Property PropertyDescriptors() As PropertyDescriptorDictionary
        Get
            Return _PropertyDescriptors
        End Get
    End Property

    ''' <summary>
    ''' A private field used to store the System.Type of this business object for use by the FieldPropertyDescriptor classes.
    ''' </summary>
    ''' <remarks></remarks>

    Private Shared _ComponentType As System.Type = GetType(OrdersBO)

    ''' <summary>
    ''' A PropertyDescriptor class used to Get and Set the value of the or_pk property.
    ''' </summary>
    ''' <remarks></remarks>
    Private Class Field_or_pk_Descriptor
        Inherits MicroFour.StrataFrame.Business.FieldPropertyDescriptor
        Public Sub New()
            MyBase.New("or_pk")
        End Sub
        Private _PropertyType As System.Type = GetType(System.Int32)
        Public Overrides Function GetValue(ByVal component As Object) As Object
            Return CType(component, OrdersBO).or_pk
        End Function
        Public Overrides Sub SetValue(ByVal component As Object, ByVal Value As Object)
            CType(component, OrdersBO).or_pk = CType(Value, System.Int32)
        End Sub
        Public Overrides ReadOnly Property PropertyType() As System.Type
            Get
                Return Me._PropertyType
            End Get
        End Property
        Public Overrides ReadOnly Property ComponentType() As System.Type
            Get
                Return _ComponentType
            End Get
        End Property
    End Class

    ''' <summary>
    ''' A PropertyDescriptor class used to Get and Set the value of the or_cust_pk property.
    ''' </summary>
    ''' <remarks></remarks>
    Private Class Field_or_cust_pk_Descriptor
        Inherits MicroFour.StrataFrame.Business.FieldPropertyDescriptor
        Public Sub New()
            MyBase.New("or_cust_pk")
        End Sub
        Private _PropertyType As System.Type = GetType(System.Int32)
        Public Overrides Function GetValue(ByVal component As Object) As Object
            Return CType(component, OrdersBO).or_cust_pk
        End Function
        Public Overrides Sub SetValue(ByVal component As Object, ByVal Value As Object)
            CType(component, OrdersBO).or_cust_pk = CType(Value, System.Int32)
        End Sub
        Public Overrides ReadOnly Property PropertyType() As System.Type
            Get
                Return Me._PropertyType
            End Get
        End Property
        Public Overrides ReadOnly Property ComponentType() As System.Type
            Get
                Return _ComponentType
            End Get
        End Property
    End Class

    ''' <summary>
    ''' A PropertyDescriptor class used to Get and Set the value of the or_ponumber property.
    ''' </summary>
    ''' <remarks></remarks>
    Private Class Field_or_ponumber_Descriptor
        Inherits MicroFour.StrataFrame.Business.FieldPropertyDescriptor
        Public Sub New()
            MyBase.New("or_ponumber")
        End Sub
        Private _PropertyType As System.Type = GetType(System.String)
        Public Overrides Function GetValue(ByVal component As Object) As Object
            Return CType(component, OrdersBO).or_ponumber
        End Function
        Public Overrides Sub SetValue(ByVal component As Object, ByVal Value As Object)
            CType(component, OrdersBO).or_ponumber = CType(Value, System.String)
        End Sub
        Public Overrides ReadOnly Property PropertyType() As System.Type
            Get
                Return Me._PropertyType
            End Get
        End Property
        Public Overrides ReadOnly Property ComponentType() As System.Type
            Get
                Return _ComponentType
            End Get
        End Property
    End Class

    ''' <summary>
    ''' A PropertyDescriptor class used to Get and Set the value of the or_Created property.
    ''' </summary>
    ''' <remarks></remarks>
    Private Class Field_or_Created_Descriptor
        Inherits MicroFour.StrataFrame.Business.FieldPropertyDescriptor
        Public Sub New()
            MyBase.New("or_Created")
        End Sub
        Private _PropertyType As System.Type = GetType(System.DateTime)
        Public Overrides Function GetValue(ByVal component As Object) As Object
            Return CType(component, OrdersBO).or_Created
        End Function
        Public Overrides Sub SetValue(ByVal component As Object, ByVal Value As Object)
            CType(component, OrdersBO).or_Created = CType(Value, System.DateTime)
        End Sub
        Public Overrides ReadOnly Property PropertyType() As System.Type
            Get
                Return Me._PropertyType
            End Get
        End Property
        Public Overrides ReadOnly Property ComponentType() As System.Type
            Get
                Return _ComponentType
            End Get
        End Property
    End Class

    ''' <summary>
    ''' A PropertyDescriptor class used to Get and Set the value of the or_Version property.
    ''' </summary>
    ''' <remarks></remarks>
    Private Class Field_or_Version_Descriptor
        Inherits MicroFour.StrataFrame.Business.FieldPropertyDescriptor
        Public Sub New()
            MyBase.New("or_Version")
        End Sub
        Private _PropertyType As System.Type = GetType(System.Int32)
        Public Overrides Function GetValue(ByVal component As Object) As Object
            Return CType(component, OrdersBO).or_Version
        End Function
        Public Overrides Sub SetValue(ByVal component As Object, ByVal Value As Object)
            CType(component, OrdersBO).or_Version = CType(Value, System.Int32)
        End Sub
        Public Overrides ReadOnly Property PropertyType() As System.Type
            Get
                Return Me._PropertyType
            End Get
        End Property
        Public Overrides ReadOnly Property ComponentType() As System.Type
            Get
                Return _ComponentType
            End Get
        End Property
    End Class

#End Region

End Class

