📄 frmdepmanage.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmDepManage
Caption = "机构设置及编码"
ClientHeight = 5580
ClientLeft = 60
ClientTop = 345
ClientWidth = 9135
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 5580
ScaleWidth = 9135
Begin VB.CommandButton btnDel
Caption = "删除"
Height = 375
Left = 6240
TabIndex = 11
Top = 3840
Width = 1575
End
Begin VB.CommandButton btnAddSub
Caption = "增加为子级别"
Height = 375
Left = 6240
TabIndex = 10
Top = 3360
Width = 1575
End
Begin VB.CommandButton btnAddEql
Caption = "增加为本级别"
Height = 375
Left = 6240
TabIndex = 9
Top = 2880
Width = 1575
End
Begin VB.CommandButton btnAddBas
Caption = "增加为第一级别"
Height = 375
Left = 6240
TabIndex = 8
Top = 2400
Width = 1575
End
Begin VB.CommandButton btnModify
Caption = "修改"
Height = 375
Left = 6240
TabIndex = 7
Top = 1920
Width = 1575
End
Begin VB.TextBox txbDepCode
Enabled = 0 'False
Height = 375
Left = 6720
TabIndex = 6
Top = 1200
Width = 1215
End
Begin VB.TextBox txbLKindCode
Height = 375
Left = 6720
TabIndex = 5
Top = 720
Width = 1215
End
Begin VB.TextBox txbName
Height = 375
Left = 6720
TabIndex = 4
Top = 240
Width = 1215
End
Begin MSComctlLib.TreeView trvList
Height = 4935
Left = 240
TabIndex = 0
Top = 240
Width = 4335
_ExtentX = 7646
_ExtentY = 8705
_Version = 393217
Style = 7
Appearance = 1
End
Begin VB.Label Label3
Caption = "机构合成编码"
Height = 255
Left = 5520
TabIndex = 3
Top = 1320
Width = 1215
End
Begin VB.Label Label2
Caption = "本级别编码"
Height = 255
Left = 5640
TabIndex = 2
Top = 840
Width = 975
End
Begin VB.Label Label1
Caption = "机构名称"
Height = 255
Left = 5760
TabIndex = 1
Top = 360
Width = 855
End
End
Attribute VB_Name = "frmDepManage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'InitTree是用递归方法初始化TreeView控件的节点
Private Sub InitTree(ByRef ndParentNode As Node, ByVal sParentIndex As String)
Dim db As New DataBases
Dim rs As Recordset
Dim ndNew As Node
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE ParentIndex='" + sParentIndex + "'")
While (Not rs.EOF)
Set ndNew = trvList.Nodes.Add(ndParentNode, 4, , rs("类别"))
InitTree ndNew, rs("AbsIndex")
rs.MoveNext
Wend
db.CloseConn
End Sub
Private Sub btnAddEql_Click()
'判断修改条件
If Len(Trim(txbLKindCode.Text)) = 0 _
Or Len(Trim(txbDepCode.Text)) = 0 Then
Exit Sub
End If
'对编码进行验证
Dim sTmp As String
Dim db As New DataBases
Dim rs As Recordset
Dim tmpNode As Node
Set tmpNode = trvList.SelectedItem
sTmp = Trim(txbLKindCode.Text)
While Not tmpNode = tmpNode.Root
Set tmpNode = tmpNode.Parent
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE 类别='" + tmpNode.Text + "'")
sTmp = Trim(rs("类别号")) + sTmp
Wend
If Len(Trim(sTmp)) > 12 Then
'编码超长删除节点
MsgBox "编码超长,已被删除!"
Else
'向树控件加入新节点
Dim AbsIndex As String
Dim ItemIndex As String
Dim ParentIndex As String
Dim ItemLevel As String
Set tmpNode = trvList.Nodes.Add(trvList.SelectedItem.Parent, tvwChild, , txbName.Text)
'取得AbsIndex
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE 类别='" + trvList.SelectedItem.Text + "'")
ParentIndex = rs("ParentIndex")
ItemLevel = rs("ItemLevel")
Set rs = db.RunSelectSQL("SELECT MAX(AbsIndex) AS AbsIndex FROM 组织机构编码表")
AbsIndex = CInt(rs("AbsIndex")) + 1
Set rs = db.RunSelectSQL("SELECT MAX(ItemIndex) AS ItemIndex FROM 组织机构编码表 WHERE ParentIndex='" + ParentIndex + "'")
ItemIndex = CInt(rs("ItemIndex")) + 1
'编码符合要求,修改相应节点
Dim strSQL As String
strSQL = "INSERT INTO 组织机构编码表 (类别,类别号,单位编号,AbsIndex,ItemIndex,ItemLevel,ParentIndex) VALUES ('"
strSQL = strSQL + Trim(txbName.Text) + "','" + Trim(txbLKindCode.Text)
strSQL = strSQL + "','" + sTmp + "','" + AbsIndex + "','" + ItemIndex + "','" + ItemLevel + "','" + ParentIndex + "')"
Debug.Print
Debug.Print strSQL
db.RunSelectSQL (strSQL)
txbDepCode.Text = sTmp
End If
End Sub
Private Sub btnAddBas_Click()
'判断修改条件
If Len(Trim(txbLKindCode.Text)) = 0 _
Or Len(Trim(txbDepCode.Text)) = 0 Then
Exit Sub
End If
'对编码进行验证
Dim sTmp As String
Dim db As New DataBases
sTmp = "0" + Trim(txbLKindCode.Text)
If Len(Trim(sTmp)) > 12 Then
'编码超长删除节点
MsgBox "编码超长,已被删除!"
Else
'向树控件加入新节点
Dim tmpNode As Node
Dim AbsIndex As String
Dim ItemIndex As String
Set tmpNode = trvList.Nodes.Add(trvList.SelectedItem.Root, tvwChild, , txbName.Text)
'取得AbsIndex
Dim rs As Recordset
Set rs = db.RunSelectSQL("SELECT MAX(AbsIndex) AS AbsIndex FROM 组织机构编码表")
AbsIndex = CInt(rs("AbsIndex")) + 1
Set rs = db.RunSelectSQL("SELECT MAX(ItemIndex) AS ItemIndex FROM 组织机构编码表 WHERE ItemLevel='1'")
ItemIndex = CInt(rs("ItemIndex")) + 1
'编码符合要求,修改相应节点
Dim strSQL As String
strSQL = "INSERT INTO 组织机构编码表 (类别,类别号,单位编号,AbsIndex,ItemIndex,ItemLevel,ParentIndex) VALUES ('"
strSQL = strSQL + Trim(txbName.Text) + "','" + Trim(txbLKindCode.Text)
strSQL = strSQL + "','" + sTmp + "','" + AbsIndex + "','" + ItemIndex + "','1','0')"
Debug.Print
Debug.Print strSQL
db.RunSelectSQL (strSQL)
txbDepCode.Text = sTmp
End If
End Sub
Private Sub btnAddSub_Click()
'判断修改条件
If Len(Trim(txbLKindCode.Text)) = 0 _
Or Len(Trim(txbDepCode.Text)) = 0 Then
Exit Sub
End If
'对编码进行验证
Dim sTmp As String
Dim db As New DataBases
Dim rs As Recordset
Dim tmpNode As Node
Set tmpNode = trvList.SelectedItem
sTmp = Trim(txbLKindCode.Text)
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE 类别='" + tmpNode.Text + "'")
sTmp = Trim(rs("类别号")) + sTmp
While Not tmpNode = tmpNode.Root
Set tmpNode = tmpNode.Parent
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE 类别='" + tmpNode.Text + "'")
sTmp = Trim(rs("类别号")) + sTmp
Wend
If Len(Trim(sTmp)) > 12 Then
'编码超长删除节点
MsgBox "编码超长,已被删除!"
Else
'向树控件加入新节点
Dim AbsIndex As String
Dim ItemIndex As String
Dim ParentIndex As String
Dim ItemLevel As String
Set tmpNode = trvList.Nodes.Add(trvList.SelectedItem, tvwChild, , txbName.Text)
'取得AbsIndex
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE 类别='" + trvList.SelectedItem.Text + "'")
ParentIndex = rs("AbsIndex")
ItemLevel = CInt(rs("ItemLevel")) + 1
Set rs = db.RunSelectSQL("SELECT MAX(AbsIndex) AS AbsIndex FROM 组织机构编码表")
AbsIndex = CInt(rs("AbsIndex")) + 1
Set rs = db.RunSelectSQL("SELECT MAX(ItemIndex) AS ItemIndex FROM 组织机构编码表 WHERE ParentIndex='" + ParentIndex + "'")
If Not rs Then
ItemIndex = "0"
Else
ItemIndex = CInt(rs("ItemIndex")) + 1
End If
'编码符合要求,修改相应节点
Dim strSQL As String
strSQL = "INSERT INTO 组织机构编码表 (类别,类别号,单位编号,AbsIndex,ItemIndex,ItemLevel,ParentIndex) VALUES ('"
strSQL = strSQL + Trim(txbName.Text) + "','" + Trim(txbLKindCode.Text)
strSQL = strSQL + "','" + sTmp + "','" + AbsIndex + "','" + ItemIndex + "','" + ItemLevel + "','" + ParentIndex + "')"
Debug.Print
Debug.Print strSQL
db.RunSelectSQL (strSQL)
txbDepCode.Text = sTmp
End If
End Sub
Private Sub btnDel_Click()
Dim db As New DataBases
Dim rs As Recordset
Dim AbsIndex As String
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE 类别='" + txbName.Text + "'")
AbsIndex = rs("AbsIndex")
Debug.Print "SELECT * FROM 组织机构编码表 WHERE ParentIndex='" + AbsIndex + "'"
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE ParentIndex='" + AbsIndex + "'")
If rs.EOF Then
db.RunSelectSQL ("DELETE FROM 组织机构编码表 WHERE AbsIndex='" + AbsIndex + "'")
trvList.Nodes.Remove (trvList.SelectedItem.Index)
Else
If MsgBox("含有子节点,连子节点一起删除吗?", vbYesNo) = vbYes Then
db.RunSelectSQL ("DELETE FROM 组织机构编码表 WHERE ParentIndex='" + AbsIndex + "'")
db.RunSelectSQL ("DELETE FROM 组织机构编码表 WHERE AbsIndex='" + AbsIndex + "'")
trvList.Nodes.Remove (trvList.SelectedItem.Index)
End If
End If
End Sub
Private Sub btnModify_Click()
'判断修改条件
If Len(Trim(txbLKindCode.Text)) = 0 _
Or Len(Trim(txbDepCode.Text)) = 0 Then
Exit Sub
End If
'获得当前选中的节点
Dim tmpNode As Node
Set tmpNode = trvList.SelectedItem
'对编码进行验证
Dim sTmp As String
Dim sNum As String
Dim db As New DataBases
Dim rs As Recordset
sTmp = Trim(txbLKindCode.Text)
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE 类别='" + tmpNode.Text + "'")
sNum = rs("单位编号")
While Not tmpNode = tmpNode.Root
Set tmpNode = tmpNode.Parent
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE 类别='" + tmpNode.Text + "'")
sTmp = Trim(rs("类别号")) + sTmp
Wend
If Len(Trim(sTmp)) > 12 Then
'编码超长删除节点
trvList.Nodes.Remove (trvList.SelectedItem)
MessageBox.Show ("编码超长,已被删除!")
Else
trvList.SelectedItem.Text = txbName.Text
'编码符合要求,修改相应节点
Dim strSQL As String
strSQL = "UPDATE 组织机构编码表 SET 类别='" + Trim(txbName.Text)
strSQL = strSQL + "',类别号='" + Trim(txbLKindCode.Text)
strSQL = strSQL + "',单位编号='" + sTmp + "' WHERE 单位编号='"
strSQL = strSQL + sNum + "'"
db.RunSelectSQL (strSQL)
trvList.SelectedItem.Text = Trim(txbName.Text)
txbDepCode.Text = sTmp
End If
End Sub
Private Sub Form_Load()
Dim db As New DataBases
Dim rs As Recordset
Dim ndNew As Node
Set rs = db.RunSelectSQL("SELECT * FROM 组织机构编码表 WHERE ParentIndex='-1'")
Set ndNew = trvList.Nodes.Add(, , , rs("类别"))
InitTree ndNew, rs("AbsIndex")
trvList.Nodes(1).Child.EnsureVisible
End Sub
Private Sub trvList_NodeClick(ByVal Node As MSComctlLib.Node)
Dim db As New DataBases
Dim rs As Recordset
Dim strSQL As String
strSQL = "SELECT * FROM 组织机构编码表 WHERE 类别='" + trvList.SelectedItem.Text + "'"
Set rs = db.RunSelectSQL(strSQL)
txbName.Text = rs("类别")
txbLKindCode.Text = rs("类别号")
txbDepCode.Text = rs("单位编号")
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -