From a2debce52e02c0d511dcaa6c5e5eb4bedd60a49c Mon Sep 17 00:00:00 2001 From: DevExpressExampleBot Date: Tue, 7 Sep 2021 15:58:52 +0300 Subject: [PATCH 1/2] autogenerate VB --- .../Application.xaml | 2 +- .../Application.xaml.vb | 12 +- ...id_ShowCheckBoxInColumnHeaders.Net5.vbproj | 24 +- .../DXGrid_ShowCheckBoxInColumnHeaders.vbproj | 69 +- .../My Project/AssemblyInfo.vb | 6 +- .../My Project/Resources.Designer.vb | 86 +- .../My Project/Settings.Designer.vb | 36 +- .../Window1.xaml | 2 +- .../Window1.xaml.vb | 50 +- .../nwindDataSet.Designer.vb | 2206 +++++++++-------- VB/E1517/E1517.Net5.sln | 2 +- VB/E1517/E1517.sln | 2 +- 12 files changed, 1266 insertions(+), 1231 deletions(-) diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Application.xaml b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Application.xaml index 76b9597..5886b98 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Application.xaml +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Application.xaml @@ -1,4 +1,4 @@ - + diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Application.xaml.vb b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Application.xaml.vb index f211e06..3f450b7 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Application.xaml.vb +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Application.xaml.vb @@ -16,11 +16,11 @@ Imports System.Linq Imports System.Windows Namespace DXGrid_ShowCheckBoxInColumnHeaders - ''' - ''' Interaction logic for App.xaml - ''' - Partial Public Class App - Inherits Application + ''' + ''' Interaction logic for App.xaml + ''' + Partial Public Class App + Inherits Application - End Class + End Class End Namespace diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/DXGrid_ShowCheckBoxInColumnHeaders.Net5.vbproj b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/DXGrid_ShowCheckBoxInColumnHeaders.Net5.vbproj index df71aed..3c39059 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/DXGrid_ShowCheckBoxInColumnHeaders.Net5.vbproj +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/DXGrid_ShowCheckBoxInColumnHeaders.Net5.vbproj @@ -1,3 +1,4 @@ + net5.0-windows @@ -11,26 +12,11 @@ x86;AnyCPU false obj*/** + On + Binary + Off + On - - - - - - - - - - - - - - - - - - - nwindDataSet.xsd diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/DXGrid_ShowCheckBoxInColumnHeaders.vbproj b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/DXGrid_ShowCheckBoxInColumnHeaders.vbproj index 1ca0b2f..1b79d2d 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/DXGrid_ShowCheckBoxInColumnHeaders.vbproj +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/DXGrid_ShowCheckBoxInColumnHeaders.vbproj @@ -13,11 +13,11 @@ v4.5.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{F184B08F-C81C-45F6-A57F-5ABD9991F28F} + obj.NetFX On Binary Off On - obj.NetFX true @@ -27,6 +27,7 @@ true true prompt + true pdbonly @@ -35,49 +36,83 @@ false true prompt + true + + + + + + + + + + + + + + + + + + + + True + C:\DXDlls\21.1.5\DevExpress.Data.v21.1.dll True + C:\DXDlls\21.1.5\DevExpress.Mvvm.v21.1.dll True True + C:\DXDlls\21.1.5\DevExpress.Pdf.v21.1.Core.dll True + C:\DXDlls\21.1.5\DevExpress.Office.v21.1.Core.dll True + C:\DXDlls\21.1.5\DevExpress.RichEdit.v21.1.Core.dll True + C:\DXDlls\21.1.5\DevExpress.RichEdit.v21.1.Export.dll True + C:\DXDlls\21.1.5\DevExpress.Printing.v21.1.Core.dll True + C:\DXDlls\21.1.5\DevExpress.Xpf.CodeView.v21.1.dll True + C:\DXDlls\21.1.5\DevExpress.Data.Desktop.v21.1.dll True + C:\DXDlls\21.1.5\DevExpress.Xpf.Core.v21.1.dll True + C:\DXDlls\21.1.5\DevExpress.Xpf.Grid.v21.1.Core.dll True + C:\DXDlls\21.1.5\DevExpress.Xpf.Printing.v21.1.dll True + C:\DXDlls\21.1.5\DevExpress.Xpf.Grid.v21.1.dll @@ -96,25 +131,6 @@ - - - - - - - - - - - - - - - - - - - MSBuild:Compile @@ -172,6 +188,7 @@ SettingsSingleFileGenerator Settings.Designer.vb + My @@ -181,11 +198,11 @@ - \ No newline at end of file diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/AssemblyInfo.vb b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/AssemblyInfo.vb index e9727ee..e9317c9 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/AssemblyInfo.vb +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/AssemblyInfo.vb @@ -41,11 +41,7 @@ Imports System.Windows '[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - 'where the generic resource dictionary is located - where theme specific resource dictionaries are located - '(used if a resource is not found in the page, - ' or application resource dictionaries) - '(used if a resource is not found in the page, - ' app, or any theme specific resource dictionaries) + ' Version information for an assembly consists of the following four values: diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/Resources.Designer.vb b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/Resources.Designer.vb index 0ee5964..3c64556 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/Resources.Designer.vb +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/Resources.Designer.vb @@ -21,51 +21,53 @@ Namespace My.Resources - ''' - ''' A strongly-typed resource class, for looking up localized strings, etc. - ''' - ' This class was auto-generated by the StronglyTypedResourceBuilder - ' class via a tool like ResGen or Visual Studio. - ' To add or remove a member, edit your .ResX file then rerun ResGen - ' with the /str option, or rebuild your VS project. - _ - Friend Module Resources + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + ' This class was auto-generated by the StronglyTypedResourceBuilder + ' class via a tool like ResGen or Visual Studio. + ' To add or remove a member, edit your .ResX file then rerun ResGen + ' with the /str option, or rebuild your VS project. + + + + Friend Module Resources - Private resourceMan As Global.System.Resources.ResourceManager + Private resourceMan As System.Resources.ResourceManager - Private resourceCulture As Global.System.Globalization.CultureInfo + Private resourceCulture As System.Globalization.CultureInfo -' internal Resources() -' { -' } +' internal Resources() +' { +' } - ''' - ''' Returns the cached ResourceManager instance used by this class. - ''' - _ - Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager - Get - If (resourceMan Is Nothing) Then - Dim temp As New Global.System.Resources.ResourceManager("Resources", GetType(Resources).Assembly) - resourceMan = temp - End If - Return resourceMan - End Get - End Property + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + + Friend ReadOnly Property ResourceManager() As System.Resources.ResourceManager + Get + If (resourceMan Is Nothing) Then + Dim temp As New System.Resources.ResourceManager("Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property - ''' - ''' Overrides the current thread's CurrentUICulture property for all - ''' resource lookups using this strongly typed resource class. - ''' - _ - Friend Property Culture() As Global.System.Globalization.CultureInfo - Get - Return resourceCulture - End Get - Set(ByVal value As System.Globalization.CultureInfo) - resourceCulture = value - End Set - End Property - End Module + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + + Friend Property Culture() As System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set(ByVal value As System.Globalization.CultureInfo) + resourceCulture = value + End Set + End Property + End Module End Namespace diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/Settings.Designer.vb b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/Settings.Designer.vb index 5541cd7..ba557eb 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/Settings.Designer.vb +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/My Project/Settings.Designer.vb @@ -21,23 +21,27 @@ Namespace My - _ - Friend NotInheritable Partial Class Settings - Inherits System.Configuration.ApplicationSettingsBase + + + Friend NotInheritable Partial Class Settings + Inherits System.Configuration.ApplicationSettingsBase - Private Shared defaultInstance As Settings = (CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()), Settings)) + Private Shared defaultInstance As Settings = (CType(System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()), Settings)) - Public Shared ReadOnly Property [Default]() As Settings - Get - Return defaultInstance - End Get - End Property + Public Shared ReadOnly Property [Default]() As Settings + Get + Return defaultInstance + End Get + End Property - _ - Public ReadOnly Property nwindConnectionString() As String - Get - Return (DirectCast(Me("nwindConnectionString"), String)) - End Get - End Property - End Class + + + + + Public ReadOnly Property nwindConnectionString() As String + Get + Return (DirectCast(Me("nwindConnectionString"), String)) + End Get + End Property + End Class End Namespace diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Window1.xaml b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Window1.xaml index 457db2f..606b473 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Window1.xaml +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Window1.xaml @@ -1,4 +1,4 @@ - + diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Window1.xaml.vb b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Window1.xaml.vb index 24dc213..3888641 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Window1.xaml.vb +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/Window1.xaml.vb @@ -25,34 +25,34 @@ Imports DevExpress.Xpf.Editors Imports DevExpress.Xpf.Grid Namespace DXGrid_ShowCheckBoxInColumnHeaders - Partial Public Class Window1 - Inherits Window + Partial Public Class Window1 + Inherits Window - Public Sub New() - InitializeComponent() - CreateList() - DataContext = Me + Public Sub New() + InitializeComponent() + CreateList() + DataContext = Me - End Sub - Public Property ListPerson() As List(Of Person) - Private Sub CreateList() - ListPerson = New List(Of Person)() - For i As Integer = 0 To 9 - ListPerson.Add(New Person(i)) - Next i - End Sub - End Class + End Sub + Public Property ListPerson() As List(Of Person) + Private Sub CreateList() + ListPerson = New List(Of Person)() + For i As Integer = 0 To 9 + ListPerson.Add(New Person(i)) + Next i + End Sub + End Class - Public Class Person - Public Sub New(ByVal i As Integer) - FirstName = "FirstName" & i - LastName = "LastName" & i - Age = i * 10 - End Sub - Public Property FirstName() As String - Public Property LastName() As String - Public Property Age() As Integer + Public Class Person + Public Sub New(ByVal i As Integer) + FirstName = "FirstName" & i + LastName = "LastName" & i + Age = i * 10 + End Sub + Public Property FirstName() As String + Public Property LastName() As String + Public Property Age() As Integer - End Class + End Class End Namespace diff --git a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/nwindDataSet.Designer.vb b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/nwindDataSet.Designer.vb index da97763..c5f8700 100644 --- a/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/nwindDataSet.Designer.vb +++ b/VB/E1517/DXGrid_ShowCheckBoxInColumnHeaders/nwindDataSet.Designer.vb @@ -18,1101 +18,1131 @@ ' '------------------------------------------------------------------------------ -'#pragma warning disable 1591 +#Disable Warning BC1591 Namespace DXGrid_ShowCheckBoxInColumnHeaders - ''' - '''Represents a strongly typed in-memory cache of data. - ''' - _ - Partial Public Class nwindDataSet - Inherits System.Data.DataSet - - Private tableProducts As ProductsDataTable - - Private _schemaSerializationMode As Global.System.Data.SchemaSerializationMode = Global.System.Data.SchemaSerializationMode.IncludeSchema - - _ - Public Sub New() - Me.BeginInit() - Me.InitClass() - Dim schemaChangedHandler As New Global.System.ComponentModel.CollectionChangeEventHandler(AddressOf Me.SchemaChanged) - AddHandler MyBase.Tables.CollectionChanged, schemaChangedHandler - AddHandler MyBase.Relations.CollectionChanged, schemaChangedHandler - Me.EndInit() - End Sub - - _ - Protected Sub New(ByVal info As Global.System.Runtime.Serialization.SerializationInfo, ByVal context As Global.System.Runtime.Serialization.StreamingContext) - MyBase.New(info, context, False) - If (Me.IsBinarySerialized(info, context) = True) Then - Me.InitVars(False) - Dim schemaChangedHandler1 As New Global.System.ComponentModel.CollectionChangeEventHandler(AddressOf Me.SchemaChanged) - AddHandler Me.Tables.CollectionChanged, schemaChangedHandler1 - AddHandler Me.Relations.CollectionChanged, schemaChangedHandler1 - Return - End If - Dim strSchema As String = (DirectCast(info.GetValue("XmlSchema", GetType(String)), String)) - If (Me.DetermineSchemaSerializationMode(info, context) = Global.System.Data.SchemaSerializationMode.IncludeSchema) Then - Dim ds As New Global.System.Data.DataSet() - ds.ReadXmlSchema(New Global.System.Xml.XmlTextReader(New Global.System.IO.StringReader(strSchema))) - If (ds.Tables("Products") IsNot Nothing) Then - MyBase.Tables.Add(New ProductsDataTable(ds.Tables("Products"))) - End If - Me.DataSetName = ds.DataSetName - Me.Prefix = ds.Prefix - Me.Namespace = ds.Namespace - Me.Locale = ds.Locale - Me.CaseSensitive = ds.CaseSensitive - Me.EnforceConstraints = ds.EnforceConstraints - Me.Merge(ds, False, Global.System.Data.MissingSchemaAction.Add) - Me.InitVars() - Else - Me.ReadXmlSchema(New Global.System.Xml.XmlTextReader(New Global.System.IO.StringReader(strSchema))) - End If - Me.GetSerializationData(info, context) - Dim schemaChangedHandler As New Global.System.ComponentModel.CollectionChangeEventHandler(AddressOf Me.SchemaChanged) - AddHandler MyBase.Tables.CollectionChanged, schemaChangedHandler - AddHandler Me.Relations.CollectionChanged, schemaChangedHandler - End Sub - - _ - Public ReadOnly Property Products() As ProductsDataTable - Get - Return Me.tableProducts - End Get - End Property - - _ - Public Overrides Property SchemaSerializationMode() As Global.System.Data.SchemaSerializationMode - Get - Return Me._schemaSerializationMode - End Get - Set(ByVal value As System.Data.SchemaSerializationMode) - Me._schemaSerializationMode = value - End Set - End Property - - _ - Public Shadows ReadOnly Property Tables() As Global.System.Data.DataTableCollection - Get - Return MyBase.Tables - End Get - End Property - - _ - Public Shadows ReadOnly Property Relations() As Global.System.Data.DataRelationCollection - Get - Return MyBase.Relations - End Get - End Property - - _ - Protected Overrides Sub InitializeDerivedDataSet() - Me.BeginInit() - Me.InitClass() - Me.EndInit() - End Sub - - _ - Public Overrides Function Clone() As Global.System.Data.DataSet - Dim cln As nwindDataSet = (DirectCast(MyBase.Clone(), nwindDataSet)) - cln.InitVars() - cln.SchemaSerializationMode = Me.SchemaSerializationMode - Return cln - End Function - - _ - Protected Overrides Function ShouldSerializeTables() As Boolean - Return False - End Function - - _ - Protected Overrides Function ShouldSerializeRelations() As Boolean - Return False - End Function - - _ - Protected Overrides Sub ReadXmlSerializable(ByVal reader As Global.System.Xml.XmlReader) - If (Me.DetermineSchemaSerializationMode(reader) = Global.System.Data.SchemaSerializationMode.IncludeSchema) Then - Me.Reset() - Dim ds As New Global.System.Data.DataSet() - ds.ReadXml(reader) - If (ds.Tables("Products") IsNot Nothing) Then - MyBase.Tables.Add(New ProductsDataTable(ds.Tables("Products"))) - End If - Me.DataSetName = ds.DataSetName - Me.Prefix = ds.Prefix - Me.Namespace = ds.Namespace - Me.Locale = ds.Locale - Me.CaseSensitive = ds.CaseSensitive - Me.EnforceConstraints = ds.EnforceConstraints - Me.Merge(ds, False, Global.System.Data.MissingSchemaAction.Add) - Me.InitVars() - Else - Me.ReadXml(reader) - Me.InitVars() - End If - End Sub - - _ - Protected Overrides Function GetSchemaSerializable() As Global.System.Xml.Schema.XmlSchema - Dim stream As New Global.System.IO.MemoryStream() - Me.WriteXmlSchema(New Global.System.Xml.XmlTextWriter(stream, Nothing)) - stream.Position = 0 - Return Global.System.Xml.Schema.XmlSchema.Read(New Global.System.Xml.XmlTextReader(stream), Nothing) - End Function - - _ - Friend Sub InitVars() - Me.InitVars(True) - End Sub - - _ - Friend Sub InitVars(ByVal initTable As Boolean) - Me.tableProducts = (CType(MyBase.Tables("Products"), ProductsDataTable)) - If (initTable = True) Then - If (Me.tableProducts IsNot Nothing) Then - Me.tableProducts.InitVars() - End If - End If - End Sub - - _ - Private Sub InitClass() - Me.DataSetName = "nwindDataSet" - Me.Prefix = "" - Me.Namespace = "http://tempuri.org/nwindDataSet.xsd" - Me.EnforceConstraints = True - Me.SchemaSerializationMode = Global.System.Data.SchemaSerializationMode.IncludeSchema - Me.tableProducts = New ProductsDataTable() - MyBase.Tables.Add(Me.tableProducts) - End Sub - - _ - Private Function ShouldSerializeProducts() As Boolean - Return False - End Function - - _ - Private Sub SchemaChanged(ByVal sender As Object, ByVal e As Global.System.ComponentModel.CollectionChangeEventArgs) - If (e.Action = Global.System.ComponentModel.CollectionChangeAction.Remove) Then - Me.InitVars() - End If - End Sub - - _ - Public Shared Function GetTypedDataSetSchema(ByVal xs As Global.System.Xml.Schema.XmlSchemaSet) As Global.System.Xml.Schema.XmlSchemaComplexType - Dim ds As New nwindDataSet() - Dim type As New Global.System.Xml.Schema.XmlSchemaComplexType() - Dim sequence As New Global.System.Xml.Schema.XmlSchemaSequence() - Dim any As New Global.System.Xml.Schema.XmlSchemaAny() - any.Namespace = ds.Namespace - sequence.Items.Add(any) - type.Particle = sequence - Dim dsSchema As Global.System.Xml.Schema.XmlSchema = ds.GetSchemaSerializable() - If xs.Contains(dsSchema.TargetNamespace) Then - Dim s1 As New Global.System.IO.MemoryStream() - Dim s2 As New Global.System.IO.MemoryStream() - Try - Dim schema As Global.System.Xml.Schema.XmlSchema = Nothing - dsSchema.Write(s1) - Dim schemas As System.Collections.IEnumerator = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator() - Do While schemas.MoveNext() - schema = (DirectCast(schemas.Current, Global.System.Xml.Schema.XmlSchema)) - s2.SetLength(0) - schema.Write(s2) - If (s1.Length = s2.Length) Then - s1.Position = 0 - s2.Position = 0 - Do While ((s1.Position <> s1.Length) AndAlso (s1.ReadByte() = s2.ReadByte())) - - Loop - If (s1.Position = s1.Length) Then - Return type - End If - End If - Loop - Finally - If (s1 IsNot Nothing) Then - s1.Close() - End If - If (s2 IsNot Nothing) Then - s2.Close() - End If - End Try - End If - xs.Add(dsSchema) - Return type - End Function - - Public Delegate Sub ProductsRowChangeEventHandler(ByVal sender As Object, ByVal e As ProductsRowChangeEvent) - - ''' - '''Represents the strongly named DataTable class. - ''' - _ - Partial Public Class ProductsDataTable - Inherits System.Data.TypedTableBase(Of ProductsRow) - - Private columnProductName As Global.System.Data.DataColumn - - Private columnUnitPrice As Global.System.Data.DataColumn - - Private columnUnitsInStock As Global.System.Data.DataColumn - - Private columnUnitsOnOrder As Global.System.Data.DataColumn - - _ - Public Sub New() - Me.TableName = "Products" - Me.BeginInit() - Me.InitClass() - Me.EndInit() - End Sub - - _ - Friend Sub New(ByVal table As Global.System.Data.DataTable) - Me.TableName = table.TableName - If (table.CaseSensitive <> table.DataSet.CaseSensitive) Then - Me.CaseSensitive = table.CaseSensitive - End If - If (table.Locale.ToString() <> table.DataSet.Locale.ToString()) Then - Me.Locale = table.Locale - End If - If (table.Namespace <> table.DataSet.Namespace) Then - Me.Namespace = table.Namespace - End If - Me.Prefix = table.Prefix - Me.MinimumCapacity = table.MinimumCapacity - End Sub - - _ - Protected Sub New(ByVal info As Global.System.Runtime.Serialization.SerializationInfo, ByVal context As Global.System.Runtime.Serialization.StreamingContext) - MyBase.New(info, context) - Me.InitVars() - End Sub - - _ - Public ReadOnly Property ProductNameColumn() As Global.System.Data.DataColumn - Get - Return Me.columnProductName - End Get - End Property - - _ - Public ReadOnly Property UnitPriceColumn() As Global.System.Data.DataColumn - Get - Return Me.columnUnitPrice - End Get - End Property - - _ - Public ReadOnly Property UnitsInStockColumn() As Global.System.Data.DataColumn - Get - Return Me.columnUnitsInStock - End Get - End Property - - _ - Public ReadOnly Property UnitsOnOrderColumn() As Global.System.Data.DataColumn - Get - Return Me.columnUnitsOnOrder - End Get - End Property - - _ - Public ReadOnly Property Count() As Integer - Get - Return Me.Rows.Count - End Get - End Property - - _ - Default Public ReadOnly Property Item(ByVal index As Integer) As ProductsRow - Get - Return (DirectCast(Me.Rows(index), ProductsRow)) - End Get - End Property - - Public Event ProductsRowChanging As ProductsRowChangeEventHandler - - Public Event ProductsRowChanged As ProductsRowChangeEventHandler - - Public Event ProductsRowDeleting As ProductsRowChangeEventHandler - - Public Event ProductsRowDeleted As ProductsRowChangeEventHandler - - _ - Public Sub AddProductsRow(ByVal row As ProductsRow) - Me.Rows.Add(row) - End Sub - - _ - Public Function AddProductsRow(ByVal ProductName As String, ByVal UnitPrice As Decimal, ByVal UnitsInStock As Short, ByVal UnitsOnOrder As Short) As ProductsRow - Dim rowProductsRow As ProductsRow = (DirectCast(Me.NewRow(), ProductsRow)) - Dim columnValuesArray() As Object = { ProductName, UnitPrice, UnitsInStock, UnitsOnOrder} - rowProductsRow.ItemArray = columnValuesArray - Me.Rows.Add(rowProductsRow) - Return rowProductsRow - End Function - - _ - Public Overrides Function Clone() As Global.System.Data.DataTable - Dim cln As ProductsDataTable = (DirectCast(MyBase.Clone(), ProductsDataTable)) - cln.InitVars() - Return cln - End Function - - _ - Protected Overrides Function CreateInstance() As Global.System.Data.DataTable - Return New ProductsDataTable() - End Function - - _ - Friend Sub InitVars() - Me.columnProductName = MyBase.Columns("ProductName") - Me.columnUnitPrice = MyBase.Columns("UnitPrice") - Me.columnUnitsInStock = MyBase.Columns("UnitsInStock") - Me.columnUnitsOnOrder = MyBase.Columns("UnitsOnOrder") - End Sub - - _ - Private Sub InitClass() - Me.columnProductName = New Global.System.Data.DataColumn("ProductName", GetType(String), Nothing, Global.System.Data.MappingType.Element) - MyBase.Columns.Add(Me.columnProductName) - Me.columnUnitPrice = New Global.System.Data.DataColumn("UnitPrice", GetType(Decimal), Nothing, Global.System.Data.MappingType.Element) - MyBase.Columns.Add(Me.columnUnitPrice) - Me.columnUnitsInStock = New Global.System.Data.DataColumn("UnitsInStock", GetType(Short), Nothing, Global.System.Data.MappingType.Element) - MyBase.Columns.Add(Me.columnUnitsInStock) - Me.columnUnitsOnOrder = New Global.System.Data.DataColumn("UnitsOnOrder", GetType(Short), Nothing, Global.System.Data.MappingType.Element) - MyBase.Columns.Add(Me.columnUnitsOnOrder) - Me.columnProductName.MaxLength = 40 - End Sub - - _ - Public Function NewProductsRow() As ProductsRow - Return (DirectCast(Me.NewRow(), ProductsRow)) - End Function - - _ - Protected Overrides Function NewRowFromBuilder(ByVal builder As Global.System.Data.DataRowBuilder) As Global.System.Data.DataRow - Return New ProductsRow(builder) - End Function - - _ - Protected Overrides Function GetRowType() As Global.System.Type - Return GetType(ProductsRow) - End Function - - _ - Protected Overrides Sub OnRowChanged(ByVal e As Global.System.Data.DataRowChangeEventArgs) - MyBase.OnRowChanged(e) - RaiseEvent ProductsRowChanged(Me, New ProductsRowChangeEvent((DirectCast(e.Row, ProductsRow)), e.Action)) - End Sub - - _ - Protected Overrides Sub OnRowChanging(ByVal e As Global.System.Data.DataRowChangeEventArgs) - MyBase.OnRowChanging(e) - RaiseEvent ProductsRowChanging(Me, New ProductsRowChangeEvent((DirectCast(e.Row, ProductsRow)), e.Action)) - End Sub - - _ - Protected Overrides Sub OnRowDeleted(ByVal e As Global.System.Data.DataRowChangeEventArgs) - MyBase.OnRowDeleted(e) - RaiseEvent ProductsRowDeleted(Me, New ProductsRowChangeEvent((DirectCast(e.Row, ProductsRow)), e.Action)) - End Sub - - _ - Protected Overrides Sub OnRowDeleting(ByVal e As Global.System.Data.DataRowChangeEventArgs) - MyBase.OnRowDeleting(e) - RaiseEvent ProductsRowDeleting(Me, New ProductsRowChangeEvent((DirectCast(e.Row, ProductsRow)), e.Action)) - End Sub - - _ - Public Sub RemoveProductsRow(ByVal row As ProductsRow) - Me.Rows.Remove(row) - End Sub - - _ - Public Shared Function GetTypedTableSchema(ByVal xs As Global.System.Xml.Schema.XmlSchemaSet) As Global.System.Xml.Schema.XmlSchemaComplexType - Dim type As New Global.System.Xml.Schema.XmlSchemaComplexType() - Dim sequence As New Global.System.Xml.Schema.XmlSchemaSequence() - Dim ds As New nwindDataSet() - Dim any1 As New Global.System.Xml.Schema.XmlSchemaAny() - any1.Namespace = "http://www.w3.org/2001/XMLSchema" - any1.MinOccurs = New Decimal(0) - any1.MaxOccurs = Decimal.MaxValue - any1.ProcessContents = Global.System.Xml.Schema.XmlSchemaContentProcessing.Lax - sequence.Items.Add(any1) - Dim any2 As New Global.System.Xml.Schema.XmlSchemaAny() - any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1" - any2.MinOccurs = New Decimal(1) - any2.ProcessContents = Global.System.Xml.Schema.XmlSchemaContentProcessing.Lax - sequence.Items.Add(any2) - Dim attribute1 As New Global.System.Xml.Schema.XmlSchemaAttribute() - attribute1.Name = "namespace" - attribute1.FixedValue = ds.Namespace - type.Attributes.Add(attribute1) - Dim attribute2 As New Global.System.Xml.Schema.XmlSchemaAttribute() - attribute2.Name = "tableTypeName" - attribute2.FixedValue = "ProductsDataTable" - type.Attributes.Add(attribute2) - type.Particle = sequence - Dim dsSchema As Global.System.Xml.Schema.XmlSchema = ds.GetSchemaSerializable() - If xs.Contains(dsSchema.TargetNamespace) Then - Dim s1 As New Global.System.IO.MemoryStream() - Dim s2 As New Global.System.IO.MemoryStream() - Try - Dim schema As Global.System.Xml.Schema.XmlSchema = Nothing - dsSchema.Write(s1) - Dim schemas As System.Collections.IEnumerator = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator() - Do While schemas.MoveNext() - schema = (DirectCast(schemas.Current, Global.System.Xml.Schema.XmlSchema)) - s2.SetLength(0) - schema.Write(s2) - If (s1.Length = s2.Length) Then - s1.Position = 0 - s2.Position = 0 - Do While ((s1.Position <> s1.Length) AndAlso (s1.ReadByte() = s2.ReadByte())) - - Loop - If (s1.Position = s1.Length) Then - Return type - End If - End If - Loop - Finally - If (s1 IsNot Nothing) Then - s1.Close() - End If - If (s2 IsNot Nothing) Then - s2.Close() - End If - End Try - End If - xs.Add(dsSchema) - Return type - End Function - End Class - - ''' - '''Represents strongly named DataRow class. - ''' - _ - Partial Public Class ProductsRow - Inherits System.Data.DataRow - - Private tableProducts As ProductsDataTable - - _ - Friend Sub New(ByVal rb As Global.System.Data.DataRowBuilder) - MyBase.New(rb) - Me.tableProducts = (CType(Me.Table, ProductsDataTable)) - End Sub - - _ - Public Property ProductName() As String - Get - Try - Return (DirectCast(Me(Me.tableProducts.ProductNameColumn), String)) - Catch e As Global.System.InvalidCastException - Throw New Global.System.Data.StrongTypingException("The value for column 'ProductName' in table 'Products' is DBNull.", e) - End Try - End Get - Set(ByVal value As String) - Me(Me.tableProducts.ProductNameColumn) = value - End Set - End Property - - _ - Public Property UnitPrice() As Decimal - Get - Try - Return (DirectCast(Me(Me.tableProducts.UnitPriceColumn), Decimal)) - Catch e As Global.System.InvalidCastException - Throw New Global.System.Data.StrongTypingException("The value for column 'UnitPrice' in table 'Products' is DBNull.", e) - End Try - End Get - Set(ByVal value As Decimal) - Me(Me.tableProducts.UnitPriceColumn) = value - End Set - End Property - - _ - Public Property UnitsInStock() As Short - Get - Try - Return (DirectCast(Me(Me.tableProducts.UnitsInStockColumn), Short)) - Catch e As Global.System.InvalidCastException - Throw New Global.System.Data.StrongTypingException("The value for column 'UnitsInStock' in table 'Products' is DBNull.", e) - End Try - End Get - Set(ByVal value As Short) - Me(Me.tableProducts.UnitsInStockColumn) = value - End Set - End Property - - _ - Public Property UnitsOnOrder() As Short - Get - Try - Return (DirectCast(Me(Me.tableProducts.UnitsOnOrderColumn), Short)) - Catch e As Global.System.InvalidCastException - Throw New Global.System.Data.StrongTypingException("The value for column 'UnitsOnOrder' in table 'Products' is DBNull.", e) - End Try - End Get - Set(ByVal value As Short) - Me(Me.tableProducts.UnitsOnOrderColumn) = value - End Set - End Property - - _ - Public Function IsProductNameNull() As Boolean - Return Me.IsNull(Me.tableProducts.ProductNameColumn) - End Function - - _ - Public Sub SetProductNameNull() - Me(Me.tableProducts.ProductNameColumn) = Global.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) = Global.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) = Global.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) = Global.System.Convert.DBNull - End Sub - End Class - - ''' - '''Row event argument class - ''' - _ - Public Class ProductsRowChangeEvent - Inherits System.EventArgs - - Private eventRow As ProductsRow - - Private eventAction As Global.System.Data.DataRowAction - - _ - Public Sub New(ByVal row As ProductsRow, ByVal action As Global.System.Data.DataRowAction) - 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 Global.System.Data.DataRowAction - Get - Return Me.eventAction - End Get - End Property - End Class - End Class + ''' + '''Represents a strongly typed in-memory cache of data. + ''' + + + + + + + + Partial Public Class nwindDataSet + Inherits System.Data.DataSet + + Private tableProducts As ProductsDataTable + + Private _schemaSerializationMode As System.Data.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema + + + Public Sub New() + Me.BeginInit() + Me.InitClass() + Dim schemaChangedHandler As New System.ComponentModel.CollectionChangeEventHandler(AddressOf Me.SchemaChanged) + AddHandler MyBase.Tables.CollectionChanged, schemaChangedHandler + AddHandler MyBase.Relations.CollectionChanged, schemaChangedHandler + Me.EndInit() + End Sub + + + Protected Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) + MyBase.New(info, context, False) + If (Me.IsBinarySerialized(info, context) = True) Then + Me.InitVars(False) + Dim schemaChangedHandler1 As New System.ComponentModel.CollectionChangeEventHandler(AddressOf Me.SchemaChanged) + AddHandler Me.Tables.CollectionChanged, schemaChangedHandler1 + AddHandler Me.Relations.CollectionChanged, schemaChangedHandler1 + Return + End If + Dim strSchema As String = (CStr(info.GetValue("XmlSchema", GetType(String)))) + If (Me.DetermineSchemaSerializationMode(info, context) = System.Data.SchemaSerializationMode.IncludeSchema) Then + Dim ds As New System.Data.DataSet() + ds.ReadXmlSchema(New System.Xml.XmlTextReader(New System.IO.StringReader(strSchema))) + If (ds.Tables("Products") IsNot Nothing) Then + MyBase.Tables.Add(New ProductsDataTable(ds.Tables("Products"))) + End If + Me.DataSetName = ds.DataSetName + Me.Prefix = ds.Prefix + Me.Namespace = ds.Namespace + Me.Locale = ds.Locale + Me.CaseSensitive = ds.CaseSensitive + Me.EnforceConstraints = ds.EnforceConstraints + Me.Merge(ds, False, System.Data.MissingSchemaAction.Add) + Me.InitVars() + Else + Me.ReadXmlSchema(New System.Xml.XmlTextReader(New System.IO.StringReader(strSchema))) + End If + Me.GetSerializationData(info, context) + Dim schemaChangedHandler As New System.ComponentModel.CollectionChangeEventHandler(AddressOf Me.SchemaChanged) + AddHandler MyBase.Tables.CollectionChanged, schemaChangedHandler + AddHandler Me.Relations.CollectionChanged, schemaChangedHandler + End Sub + + + + + Public ReadOnly Property Products() As ProductsDataTable + Get + Return Me.tableProducts + End Get + End Property + + + + + Public Overrides Property SchemaSerializationMode() As System.Data.SchemaSerializationMode + Get + Return Me._schemaSerializationMode + End Get + Set(ByVal value As System.Data.SchemaSerializationMode) + Me._schemaSerializationMode = value + End Set + End Property + + + + Public Shadows ReadOnly Property Tables() As System.Data.DataTableCollection + Get + Return MyBase.Tables + End Get + End Property + + + + Public Shadows ReadOnly Property Relations() As System.Data.DataRelationCollection + Get + Return MyBase.Relations + End Get + End Property + + + Protected Overrides Sub InitializeDerivedDataSet() + Me.BeginInit() + Me.InitClass() + Me.EndInit() + End Sub + + + Public Overrides Function Clone() As System.Data.DataSet + Dim cln As nwindDataSet = (CType(MyBase.Clone(), nwindDataSet)) + cln.InitVars() + cln.SchemaSerializationMode = Me.SchemaSerializationMode + Return cln + End Function + + + Protected Overrides Function ShouldSerializeTables() As Boolean + Return False + End Function + + + Protected Overrides Function ShouldSerializeRelations() As Boolean + Return False + End Function + + + Protected Overrides Sub ReadXmlSerializable(ByVal reader As System.Xml.XmlReader) + If (Me.DetermineSchemaSerializationMode(reader) = System.Data.SchemaSerializationMode.IncludeSchema) Then + Me.Reset() + Dim ds As New System.Data.DataSet() + ds.ReadXml(reader) + If (ds.Tables("Products") IsNot Nothing) Then + MyBase.Tables.Add(New ProductsDataTable(ds.Tables("Products"))) + End If + Me.DataSetName = ds.DataSetName + Me.Prefix = ds.Prefix + Me.Namespace = ds.Namespace + Me.Locale = ds.Locale + Me.CaseSensitive = ds.CaseSensitive + Me.EnforceConstraints = ds.EnforceConstraints + Me.Merge(ds, False, System.Data.MissingSchemaAction.Add) + Me.InitVars() + Else + Me.ReadXml(reader) + Me.InitVars() + End If + End Sub + + + Protected Overrides Function GetSchemaSerializable() As System.Xml.Schema.XmlSchema + Dim stream As New System.IO.MemoryStream() + Me.WriteXmlSchema(New System.Xml.XmlTextWriter(stream, Nothing)) + stream.Position = 0 + Return System.Xml.Schema.XmlSchema.Read(New System.Xml.XmlTextReader(stream), Nothing) + End Function + + + Friend Sub InitVars() + Me.InitVars(True) + End Sub + + + Friend Sub InitVars(ByVal initTable As Boolean) + Me.tableProducts = (CType(MyBase.Tables("Products"), ProductsDataTable)) + If (initTable = True) Then + If (Me.tableProducts IsNot Nothing) Then + Me.tableProducts.InitVars() + End If + End If + End Sub + + + Private Sub InitClass() + Me.DataSetName = "nwindDataSet" + Me.Prefix = "" + Me.Namespace = "http://tempuri.org/nwindDataSet.xsd" + Me.EnforceConstraints = True + Me.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema + Me.tableProducts = New ProductsDataTable() + MyBase.Tables.Add(Me.tableProducts) + End Sub + + + Private Function ShouldSerializeProducts() As Boolean + Return False + End Function + + + Private Sub SchemaChanged(ByVal sender As Object, ByVal e As System.ComponentModel.CollectionChangeEventArgs) + If (e.Action = System.ComponentModel.CollectionChangeAction.Remove) Then + Me.InitVars() + End If + End Sub + + + Public Shared Function GetTypedDataSetSchema(ByVal xs As System.Xml.Schema.XmlSchemaSet) As System.Xml.Schema.XmlSchemaComplexType + Dim ds As New nwindDataSet() + Dim type As New System.Xml.Schema.XmlSchemaComplexType() + Dim sequence As New System.Xml.Schema.XmlSchemaSequence() + Dim any As New System.Xml.Schema.XmlSchemaAny() + any.Namespace = ds.Namespace + sequence.Items.Add(any) + type.Particle = sequence + Dim dsSchema As System.Xml.Schema.XmlSchema = ds.GetSchemaSerializable() + If xs.Contains(dsSchema.TargetNamespace) Then + Dim s1 As New System.IO.MemoryStream() + Dim s2 As New System.IO.MemoryStream() + Try + Dim schema As System.Xml.Schema.XmlSchema = Nothing + dsSchema.Write(s1) + Dim schemas As System.Collections.IEnumerator = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator() + Do While schemas.MoveNext() + schema = (CType(schemas.Current, System.Xml.Schema.XmlSchema)) + s2.SetLength(0) + schema.Write(s2) + If (s1.Length = s2.Length) Then + s1.Position = 0 + s2.Position = 0 + Do While ((s1.Position <> s1.Length) AndAlso (s1.ReadByte() = s2.ReadByte())) + + Loop + If (s1.Position = s1.Length) Then + Return type + End If + End If + Loop + Finally + If (s1 IsNot Nothing) Then + s1.Close() + End If + If (s2 IsNot Nothing) Then + s2.Close() + End If + End Try + End If + xs.Add(dsSchema) + Return type + End Function + + Public Delegate Sub ProductsRowChangeEventHandler(ByVal sender As Object, ByVal e As ProductsRowChangeEvent) + + ''' + '''Represents the strongly named DataTable class. + ''' + + + + Partial Public Class ProductsDataTable + Inherits System.Data.TypedTableBase(Of ProductsRow) + + Private columnProductName As System.Data.DataColumn + + Private columnUnitPrice As System.Data.DataColumn + + Private columnUnitsInStock As System.Data.DataColumn + + Private columnUnitsOnOrder As System.Data.DataColumn + + + Public Sub New() + Me.TableName = "Products" + Me.BeginInit() + Me.InitClass() + Me.EndInit() + End Sub + + + Friend Sub New(ByVal table As System.Data.DataTable) + Me.TableName = table.TableName + If (table.CaseSensitive <> table.DataSet.CaseSensitive) Then + Me.CaseSensitive = table.CaseSensitive + End If + If (table.Locale.ToString() <> table.DataSet.Locale.ToString()) Then + Me.Locale = table.Locale + End If + If (table.Namespace <> table.DataSet.Namespace) Then + Me.Namespace = table.Namespace + End If + Me.Prefix = table.Prefix + Me.MinimumCapacity = table.MinimumCapacity + End Sub + + + Protected Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext) + MyBase.New(info, context) + Me.InitVars() + End Sub + + + Public ReadOnly Property ProductNameColumn() As System.Data.DataColumn + Get + Return Me.columnProductName + End Get + End Property + + + Public ReadOnly Property UnitPriceColumn() As System.Data.DataColumn + Get + Return Me.columnUnitPrice + End Get + End Property + + + Public ReadOnly Property UnitsInStockColumn() As System.Data.DataColumn + Get + Return Me.columnUnitsInStock + End Get + End Property + + + Public ReadOnly Property UnitsOnOrderColumn() As System.Data.DataColumn + Get + Return Me.columnUnitsOnOrder + End Get + End Property + + + + Public ReadOnly Property Count() As Integer + Get + Return Me.Rows.Count + End Get + End Property + + + Default Public ReadOnly Property Item(ByVal index As Integer) As ProductsRow + Get + Return (CType(Me.Rows(index), ProductsRow)) + End Get + End Property + + Public Event ProductsRowChanging As ProductsRowChangeEventHandler + + Public Event ProductsRowChanged As ProductsRowChangeEventHandler + + Public Event ProductsRowDeleting As ProductsRowChangeEventHandler + + Public Event ProductsRowDeleted As ProductsRowChangeEventHandler + + + Public Sub AddProductsRow(ByVal row As ProductsRow) + Me.Rows.Add(row) + End Sub + + + Public Function AddProductsRow(ByVal ProductName As String, ByVal UnitPrice As Decimal, ByVal UnitsInStock As Short, ByVal UnitsOnOrder As Short) As ProductsRow + Dim rowProductsRow As ProductsRow = (CType(Me.NewRow(), ProductsRow)) + Dim columnValuesArray() As Object = { ProductName, UnitPrice, UnitsInStock, UnitsOnOrder} + rowProductsRow.ItemArray = columnValuesArray + Me.Rows.Add(rowProductsRow) + Return rowProductsRow + End Function + + + Public Overrides Function Clone() As System.Data.DataTable + Dim cln As ProductsDataTable = (CType(MyBase.Clone(), ProductsDataTable)) + cln.InitVars() + Return cln + End Function + + + Protected Overrides Function CreateInstance() As System.Data.DataTable + Return New ProductsDataTable() + End Function + + + Friend Sub InitVars() + Me.columnProductName = MyBase.Columns("ProductName") + Me.columnUnitPrice = MyBase.Columns("UnitPrice") + Me.columnUnitsInStock = MyBase.Columns("UnitsInStock") + Me.columnUnitsOnOrder = MyBase.Columns("UnitsOnOrder") + End Sub + + + Private Sub InitClass() + Me.columnProductName = New System.Data.DataColumn("ProductName", GetType(String), Nothing, System.Data.MappingType.Element) + MyBase.Columns.Add(Me.columnProductName) + Me.columnUnitPrice = New System.Data.DataColumn("UnitPrice", GetType(Decimal), Nothing, System.Data.MappingType.Element) + MyBase.Columns.Add(Me.columnUnitPrice) + Me.columnUnitsInStock = New System.Data.DataColumn("UnitsInStock", GetType(Short), Nothing, System.Data.MappingType.Element) + MyBase.Columns.Add(Me.columnUnitsInStock) + Me.columnUnitsOnOrder = New System.Data.DataColumn("UnitsOnOrder", GetType(Short), Nothing, System.Data.MappingType.Element) + MyBase.Columns.Add(Me.columnUnitsOnOrder) + Me.columnProductName.MaxLength = 40 + End Sub + + + Public Function NewProductsRow() As ProductsRow + Return (CType(Me.NewRow(), ProductsRow)) + End Function + + + Protected Overrides Function NewRowFromBuilder(ByVal builder As System.Data.DataRowBuilder) As System.Data.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 System.Data.DataRowChangeEventArgs) + MyBase.OnRowChanged(e) + RaiseEvent ProductsRowChanged(Me, New ProductsRowChangeEvent((CType(e.Row, ProductsRow)), e.Action)) + End Sub + + + Protected Overrides Sub OnRowChanging(ByVal e As System.Data.DataRowChangeEventArgs) + MyBase.OnRowChanging(e) + RaiseEvent ProductsRowChanging(Me, New ProductsRowChangeEvent((CType(e.Row, ProductsRow)), e.Action)) + End Sub + + + Protected Overrides Sub OnRowDeleted(ByVal e As System.Data.DataRowChangeEventArgs) + MyBase.OnRowDeleted(e) + RaiseEvent ProductsRowDeleted(Me, New ProductsRowChangeEvent((CType(e.Row, ProductsRow)), e.Action)) + End Sub + + + Protected Overrides Sub OnRowDeleting(ByVal e As System.Data.DataRowChangeEventArgs) + MyBase.OnRowDeleting(e) + RaiseEvent ProductsRowDeleting(Me, New ProductsRowChangeEvent((CType(e.Row, ProductsRow)), e.Action)) + End Sub + + + Public Sub RemoveProductsRow(ByVal row As ProductsRow) + Me.Rows.Remove(row) + End Sub + + + Public Shared Function GetTypedTableSchema(ByVal xs As System.Xml.Schema.XmlSchemaSet) As System.Xml.Schema.XmlSchemaComplexType + Dim type As New System.Xml.Schema.XmlSchemaComplexType() + Dim sequence As New System.Xml.Schema.XmlSchemaSequence() + Dim ds As New nwindDataSet() + Dim any1 As New System.Xml.Schema.XmlSchemaAny() + any1.Namespace = "http://www.w3.org/2001/XMLSchema" + any1.MinOccurs = New Decimal(0) + any1.MaxOccurs = Decimal.MaxValue + any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax + sequence.Items.Add(any1) + Dim any2 As New System.Xml.Schema.XmlSchemaAny() + any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1" + any2.MinOccurs = New Decimal(1) + any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax + sequence.Items.Add(any2) + Dim attribute1 As New System.Xml.Schema.XmlSchemaAttribute() + attribute1.Name = "namespace" + attribute1.FixedValue = ds.Namespace + type.Attributes.Add(attribute1) + Dim attribute2 As New System.Xml.Schema.XmlSchemaAttribute() + attribute2.Name = "tableTypeName" + attribute2.FixedValue = "ProductsDataTable" + type.Attributes.Add(attribute2) + type.Particle = sequence + Dim dsSchema As System.Xml.Schema.XmlSchema = ds.GetSchemaSerializable() + If xs.Contains(dsSchema.TargetNamespace) Then + Dim s1 As New System.IO.MemoryStream() + Dim s2 As New System.IO.MemoryStream() + Try + Dim schema As System.Xml.Schema.XmlSchema = Nothing + dsSchema.Write(s1) + Dim schemas As System.Collections.IEnumerator = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator() + Do While schemas.MoveNext() + schema = (CType(schemas.Current, System.Xml.Schema.XmlSchema)) + s2.SetLength(0) + schema.Write(s2) + If (s1.Length = s2.Length) Then + s1.Position = 0 + s2.Position = 0 + Do While ((s1.Position <> s1.Length) AndAlso (s1.ReadByte() = s2.ReadByte())) + + Loop + If (s1.Position = s1.Length) Then + Return type + End If + End If + Loop + Finally + If (s1 IsNot Nothing) Then + s1.Close() + End If + If (s2 IsNot Nothing) Then + s2.Close() + End If + End Try + End If + xs.Add(dsSchema) + Return type + End Function + End Class + + ''' + '''Represents strongly named DataRow class. + ''' + + Partial Public Class ProductsRow + Inherits System.Data.DataRow + + Private tableProducts As ProductsDataTable + + + Friend Sub New(ByVal rb As System.Data.DataRowBuilder) + MyBase.New(rb) + Me.tableProducts = (CType(Me.Table, ProductsDataTable)) + End Sub + + + Public Property ProductName() As String + Get + Try + Return (CStr(Me(Me.tableProducts.ProductNameColumn))) + Catch e As System.InvalidCastException + Throw New System.Data.StrongTypingException("The value for column 'ProductName' in table 'Products' is DBNull.", e) + End Try + End Get + Set(ByVal value As String) + Me(Me.tableProducts.ProductNameColumn) = value + End Set + End Property + + + Public Property UnitPrice() As Decimal + Get + Try + Return (CDec(Me(Me.tableProducts.UnitPriceColumn))) + Catch e As System.InvalidCastException + Throw New System.Data.StrongTypingException("The value for column 'UnitPrice' in table 'Products' is DBNull.", e) + End Try + End Get + Set(ByVal value As Decimal) + Me(Me.tableProducts.UnitPriceColumn) = value + End Set + End Property + + + Public Property UnitsInStock() As Short + Get + Try + Return (CShort(Me(Me.tableProducts.UnitsInStockColumn))) + Catch e As System.InvalidCastException + Throw New System.Data.StrongTypingException("The value for column 'UnitsInStock' in table 'Products' is DBNull.", e) + End Try + End Get + Set(ByVal value As Short) + Me(Me.tableProducts.UnitsInStockColumn) = value + End Set + End Property + + + Public Property UnitsOnOrder() As Short + Get + Try + Return (CShort(Me(Me.tableProducts.UnitsOnOrderColumn))) + Catch e As System.InvalidCastException + Throw New System.Data.StrongTypingException("The value for column 'UnitsOnOrder' in table 'Products' is DBNull.", e) + End Try + End Get + Set(ByVal value As Short) + Me(Me.tableProducts.UnitsOnOrderColumn) = value + End Set + End Property + + + 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 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 + End Class + + ''' + '''Row event argument class + ''' + + Public Class ProductsRowChangeEvent + Inherits System.EventArgs + + Private eventRow As ProductsRow + + Private eventAction As System.Data.DataRowAction + + + Public Sub New(ByVal row As ProductsRow, ByVal action As System.Data.DataRowAction) + 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 System.Data.DataRowAction + Get + Return Me.eventAction + End Get + End Property + End Class + End Class End Namespace Namespace DXGrid_ShowCheckBoxInColumnHeaders.nwindDataSetTableAdapters - ''' - '''Represents the connection and commands used to retrieve and save data. - ''' - _ - Partial Public Class ProductsTableAdapter - Inherits System.ComponentModel.Component - - Private _adapter As Global.System.Data.OleDb.OleDbDataAdapter - - Private _connection As Global.System.Data.OleDb.OleDbConnection - - Private _transaction As Global.System.Data.OleDb.OleDbTransaction - - Private _commandCollection() As Global.System.Data.OleDb.OleDbCommand - - Private _clearBeforeFill As Boolean - - _ - Public Sub New() - Me.ClearBeforeFill = True - End Sub - - _ - Protected Friend ReadOnly Property Adapter() As Global.System.Data.OleDb.OleDbDataAdapter - Get - If (Me._adapter Is Nothing) Then - Me.InitAdapter() - End If - Return Me._adapter - End Get - End Property - - _ - Friend Property Connection() As Global.System.Data.OleDb.OleDbConnection - Get - If (Me._connection Is Nothing) Then - Me.InitConnection() - End If - Return Me._connection - End Get - Set(ByVal value As System.Data.OleDb.OleDbConnection) - Me._connection = value - If (Me.Adapter.InsertCommand IsNot Nothing) Then - Me.Adapter.InsertCommand.Connection = value - End If - If (Me.Adapter.DeleteCommand IsNot Nothing) Then - Me.Adapter.DeleteCommand.Connection = value - End If - If (Me.Adapter.UpdateCommand IsNot Nothing) Then - Me.Adapter.UpdateCommand.Connection = value - End If - Dim i As Integer = 0 - Do While (i < Me.CommandCollection.Length) - If (Me.CommandCollection(i) IsNot Nothing) Then - CType(Me.CommandCollection(i), Global.System.Data.OleDb.OleDbCommand).Connection = value - End If - i = (i + 1) - Loop - End Set - End Property - - _ - Friend Property Transaction() As Global.System.Data.OleDb.OleDbTransaction - Get - Return Me._transaction - End Get - Set(ByVal value As System.Data.OleDb.OleDbTransaction) - Me._transaction = value - Dim i As Integer = 0 - Do While (i < Me.CommandCollection.Length) - Me.CommandCollection(i).Transaction = Me._transaction - i = (i + 1) - Loop - If ((Me.Adapter IsNot Nothing) AndAlso (Me.Adapter.DeleteCommand IsNot Nothing)) Then - Me.Adapter.DeleteCommand.Transaction = Me._transaction - End If - If ((Me.Adapter IsNot Nothing) AndAlso (Me.Adapter.InsertCommand IsNot Nothing)) Then - Me.Adapter.InsertCommand.Transaction = Me._transaction - End If - If ((Me.Adapter IsNot Nothing) AndAlso (Me.Adapter.UpdateCommand IsNot Nothing)) Then - Me.Adapter.UpdateCommand.Transaction = Me._transaction - End If - End Set - End Property - - _ - Protected ReadOnly Property CommandCollection() As Global.System.Data.OleDb.OleDbCommand() - Get - If (Me._commandCollection Is Nothing) Then - Me.InitCommandCollection() - End If - Return Me._commandCollection - End Get - End Property - - _ - Public Property ClearBeforeFill() As Boolean - Get - Return Me._clearBeforeFill - End Get - Set(ByVal value As Boolean) - Me._clearBeforeFill = value - End Set - End Property - - _ - Private Sub InitAdapter() - Me._adapter = New Global.System.Data.OleDb.OleDbDataAdapter() - Dim tableMapping As New Global.System.Data.Common.DataTableMapping() - tableMapping.SourceTable = "Table" - tableMapping.DataSetTable = "Products" - tableMapping.ColumnMappings.Add("ProductName", "ProductName") - tableMapping.ColumnMappings.Add("UnitPrice", "UnitPrice") - tableMapping.ColumnMappings.Add("UnitsInStock", "UnitsInStock") - tableMapping.ColumnMappings.Add("UnitsOnOrder", "UnitsOnOrder") - Me._adapter.TableMappings.Add(tableMapping) - End Sub - - _ - Private Sub InitConnection() - Me._connection = New Global.System.Data.OleDb.OleDbConnection() - Me._connection.ConnectionString = My.Settings.Default.nwindConnectionString - End Sub - - _ - Private Sub InitCommandCollection() - Me._commandCollection = New Global.System.Data.OleDb.OleDbCommand(0){} - Me._commandCollection(0) = New Global.System.Data.OleDb.OleDbCommand() - Me._commandCollection(0).Connection = Me.Connection - Me._commandCollection(0).CommandText = "SELECT ProductName, UnitPrice, UnitsInStock, UnitsOnOrder FROM Products" - Me._commandCollection(0).CommandType = Global.System.Data.CommandType.Text - End Sub - - _ - Public Overridable Function Fill(ByVal dataTable As nwindDataSet.ProductsDataTable) As Integer - Me.Adapter.SelectCommand = Me.CommandCollection(0) - If (Me.ClearBeforeFill = True) Then - dataTable.Clear() - End If - Dim returnValue As Integer = Me.Adapter.Fill(dataTable) - Return returnValue - End Function - - _ - Public Overridable Function GetData() As nwindDataSet.ProductsDataTable - Me.Adapter.SelectCommand = Me.CommandCollection(0) - Dim dataTable As New nwindDataSet.ProductsDataTable() - Me.Adapter.Fill(dataTable) - Return dataTable - End Function - End Class - - ''' - '''TableAdapterManager is used to coordinate TableAdapters in the dataset to enable Hierarchical Update scenarios - ''' - _ - Partial Public Class TableAdapterManager - Inherits System.ComponentModel.Component - - Private _updateOrder As UpdateOrderOption - - Private _backupDataSetBeforeUpdate As Boolean - - Private _connection As Global.System.Data.IDbConnection - - _ - Public Property UpdateOrder() As UpdateOrderOption - Get - Return Me._updateOrder - End Get - Set(ByVal value As UpdateOrderOption) - Me._updateOrder = value - End Set - End Property - - _ - Public Property BackupDataSetBeforeUpdate() As Boolean - Get - Return Me._backupDataSetBeforeUpdate - End Get - Set(ByVal value As Boolean) - Me._backupDataSetBeforeUpdate = value - End Set - End Property - - _ - Public Property Connection() As Global.System.Data.IDbConnection - Get - If (Me._connection IsNot Nothing) Then - Return Me._connection - End If - Return Nothing - End Get - Set(ByVal value As System.Data.IDbConnection) - Me._connection = value - End Set - End Property - - _ - Public ReadOnly Property TableAdapterInstanceCount() As Integer - Get - Dim count As Integer = 0 - Return count - End Get - End Property - - ''' - '''Update rows in top-down order. - ''' - _ - Private Function UpdateUpdatedRows(ByVal dataSet As nwindDataSet, ByVal allChangedRows As Global.System.Collections.Generic.List(Of Global.System.Data.DataRow), ByVal allAddedRows As Global.System.Collections.Generic.List(Of Global.System.Data.DataRow)) As Integer - Dim result As Integer = 0 - Return result - End Function - - ''' - '''Insert rows in top-down order. - ''' - _ - Private Function UpdateInsertedRows(ByVal dataSet As nwindDataSet, ByVal allAddedRows As Global.System.Collections.Generic.List(Of Global.System.Data.DataRow)) As Integer - Dim result As Integer = 0 - Return result - End Function - - ''' - '''Delete rows in bottom-up order. - ''' - _ - Private Function UpdateDeletedRows(ByVal dataSet As nwindDataSet, ByVal allChangedRows As Global.System.Collections.Generic.List(Of Global.System.Data.DataRow)) As Integer - Dim result As Integer = 0 - Return result - End Function - - ''' - '''Remove inserted rows that become updated rows after calling TableAdapter.Update(inserted rows) first - ''' - _ - Private Function GetRealUpdatedRows(ByVal updatedRows() As Global.System.Data.DataRow, ByVal allAddedRows As Global.System.Collections.Generic.List(Of Global.System.Data.DataRow)) As Global.System.Data.DataRow() - If ((updatedRows Is Nothing) OrElse (updatedRows.Length < 1)) Then - Return updatedRows - End If - If ((allAddedRows Is Nothing) OrElse (allAddedRows.Count < 1)) Then - Return updatedRows - End If - Dim realUpdatedRows As New Global.System.Collections.Generic.List(Of Global.System.Data.DataRow)() - Dim i As Integer = 0 - Do While (i < updatedRows.Length) - Dim row As Global.System.Data.DataRow = updatedRows(i) - If (allAddedRows.Contains(row) = False) Then - realUpdatedRows.Add(row) - End If - i = (i + 1) - Loop - Return realUpdatedRows.ToArray() - End Function - - ''' - '''Update all changes to the dataset. - ''' - _ - Public Overridable Function UpdateAll(ByVal dataSet As nwindDataSet) As Integer - If (dataSet Is Nothing) Then - Throw New Global.System.ArgumentNullException("dataSet") - End If - If (dataSet.HasChanges() = False) Then - Return 0 - End If - Dim workConnection As Global.System.Data.IDbConnection = Me.Connection - If (workConnection Is Nothing) Then - Throw New Global.System.ApplicationException("TableAdapterManager contains no connection information. Set each TableAdapterMana" & "ger TableAdapter property to a valid TableAdapter instance.") - End If - Dim workConnOpened As Boolean = False - If ((workConnection.State And Global.System.Data.ConnectionState.Broken) = Global.System.Data.ConnectionState.Broken) Then - workConnection.Close() - End If - If (workConnection.State = Global.System.Data.ConnectionState.Closed) Then - workConnection.Open() - workConnOpened = True - End If - Dim workTransaction As Global.System.Data.IDbTransaction = workConnection.BeginTransaction() - If (workTransaction Is Nothing) Then - Throw New Global.System.ApplicationException("The transaction cannot begin. The current data connection does not support transa" & "ctions or the current state is not allowing the transaction to begin.") - End If - Dim allChangedRows As New Global.System.Collections.Generic.List(Of Global.System.Data.DataRow)() - Dim allAddedRows As New Global.System.Collections.Generic.List(Of Global.System.Data.DataRow)() - Dim adaptersWithAcceptChangesDuringUpdate As New Global.System.Collections.Generic.List(Of Global.System.Data.Common.DataAdapter)() - Dim revertConnections As New Global.System.Collections.Generic.Dictionary(Of Object, Global.System.Data.IDbConnection)() - Dim result As Integer = 0 - Dim backupDataSet As Global.System.Data.DataSet = Nothing - If Me.BackupDataSetBeforeUpdate Then - backupDataSet = New Global.System.Data.DataSet() - backupDataSet.Merge(dataSet) - End If - Try - ' ---- Prepare for update ----------- - ' - ' - '---- Perform updates ----------- - ' - If (Me.UpdateOrder = UpdateOrderOption.UpdateInsertDelete) Then - result = (result + Me.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows)) - result = (result + Me.UpdateInsertedRows(dataSet, allAddedRows)) - Else - result = (result + Me.UpdateInsertedRows(dataSet, allAddedRows)) - result = (result + Me.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows)) - End If - result = (result + Me.UpdateDeletedRows(dataSet, allChangedRows)) - ' - '---- Commit updates ----------- - ' - workTransaction.Commit() - If (0 < allAddedRows.Count) Then - Dim rows(allAddedRows.Count - 1) As Global.System.Data.DataRow - allAddedRows.CopyTo(rows) - Dim i As Integer = 0 - Do While (i < rows.Length) - Dim row As Global.System.Data.DataRow = rows(i) - row.AcceptChanges() - i = (i + 1) - Loop - End If - If (0 < allChangedRows.Count) Then - Dim rows(allChangedRows.Count - 1) As Global.System.Data.DataRow - allChangedRows.CopyTo(rows) - Dim i As Integer = 0 - Do While (i < rows.Length) - Dim row As Global.System.Data.DataRow = rows(i) - row.AcceptChanges() - i = (i + 1) - Loop - End If - Catch ex As Global.System.Exception - workTransaction.Rollback() - ' ---- Restore the dataset ----------- - If Me.BackupDataSetBeforeUpdate Then - Global.System.Diagnostics.Debug.Assert((backupDataSet IsNot Nothing)) - dataSet.Clear() - dataSet.Merge(backupDataSet) - Else - If (0 < allAddedRows.Count) Then - Dim rows(allAddedRows.Count - 1) As Global.System.Data.DataRow - allAddedRows.CopyTo(rows) - Dim i As Integer = 0 - Do While (i < rows.Length) - Dim row As Global.System.Data.DataRow = rows(i) - row.AcceptChanges() - row.SetAdded() - i = (i + 1) - Loop - End If - End If - Throw ex - Finally - If workConnOpened Then - workConnection.Close() - End If - If (0 < adaptersWithAcceptChangesDuringUpdate.Count) Then - Dim adapters(adaptersWithAcceptChangesDuringUpdate.Count - 1) As Global.System.Data.Common.DataAdapter - adaptersWithAcceptChangesDuringUpdate.CopyTo(adapters) - Dim i As Integer = 0 - Do While (i < adapters.Length) - Dim adapter As Global.System.Data.Common.DataAdapter = adapters(i) - adapter.AcceptChangesDuringUpdate = True - i = (i + 1) - Loop - End If - End Try - Return result - End Function - - _ - Protected Overridable Sub SortSelfReferenceRows(ByVal rows() As Global.System.Data.DataRow, ByVal relation As Global.System.Data.DataRelation, ByVal childFirst As Boolean) - Global.System.Array.Sort(Of Global.System.Data.DataRow)(rows, New SelfReferenceComparer(relation, childFirst)) - End Sub - - _ - Protected Overridable Function MatchTableAdapterConnection(ByVal inputConnection As Global.System.Data.IDbConnection) As Boolean - If (Me._connection IsNot Nothing) Then - Return True - End If - If ((Me.Connection Is Nothing) OrElse (inputConnection Is Nothing)) Then - Return True - End If - If String.Equals(Me.Connection.ConnectionString, inputConnection.ConnectionString, Global.System.StringComparison.Ordinal) Then - Return True - End If - Return False - End Function - - ''' - '''Update Order Option - ''' - _ - Public Enum UpdateOrderOption - - InsertUpdateDelete = 0 - - UpdateInsertDelete = 1 - End Enum - - ''' - '''Used to sort self-referenced table's rows - ''' - _ - Private Class SelfReferenceComparer - Inherits Object - Implements System.Collections.Generic.IComparer(Of System.Data.DataRow) - - Private _relation As Global.System.Data.DataRelation - - Private _childFirst As Integer - - _ - Friend Sub New(ByVal relation As Global.System.Data.DataRelation, ByVal childFirst As Boolean) - Me._relation = relation - If childFirst Then - Me._childFirst = -1 - Else - Me._childFirst = 1 - End If - End Sub - - _ - Private Function IsChildAndParent(ByVal child As Global.System.Data.DataRow, ByVal parent As Global.System.Data.DataRow) As Boolean - Global.System.Diagnostics.Debug.Assert((child IsNot Nothing)) - Global.System.Diagnostics.Debug.Assert((parent IsNot Nothing)) - Dim newParent As Global.System.Data.DataRow = child.GetParentRow(Me._relation, Global.System.Data.DataRowVersion.Default) - Do While ((newParent IsNot Nothing) AndAlso ((Object.ReferenceEquals(newParent, child) = False) AndAlso (Object.ReferenceEquals(newParent, parent) = False))) - newParent = newParent.GetParentRow(Me._relation, Global.System.Data.DataRowVersion.Default) - Loop - If (newParent Is Nothing) Then - newParent = child.GetParentRow(Me._relation, System.Data.DataRowVersion.Original) - Do While ((newParent IsNot Nothing) AndAlso ((Object.ReferenceEquals(newParent, child) = False) AndAlso (Object.ReferenceEquals(newParent, parent) = False))) - newParent = newParent.GetParentRow(Me._relation, Global.System.Data.DataRowVersion.Original) - Loop - End If - If Object.ReferenceEquals(newParent, parent) Then - Return True - End If - Return False - End Function - - _ - Public Function Compare(ByVal row1 As Global.System.Data.DataRow, ByVal row2 As Global.System.Data.DataRow) As Integer Implements IComparer(Of Global.System.Data.DataRow).Compare - If Object.ReferenceEquals(row1, row2) Then - Return 0 - End If - If (row1 Is Nothing) Then - Return -1 - End If - If (row2 Is Nothing) Then - Return 1 - End If - - ' Is row1 the child or grandchild of row2 - If Me.IsChildAndParent(row1, row2) Then - Return Me._childFirst - End If - - ' Is row2 the child or grandchild of row1 - If Me.IsChildAndParent(row2, row1) Then - Return (-1 * Me._childFirst) - End If - Return 0 - End Function - End Class - End Class + ''' + '''Represents the connection and commands used to retrieve and save data. + ''' + + + + + + + Partial Public Class ProductsTableAdapter + Inherits System.ComponentModel.Component + + Private _adapter As System.Data.OleDb.OleDbDataAdapter + + Private _connection As System.Data.OleDb.OleDbConnection + + Private _transaction As System.Data.OleDb.OleDbTransaction + + Private _commandCollection() As System.Data.OleDb.OleDbCommand + + Private _clearBeforeFill As Boolean + + + Public Sub New() + Me.ClearBeforeFill = True + End Sub + + + Protected Friend ReadOnly Property Adapter() As System.Data.OleDb.OleDbDataAdapter + Get + If (Me._adapter Is Nothing) Then + Me.InitAdapter() + End If + Return Me._adapter + End Get + End Property + + + Friend Property Connection() As System.Data.OleDb.OleDbConnection + Get + If (Me._connection Is Nothing) Then + Me.InitConnection() + End If + Return Me._connection + End Get + Set(ByVal value As System.Data.OleDb.OleDbConnection) + Me._connection = value + If (Me.Adapter.InsertCommand IsNot Nothing) Then + Me.Adapter.InsertCommand.Connection = value + End If + If (Me.Adapter.DeleteCommand IsNot Nothing) Then + Me.Adapter.DeleteCommand.Connection = value + End If + If (Me.Adapter.UpdateCommand IsNot Nothing) Then + Me.Adapter.UpdateCommand.Connection = value + End If + Dim i As Integer = 0 + Do While (i < Me.CommandCollection.Length) + If (Me.CommandCollection(i) IsNot Nothing) Then + CType(Me.CommandCollection(i), System.Data.OleDb.OleDbCommand).Connection = value + End If + i = (i + 1) + Loop + End Set + End Property + + + Friend Property Transaction() As System.Data.OleDb.OleDbTransaction + Get + Return Me._transaction + End Get + Set(ByVal value As System.Data.OleDb.OleDbTransaction) + Me._transaction = value + Dim i As Integer = 0 + Do While (i < Me.CommandCollection.Length) + Me.CommandCollection(i).Transaction = Me._transaction + i = (i + 1) + Loop + If ((Me.Adapter IsNot Nothing) AndAlso (Me.Adapter.DeleteCommand IsNot Nothing)) Then + Me.Adapter.DeleteCommand.Transaction = Me._transaction + End If + If ((Me.Adapter IsNot Nothing) AndAlso (Me.Adapter.InsertCommand IsNot Nothing)) Then + Me.Adapter.InsertCommand.Transaction = Me._transaction + End If + If ((Me.Adapter IsNot Nothing) AndAlso (Me.Adapter.UpdateCommand IsNot Nothing)) Then + Me.Adapter.UpdateCommand.Transaction = Me._transaction + End If + End Set + End Property + + + Protected ReadOnly Property CommandCollection() As System.Data.OleDb.OleDbCommand() + Get + If (Me._commandCollection Is Nothing) Then + Me.InitCommandCollection() + End If + Return Me._commandCollection + End Get + End Property + + + Public Property ClearBeforeFill() As Boolean + Get + Return Me._clearBeforeFill + End Get + Set(ByVal value As Boolean) + Me._clearBeforeFill = value + End Set + End Property + + + Private Sub InitAdapter() + Me._adapter = New System.Data.OleDb.OleDbDataAdapter() + Dim tableMapping As New System.Data.Common.DataTableMapping() + tableMapping.SourceTable = "Table" + tableMapping.DataSetTable = "Products" + tableMapping.ColumnMappings.Add("ProductName", "ProductName") + tableMapping.ColumnMappings.Add("UnitPrice", "UnitPrice") + tableMapping.ColumnMappings.Add("UnitsInStock", "UnitsInStock") + tableMapping.ColumnMappings.Add("UnitsOnOrder", "UnitsOnOrder") + Me._adapter.TableMappings.Add(tableMapping) + End Sub + + + Private Sub InitConnection() + Me._connection = New System.Data.OleDb.OleDbConnection() + Me._connection.ConnectionString = Global.DXGrid_ShowCheckBoxInColumnHeaders.Properties.Settings.Default.nwindConnectionString + End Sub + + + Private Sub InitCommandCollection() + Me._commandCollection = New System.Data.OleDb.OleDbCommand(0){} + Me._commandCollection(0) = New System.Data.OleDb.OleDbCommand() + Me._commandCollection(0).Connection = Me.Connection + Me._commandCollection(0).CommandText = "SELECT ProductName, UnitPrice, UnitsInStock, UnitsOnOrder FROM Products" + Me._commandCollection(0).CommandType = System.Data.CommandType.Text + End Sub + + + + + Public Overridable Function Fill(ByVal dataTable As nwindDataSet.ProductsDataTable) As Integer + Me.Adapter.SelectCommand = Me.CommandCollection(0) + If (Me.ClearBeforeFill = True) Then + dataTable.Clear() + End If + Dim returnValue As Integer = Me.Adapter.Fill(dataTable) + Return returnValue + End Function + + + + + Public Overridable Function GetData() As nwindDataSet.ProductsDataTable + Me.Adapter.SelectCommand = Me.CommandCollection(0) + Dim dataTable As New nwindDataSet.ProductsDataTable() + Me.Adapter.Fill(dataTable) + Return dataTable + End Function + End Class + + ''' + '''TableAdapterManager is used to coordinate TableAdapters in the dataset to enable Hierarchical Update scenarios + ''' + + + + + + Partial Public Class TableAdapterManager + Inherits System.ComponentModel.Component + + Private _updateOrder As UpdateOrderOption + + Private _backupDataSetBeforeUpdate As Boolean + + Private _connection As System.Data.IDbConnection + + + Public Property UpdateOrder() As UpdateOrderOption + Get + Return Me._updateOrder + End Get + Set(ByVal value As UpdateOrderOption) + Me._updateOrder = value + End Set + End Property + + + Public Property BackupDataSetBeforeUpdate() As Boolean + Get + Return Me._backupDataSetBeforeUpdate + End Get + Set(ByVal value As Boolean) + Me._backupDataSetBeforeUpdate = value + End Set + End Property + + + + Public Property Connection() As System.Data.IDbConnection + Get + If (Me._connection IsNot Nothing) Then + Return Me._connection + End If + Return Nothing + End Get + Set(ByVal value As System.Data.IDbConnection) + Me._connection = value + End Set + End Property + + + + Public ReadOnly Property TableAdapterInstanceCount() As Integer + Get + Dim count As Integer = 0 + Return count + End Get + End Property + + ''' + '''Update rows in top-down order. + ''' + + Private Function UpdateUpdatedRows(ByVal dataSet As nwindDataSet, ByVal allChangedRows As System.Collections.Generic.List(Of System.Data.DataRow), ByVal allAddedRows As System.Collections.Generic.List(Of System.Data.DataRow)) As Integer + Dim result As Integer = 0 + Return result + End Function + + ''' + '''Insert rows in top-down order. + ''' + + Private Function UpdateInsertedRows(ByVal dataSet As nwindDataSet, ByVal allAddedRows As System.Collections.Generic.List(Of System.Data.DataRow)) As Integer + Dim result As Integer = 0 + Return result + End Function + + ''' + '''Delete rows in bottom-up order. + ''' + + Private Function UpdateDeletedRows(ByVal dataSet As nwindDataSet, ByVal allChangedRows As System.Collections.Generic.List(Of System.Data.DataRow)) As Integer + Dim result As Integer = 0 + Return result + End Function + + ''' + '''Remove inserted rows that become updated rows after calling TableAdapter.Update(inserted rows) first + ''' + + Private Function GetRealUpdatedRows(ByVal updatedRows() As System.Data.DataRow, ByVal allAddedRows As System.Collections.Generic.List(Of System.Data.DataRow)) As System.Data.DataRow() + If ((updatedRows Is Nothing) OrElse (updatedRows.Length < 1)) Then + Return updatedRows + End If + If ((allAddedRows Is Nothing) OrElse (allAddedRows.Count < 1)) Then + Return updatedRows + End If + Dim realUpdatedRows As New System.Collections.Generic.List(Of System.Data.DataRow)() + Dim i As Integer = 0 + Do While (i < updatedRows.Length) + Dim row As System.Data.DataRow = updatedRows(i) + If (allAddedRows.Contains(row) = False) Then + realUpdatedRows.Add(row) + End If + i = (i + 1) + Loop + Return realUpdatedRows.ToArray() + End Function + + ''' + '''Update all changes to the dataset. + ''' + + Public Overridable Function UpdateAll(ByVal dataSet As nwindDataSet) As Integer + If (dataSet Is Nothing) Then + Throw New System.ArgumentNullException("dataSet") + End If + If (dataSet.HasChanges() = False) Then + Return 0 + End If + Dim workConnection As System.Data.IDbConnection = Me.Connection + If (workConnection Is Nothing) Then + Throw New System.ApplicationException("TableAdapterManager contains no connection information. Set each TableAdapterMana" & "ger TableAdapter property to a valid TableAdapter instance.") + End If + Dim workConnOpened As Boolean = False + If ((workConnection.State And System.Data.ConnectionState.Broken) = System.Data.ConnectionState.Broken) Then + workConnection.Close() + End If + If (workConnection.State = System.Data.ConnectionState.Closed) Then + workConnection.Open() + workConnOpened = True + End If + Dim workTransaction As System.Data.IDbTransaction = workConnection.BeginTransaction() + If (workTransaction Is Nothing) Then + Throw New System.ApplicationException("The transaction cannot begin. The current data connection does not support transa" & "ctions or the current state is not allowing the transaction to begin.") + End If + Dim allChangedRows As New System.Collections.Generic.List(Of System.Data.DataRow)() + Dim allAddedRows As New System.Collections.Generic.List(Of System.Data.DataRow)() + Dim adaptersWithAcceptChangesDuringUpdate As New System.Collections.Generic.List(Of System.Data.Common.DataAdapter)() + Dim revertConnections As New System.Collections.Generic.Dictionary(Of Object, System.Data.IDbConnection)() + Dim result As Integer = 0 + Dim backupDataSet As System.Data.DataSet = Nothing + If Me.BackupDataSetBeforeUpdate Then + backupDataSet = New System.Data.DataSet() + backupDataSet.Merge(dataSet) + End If + Try + ' ---- Prepare for update ----------- + ' + ' + '---- Perform updates ----------- + ' + If (Me.UpdateOrder = UpdateOrderOption.UpdateInsertDelete) Then + result = (result + Me.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows)) + result = (result + Me.UpdateInsertedRows(dataSet, allAddedRows)) + Else + result = (result + Me.UpdateInsertedRows(dataSet, allAddedRows)) + result = (result + Me.UpdateUpdatedRows(dataSet, allChangedRows, allAddedRows)) + End If + result = (result + Me.UpdateDeletedRows(dataSet, allChangedRows)) + ' + '---- Commit updates ----------- + ' + workTransaction.Commit() + If (0 < allAddedRows.Count) Then + Dim rows(allAddedRows.Count - 1) As System.Data.DataRow + allAddedRows.CopyTo(rows) + Dim i As Integer = 0 + Do While (i < rows.Length) + Dim row As System.Data.DataRow = rows(i) + row.AcceptChanges() + i = (i + 1) + Loop + End If + If (0 < allChangedRows.Count) Then + Dim rows(allChangedRows.Count - 1) As System.Data.DataRow + allChangedRows.CopyTo(rows) + Dim i As Integer = 0 + Do While (i < rows.Length) + Dim row As System.Data.DataRow = rows(i) + row.AcceptChanges() + i = (i + 1) + Loop + End If + Catch ex As System.Exception + workTransaction.Rollback() + ' ---- Restore the dataset ----------- + If Me.BackupDataSetBeforeUpdate Then + System.Diagnostics.Debug.Assert((backupDataSet IsNot Nothing)) + dataSet.Clear() + dataSet.Merge(backupDataSet) + Else + If (0 < allAddedRows.Count) Then + Dim rows(allAddedRows.Count - 1) As System.Data.DataRow + allAddedRows.CopyTo(rows) + Dim i As Integer = 0 + Do While (i < rows.Length) + Dim row As System.Data.DataRow = rows(i) + row.AcceptChanges() + row.SetAdded() + i = (i + 1) + Loop + End If + End If + Throw ex + Finally + If workConnOpened Then + workConnection.Close() + End If + If (0 < adaptersWithAcceptChangesDuringUpdate.Count) Then + Dim adapters(adaptersWithAcceptChangesDuringUpdate.Count - 1) As System.Data.Common.DataAdapter + adaptersWithAcceptChangesDuringUpdate.CopyTo(adapters) + Dim i As Integer = 0 + Do While (i < adapters.Length) + Dim adapter As System.Data.Common.DataAdapter = adapters(i) + adapter.AcceptChangesDuringUpdate = True + i = (i + 1) + Loop + End If + End Try + Return result + End Function + + + Protected Overridable Sub SortSelfReferenceRows(ByVal rows() As System.Data.DataRow, ByVal relation As System.Data.DataRelation, ByVal childFirst As Boolean) + System.Array.Sort(Of System.Data.DataRow)(rows, New SelfReferenceComparer(relation, childFirst)) + End Sub + + + Protected Overridable Function MatchTableAdapterConnection(ByVal inputConnection As System.Data.IDbConnection) As Boolean + If (Me._connection IsNot Nothing) Then + Return True + End If + If ((Me.Connection Is Nothing) OrElse (inputConnection Is Nothing)) Then + Return True + End If + If String.Equals(Me.Connection.ConnectionString, inputConnection.ConnectionString, System.StringComparison.Ordinal) Then + Return True + End If + Return False + End Function + + ''' + '''Update Order Option + ''' + + Public Enum UpdateOrderOption + + InsertUpdateDelete = 0 + + UpdateInsertDelete = 1 + End Enum + + ''' + '''Used to sort self-referenced table's rows + ''' + + Private Class SelfReferenceComparer + Inherits Object + Implements System.Collections.Generic.IComparer(Of System.Data.DataRow) + + Private _relation As System.Data.DataRelation + + Private _childFirst As Integer + + + Friend Sub New(ByVal relation As System.Data.DataRelation, ByVal childFirst As Boolean) + Me._relation = relation + If childFirst Then + Me._childFirst = -1 + Else + Me._childFirst = 1 + End If + End Sub + + + Private Function IsChildAndParent(ByVal child As System.Data.DataRow, ByVal parent As System.Data.DataRow) As Boolean + System.Diagnostics.Debug.Assert((child IsNot Nothing)) + System.Diagnostics.Debug.Assert((parent IsNot Nothing)) + Dim newParent As System.Data.DataRow = child.GetParentRow(Me._relation, System.Data.DataRowVersion.Default) + Do While ((newParent IsNot Nothing) AndAlso ((Object.ReferenceEquals(newParent, child) = False) AndAlso (Object.ReferenceEquals(newParent, parent) = False))) + newParent = newParent.GetParentRow(Me._relation, System.Data.DataRowVersion.Default) + Loop + If (newParent Is Nothing) Then + newParent = child.GetParentRow(Me._relation, System.Data.DataRowVersion.Original) + Do While ((newParent IsNot Nothing) AndAlso ((Object.ReferenceEquals(newParent, child) = False) AndAlso (Object.ReferenceEquals(newParent, parent) = False))) + newParent = newParent.GetParentRow(Me._relation, System.Data.DataRowVersion.Original) + Loop + End If + If Object.ReferenceEquals(newParent, parent) Then + Return True + End If + Return False + End Function + + + Public Function Compare(ByVal row1 As System.Data.DataRow, ByVal row2 As System.Data.DataRow) As Integer Implements System.Collections.Generic.IComparer(Of System.Data.DataRow).Compare + If Object.ReferenceEquals(row1, row2) Then + Return 0 + End If + If (row1 Is Nothing) Then + Return -1 + End If + If (row2 Is Nothing) Then + Return 1 + End If + + ' Is row1 the child or grandchild of row2 + If Me.IsChildAndParent(row1, row2) Then + Return Me._childFirst + End If + + ' Is row2 the child or grandchild of row1 + If Me.IsChildAndParent(row2, row1) Then + Return (-1 * Me._childFirst) + End If + Return 0 + End Function + End Class + End Class End Namespace -'#pragma warning restore 1591 \ No newline at end of file +#Enable Warning BC1591 \ No newline at end of file diff --git a/VB/E1517/E1517.Net5.sln b/VB/E1517/E1517.Net5.sln index e0b568d..a9835fc 100644 --- a/VB/E1517/E1517.Net5.sln +++ b/VB/E1517/E1517.Net5.sln @@ -1,4 +1,4 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 16 Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "DXGrid_ShowCheckBoxInColumnHeaders", "DXGrid_ShowCheckBoxInColumnHeaders\DXGrid_ShowCheckBoxInColumnHeaders.Net5.vbproj", "{72CC2ABE-8F4C-4A5A-907E-25C5008B9A8F}" EndProject diff --git a/VB/E1517/E1517.sln b/VB/E1517/E1517.sln index c75fd3f..f16ef18 100644 --- a/VB/E1517/E1517.sln +++ b/VB/E1517/E1517.sln @@ -1,4 +1,4 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 +Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "DXGrid_ShowCheckBoxInColumnHeaders", "DXGrid_ShowCheckBoxInColumnHeaders\DXGrid_ShowCheckBoxInColumnHeaders.vbproj", "{72CC2ABE-8F4C-4A5A-907E-25C5008B9A8F}" EndProject From 42d72aebd2901c30341645bdc69f2ba38dca6132 Mon Sep 17 00:00:00 2001 From: DevExpressExampleBot Date: Tue, 7 Sep 2021 16:12:22 +0300 Subject: [PATCH 2/2] README auto update [skip ci] --- Readme.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Readme.md b/Readme.md index 3227453..0869d43 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,4 @@ -![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128649836/13.1.4%2B) [![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E1517) [![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)