⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsproducts.vb

📁 Mastering VBNet Include Source Code
💻 VB
📖 第 1 页 / 共 3 页
字号:
        
        Public Property ReorderLevel As Short
            Get
                Try 
                    Return CType(Me(Me.tableProducts.ReorderLevelColumn),Short)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
                End Try
            End Get
            Set
                Me(Me.tableProducts.ReorderLevelColumn) = value
            End Set
        End Property
        
        Public Property Discontinued As Boolean
            Get
                Return CType(Me(Me.tableProducts.DiscontinuedColumn),Boolean)
            End Get
            Set
                Me(Me.tableProducts.DiscontinuedColumn) = value
            End Set
        End Property
        
        Public Property CategoriesRow As CategoriesRow
            Get
                Return CType(Me.GetParentRow(Me.Table.ParentRelations("CategoriesProducts")),CategoriesRow)
            End Get
            Set
                Me.SetParentRow(value, Me.Table.ParentRelations("CategoriesProducts"))
            End Set
        End Property
        
        Public Property SuppliersRow As SuppliersRow
            Get
                Return CType(Me.GetParentRow(Me.Table.ParentRelations("SuppliersProducts")),SuppliersRow)
            End Get
            Set
                Me.SetParentRow(value, Me.Table.ParentRelations("SuppliersProducts"))
            End Set
        End Property
        
        Public Function IsSupplierIDNull() As Boolean
            Return Me.IsNull(Me.tableProducts.SupplierIDColumn)
        End Function
        
        Public Sub SetSupplierIDNull()
            Me(Me.tableProducts.SupplierIDColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsCategoryIDNull() As Boolean
            Return Me.IsNull(Me.tableProducts.CategoryIDColumn)
        End Function
        
        Public Sub SetCategoryIDNull()
            Me(Me.tableProducts.CategoryIDColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsQuantityPerUnitNull() As Boolean
            Return Me.IsNull(Me.tableProducts.QuantityPerUnitColumn)
        End Function
        
        Public Sub SetQuantityPerUnitNull()
            Me(Me.tableProducts.QuantityPerUnitColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsUnitPriceNull() As Boolean
            Return Me.IsNull(Me.tableProducts.UnitPriceColumn)
        End Function
        
        Public Sub SetUnitPriceNull()
            Me(Me.tableProducts.UnitPriceColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsUnitsInStockNull() As Boolean
            Return Me.IsNull(Me.tableProducts.UnitsInStockColumn)
        End Function
        
        Public Sub SetUnitsInStockNull()
            Me(Me.tableProducts.UnitsInStockColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsUnitsOnOrderNull() As Boolean
            Return Me.IsNull(Me.tableProducts.UnitsOnOrderColumn)
        End Function
        
        Public Sub SetUnitsOnOrderNull()
            Me(Me.tableProducts.UnitsOnOrderColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsReorderLevelNull() As Boolean
            Return Me.IsNull(Me.tableProducts.ReorderLevelColumn)
        End Function
        
        Public Sub SetReorderLevelNull()
            Me(Me.tableProducts.ReorderLevelColumn) = System.Convert.DBNull
        End Sub
    End Class
    
    Public Class ProductsRowChangeEvent
        Inherits EventArgs
        
        Private eventRow As ProductsRow
        
        Private eventAction As System.Data.DataRowAction
        
        Public Sub New(ByVal row As ProductsRow, ByVal action As DataRowAction)
            MyBase.New
            Me.eventRow = row
            Me.eventAction = action
        End Sub
        
        Public ReadOnly Property Row As ProductsRow
            Get
                Return Me.eventRow
            End Get
        End Property
        
        Public ReadOnly Property Action As DataRowAction
            Get
                Return Me.eventAction
            End Get
        End Property
    End Class
    
    Public Class SuppliersDataTable
        Inherits DataTable
        Implements System.Collections.IEnumerable
        
        Private columnSupplierID As DataColumn
        
        Private columnCompanyName As DataColumn
        
        Friend Sub New()
            MyBase.New("Suppliers")
            Me.InitClass
        End Sub
        
        <System.ComponentModel.Browsable(false)>  _
        Public ReadOnly Property Count As Integer
            Get
                Return Me.Rows.Count
            End Get
        End Property
        
        Friend ReadOnly Property SupplierIDColumn As DataColumn
            Get
                Return Me.columnSupplierID
            End Get
        End Property
        
        Friend ReadOnly Property CompanyNameColumn As DataColumn
            Get
                Return Me.columnCompanyName
            End Get
        End Property
        
        Public Default ReadOnly Property Item(ByVal index As Integer) As SuppliersRow
            Get
                Return CType(Me.Rows(index),SuppliersRow)
            End Get
        End Property
        
        Public Event SuppliersRowChanged As SuppliersRowChangeEventHandler
        
        Public Event SuppliersRowChanging As SuppliersRowChangeEventHandler
        
        Public Event SuppliersRowDeleted As SuppliersRowChangeEventHandler
        
        Public Event SuppliersRowDeleting As SuppliersRowChangeEventHandler
        
        Public Overloads Sub AddSuppliersRow(ByVal row As SuppliersRow)
            Me.Rows.Add(row)
        End Sub
        
        Public Overloads Function AddSuppliersRow(ByVal CompanyName As String) As SuppliersRow
            Dim rowSuppliersRow As SuppliersRow = CType(Me.NewRow,SuppliersRow)
            rowSuppliersRow.ItemArray = New Object() {Nothing, CompanyName}
            Me.Rows.Add(rowSuppliersRow)
            Return rowSuppliersRow
        End Function
        
        Public Function FindBySupplierID(ByVal SupplierID As Integer) As SuppliersRow
            Return CType(Me.Rows.Find(New Object() {SupplierID}),SuppliersRow)
        End Function
        
        Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
            Return Me.Rows.GetEnumerator
        End Function
        
        Private Sub InitClass()
            Me.columnSupplierID = New DataColumn("SupplierID", GetType(System.Int32), "", System.Data.MappingType.Element)
            Me.columnSupplierID.AutoIncrement = true
            Me.columnSupplierID.AllowDBNull = false
            Me.columnSupplierID.ReadOnly = true
            Me.columnSupplierID.Unique = true
            Me.Columns.Add(Me.columnSupplierID)
            Me.columnCompanyName = New DataColumn("CompanyName", GetType(System.String), "", System.Data.MappingType.Element)
            Me.columnCompanyName.AllowDBNull = false
            Me.Columns.Add(Me.columnCompanyName)
            Me.PrimaryKey = New DataColumn() {Me.columnSupplierID}
        End Sub
        
        Public Function NewSuppliersRow() As SuppliersRow
            Return CType(Me.NewRow,SuppliersRow)
        End Function
        
        Protected Overrides Function NewRowFromBuilder(ByVal builder As DataRowBuilder) As DataRow
            'We need to ensure that all Rows in the tabled are typed rows.
            'Table calls newRow whenever it needs to create a row.
            'So the following conditions are covered by Row newRow(Record record)
            '* Cursor calls table.addRecord(record) 
            '* table.addRow(object[] values) calls newRow(record)    
            Return New SuppliersRow(builder)
        End Function
        
        Protected Overrides Function GetRowType() As System.Type
            Return GetType(SuppliersRow)
        End Function
        
        Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowChanged(e)
            If (Not (Me.SuppliersRowChangedEvent) Is Nothing) Then
                RaiseEvent SuppliersRowChanged(Me, New SuppliersRowChangeEvent(CType(e.Row,SuppliersRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowChanging(e)
            If (Not (Me.SuppliersRowChangingEvent) Is Nothing) Then
                RaiseEvent SuppliersRowChanging(Me, New SuppliersRowChangeEvent(CType(e.Row,SuppliersRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowDeleted(e)
            If (Not (Me.SuppliersRowDeletedEvent) Is Nothing) Then
                RaiseEvent SuppliersRowDeleted(Me, New SuppliersRowChangeEvent(CType(e.Row,SuppliersRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowDeleting(e)
            If (Not (Me.SuppliersRowDeletingEvent) Is Nothing) Then
                RaiseEvent SuppliersRowDeleting(Me, New SuppliersRowChangeEvent(CType(e.Row,SuppliersRow), e.Action))
            End If
        End Sub
        
        Public Sub RemoveSuppliersRow(ByVal row As SuppliersRow)
            Me.Rows.Remove(row)
        End Sub
    End Class
    
    Public Class SuppliersRow
        Inherits DataRow
        
        Private tableSuppliers As SuppliersDataTable
        
        Friend Sub New(ByVal rb As DataRowBuilder)
            MyBase.New(rb)
            Me.tableSuppliers = CType(Me.Table,SuppliersDataTable)
        End Sub
        
        Public Property SupplierID As Integer
            Get
                Return CType(Me(Me.tableSuppliers.SupplierIDColumn),Integer)
            End Get
            Set
                Me(Me.tableSuppliers.SupplierIDColumn) = value
            End Set
        End Property
        
        Public Property CompanyName As String
            Get
                Return CType(Me(Me.tableSuppliers.CompanyNameColumn),String)
            End Get
            Set
                Me(Me.tableSuppliers.CompanyNameColumn) = value
            End Set
        End Property
        
        Public Function GetProductsRows() As ProductsRow()
            Return CType(Me.GetChildRows(Me.Table.ChildRelations("SuppliersProducts")),ProductsRow())
        End Function
    End Class
    
    Public Class SuppliersRowChangeEvent
        Inherits EventArgs
        
        Private eventRow As SuppliersRow
        
        Private eventAction As System.Data.DataRowAction
        
        Public Sub New(ByVal row As SuppliersRow, ByVal action As DataRowAction)
            MyBase.New
            Me.eventRow = row
            Me.eventAction = action
        End Sub
        
        Public ReadOnly Property Row As SuppliersRow
            Get
                Return Me.eventRow
            End Get
        End Property
        
        Public ReadOnly Property Action As DataRowAction
            Get
                Return Me.eventAction
            End Get
        End Property
    End Class
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -