📄 dsproducts.vb
字号:
Me.columnPicture = New DataColumn("Picture", GetType(System.Byte()), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.columnPicture)
Me.PrimaryKey = New DataColumn() {Me.columnCategoryID}
End Sub
Public Function NewCategoriesRow() As CategoriesRow
Return CType(Me.NewRow,CategoriesRow)
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 CategoriesRow(builder)
End Function
Protected Overrides Function GetRowType() As System.Type
Return GetType(CategoriesRow)
End Function
Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs)
MyBase.OnRowChanged(e)
If (Not (Me.CategoriesRowChangedEvent) Is Nothing) Then
RaiseEvent CategoriesRowChanged(Me, New CategoriesRowChangeEvent(CType(e.Row,CategoriesRow), e.Action))
End If
End Sub
Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs)
MyBase.OnRowChanging(e)
If (Not (Me.CategoriesRowChangingEvent) Is Nothing) Then
RaiseEvent CategoriesRowChanging(Me, New CategoriesRowChangeEvent(CType(e.Row,CategoriesRow), e.Action))
End If
End Sub
Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs)
MyBase.OnRowDeleted(e)
If (Not (Me.CategoriesRowDeletedEvent) Is Nothing) Then
RaiseEvent CategoriesRowDeleted(Me, New CategoriesRowChangeEvent(CType(e.Row,CategoriesRow), e.Action))
End If
End Sub
Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs)
MyBase.OnRowDeleting(e)
If (Not (Me.CategoriesRowDeletingEvent) Is Nothing) Then
RaiseEvent CategoriesRowDeleting(Me, New CategoriesRowChangeEvent(CType(e.Row,CategoriesRow), e.Action))
End If
End Sub
Public Sub RemoveCategoriesRow(ByVal row As CategoriesRow)
Me.Rows.Remove(row)
End Sub
End Class
Public Class CategoriesRow
Inherits DataRow
Private tableCategories As CategoriesDataTable
Friend Sub New(ByVal rb As DataRowBuilder)
MyBase.New(rb)
Me.tableCategories = CType(Me.Table,CategoriesDataTable)
End Sub
Public Property CategoryID As Integer
Get
Return CType(Me(Me.tableCategories.CategoryIDColumn),Integer)
End Get
Set
Me(Me.tableCategories.CategoryIDColumn) = value
End Set
End Property
Public Property CategoryName As String
Get
Return CType(Me(Me.tableCategories.CategoryNameColumn),String)
End Get
Set
Me(Me.tableCategories.CategoryNameColumn) = value
End Set
End Property
Public Property Description As String
Get
Try
Return CType(Me(Me.tableCategories.DescriptionColumn),String)
Catch e As InvalidCastException
Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
End Try
End Get
Set
Me(Me.tableCategories.DescriptionColumn) = value
End Set
End Property
Public Property Picture As Byte()
Get
Try
Return CType(Me(Me.tableCategories.PictureColumn),Byte())
Catch e As InvalidCastException
Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
End Try
End Get
Set
Me(Me.tableCategories.PictureColumn) = value
End Set
End Property
Public Function IsDescriptionNull() As Boolean
Return Me.IsNull(Me.tableCategories.DescriptionColumn)
End Function
Public Sub SetDescriptionNull()
Me(Me.tableCategories.DescriptionColumn) = System.Convert.DBNull
End Sub
Public Function IsPictureNull() As Boolean
Return Me.IsNull(Me.tableCategories.PictureColumn)
End Function
Public Sub SetPictureNull()
Me(Me.tableCategories.PictureColumn) = System.Convert.DBNull
End Sub
Public Function GetProductsRows() As ProductsRow()
Return CType(Me.GetChildRows(Me.Table.ChildRelations("CategoriesProducts")),ProductsRow())
End Function
End Class
Public Class CategoriesRowChangeEvent
Inherits EventArgs
Private eventRow As CategoriesRow
Private eventAction As System.Data.DataRowAction
Public Sub New(ByVal row As CategoriesRow, ByVal action As DataRowAction)
MyBase.New
Me.eventRow = row
Me.eventAction = action
End Sub
Public ReadOnly Property Row As CategoriesRow
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
Private columnContactName As DataColumn
Private columnContactTitle As DataColumn
Private columnAddress As DataColumn
Private columnCity As DataColumn
Private column_Region As DataColumn
Private columnPostalCode As DataColumn
Private columnCountry As DataColumn
Private columnPhone As DataColumn
Private columnFax As DataColumn
Private columnHomePage 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
Friend ReadOnly Property ContactNameColumn As DataColumn
Get
Return Me.columnContactName
End Get
End Property
Friend ReadOnly Property ContactTitleColumn As DataColumn
Get
Return Me.columnContactTitle
End Get
End Property
Friend ReadOnly Property AddressColumn As DataColumn
Get
Return Me.columnAddress
End Get
End Property
Friend ReadOnly Property CityColumn As DataColumn
Get
Return Me.columnCity
End Get
End Property
Friend ReadOnly Property _RegionColumn As DataColumn
Get
Return Me.column_Region
End Get
End Property
Friend ReadOnly Property PostalCodeColumn As DataColumn
Get
Return Me.columnPostalCode
End Get
End Property
Friend ReadOnly Property CountryColumn As DataColumn
Get
Return Me.columnCountry
End Get
End Property
Friend ReadOnly Property PhoneColumn As DataColumn
Get
Return Me.columnPhone
End Get
End Property
Friend ReadOnly Property FaxColumn As DataColumn
Get
Return Me.columnFax
End Get
End Property
Friend ReadOnly Property HomePageColumn As DataColumn
Get
Return Me.columnHomePage
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, ByVal ContactName As String, ByVal ContactTitle As String, ByVal Address As String, ByVal City As String, ByVal _Region As String, ByVal PostalCode As String, ByVal Country As String, ByVal Phone As String, ByVal Fax As String, ByVal HomePage As String) As SuppliersRow
Dim rowSuppliersRow As SuppliersRow = CType(Me.NewRow,SuppliersRow)
rowSuppliersRow.ItemArray = New Object() {Nothing, CompanyName, ContactName, ContactTitle, Address, City, _Region, PostalCode, Country, Phone, Fax, HomePage}
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.columnContactName = New DataColumn("ContactName", GetType(System.String), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.columnContactName)
Me.columnContactTitle = New DataColumn("ContactTitle", GetType(System.String), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.columnContactTitle)
Me.columnAddress = New DataColumn("Address", GetType(System.String), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.columnAddress)
Me.columnCity = New DataColumn("City", GetType(System.String), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.columnCity)
Me.column_Region = New DataColumn("Region", GetType(System.String), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.column_Region)
Me.columnPostalCode = New DataColumn("PostalCode", GetType(System.String), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.columnPostalCode)
Me.columnCountry = New DataColumn("Country", GetType(System.String), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.columnCountry)
Me.columnPhone = New DataColumn("Phone", GetType(System.String), "", System.Data.MappingType.Element)
Me.Columns.Add(Me.columnPhone)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -