📄
字号:
Dim sRCode As String
Dim sPmSort As String
Dim s As String
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim sTable As String
Dim sField As String
Dim bBeginTrans As Boolean
'判断有效性
sRCode = GetComboKey(Me.ImgCmb_Sort, 0)
With Me.ImgCmb_PmSort
If Not .SelectedItem Is Nothing Then
sPmSort = .SelectedItem.Tag
End If
End With
If Trim(sRCode) = "" Or Trim(sPmSort) = "" Then
MsgBox "报表编码和工资类别不能为空!", vbOKOnly + vbCritical
Exit Sub
End If
s = " delete FROM PM_ReportItem where RCode='" & sRCode & "' AND PmSort='" & sPmSort & "'"
With Me.vsFG_Choose
For i = .FixedRows To .Rows - 1
If GetTableField(Trim(.TextMatrix(i, 2)), sTable, sField, ".") <> 1 Then
MsgBox "出现未知错误,程序返回原始状态!", vbOKOnly + vbCritical
Exit Sub
End If
s = s & " INSERT INTO PM_ReportItem VALUES('" & sRCode & "','" & sPmSort & "','" & sField & "','" & sTable & "'," & i - .FixedRows & ",1000,1) " & Chr(10)
Next i
End With
'保存
Cw_DataEnvi.DataConnect.BeginTrans
bBeginTrans = True
Cw_DataEnvi.DataConnect.Execute (s)
Cw_DataEnvi.DataConnect.CommitTrans
MsgBox "保存完毕!", vbOKOnly + vbInformation
Exit Sub
ErrCtrl:
If bBeginTrans = True Then
Cw_DataEnvi.DataConnect.RollbackTrans
End If
MsgBox "出现未知错误,程序返回原始状态!", vbOKOnly + vbCritical
End Sub
Private Sub Cmd_Remove_Click()
Call vsFG_Choose_DblClick
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) '快捷方式
If Shift = 4 Then '按住Alt
Select Case KeyCode
Case 190 '>
Call Cmd_Choose_Click
Case 188 '<
Call Cmd_Remove_Click
End Select
End If
End Sub
Private Sub Form_Load()
On Error GoTo ErrCtrl
'添加工资类别
Dim s As String
Dim rs As New ADODB.Recordset
Dim itm As ComboItem
s = "SELECT b.SortID,b.SortName FROM PM_OpeSort a inner join PM_Sort b on a.SortID=b.SortID where a.Czybm='" & Xtczybm & "'"
Set rs = Cw_DataEnvi.DataConnect.Execute(s)
With rs
Do While Not .EOF()
Set itm = Me.ImgCmb_PmSort.ComboItems.Add(, "@" & Trim(!SortId), Trim(!SortName))
itm.Tag = !SortId
.MoveNext
Loop
.Close
End With
If Me.ImgCmb_PmSort.ComboItems.Count <> 0 Then
Me.ImgCmb_PmSort.ComboItems.Item(1).Selected = True
End If
Set rs = Nothing
Set itm = Nothing
FillImageCombo Me.ImgCmb_Sort, "Pm_ReportSort", 1
InitView Me.TV_PreField '初始化树并填充数据
InitGrid Me.vsFG_Choose '初始化网格结构
FillGrid '填充网格数据
'编辑(新增、修改、删除)权限索引
Str_RightEdit = "Pm_ReportItem_edit"
Exit Sub
ErrCtrl:
If rs.State = 1 Then
rs.Close
End If
Set rs = Nothing
Set itm = Nothing
End Sub
Private Function FillGrid() '填充已经选入的字段到网格同时删除树的对应节点
On Error GoTo ErrCtrl
Dim rs As New ADODB.Recordset
Dim s As String
Dim sRCode As String
Dim sPmSort As String
Me.vsFG_Choose.Redraw = False
Me.vsFG_Choose.Rows = Me.vsFG_Choose.FixedRows
'取得报表编码和工资类别
sRCode = GetComboKey(Me.ImgCmb_Sort, 0)
sPmSort = Me.ImgCmb_PmSort.SelectedItem.Tag
'调用 ChooseItem 函数
s = "SELECT FieldName ,TableName FROM PM_ReportItem where RCode='" & sRCode & "' AND PmSort='" & sPmSort & "' Order by FieldOrder"
Set rs = Cw_DataEnvi.DataConnect.Execute(s)
With rs
Do While Not .EOF()
Me.TV_PreField.SelectedItem = Me.TV_PreField.Nodes(UCase(Trim(!TableName) & "." & Trim(!FieldName)))
ChooseItem Me.TV_PreField, Me.vsFG_Choose
.MoveNext
Loop
End With
Me.vsFG_Choose.Redraw = True
Exit Function
ErrCtrl:
If rs.State = 1 Then
rs.Close
End If
Set rs = Nothing
Me.vsFG_Choose.Redraw = True
End Function
Private Sub ImgCmb_PmSort_Click()
Call ImgCmb_Sort_Click
End Sub
Private Sub ImgCmb_Sort_Click()
On Error Resume Next
InitView Me.TV_PreField
FillGrid
End Sub
Private Sub TV_PreField_BeforeLabelEdit(Cancel As Integer)
Cancel = True
End Sub
Private Function ChooseItem(tv As TreeView, vs As vsFlexGrid) '选择字段
On Error GoTo ErrCtrl
Dim nod As Node
Dim i As Integer
Dim Item As ComboItem
Set nod = tv.SelectedItem
If Not nod.Parent Is Nothing Then
'添加网格
i = nod.Parent.Index
With vs
.AddItem ""
.TextMatrix(.Rows - 1, 0) = nod.Parent.Key
.TextMatrix(.Rows - 1, 1) = nod.Parent.Text
.TextMatrix(.Rows - 1, 2) = nod.Key
.TextMatrix(.Rows - 1, 3) = nod.Text
.TextMatrix(.Rows - 1, 4) = nod.Tag
.TextMatrix(.Rows - 1, 5) = nod.Parent.Text & "." & nod.Text
End With
'删除节点
If nod.Parent.Children = 1 Then
tv.Nodes.Remove nod.Index
tv.Nodes.Remove i
Else
tv.Nodes.Remove nod.Index
End If
End If
Set nod = Nothing
Exit Function
ErrCtrl:
Dim smsg As String
Dim smsgSys As String
smsg = GetError(Err.Number)
smsgSys = Err.Number & Err.Description & "!"
MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
End Function
Private Function RemoveItem(vs As vsFlexGrid, tv As TreeView) '删除字段
On Error GoTo ErrCtrl
Dim nod As Node
'增加树节点
With Me.TV_PreField
If Not IsNodeExist(Trim(vs.TextMatrix(vs.Row, 0)), Me.TV_PreField) Then
Set nod = tv.Nodes.Add("R", tvwChild, Trim(vs.TextMatrix(vs.Row, 0)), Trim(vs.TextMatrix(vs.Row, 1)))
Set nod = tv.Nodes.Add(Trim(vs.TextMatrix(vs.Row, 0)), tvwChild, Trim(vs.TextMatrix(vs.Row, 2)), Trim(vs.TextMatrix(vs.Row, 3)))
nod.Tag = Trim(vs.TextMatrix(vs.Row, 4))
Else
Set nod = tv.Nodes.Add(Trim(vs.TextMatrix(vs.Row, 0)), tvwChild, Trim(vs.TextMatrix(vs.Row, 2)), Trim(vs.TextMatrix(vs.Row, 3)))
nod.Tag = Trim(vs.TextMatrix(vs.Row, 4))
End If
'删除当前行
vs.RemoveItem (vs.Row)
End With
Exit Function
ErrCtrl:
Dim smsg As String
Dim smsgSys As String
smsg = GetError(Err.Number)
smsgSys = Err.Number & Err.Description & "!"
MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
End Function
Private Function InitGrid(vs As vsFlexGrid) '初始化网格
'第1列:表的物理名
'第2列:表的用户名
'第3列:字段的物理名
'第4列:字段的帮助信息
'第5列:字段的用户名
On Error GoTo ErrCtrl
Dim i As Integer
With vs
.Cols = 6
For i = 0 To .Cols - 2
.ColHidden(i) = True
Next i
.ColWidth(.Cols - 1) = .Width - 100
End With
Exit Function
ErrCtrl:
Dim smsg As String
Dim smsgSys As String
smsg = GetError(Err.Number)
smsgSys = Err.Number & Err.Description & "!"
MsgBox IIf(smsg = "", smsgSys, smsg), vbOKOnly + vbCritical
End Function
Private Sub TV_PreField_DblClick()
If Me.TV_PreField.SelectedItem Is Nothing Then
Exit Sub
End If
If Me.TV_PreField.SelectedItem.Children = 0 Then
ChooseItem Me.TV_PreField, Me.vsFG_Choose
End If
End Sub
Private Sub TV_PreField_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call TV_PreField_DblClick
End If
End Sub
Private Sub vsFG_Choose_DblClick()
If Me.vsFG_Choose.Rows > 0 Then
RemoveItem Me.vsFG_Choose, Me.TV_PreField
End If
End Sub
Private Sub vsFG_Choose_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call vsFG_Choose_DblClick
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -