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

📄 productsds.vb

📁 Beginning VB.NET DatabasesAll_Code.rar
💻 VB
📖 第 1 页 / 共 2 页
字号:
        Public Event ProductsRowDeleting As ProductsRowChangeEventHandler
        
        Public Overloads Sub AddProductsRow(ByVal row As ProductsRow)
            Me.Rows.Add(row)
        End Sub
        
        Public Overloads Function AddProductsRow(ByVal ProductID As Integer, ByVal ProductName As String, ByVal ProductDescription As String, ByVal UnitPrice As Decimal) As ProductsRow
            Dim rowProductsRow As ProductsRow = CType(Me.NewRow,ProductsRow)
            rowProductsRow.ItemArray = New Object() {ProductID, ProductName, ProductDescription, UnitPrice}
            Me.Rows.Add(rowProductsRow)
            Return rowProductsRow
        End Function
        
        Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
            Return Me.Rows.GetEnumerator
        End Function
        
        Public Overrides Function Clone() As DataTable
            Dim cln As ProductsDataTable = CType(MyBase.Clone,ProductsDataTable)
            cln.InitVars
            Return cln
        End Function
        
        Protected Overrides Function CreateInstance() As DataTable
            Return New ProductsDataTable
        End Function
        
        Friend Sub InitVars()
            Me.columnProductID = Me.Columns("ProductID")
            Me.columnProductName = Me.Columns("ProductName")
            Me.columnProductDescription = Me.Columns("ProductDescription")
            Me.columnUnitPrice = Me.Columns("UnitPrice")
        End Sub
        
        Private Sub InitClass()
            Me.columnProductID = New DataColumn("ProductID", GetType(System.Int32), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnProductID)
            Me.columnProductName = New DataColumn("ProductName", GetType(System.String), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnProductName)
            Me.columnProductDescription = New DataColumn("ProductDescription", GetType(System.String), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnProductDescription)
            Me.columnUnitPrice = New DataColumn("UnitPrice", GetType(System.Decimal), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnUnitPrice)
        End Sub
        
        Public Function NewProductsRow() As ProductsRow
            Return CType(Me.NewRow,ProductsRow)
        End Function
        
        Protected Overrides Function NewRowFromBuilder(ByVal builder As DataRowBuilder) As DataRow
            Return New ProductsRow(builder)
        End Function
        
        Protected Overrides Function GetRowType() As System.Type
            Return GetType(ProductsRow)
        End Function
        
        Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowChanged(e)
            If (Not (Me.ProductsRowChangedEvent) Is Nothing) Then
                RaiseEvent ProductsRowChanged(Me, New ProductsRowChangeEvent(CType(e.Row,ProductsRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowChanging(e)
            If (Not (Me.ProductsRowChangingEvent) Is Nothing) Then
                RaiseEvent ProductsRowChanging(Me, New ProductsRowChangeEvent(CType(e.Row,ProductsRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowDeleted(e)
            If (Not (Me.ProductsRowDeletedEvent) Is Nothing) Then
                RaiseEvent ProductsRowDeleted(Me, New ProductsRowChangeEvent(CType(e.Row,ProductsRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowDeleting(e)
            If (Not (Me.ProductsRowDeletingEvent) Is Nothing) Then
                RaiseEvent ProductsRowDeleting(Me, New ProductsRowChangeEvent(CType(e.Row,ProductsRow), e.Action))
            End If
        End Sub
        
        Public Sub RemoveProductsRow(ByVal row As ProductsRow)
            Me.Rows.Remove(row)
        End Sub
    End Class
    
    <System.Diagnostics.DebuggerStepThrough()>  _
    Public Class ProductsRow
        Inherits DataRow
        
        Private tableProducts As ProductsDataTable
        
        Friend Sub New(ByVal rb As DataRowBuilder)
            MyBase.New(rb)
            Me.tableProducts = CType(Me.Table,ProductsDataTable)
        End Sub
        
        Public Property ProductID As Integer
            Get
                Try 
                    Return CType(Me(Me.tableProducts.ProductIDColumn),Integer)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
                End Try
            End Get
            Set
                Me(Me.tableProducts.ProductIDColumn) = value
            End Set
        End Property
        
        Public Property ProductName As String
            Get
                Try 
                    Return CType(Me(Me.tableProducts.ProductNameColumn),String)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
                End Try
            End Get
            Set
                Me(Me.tableProducts.ProductNameColumn) = value
            End Set
        End Property
        
        Public Property ProductDescription As String
            Get
                Try 
                    Return CType(Me(Me.tableProducts.ProductDescriptionColumn),String)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
                End Try
            End Get
            Set
                Me(Me.tableProducts.ProductDescriptionColumn) = value
            End Set
        End Property
        
        Public Property UnitPrice As Decimal
            Get
                Try 
                    Return CType(Me(Me.tableProducts.UnitPriceColumn),Decimal)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
                End Try
            End Get
            Set
                Me(Me.tableProducts.UnitPriceColumn) = value
            End Set
        End Property
        
        Public Function IsProductIDNull() As Boolean
            Return Me.IsNull(Me.tableProducts.ProductIDColumn)
        End Function
        
        Public Sub SetProductIDNull()
            Me(Me.tableProducts.ProductIDColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsProductNameNull() As Boolean
            Return Me.IsNull(Me.tableProducts.ProductNameColumn)
        End Function
        
        Public Sub SetProductNameNull()
            Me(Me.tableProducts.ProductNameColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsProductDescriptionNull() As Boolean
            Return Me.IsNull(Me.tableProducts.ProductDescriptionColumn)
        End Function
        
        Public Sub SetProductDescriptionNull()
            Me(Me.tableProducts.ProductDescriptionColumn) = 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
    End Class
    
    <System.Diagnostics.DebuggerStepThrough()>  _
    Public Class ProductsRowChangeEvent
        Inherits EventArgs
        
        Private eventRow As ProductsRow
        
        Private eventAction As 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
End Class

⌨️ 快捷键说明

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