main_jbzl_bmgl.frm
上传用户:ake0106
上传日期:2022-07-23
资源大小:4052k
文件大小:19k
- VERSION 5.00
- Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
- Begin VB.Form main_jbzl_bmgl
- BorderStyle = 3 'Fixed Dialog
- Caption = "Form1"
- ClientHeight = 4155
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 8145
- Icon = "main_jbzl_bmgl.frx":0000
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 4155
- ScaleWidth = 8145
- ShowInTaskbar = 0 'False
- StartUpPosition = 2 '屏幕中心
- Begin VB.TextBox Text1
- Height = 330
- Index = 6
- Left = 4350
- TabIndex = 14
- Top = 3720
- Width = 3690
- End
- Begin VB.TextBox Text1
- Enabled = 0 'False
- Height = 330
- Index = 0
- Left = 4350
- TabIndex = 6
- Top = 885
- Width = 1695
- End
- Begin VB.TextBox Text1
- Enabled = 0 'False
- Height = 330
- Index = 1
- Left = 4350
- TabIndex = 5
- Top = 1305
- Width = 1695
- End
- Begin VB.TextBox Text1
- Height = 330
- Index = 2
- Left = 4350
- TabIndex = 4
- Top = 1725
- Width = 3690
- End
- Begin VB.TextBox Text1
- Enabled = 0 'False
- Height = 645
- Index = 3
- Left = 4350
- Locked = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 3
- Top = 2160
- Width = 3690
- End
- Begin VB.TextBox Text1
- Height = 330
- Index = 4
- Left = 4350
- TabIndex = 2
- Top = 2880
- Width = 3690
- End
- Begin VB.TextBox Text1
- Height = 330
- Index = 5
- Left = 4350
- TabIndex = 1
- Top = 3300
- Width = 3690
- End
- Begin MSComctlLib.Toolbar Toolbar1
- Align = 1 'Align Top
- Height = 795
- Left = 0
- TabIndex = 0
- Top = 0
- Width = 8145
- _ExtentX = 14367
- _ExtentY = 1402
- ButtonWidth = 1455
- ButtonHeight = 1349
- Appearance = 1
- Style = 1
- ImageList = "ImageList1"
- _Version = 393216
- BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628}
- NumButtons = 13
- BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "确定"
- Key = "ok"
- ImageIndex = 1
- EndProperty
- BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "取消"
- Key = "cancel"
- ImageIndex = 2
- EndProperty
- BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Style = 3
- EndProperty
- BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "添加同级"
- Key = "addnew"
- ImageIndex = 3
- EndProperty
- BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "添加下级"
- Key = "child"
- ImageIndex = 4
- EndProperty
- BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Style = 3
- EndProperty
- BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "修改"
- Key = "modify"
- ImageIndex = 5
- EndProperty
- BeginProperty Button8 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "删除"
- Key = "del"
- ImageIndex = 6
- EndProperty
- BeginProperty Button9 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Style = 3
- EndProperty
- BeginProperty Button10 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "展开"
- Key = "expand"
- ImageIndex = 7
- EndProperty
- BeginProperty Button11 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "收缩"
- Key = "nexpand"
- ImageIndex = 8
- EndProperty
- BeginProperty Button12 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Style = 3
- EndProperty
- BeginProperty Button13 {66833FEA-8583-11D1-B16A-00C0F0283628}
- Caption = "退出"
- Key = "exit"
- ImageIndex = 9
- EndProperty
- EndProperty
- BorderStyle = 1
- End
- Begin MSComctlLib.ImageList ImageList1
- Left = 645
- Top = 1725
- _ExtentX = 1005
- _ExtentY = 1005
- BackColor = -2147483643
- ImageWidth = 32
- ImageHeight = 32
- MaskColor = 12632256
- _Version = 393216
- BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
- NumListImages = 9
- BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":000C
- Key = ""
- EndProperty
- BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":08E6
- Key = ""
- EndProperty
- BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":11C0
- Key = ""
- EndProperty
- BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":14DA
- Key = ""
- EndProperty
- BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":17F4
- Key = ""
- EndProperty
- BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":20CE
- Key = ""
- EndProperty
- BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":29A8
- Key = ""
- EndProperty
- BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":2CC2
- Key = ""
- EndProperty
- BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":2FDC
- Key = ""
- EndProperty
- EndProperty
- End
- Begin MSComctlLib.TreeView TreeView1
- Height = 3180
- Left = 0
- TabIndex = 7
- Top = 900
- Width = 3300
- _ExtentX = 5821
- _ExtentY = 5609
- _Version = 393217
- HideSelection = 0 'False
- Indentation = 617
- LabelEdit = 1
- LineStyle = 1
- Sorted = -1 'True
- Style = 6
- ImageList = "imlSmallIcons"
- Appearance = 1
- OLEDragMode = 1
- End
- Begin MSComctlLib.ImageList imlSmallIcons
- Left = 0
- Top = 255
- _ExtentX = 1005
- _ExtentY = 1005
- BackColor = -2147483643
- ImageWidth = 13
- ImageHeight = 13
- MaskColor = 12632256
- _Version = 393216
- BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628}
- NumListImages = 6
- BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":38B6
- Key = "closed"
- EndProperty
- BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":3A28
- Key = "cylinder"
- EndProperty
- BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":3B9A
- Key = "leaf"
- EndProperty
- BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":3D0C
- Key = "open"
- EndProperty
- BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":3E7E
- Key = "smlBook"
- EndProperty
- BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628}
- Picture = "main_jbzl_bmgl.frx":4130
- Key = ""
- EndProperty
- EndProperty
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "部门全称:"
- Height = 270
- Index = 4
- Left = 3465
- TabIndex = 15
- Top = 2220
- Width = 1380
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "部门编号:"
- Height = 270
- Index = 0
- Left = 3465
- TabIndex = 13
- Top = 945
- Width = 1380
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "本级编号:"
- Height = 270
- Index = 1
- Left = 3465
- TabIndex = 12
- Top = 1365
- Width = 1380
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "部门名称:"
- Height = 270
- Index = 2
- Left = 3465
- TabIndex = 11
- Top = 1785
- Width = 1380
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "部门主管:"
- Height = 270
- Index = 3
- Left = 3465
- TabIndex = 10
- Top = 2940
- Width = 1380
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "部门地址:"
- Height = 270
- Index = 5
- Left = 3465
- TabIndex = 9
- Top = 3360
- Width = 1380
- End
- Begin VB.Label Label1
- BackStyle = 0 'Transparent
- Caption = "部门电话:"
- Height = 270
- Index = 6
- Left = 3465
- TabIndex = 8
- Top = 3780
- Width = 1380
- End
- End
- Attribute VB_Name = "main_jbzl_bmgl"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim rs1 As New ADODB.Recordset
- Dim i As Integer
- Dim blnTJ, blnAdd As Boolean
- Dim bmjc As Integer
- Dim bmbh As String
- Public lngOL As Long
- Public Sub tree_change() '定义添加树状列表的函数
- TreeView1.Nodes.Clear
- Dim mNode As Node
- rs1.Open "select * from 部门表 order by 部门编号,编码级次", Cnn, adOpenKeyset, adLockOptimistic
- If rs1.RecordCount > 0 Then
- rs1.MoveFirst
- Do While rs1.EOF = False
- Select Case rs1.Fields("编码级次")
- Case 1
- Set mNode = TreeView1.Nodes.Add()
- mNode.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
- mNode.Key = rs1.Fields("部门全称")
- Case 2
- Set mNode1 = TreeView1.Nodes.Add(mNode.index, tvwChild)
- mNode1.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
- mNode1.Key = rs1.Fields("部门全称")
- Case 3
- Set mNode2 = TreeView1.Nodes.Add(mNode1.index, tvwChild)
- mNode2.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
- mNode2.Key = rs1.Fields("部门全称")
- Case 4
- Set mNode3 = TreeView1.Nodes.Add(mNode2.index, tvwChild)
- mNode3.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
- mNode3.Key = rs1.Fields("部门全称")
- Case 5
- Set mNode4 = TreeView1.Nodes.Add(mNode3.index, tvwChild)
- mNode4.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
- mNode4.Key = rs1.Fields("部门全称")
- End Select
- rs1.MoveNext
- Loop
- End If
- rs1.Close
- End Sub
- Sub tlbState(state As Boolean)
- With Toolbar1
- If state = True Then
- .Buttons(1).Enabled = False
- .Buttons(2).Enabled = False
- For i = 4 To 11
- .Buttons(i).Enabled = True
- Next i
- For i = 0 To Text1.UBound
- Text1(i).Locked = True
- Next i
- Else
- .Buttons(1).Enabled = True
- .Buttons(2).Enabled = True
- For i = 4 To 11
- .Buttons(i).Enabled = False
- Next i
- For i = 0 To Text1.UBound
- Text1(i).Locked = False
- Next i
- End If
- End With
- End Sub
- Private Sub Form_Load()
- Me.Caption = text
- tree_change
- tlbState True
- If TreeView1.Nodes.Count > 0 Then TreeView1.Nodes(1).Selected = True
- End Sub
- Private Sub Text1_KeyDown(index As Integer, KeyCode As Integer, Shift As Integer)
- Dim strPos As String
- If KeyCode = vbKeyReturn And index = 2 Then
- If blnAdd = False Then
- If Text1(3) <> "" Then Text1(3) = Left(Text1(3), Len(Text1(3)) - lngOL) & "(" & Text1(1) & ")" & Text1(2)
- Else
- If blnTJ = True Then
- If TreeView1.Nodes.Count > 0 Then
- strPos = InStr(1, TreeView1.SelectedItem.Key, "", 1)
- If strPos = 0 Then
- Text1(3) = "(" & Text1(1) & ")" & Text1(2)
- Else
- Text1(3) = TreeView1.SelectedItem.Parent.FullPath & "" & "(" & Text1(1) & ")" & Text1(2)
- End If
- Else
- Text1(3) = "(" & Text1(1) & ")" & Text1(2)
- End If
- Else
- Text1(3) = TreeView1.SelectedItem.FullPath & "" & "(" & Text1(1) & ")" & Text1(2)
- End If
- End If
- Text1(4).SetFocus
- End If
- If KeyCode = vbKeyReturn And index > 3 And index < 6 Then Text1(index + 1).SetFocus
- End Sub
- Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
- rs1.Open "select * from 部门表 where 部门全称='" + TreeView1.SelectedItem.Key + "'", Cnn, adOpenKeyset, adLockOptimistic
- If rs1.RecordCount > 0 Then
- For i = 0 To 6
- Text1(i) = rs1.Fields(i)
- Next i
- End If
- rs1.Close
- End Sub
- Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
- Select Case Button.Key
- Case "ok"
- tlbState True
- If Len(Text1(0)) > 10 Then
- MsgBox "部门编号超长!"
- Exit Sub
- End If
- If blnAdd = True Then
- rs1.Open "select * from 部门表", Cnn, adOpenKeyset, adLockOptimistic
- rs1.AddNew
- For i = 0 To 6
- rs1.Fields(i) = Text1(i)
- Next i
- rs1.Fields("编码级次") = Len(Text1(0)) / 2
- rs1.Update
- rs1.Close
- Else
- rs1.Open "select * from 部门表 where 部门编号='" + Text1(0) + "'", Cnn, adOpenKeyset, adLockOptimistic
- If rs1.RecordCount > 0 Then
- For i = 0 To 6
- rs1.Fields(i) = Text1(i)
- Next i
- rs1.Update
- End If
- rs1.Close
- End If
- tree_change
- Case "cancel"
- tlbState True
- Case "addnew"
- tlbState False
- blnTJ = True
- blnAdd = True
- For i = 0 To Text1.UBound
- Text1(i).text = ""
- Next i
- rs1.Open "select * from 部门表 where 部门全称='" + TreeView1.SelectedItem.Key + "'order by 编码级次", Cnn, adOpenKeyset, adLockOptimistic
- If rs1.RecordCount > 0 Then
- bmjc = rs1.Fields("编码级次")
- End If
- rs1.Close
- rs1.Open "select * from 部门表 where 部门全称 like '" + Left(TreeView1.SelectedItem.Key, (bmjc - 1) * 2) + "'+'%'and 编码级次=" & bmjc & "", Cnn, adOpenKeyset, adLockOptimistic
- If rs1.RecordCount > 0 Then
- rs1.MoveLast
- Text1(1) = Format(Val(rs1.Fields("本级编号")) + 1, "00")
- Text1(0) = Left(rs1.Fields("部门编号"), Val(bmjc - 1) * 2) & Text1(1)
- Else
- Text1(1) = "01"
- For i = 1 To bmjc
- Text1(0) = Text1(0) & "01"
- Next i
- End If
- rs1.Close
- Text1(2).SetFocus
- Case "child"
- tlbState False
- blnTJ = False
- blnAdd = True
- For i = 0 To Text1.UBound
- Text1(i).text = ""
- Next i
- rs1.Open "select * from 部门表 where 部门全称= '" + TreeView1.SelectedItem.Key + "'order by 编码级次", Cnn, adOpenKeyset, adLockOptimistic
- If rs1.RecordCount > 0 Then
- rs1.MoveLast
- bmjc = rs1.Fields("编码级次") + 1
- bmbh = rs1.Fields("部门编号")
- End If
- rs1.Close
- rs1.Open "select * from 部门表 where 部门全称 like '" + TreeView1.SelectedItem.Key + "'+'%'and 编码级次=" & bmjc & "", Cnn, adOpenKeyset, adLockOptimistic
- If rs1.RecordCount > 0 Then
- rs1.MoveLast
- Text1(1) = Format(Val(rs1.Fields("本级编号")) + 1, "00")
- Text1(0) = Left(rs1.Fields("部门编号"), Val(bmjc - 1) * 2) & Text1(1)
- Else
- Text1(1) = "01"
- For i = 1 To bmjc
- Text1(0) = bmbh & "01"
- Next i
- End If
- rs1.Close
- Text1(2).SetFocus
- Case "modify"
- blnAdd = False
- tlbState False
- lngOL = Len("(" & Text1(1) & ")" & Text1(2))
- Text1(2).SetFocus
- Case "del"
- If TreeView1.SelectedItem.Children > 0 Then
- MsgBox "此部门存在下级部门,不允许删除!"
- Exit Sub
- End If
- Cnn.Execute ("delete from 部门表 where 部门全称='" + TreeView1.SelectedItem.Key + "'")
- tree_change
- Case "expand"
- For i = 1 To TreeView1.Nodes.Count
- TreeView1.Nodes(i).Expanded = True
- Next i
- Case "nexpand"
- For i = 1 To TreeView1.Nodes.Count
- TreeView1.Nodes(i).Expanded = False
- Next i
- Case "exit"
- Unload Me
- End Select
- End Sub