ds2.vb

来自「是一个工资的管理系统 利用的是VB.NET和sql2000来完成的」· VB 代码 · 共 456 行 · 第 1/2 页

VB
456
字号
        
        Public Overloads Function AddstudentRow(ByVal sno As String, ByVal sname As String, ByVal ssex As String, ByVal sage As String, ByVal sdept As String) As studentRow
            Dim rowstudentRow As studentRow = CType(Me.NewRow,studentRow)
            rowstudentRow.ItemArray = New Object() {sno, sname, ssex, sage, sdept}
            Me.Rows.Add(rowstudentRow)
            Return rowstudentRow
        End Function
        
        Public Function FindBysno(ByVal sno As String) As studentRow
            Return CType(Me.Rows.Find(New Object() {sno}),studentRow)
        End Function
        
        Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
            Return Me.Rows.GetEnumerator
        End Function
        
        Public Overrides Function Clone() As DataTable
            Dim cln As studentDataTable = CType(MyBase.Clone,studentDataTable)
            cln.InitVars
            Return cln
        End Function
        
        Protected Overrides Function CreateInstance() As DataTable
            Return New studentDataTable
        End Function
        
        Friend Sub InitVars()
            Me.columnsno = Me.Columns("sno")
            Me.columnsname = Me.Columns("sname")
            Me.columnssex = Me.Columns("ssex")
            Me.columnsage = Me.Columns("sage")
            Me.columnsdept = Me.Columns("sdept")
        End Sub
        
        Private Sub InitClass()
            Me.columnsno = New DataColumn("sno", GetType(System.String), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnsno)
            Me.columnsname = New DataColumn("sname", GetType(System.String), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnsname)
            Me.columnssex = New DataColumn("ssex", GetType(System.String), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnssex)
            Me.columnsage = New DataColumn("sage", GetType(System.String), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnsage)
            Me.columnsdept = New DataColumn("sdept", GetType(System.String), Nothing, System.Data.MappingType.Element)
            Me.Columns.Add(Me.columnsdept)
            Me.Constraints.Add(New UniqueConstraint("Constraint1", New DataColumn() {Me.columnsno}, true))
            Me.columnsno.AllowDBNull = false
            Me.columnsno.Unique = true
        End Sub
        
        Public Function NewstudentRow() As studentRow
            Return CType(Me.NewRow,studentRow)
        End Function
        
        Protected Overrides Function NewRowFromBuilder(ByVal builder As DataRowBuilder) As DataRow
            Return New studentRow(builder)
        End Function
        
        Protected Overrides Function GetRowType() As System.Type
            Return GetType(studentRow)
        End Function
        
        Protected Overrides Sub OnRowChanged(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowChanged(e)
            If (Not (Me.studentRowChangedEvent) Is Nothing) Then
                RaiseEvent studentRowChanged(Me, New studentRowChangeEvent(CType(e.Row,studentRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowChanging(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowChanging(e)
            If (Not (Me.studentRowChangingEvent) Is Nothing) Then
                RaiseEvent studentRowChanging(Me, New studentRowChangeEvent(CType(e.Row,studentRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowDeleted(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowDeleted(e)
            If (Not (Me.studentRowDeletedEvent) Is Nothing) Then
                RaiseEvent studentRowDeleted(Me, New studentRowChangeEvent(CType(e.Row,studentRow), e.Action))
            End If
        End Sub
        
        Protected Overrides Sub OnRowDeleting(ByVal e As DataRowChangeEventArgs)
            MyBase.OnRowDeleting(e)
            If (Not (Me.studentRowDeletingEvent) Is Nothing) Then
                RaiseEvent studentRowDeleting(Me, New studentRowChangeEvent(CType(e.Row,studentRow), e.Action))
            End If
        End Sub
        
        Public Sub RemovestudentRow(ByVal row As studentRow)
            Me.Rows.Remove(row)
        End Sub
    End Class
    
    <System.Diagnostics.DebuggerStepThrough()>  _
    Public Class studentRow
        Inherits DataRow
        
        Private tablestudent As studentDataTable
        
        Friend Sub New(ByVal rb As DataRowBuilder)
            MyBase.New(rb)
            Me.tablestudent = CType(Me.Table,studentDataTable)
        End Sub
        
        Public Property sno As String
            Get
                Return CType(Me(Me.tablestudent.snoColumn),String)
            End Get
            Set
                Me(Me.tablestudent.snoColumn) = value
            End Set
        End Property
        
        Public Property sname As String
            Get
                Try 
                    Return CType(Me(Me.tablestudent.snameColumn),String)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("无法获取值,因为它是 DBNull。", e)
                End Try
            End Get
            Set
                Me(Me.tablestudent.snameColumn) = value
            End Set
        End Property
        
        Public Property ssex As String
            Get
                Try 
                    Return CType(Me(Me.tablestudent.ssexColumn),String)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("无法获取值,因为它是 DBNull。", e)
                End Try
            End Get
            Set
                Me(Me.tablestudent.ssexColumn) = value
            End Set
        End Property
        
        Public Property sage As String
            Get
                Try 
                    Return CType(Me(Me.tablestudent.sageColumn),String)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("无法获取值,因为它是 DBNull。", e)
                End Try
            End Get
            Set
                Me(Me.tablestudent.sageColumn) = value
            End Set
        End Property
        
        Public Property sdept As String
            Get
                Try 
                    Return CType(Me(Me.tablestudent.sdeptColumn),String)
                Catch e As InvalidCastException
                    Throw New StrongTypingException("无法获取值,因为它是 DBNull。", e)
                End Try
            End Get
            Set
                Me(Me.tablestudent.sdeptColumn) = value
            End Set
        End Property
        
        Public Function IssnameNull() As Boolean
            Return Me.IsNull(Me.tablestudent.snameColumn)
        End Function
        
        Public Sub SetsnameNull()
            Me(Me.tablestudent.snameColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IsssexNull() As Boolean
            Return Me.IsNull(Me.tablestudent.ssexColumn)
        End Function
        
        Public Sub SetssexNull()
            Me(Me.tablestudent.ssexColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IssageNull() As Boolean
            Return Me.IsNull(Me.tablestudent.sageColumn)
        End Function
        
        Public Sub SetsageNull()
            Me(Me.tablestudent.sageColumn) = System.Convert.DBNull
        End Sub
        
        Public Function IssdeptNull() As Boolean
            Return Me.IsNull(Me.tablestudent.sdeptColumn)
        End Function
        
        Public Sub SetsdeptNull()
            Me(Me.tablestudent.sdeptColumn) = System.Convert.DBNull
        End Sub
    End Class
    
    <System.Diagnostics.DebuggerStepThrough()>  _
    Public Class studentRowChangeEvent
        Inherits EventArgs
        
        Private eventRow As studentRow
        
        Private eventAction As DataRowAction
        
        Public Sub New(ByVal row As studentRow, ByVal action As DataRowAction)
            MyBase.New
            Me.eventRow = row
            Me.eventAction = action
        End Sub
        
        Public ReadOnly Property Row As studentRow
            Get
                Return Me.eventRow
            End Get
        End Property
        
        Public ReadOnly Property Action As DataRowAction
            Get
                Return Me.eventAction
            End Get
        End Property
    End Class
End Class

⌨️ 快捷键说明

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