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

📄 dsba240.vb

📁 通用进销存-visual basic编写
💻 VB
📖 第 1 页 / 共 2 页
字号:
        
        Public Event ProductRowDeleted As ProductRowChangeEventHandler
        
        Public Event ProductRowDeleting As ProductRowChangeEventHandler
        
        Public Overloads Sub AddProductRow(ByVal row As ProductRow)
            Me.Rows.Add(row)
        End Sub
        
        Public Overloads Function AddProductRow(ByVal ProductID As String, ByVal ProductName As String, ByVal SafeStock As Decimal, ByVal LastPurchaseDate As Date, ByVal LastDeliveryDate As Date, ByVal Quantity As Decimal) As ProductRow
            Dim rowProductRow As ProductRow = CType(Me.NewRow,ProductRow)
            rowProductRow.ItemArray = New Object() {ProductID, ProductName, SafeStock, LastPurchaseDate, LastDeliveryDate, Quantity}
            Me.Rows.Add(rowProductRow)
            Return rowProductRow
        End Function
        
        Public Function FindByProductID(ByVal ProductID As String) As ProductRow
            Return CType(Me.Rows.Find(New Object() {ProductID}),ProductRow)
        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 ProductDataTable = CType(MyBase.Clone,ProductDataTable)
            cln.InitVars
            Return cln
        End Function
        
        Protected Overrides Function CreateInstance() As DataTable
            Return New ProductDataTable
        End Function
        
        Friend Sub InitVars()
            Me.columnProductID = Me.Columns("ProductID")
            Me.columnProductName = Me.Columns("ProductName")
            Me.columnSafeStock = Me.Columns("SafeStock")
            Me.columnLastPurchaseDate = Me.Columns("LastPurchaseDate")
            Me.columnLastDeliveryDate = Me.Columns("LastDeliveryDate")
            Me.columnQuantity = Me.Columns("Quantity")
        End Sub
        
        Private Sub InitClass()
            Me.columnProductID = New DataColumn("ProductID", GetType(System.String), 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.columnSafeStock = New DataColumn("SafeStock", GetType(System.Decimal), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnSafeStock)
            Me.columnLastPurchaseDate = New DataColumn("LastPurchaseDate", GetType(System.DateTime), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnLastPurchaseDate)
            Me.columnLastDeliveryDate = New DataColumn("LastDeliveryDate", GetType(System.DateTime), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnLastDeliveryDate)
            Me.columnQuantity = New DataColumn("Quantity", GetType(System.Decimal), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnQuantity)
            Me.Constraints.Add(New UniqueConstraint("Constraint1", New DataColumn() {Me.columnProductID}, true))
            Me.columnProductID.AllowDBNull = false
            Me.columnProductID.Unique = true
            Me.columnProductName.AllowDBNull = false
            Me.columnSafeStock.AllowDBNull = false
            Me.columnQuantity.AllowDBNull = false
        End Sub
        
        Public Function NewProductRow() As ProductRow
            Return CType(Me.NewRow,ProductRow)
        End Function
        
        Protected Overrides Function NewRowFromBuilder(ByVal builder As DataRowBuilder) As DataRow
            Return New ProductRow(builder)
        End Function
        
        Protected Overrides Function GetRowType() As System.Type
            Return GetType(ProductRow)
        End Function
        
        Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowChanged(e)
            If (Not (Me.ProductRowChangedEvent) Is Nothing) Then
                RaiseEvent ProductRowChanged(Me, New ProductRowChangeEvent(CType(e.Row,ProductRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowChanging(e)
            If (Not (Me.ProductRowChangingEvent) Is Nothing) Then
                RaiseEvent ProductRowChanging(Me, New ProductRowChangeEvent(CType(e.Row,ProductRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowDeleted(e)
            If (Not (Me.ProductRowDeletedEvent) Is Nothing) Then
                RaiseEvent ProductRowDeleted(Me, New ProductRowChangeEvent(CType(e.Row,ProductRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowDeleting(e)
            If (Not (Me.ProductRowDeletingEvent) Is Nothing) Then
                RaiseEvent ProductRowDeleting(Me, New ProductRowChangeEvent(CType(e.Row,ProductRow), e.Action))
            End If
        End Sub
        
        Public Sub RemoveProductRow(ByVal row As ProductRow)
            Me.Rows.Remove(row)
        End Sub
    End Class
    
    <System.Diagnostics.DebuggerStepThrough()>  _
    Public Class ProductRow
        Inherits DataRow
        
        Private tableProduct As ProductDataTable
        
        Friend Sub New(ByVal rb As DataRowBuilder)
            MyBase.New(rb)
            Me.tableProduct = CType(Me.Table,ProductDataTable)
        End Sub
        
        Public Property ProductID As String
            Get
                Return CType(Me(Me.tableProduct.ProductIDColumn),String)
            End Get
            Set
                Me(Me.tableProduct.ProductIDColumn) = value
            End Set
        End Property
        
        Public Property ProductName As String
            Get
                Return CType(Me(Me.tableProduct.ProductNameColumn),String)
            End Get
            Set
                Me(Me.tableProduct.ProductNameColumn) = value
            End Set
        End Property
        
        Public Property SafeStock As Decimal
            Get
                Return CType(Me(Me.tableProduct.SafeStockColumn),Decimal)
            End Get
            Set
                Me(Me.tableProduct.SafeStockColumn) = value
            End Set
        End Property
        
        Public Property LastPurchaseDate As Date
            Get
                Try 
                    Return CType(Me(Me.tableProduct.LastPurchaseDateColumn),Date)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("无法获取值,因为它是 DBNull。", e)
                End Try
            End Get
            Set
                Me(Me.tableProduct.LastPurchaseDateColumn) = value
            End Set
        End Property
        
        Public Property LastDeliveryDate As Date
            Get
                Try 
                    Return CType(Me(Me.tableProduct.LastDeliveryDateColumn),Date)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("无法获取值,因为它是 DBNull。", e)
                End Try
            End Get
            Set
                Me(Me.tableProduct.LastDeliveryDateColumn) = value
            End Set
        End Property
        
        Public Property Quantity As Decimal
            Get
                Return CType(Me(Me.tableProduct.QuantityColumn),Decimal)
            End Get
            Set
                Me(Me.tableProduct.QuantityColumn) = value
            End Set
        End Property
        
        Public Function IsLastPurchaseDateNull() As Boolean
            Return Me.IsNull(Me.tableProduct.LastPurchaseDateColumn)
        End Function
        
        Public Sub SetLastPurchaseDateNull()
            Me(Me.tableProduct.LastPurchaseDateColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsLastDeliveryDateNull() As Boolean
            Return Me.IsNull(Me.tableProduct.LastDeliveryDateColumn)
        End Function
        
        Public Sub SetLastDeliveryDateNull()
            Me(Me.tableProduct.LastDeliveryDateColumn) = System.Convert.DBNull
        End Sub
    End Class
    
    <System.Diagnostics.DebuggerStepThrough()>  _
    Public Class ProductRowChangeEvent
        Inherits EventArgs
        
        Private eventRow As ProductRow
        
        Private eventAction As DataRowAction
        
        Public Sub New(ByVal row As ProductRow, ByVal action As DataRowAction)
            MyBase.New
            Me.eventRow = row
            Me.eventAction = action
        End Sub
        
        Public ReadOnly Property Row As ProductRow
            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 + -