'************************************ LMS 2017.10 ************************************
'* 装入VSFGrid(根据sql语句,从表 xt_grid中找对应字段填充表格) 默认gridcol_fieldlx = 1,文本型;2,数值型;3,日期型;4,boolean型;0,uniqueidentifier型
'* 参数: gridcol_fieldname="",该字段在表或视图或rst中不存在,Col_Start,默认从第一一列开始填写(fixcol=1)
'************************************ LMS 2017.10 ************************************
Public Sub FillVSFGrid(VSFGrid As VSFlexGrid, SQL As String, Grid_Code As String, Optional Col_Start As Integer = 1)
Dim Xh As Long, Row As Long, KK As Integer
Dim rst As New ADODB.RecordSet, rst1 As New ADODB.RecordSet, Field_Name As String '----表中字段名
'On Error GoTo err_cl
With VSFGrid
.Rows = .FixedRows
Set rst = Nothing
Set rst = DataEnv.DataConn.Execute(SQL)
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst: Xh = 1: Row = .FixedRows
Do While Not rst.EOF
.AddItem ""
.TextMatrix(Row, 0) = Xh
For KK = Col_Start To .Cols - 1 '----求列对应的表中的字段名(例如:第1列--编码、第2列--名称等)
Set rst1 = Nothing
Set rst1 = DataEnv.DataConn.Execute("select * from xt_grid where grid_code='" + Trim(Grid_Code) + "' and gridcol_int=" & KK)
If Not (rst1.EOF And rst1.BOF) Then
Field_Name = Trim(rst1("gridcol_fieldname"))
If Field_Name = "" Then '----该字段在表或视图中不存在
.TextMatrix(Row, KK) = ""
Else
If IsNull(rst(Field_Name)) Then
.TextMatrix(Row, KK) = ""
Else
If rst1("gridcol_fieldlx") = 4 Then '----逻辑型4
.TextMatrix(Row, KK) = rst(Field_Name) '---- IIf(rst(Field_Name) = 1, True, False) '----- IIf(rst(Field_Name), "√", "")
ElseIf rst1("gridcol_fieldlx") = 2 Then '----数值型2
.TextMatrix(Row, KK) = IIf(rst(Field_Name) = 0, "", rst(Field_Name))
ElseIf rst1("gridcol_fieldlx") = 3 Then '----日期型3
.TextMatrix(Row, KK) = IIf(Year(rst(Field_Name)) < 2000, "", rst(Field_Name))
Else '----uniqueidentifier型0 + 文本型1 + 日期型3
.TextMatrix(Row, KK) = rst(Field_Name)
End If
End If
End If
End If
Next KK
Xh = Xh + 1: Row = Row + 1
rst.MoveNext
Loop
End If
End With
Set rst = Nothing: Set rst1 = Nothing
Exit Sub
err_cl:
Set rst = Nothing: Set rst1 = Nothing
MsgBox Err.Description, vbOKOnly + vbCritical, "系统提示"
End Sub
'* 装入VSFGrid(根据sql语句,从表 xt_grid中找对应字段填充表格) 默认gridcol_fieldlx = 1,文本型;2,数值型;3,日期型;4,boolean型;0,uniqueidentifier型
'* 参数: gridcol_fieldname="",该字段在表或视图或rst中不存在,Col_Start,默认从第一一列开始填写(fixcol=1)
'************************************ LMS 2017.10 ************************************
Public Sub FillVSFGrid(VSFGrid As VSFlexGrid, SQL As String, Grid_Code As String, Optional Col_Start As Integer = 1)
Dim Xh As Long, Row As Long, KK As Integer
Dim rst As New ADODB.RecordSet, rst1 As New ADODB.RecordSet, Field_Name As String '----表中字段名
'On Error GoTo err_cl
With VSFGrid
.Rows = .FixedRows
Set rst = Nothing
Set rst = DataEnv.DataConn.Execute(SQL)
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst: Xh = 1: Row = .FixedRows
Do While Not rst.EOF
.AddItem ""
.TextMatrix(Row, 0) = Xh
For KK = Col_Start To .Cols - 1 '----求列对应的表中的字段名(例如:第1列--编码、第2列--名称等)
Set rst1 = Nothing
Set rst1 = DataEnv.DataConn.Execute("select * from xt_grid where grid_code='" + Trim(Grid_Code) + "' and gridcol_int=" & KK)
If Not (rst1.EOF And rst1.BOF) Then
Field_Name = Trim(rst1("gridcol_fieldname"))
If Field_Name = "" Then '----该字段在表或视图中不存在
.TextMatrix(Row, KK) = ""
Else
If IsNull(rst(Field_Name)) Then
.TextMatrix(Row, KK) = ""
Else
If rst1("gridcol_fieldlx") = 4 Then '----逻辑型4
.TextMatrix(Row, KK) = rst(Field_Name) '---- IIf(rst(Field_Name) = 1, True, False) '----- IIf(rst(Field_Name), "√", "")
ElseIf rst1("gridcol_fieldlx") = 2 Then '----数值型2
.TextMatrix(Row, KK) = IIf(rst(Field_Name) = 0, "", rst(Field_Name))
ElseIf rst1("gridcol_fieldlx") = 3 Then '----日期型3
.TextMatrix(Row, KK) = IIf(Year(rst(Field_Name)) < 2000, "", rst(Field_Name))
Else '----uniqueidentifier型0 + 文本型1 + 日期型3
.TextMatrix(Row, KK) = rst(Field_Name)
End If
End If
End If
End If
Next KK
Xh = Xh + 1: Row = Row + 1
rst.MoveNext
Loop
End If
End With
Set rst = Nothing: Set rst1 = Nothing
Exit Sub
err_cl:
Set rst = Nothing: Set rst1 = Nothing
MsgBox Err.Description, vbOKOnly + vbCritical, "系统提示"
End Sub