日期:2008-12-19  浏览次数:20489 次

 

二、EntityClass

EntityClass中的每一个文件对应数据库中的一张表,对应其字段,以及对表的操作的封装,如查询,增加、删除等。

所有的EntityClass继承了一个基类BaseEntity,基类的代码如下,主要是一些接口

Imports System.Data
Namespace EntityClass
    Public Class BaseEntity
        Public strSql As String
        Public database As Data.DataFactory
        Public dt As DataTable
        '构造函数
        Public Sub New()
            Me.database = New Data.DataFactory
            Me.dt = New DataTable
        End Sub
        '应该做成抽象的abstract
        Public Function Load() As Integer
        End Function

        Public Function Creat() As Integer
        End Function
        Public Function Updata() As Integer
        End Function
        Public Function Delete() As Integer
        End Function

        Public Function GetDataOnTable() As DataTable

            Me.dt = Me.database.DataTableResult(Me.strSql)
            Return dt
        End Function

        Public Function GetOneObj() As Object

            Return Me.database.ReadOneLog(Me.strSql)
        End Function

        Public Function ExecuteSql() As Integer
            Return Me.database.ExecuteNonQuery(Me.strSql)

        End Function
    End Class
End Namespace

这里以对用户表的操作为例,来说明EntityClass的结构,代码如下:

Imports System.Data

Namespace EntityClass
    Public Class S_User
        Inherits BaseEntity

        Const ARRAYLENGTH = 100


        Public Id_I As String
        ' 用户名
        Public UserName_S As String
        '用户密码
        Public Password_S As String

        'add by gb 20050725
        Dim array1(ARRAYLENGTH) As String
        Dim array2(ARRAYLENGTH, 1) As String
        Dim sqlarray(ARRAYLENGTH, 1) As String
        Dim len1 As Integer = 0
        Dim len2 As Integer = 0
        Dim sqllen As Integer = 0

        Private mydataset As New DataSet
        '对Array2赋初值
        Private Sub SetArray2()
            array2(0, 0) = "Id_I"
            array2(1, 0)