让大家看看一些代码
*- 数据库的操作以do开始
DEFINE CLASS DataCommand As Custom
FUNCTION Update(toDS As Record OF "DataSet.prg") As Boolean
ENDFUNC
FUNCTION Insert(toDS As Record) As Boolean
ENDFUNC
*- 删除记录
FUNCTION Delete(toDS As Record) As Boolean
ENDFUNC
FUNCTION Select(otbl As Table OF "dataset.prg") As Boolean
ENDFUNC
ENDDEFINE
DEFINE CLASS doProduct As DataCommand OF "dbcommand.prg"
ENDDEFINE
DEFINE CLASS Table As Collection
Table = ""
Caption = ""
Key = ""
*- 记录集合的类
DataRowClass = ""
Where = ""
RowCount = 0
FUNCTION BuildDataSet()
SELECT (This.Table)
GO TOP
LOCAL mi As Long
LOCAL oRow As Object
LOCAL cFD As String
LOCAL oFD As Field OF "dataset.prg"
LOCAL oDataRow As Record OF "dataset.prg"
This.RowCount = RECCOUNT(This.Table)
*- 形成记录对象
FOR mi=1 TO This.RowCount
SCATTER NAME oRow
oDataRow = NEWOBJECT(This.DataRowClass ,This.ClassLibrary)
oDataRow.RowIndex = RECNO()
FOR EACH oFD IN oDataRow.Controls
cFD = oFD.Name
oFD.Value = oRow.&cFD
NEXT
This.Add(oDataRow ,EVALUATE("oDataRow." + oDataRow.KEY + ".Value"))
SKIP 1
ENDFOR
GO TOP
ENDFUNC
FUNCTION ToCursor() As Boolean
ENDFUNC
FUNCTION ToXml() As Boolean
ENDFUNC
ENDDEFINE
*- 数据记录的类以rrd开头命名类
DEFINE CLASS Record As Custom
Table = ""
Caption = ""
Key = ""
RowIndex = 0
ENDDEFINE
*- 产品表
*- 用于描述产品的类型
DEFINE CLASS rrdProduct As Record
Table = "产品库"
Caption = "产品库"
Key = "编号"
ADD OBJECT 编号 As Field WITH Caption="编号" ,len=12 ,type="nchar" ,Default="" ,Primary=.T.
ADD OBJECT 型号 As Field WITH Caption="型号" ,len=30 ,type="nchar" ,Default=""
ADD OBJECT 别名 As Field WITH Caption="别名" ,len=20 ,type="nchar" ,Default=""
ADD OBJECT 价格 As Field WITH Caption="价格" ,len=6 ,Decimal = 2 ,type="numeric" ,Default=0.00
ADD OBJECT 数量 As Field WITH Caption="数量" ,len=10 ,type="int" ,Default= 0
ADD OBJECT 厂家 As Field WITH Caption="厂家" ,len=40 ,type="nchar" ,Default=""
ENDDEFINE
DEFINE CLASS Field As Custom
*- 字段类型
Type = ""
*- 字段长度
Len = 0
*- 小数点
Decimal = 0
*- 值
Value = ""
*- 标题
Caption = ""
*- 初始化值
Default = ""
*- 次字段不允许更新
noUpdate = .F.
*- 关键字段
Primary = .F.
*- 只读
ReadOnly = .F.
*- 是否是密码
Password=.F.
*- 是否被修改
lEdit = .F.
ENDDEFINE