| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 561 人关注过本帖
标题:高手帮忙,感激不尽!
只看楼主 加入收藏
fourthofjuly
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-10-27
收藏
 问题点数:0 回复次数:1 
高手帮忙,感激不尽!

这是一个管理信息系统中控件grid的源代码,高手们百忙之中能不能帮着看看,给个注解越详细越好,小弟我真是看不明白,拜托了!
Dim t As Integer
Dim CZYname As String
Dim RS1 As ADODB.Recordset

Private Sub GridIni(OrdSql As String, t As Integer)

Set RS1 = New ADODB.Recordset

On Error GoTo errorhandle

grid.Clear
grid.Rows = 2
grid.FormatString = ">序号|<出库编号|<入库编号|<药品编号|<药品名称|<药品规格|出库数量|<价格|<出库日期|<出库发票号|>出库操作员工号|>出库操作日期"
grid.TextMatrix(1, 1) = "CKBH"
grid.TextMatrix(1, 2) = "RKBH"
grid.TextMatrix(1, 3) = "YPBH"
grid.TextMatrix(1, 4) = "YPMC"
grid.TextMatrix(1, 5) = "YPGG"
grid.TextMatrix(1, 6) = "CKSL"
grid.TextMatrix(1, 7) = "JG"
grid.TextMatrix(1, 8) = "CKRQ"
grid.TextMatrix(1, 9) = "CKFPHM"
grid.TextMatrix(1, 10) = "CKCZYGH"
grid.TextMatrix(1, 11) = "CKCZRQ"
grid.RowHeight(1) = 0
grid.ColWidth(1) = 0


SQL = "select * from CKMXZB AS Z INNER JOIN CKMXCB AS C ON Z.CKBH=C.CKBH where RFRQ IS NULL and YYJGBH='" & TemYYJGBH & "'"
If OrdSql <> "" Then
SQL = SQL & " order by " & OrdSql
If t = 1 Then
SQL = SQL & " asc"
Else
SQL = SQL & " desc"
End If
End If

RS.Open SQL, myConn

If Not RS.EOF Then
With RS
.MoveFirst
While Not .EOF
grid.Rows = grid.Rows + 1
grid.Row = grid.Rows - 1
grid.TextMatrix(grid.Row, 0) = grid.Row - 1

SQL = "select * from YPZD where YPBH='" & .Fields("YPBH") & "'"
RS1.Open SQL, myConn
If RS1.EOF Then
MsgBox "无药品编号为" & .Fields("YPBH") & "的药品信息,请检查药品字典", , "注意"
RS.Close
RS1.Close
End
Exit Sub
End If

For i = 1 To grid.Cols - 1

Select Case i
Case 4
grid.TextMatrix(grid.Row, i) = RS1.Fields("YPMC")
Case 5
grid.TextMatrix(grid.Row, i) = RS1.Fields("YPGG")
Case Else
grid.TextMatrix(grid.Row, i) = IIf(IsNull(.Fields(grid.TextMatrix(1, i))), "", .Fields(grid.TextMatrix(1, i)))
End Select


Next i
RS1.Close
.MoveNext
Wend
End With
End If
RS.Close
grid.Rows = grid.Rows + 1
grid.TextMatrix(grid.Rows - 1, 0) = grid.Rows - 2
Exit Sub

errorhandle:
myErrorHandle

End Sub

搜索更多相关主题的帖子: 感激不尽 
2005-11-10 12:32
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
'声明变量部分
Dim t As Integer
Dim CZYname As String
Dim RS1 As ADODB.Recordset'这里声明了一个数据库记录集对象

Private Sub GridIni(OrdSql As String, t As Integer)
'这是一个过程的开始GridIni不清楚应该是自定义过程

Set RS1 = New ADODB.Recordset

'这里将刚才的记录集对象实例化,应该是准备在后面使用(调用)该对象。

On Error GoTo errorhandle
'错误处理发生错误后跳转到errorhandle继续执行。


'以下代码中的grid应该是一个网格控件,这段代码的作用就是对
'网格控件初始化要显示的信息。
grid.Clear
grid.Rows = 2
grid.FormatString = ">序号|<出库编号|<入库编号|<药品编号|<药品名称|<药品规格|出库数量|<价格|<出库日期|<出库发票号|>出库操作员工号|>出库操作日期"
grid.TextMatrix(1, 1) = "CKBH"
grid.TextMatrix(1, 2) = "RKBH"
grid.TextMatrix(1, 3) = "YPBH"
grid.TextMatrix(1, 4) = "YPMC"
grid.TextMatrix(1, 5) = "YPGG"
grid.TextMatrix(1, 6) = "CKSL"
grid.TextMatrix(1, 7) = "JG"
grid.TextMatrix(1, 8) = "CKRQ"
grid.TextMatrix(1, 9) = "CKFPHM"
grid.TextMatrix(1, 10) = "CKCZYGH"
grid.TextMatrix(1, 11) = "CKCZRQ"
grid.RowHeight(1) = 0
grid.ColWidth(1) = 0


SQL = "select * from CKMXZB AS Z INNER JOIN CKMXCB AS C ON Z.CKBH=C.CKBH where RFRQ IS NULL and YYJGBH='" & TemYYJGBH & "'"
'SQL语句select应该是查询语句里面用了JOIN关键字看样子是联合查询。
If OrdSql <> "" Then
'仔细观察这个IF的作用应该是来对SQL语句的查询结果排序
SQL = SQL & " order by " & OrdSql
If t = 1 Then
SQL = SQL & " asc"'按从小到大的顺序排列
Else
SQL = SQL & " desc"'按从大到小的顺序排列
End If
End If

RS.Open SQL, myConn
'这里这个rs也应该是数据库记录集对象,不过这个对象的声明没有在楼主给
'的代码中。可能在外部声明。

If Not RS.EOF Then'判断rs对象中是否有数据。
With RS'VB语法的概念,这里是为了后面编写代码省事来做的。
.MoveFirst'因为上面用了With RS这里其实是把rs省略掉了。
'把rs中所有的数据循环读取出来,并用grid网格控件显示出来。
While Not .EOF
grid.Rows = grid.Rows + 1
grid.Row = grid.Rows - 1
grid.TextMatrix(grid.Row, 0) = grid.Row - 1

SQL = "select * from YPZD where YPBH='" & .Fields("YPBH") & "'"
RS1.Open SQL, myConn
If RS1.EOF Then
MsgBox "无药品编号为" & .Fields("YPBH") & "的药品信息,请检查药品字典", , "注意"
RS.Close
RS1.Close
End
Exit Sub
End If

For i = 1 To grid.Cols - 1

Select Case i
Case 4
grid.TextMatrix(grid.Row, i) = RS1.Fields("YPMC")
Case 5
grid.TextMatrix(grid.Row, i) = RS1.Fields("YPGG")
Case Else
grid.TextMatrix(grid.Row, i) = IIf(IsNull(.Fields(grid.TextMatrix(1, i))), "", .Fields(grid.TextMatrix(1, i)))
End Select


Next i
RS1.Close
.MoveNext
Wend
End With
End If
RS.Close
grid.Rows = grid.Rows + 1
grid.TextMatrix(grid.Rows - 1, 0) = grid.Rows - 2
Exit Sub

errorhandle:
myErrorHandle

End Sub

2005-11-11 13:26
快速回复:高手帮忙,感激不尽!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019803 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved