home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic .NET - Read Less - Learn More / Visual_Basic.NET_Read_Less_Learn_More_Richard_Bowman_Visual_2002.iso / Resources / Code / Ch9-WorkWithDataRows / DsNorthwind.vb < prev    next >
Text File  |  2001-08-23  |  20KB  |  538 lines

  1. '------------------------------------------------------------------------------
  2. ' <autogenerated>
  3. '     This code was generated by a tool.
  4. '     Runtime Version: 1.0.2914.16
  5. '
  6. '     Changes to this file may cause incorrect behavior and will be lost if 
  7. '     the code is regenerated.
  8. ' </autogenerated>
  9. '------------------------------------------------------------------------------
  10.  
  11. Option Strict Off
  12. Option Explicit On
  13.  
  14. Imports System
  15. Imports System.Data
  16. Imports System.Runtime.Serialization
  17. Imports System.Xml
  18.  
  19.  
  20. <Serializable(),  _
  21.  System.ComponentModel.DesignerCategoryAttribute("code")>  _
  22. Public Class DsNorthwind
  23.     Inherits System.Data.DataSet
  24.     
  25.     Private tableCustomers As CustomersDataTable
  26.     
  27.     Public Sub New()
  28.         MyBase.New
  29.         Me.InitClass
  30.     End Sub
  31.     
  32.     Private Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
  33.         MyBase.New
  34.         Me.InitClass
  35.         Me.GetSerializationData(info, context)
  36.     End Sub
  37.     
  38.     <System.ComponentModel.Browsable(false),  _
  39.      System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)>  _
  40.     Public ReadOnly Property Customers As CustomersDataTable
  41.         Get
  42.             Return Me.tableCustomers
  43.         End Get
  44.     End Property
  45.     
  46.     Protected Overrides Function ShouldSerializeTables() As Boolean
  47.         Return false
  48.     End Function
  49.     
  50.     Protected Overrides Function ShouldSerializeRelations() As Boolean
  51.         Return false
  52.     End Function
  53.     
  54.     Protected Overrides Sub ReadXmlSerializable(ByVal reader As XmlReader)
  55.         Me.ReadXml(reader, XmlReadMode.IgnoreSchema)
  56.     End Sub
  57.     
  58.     Protected Overrides Function GetSchemaSerializable() As System.Xml.Schema.XmlSchema
  59.         Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream
  60.         Me.WriteXmlSchema(New XmlTextWriter(stream, Nothing))
  61.         stream.Position = 0
  62.         Return System.Xml.Schema.XmlSchema.Read(New XmlTextReader(stream), Nothing)
  63.     End Function
  64.     
  65.     Private Sub InitClass()
  66.         Me.DataSetName = "DsNorthwind"
  67.         Me.Namespace = "http://www.tempuri.org/DsNorthwind.xsd"
  68.         Me.tableCustomers = New CustomersDataTable
  69.         Me.Tables.Add(Me.tableCustomers)
  70.     End Sub
  71.     
  72.     Private Function ShouldSerializeCustomers() As Boolean
  73.         Return false
  74.     End Function
  75.     
  76.     Public Delegate Sub CustomersRowChangeEventHandler(ByVal sender As Object, ByVal e As CustomersRowChangeEvent)
  77.     
  78.     Public Class CustomersDataTable
  79.         Inherits DataTable
  80.         Implements System.Collections.IEnumerable
  81.         
  82.         Private columnCustomerID As DataColumn
  83.         
  84.         Private columnCompanyName As DataColumn
  85.         
  86.         Private columnContactName As DataColumn
  87.         
  88.         Private columnContactTitle As DataColumn
  89.         
  90.         Private columnAddress As DataColumn
  91.         
  92.         Private columnCity As DataColumn
  93.         
  94.         Private column_Region As DataColumn
  95.         
  96.         Private columnPostalCode As DataColumn
  97.         
  98.         Private columnCountry As DataColumn
  99.         
  100.         Private columnPhone As DataColumn
  101.         
  102.         Private columnFax As DataColumn
  103.         
  104.         Friend Sub New()
  105.             MyBase.New("Customers")
  106.             Me.InitClass
  107.         End Sub
  108.         
  109.         <System.ComponentModel.Browsable(false)>  _
  110.         Public ReadOnly Property Count As Integer
  111.             Get
  112.                 Return Me.Rows.Count
  113.             End Get
  114.         End Property
  115.         
  116.         Friend ReadOnly Property CustomerIDColumn As DataColumn
  117.             Get
  118.                 Return Me.columnCustomerID
  119.             End Get
  120.         End Property
  121.         
  122.         Friend ReadOnly Property CompanyNameColumn As DataColumn
  123.             Get
  124.                 Return Me.columnCompanyName
  125.             End Get
  126.         End Property
  127.         
  128.         Friend ReadOnly Property ContactNameColumn As DataColumn
  129.             Get
  130.                 Return Me.columnContactName
  131.             End Get
  132.         End Property
  133.         
  134.         Friend ReadOnly Property ContactTitleColumn As DataColumn
  135.             Get
  136.                 Return Me.columnContactTitle
  137.             End Get
  138.         End Property
  139.         
  140.         Friend ReadOnly Property AddressColumn As DataColumn
  141.             Get
  142.                 Return Me.columnAddress
  143.             End Get
  144.         End Property
  145.         
  146.         Friend ReadOnly Property CityColumn As DataColumn
  147.             Get
  148.                 Return Me.columnCity
  149.             End Get
  150.         End Property
  151.         
  152.         Friend ReadOnly Property _RegionColumn As DataColumn
  153.             Get
  154.                 Return Me.column_Region
  155.             End Get
  156.         End Property
  157.         
  158.         Friend ReadOnly Property PostalCodeColumn As DataColumn
  159.             Get
  160.                 Return Me.columnPostalCode
  161.             End Get
  162.         End Property
  163.         
  164.         Friend ReadOnly Property CountryColumn As DataColumn
  165.             Get
  166.                 Return Me.columnCountry
  167.             End Get
  168.         End Property
  169.         
  170.         Friend ReadOnly Property PhoneColumn As DataColumn
  171.             Get
  172.                 Return Me.columnPhone
  173.             End Get
  174.         End Property
  175.         
  176.         Friend ReadOnly Property FaxColumn As DataColumn
  177.             Get
  178.                 Return Me.columnFax
  179.             End Get
  180.         End Property
  181.         
  182.         Public Default ReadOnly Property Item(ByVal index As Integer) As CustomersRow
  183.             Get
  184.                 Return CType(Me.Rows(index),CustomersRow)
  185.             End Get
  186.         End Property
  187.         
  188.         Public Event CustomersRowChanged As CustomersRowChangeEventHandler
  189.         
  190.         Public Event CustomersRowChanging As CustomersRowChangeEventHandler
  191.         
  192.         Public Event CustomersRowDeleted As CustomersRowChangeEventHandler
  193.         
  194.         Public Event CustomersRowDeleting As CustomersRowChangeEventHandler
  195.         
  196.         Public Overloads Sub AddCustomersRow(ByVal row As CustomersRow)
  197.             Me.Rows.Add(row)
  198.         End Sub
  199.         
  200.         Public Overloads Function AddCustomersRow(ByVal CustomerID As String, 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) As CustomersRow
  201.             Dim rowCustomersRow As CustomersRow = CType(Me.NewRow,CustomersRow)
  202.             rowCustomersRow.ItemArray = New Object() {CustomerID, CompanyName, ContactName, ContactTitle, Address, City, _Region, PostalCode, Country, Phone, Fax}
  203.             Me.Rows.Add(rowCustomersRow)
  204.             Return rowCustomersRow
  205.         End Function
  206.         
  207.         Public Function FindByCustomerID(ByVal CustomerID As String) As CustomersRow
  208.             Return CType(Me.Rows.Find(New Object() {CustomerID}),CustomersRow)
  209.         End Function
  210.         
  211.         Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
  212.             Return Me.Rows.GetEnumerator
  213.         End Function
  214.         
  215.         Private Sub InitClass()
  216.             Me.columnCustomerID = New DataColumn("CustomerID", GetType(System.String), "", System.Data.MappingType.Element)
  217.             Me.columnCustomerID.AllowDBNull = false
  218.             Me.columnCustomerID.Unique = true
  219.             Me.Columns.Add(Me.columnCustomerID)
  220.             Me.columnCompanyName = New DataColumn("CompanyName", GetType(System.String), "", System.Data.MappingType.Element)
  221.             Me.columnCompanyName.AllowDBNull = false
  222.             Me.Columns.Add(Me.columnCompanyName)
  223.             Me.columnContactName = New DataColumn("ContactName", GetType(System.String), "", System.Data.MappingType.Element)
  224.             Me.Columns.Add(Me.columnContactName)
  225.             Me.columnContactTitle = New DataColumn("ContactTitle", GetType(System.String), "", System.Data.MappingType.Element)
  226.             Me.Columns.Add(Me.columnContactTitle)
  227.             Me.columnAddress = New DataColumn("Address", GetType(System.String), "", System.Data.MappingType.Element)
  228.             Me.Columns.Add(Me.columnAddress)
  229.             Me.columnCity = New DataColumn("City", GetType(System.String), "", System.Data.MappingType.Element)
  230.             Me.Columns.Add(Me.columnCity)
  231.             Me.column_Region = New DataColumn("Region", GetType(System.String), "", System.Data.MappingType.Element)
  232.             Me.Columns.Add(Me.column_Region)
  233.             Me.columnPostalCode = New DataColumn("PostalCode", GetType(System.String), "", System.Data.MappingType.Element)
  234.             Me.Columns.Add(Me.columnPostalCode)
  235.             Me.columnCountry = New DataColumn("Country", GetType(System.String), "", System.Data.MappingType.Element)
  236.             Me.Columns.Add(Me.columnCountry)
  237.             Me.columnPhone = New DataColumn("Phone", GetType(System.String), "", System.Data.MappingType.Element)
  238.             Me.Columns.Add(Me.columnPhone)
  239.             Me.columnFax = New DataColumn("Fax", GetType(System.String), "", System.Data.MappingType.Element)
  240.             Me.Columns.Add(Me.columnFax)
  241.             Me.PrimaryKey = New DataColumn() {Me.columnCustomerID}
  242.         End Sub
  243.         
  244.         Public Function NewCustomersRow() As CustomersRow
  245.             Return CType(Me.NewRow,CustomersRow)
  246.         End Function
  247.         
  248.         Protected Overrides Function NewRowFromBuilder(ByVal builder As DataRowBuilder) As DataRow
  249.             'We need to ensure that all Rows in the tabled are typed rows.
  250.             'Table calls newRow whenever it needs to create a row.
  251.             'So the following conditions are covered by Row newRow(Record record)
  252.             '* Cursor calls table.addRecord(record) 
  253.             '* table.addRow(object[] values) calls newRow(record)    
  254.             Return New CustomersRow(builder)
  255.         End Function
  256.         
  257.         Protected Overrides Function GetRowType() As System.Type
  258.             Return GetType(CustomersRow)
  259.         End Function
  260.         
  261.         Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs)
  262.             MyBase.OnRowChanged(e)
  263.             If (Not (Me.CustomersRowChangedEvent) Is Nothing) Then
  264.                 RaiseEvent CustomersRowChanged(Me, New CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action))
  265.             End If
  266.         End Sub
  267.         
  268.         Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs)
  269.             MyBase.OnRowChanging(e)
  270.             If (Not (Me.CustomersRowChangingEvent) Is Nothing) Then
  271.                 RaiseEvent CustomersRowChanging(Me, New CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action))
  272.             End If
  273.         End Sub
  274.         
  275.         Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs)
  276.             MyBase.OnRowDeleted(e)
  277.             If (Not (Me.CustomersRowDeletedEvent) Is Nothing) Then
  278.                 RaiseEvent CustomersRowDeleted(Me, New CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action))
  279.             End If
  280.         End Sub
  281.         
  282.         Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs)
  283.             MyBase.OnRowDeleting(e)
  284.             If (Not (Me.CustomersRowDeletingEvent) Is Nothing) Then
  285.                 RaiseEvent CustomersRowDeleting(Me, New CustomersRowChangeEvent(CType(e.Row,CustomersRow), e.Action))
  286.             End If
  287.         End Sub
  288.         
  289.         Public Sub RemoveCustomersRow(ByVal row As CustomersRow)
  290.             Me.Rows.Remove(row)
  291.         End Sub
  292.     End Class
  293.     
  294.     Public Class CustomersRow
  295.         Inherits DataRow
  296.         
  297.         Private tableCustomers As CustomersDataTable
  298.         
  299.         Friend Sub New(ByVal rb As DataRowBuilder)
  300.             MyBase.New(rb)
  301.             Me.tableCustomers = CType(Me.Table,CustomersDataTable)
  302.         End Sub
  303.         
  304.         Public Property CustomerID As String
  305.             Get
  306.                 Return CType(Me(Me.tableCustomers.CustomerIDColumn),String)
  307.             End Get
  308.             Set
  309.                 Me(Me.tableCustomers.CustomerIDColumn) = value
  310.             End Set
  311.         End Property
  312.         
  313.         Public Property CompanyName As String
  314.             Get
  315.                 Return CType(Me(Me.tableCustomers.CompanyNameColumn),String)
  316.             End Get
  317.             Set
  318.                 Me(Me.tableCustomers.CompanyNameColumn) = value
  319.             End Set
  320.         End Property
  321.         
  322.         Public Property ContactName As String
  323.             Get
  324.                 Try 
  325.                     Return CType(Me(Me.tableCustomers.ContactNameColumn),String)
  326.                 Catch e As InvalidCastException
  327.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  328.                 End Try
  329.             End Get
  330.             Set
  331.                 Me(Me.tableCustomers.ContactNameColumn) = value
  332.             End Set
  333.         End Property
  334.         
  335.         Public Property ContactTitle As String
  336.             Get
  337.                 Try 
  338.                     Return CType(Me(Me.tableCustomers.ContactTitleColumn),String)
  339.                 Catch e As InvalidCastException
  340.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  341.                 End Try
  342.             End Get
  343.             Set
  344.                 Me(Me.tableCustomers.ContactTitleColumn) = value
  345.             End Set
  346.         End Property
  347.         
  348.         Public Property Address As String
  349.             Get
  350.                 Try 
  351.                     Return CType(Me(Me.tableCustomers.AddressColumn),String)
  352.                 Catch e As InvalidCastException
  353.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  354.                 End Try
  355.             End Get
  356.             Set
  357.                 Me(Me.tableCustomers.AddressColumn) = value
  358.             End Set
  359.         End Property
  360.         
  361.         Public Property City As String
  362.             Get
  363.                 Try 
  364.                     Return CType(Me(Me.tableCustomers.CityColumn),String)
  365.                 Catch e As InvalidCastException
  366.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  367.                 End Try
  368.             End Get
  369.             Set
  370.                 Me(Me.tableCustomers.CityColumn) = value
  371.             End Set
  372.         End Property
  373.         
  374.         Public Property _Region As String
  375.             Get
  376.                 Try 
  377.                     Return CType(Me(Me.tableCustomers._RegionColumn),String)
  378.                 Catch e As InvalidCastException
  379.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  380.                 End Try
  381.             End Get
  382.             Set
  383.                 Me(Me.tableCustomers._RegionColumn) = value
  384.             End Set
  385.         End Property
  386.         
  387.         Public Property PostalCode As String
  388.             Get
  389.                 Try 
  390.                     Return CType(Me(Me.tableCustomers.PostalCodeColumn),String)
  391.                 Catch e As InvalidCastException
  392.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  393.                 End Try
  394.             End Get
  395.             Set
  396.                 Me(Me.tableCustomers.PostalCodeColumn) = value
  397.             End Set
  398.         End Property
  399.         
  400.         Public Property Country As String
  401.             Get
  402.                 Try 
  403.                     Return CType(Me(Me.tableCustomers.CountryColumn),String)
  404.                 Catch e As InvalidCastException
  405.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  406.                 End Try
  407.             End Get
  408.             Set
  409.                 Me(Me.tableCustomers.CountryColumn) = value
  410.             End Set
  411.         End Property
  412.         
  413.         Public Property Phone As String
  414.             Get
  415.                 Try 
  416.                     Return CType(Me(Me.tableCustomers.PhoneColumn),String)
  417.                 Catch e As InvalidCastException
  418.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  419.                 End Try
  420.             End Get
  421.             Set
  422.                 Me(Me.tableCustomers.PhoneColumn) = value
  423.             End Set
  424.         End Property
  425.         
  426.         Public Property Fax As String
  427.             Get
  428.                 Try 
  429.                     Return CType(Me(Me.tableCustomers.FaxColumn),String)
  430.                 Catch e As InvalidCastException
  431.                     Throw New StrongTypingException("Cannot get value because it is DBNull.", e)
  432.                 End Try
  433.             End Get
  434.             Set
  435.                 Me(Me.tableCustomers.FaxColumn) = value
  436.             End Set
  437.         End Property
  438.         
  439.         Public Function IsContactNameNull() As Boolean
  440.             Return Me.IsNull(Me.tableCustomers.ContactNameColumn)
  441.         End Function
  442.         
  443.         Public Sub SetContactNameNull()
  444.             Me(Me.tableCustomers.ContactNameColumn) = System.Convert.DBNull
  445.         End Sub
  446.         
  447.         Public Function IsContactTitleNull() As Boolean
  448.             Return Me.IsNull(Me.tableCustomers.ContactTitleColumn)
  449.         End Function
  450.         
  451.         Public Sub SetContactTitleNull()
  452.             Me(Me.tableCustomers.ContactTitleColumn) = System.Convert.DBNull
  453.         End Sub
  454.         
  455.         Public Function IsAddressNull() As Boolean
  456.             Return Me.IsNull(Me.tableCustomers.AddressColumn)
  457.         End Function
  458.         
  459.         Public Sub SetAddressNull()
  460.             Me(Me.tableCustomers.AddressColumn) = System.Convert.DBNull
  461.         End Sub
  462.         
  463.         Public Function IsCityNull() As Boolean
  464.             Return Me.IsNull(Me.tableCustomers.CityColumn)
  465.         End Function
  466.         
  467.         Public Sub SetCityNull()
  468.             Me(Me.tableCustomers.CityColumn) = System.Convert.DBNull
  469.         End Sub
  470.         
  471.         Public Function Is_RegionNull() As Boolean
  472.             Return Me.IsNull(Me.tableCustomers._RegionColumn)
  473.         End Function
  474.         
  475.         Public Sub Set_RegionNull()
  476.             Me(Me.tableCustomers._RegionColumn) = System.Convert.DBNull
  477.         End Sub
  478.         
  479.         Public Function IsPostalCodeNull() As Boolean
  480.             Return Me.IsNull(Me.tableCustomers.PostalCodeColumn)
  481.         End Function
  482.         
  483.         Public Sub SetPostalCodeNull()
  484.             Me(Me.tableCustomers.PostalCodeColumn) = System.Convert.DBNull
  485.         End Sub
  486.         
  487.         Public Function IsCountryNull() As Boolean
  488.             Return Me.IsNull(Me.tableCustomers.CountryColumn)
  489.         End Function
  490.         
  491.         Public Sub SetCountryNull()
  492.             Me(Me.tableCustomers.CountryColumn) = System.Convert.DBNull
  493.         End Sub
  494.         
  495.         Public Function IsPhoneNull() As Boolean
  496.             Return Me.IsNull(Me.tableCustomers.PhoneColumn)
  497.         End Function
  498.         
  499.         Public Sub SetPhoneNull()
  500.             Me(Me.tableCustomers.PhoneColumn) = System.Convert.DBNull
  501.         End Sub
  502.         
  503.         Public Function IsFaxNull() As Boolean
  504.             Return Me.IsNull(Me.tableCustomers.FaxColumn)
  505.         End Function
  506.         
  507.         Public Sub SetFaxNull()
  508.             Me(Me.tableCustomers.FaxColumn) = System.Convert.DBNull
  509.         End Sub
  510.     End Class
  511.     
  512.     Public Class CustomersRowChangeEvent
  513.         Inherits EventArgs
  514.         
  515.         Private eventRow As CustomersRow
  516.         
  517.         Private eventAction As System.Data.DataRowAction
  518.         
  519.         Public Sub New(ByVal row As CustomersRow, ByVal action As DataRowAction)
  520.             MyBase.New
  521.             Me.eventRow = row
  522.             Me.eventAction = action
  523.         End Sub
  524.         
  525.         Public ReadOnly Property Row As CustomersRow
  526.             Get
  527.                 Return Me.eventRow
  528.             End Get
  529.         End Property
  530.         
  531.         Public ReadOnly Property Action As DataRowAction
  532.             Get
  533.                 Return Me.eventAction
  534.             End Get
  535.         End Property
  536.     End Class
  537. End Class
  538.