main_jbzl_bmgl.frm
上传用户:ake0106
上传日期:2022-07-23
资源大小:4052k
文件大小:19k
源码类别:

企业管理

开发平台:

Visual Basic

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form main_jbzl_bmgl 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Form1"
  6.    ClientHeight    =   4155
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   8145
  10.    Icon            =   "main_jbzl_bmgl.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4155
  15.    ScaleWidth      =   8145
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   2  '屏幕中心
  18.    Begin VB.TextBox Text1 
  19.       Height          =   330
  20.       Index           =   6
  21.       Left            =   4350
  22.       TabIndex        =   14
  23.       Top             =   3720
  24.       Width           =   3690
  25.    End
  26.    Begin VB.TextBox Text1 
  27.       Enabled         =   0   'False
  28.       Height          =   330
  29.       Index           =   0
  30.       Left            =   4350
  31.       TabIndex        =   6
  32.       Top             =   885
  33.       Width           =   1695
  34.    End
  35.    Begin VB.TextBox Text1 
  36.       Enabled         =   0   'False
  37.       Height          =   330
  38.       Index           =   1
  39.       Left            =   4350
  40.       TabIndex        =   5
  41.       Top             =   1305
  42.       Width           =   1695
  43.    End
  44.    Begin VB.TextBox Text1 
  45.       Height          =   330
  46.       Index           =   2
  47.       Left            =   4350
  48.       TabIndex        =   4
  49.       Top             =   1725
  50.       Width           =   3690
  51.    End
  52.    Begin VB.TextBox Text1 
  53.       Enabled         =   0   'False
  54.       Height          =   645
  55.       Index           =   3
  56.       Left            =   4350
  57.       Locked          =   -1  'True
  58.       ScrollBars      =   2  'Vertical
  59.       TabIndex        =   3
  60.       Top             =   2160
  61.       Width           =   3690
  62.    End
  63.    Begin VB.TextBox Text1 
  64.       Height          =   330
  65.       Index           =   4
  66.       Left            =   4350
  67.       TabIndex        =   2
  68.       Top             =   2880
  69.       Width           =   3690
  70.    End
  71.    Begin VB.TextBox Text1 
  72.       Height          =   330
  73.       Index           =   5
  74.       Left            =   4350
  75.       TabIndex        =   1
  76.       Top             =   3300
  77.       Width           =   3690
  78.    End
  79.    Begin MSComctlLib.Toolbar Toolbar1 
  80.       Align           =   1  'Align Top
  81.       Height          =   795
  82.       Left            =   0
  83.       TabIndex        =   0
  84.       Top             =   0
  85.       Width           =   8145
  86.       _ExtentX        =   14367
  87.       _ExtentY        =   1402
  88.       ButtonWidth     =   1455
  89.       ButtonHeight    =   1349
  90.       Appearance      =   1
  91.       Style           =   1
  92.       ImageList       =   "ImageList1"
  93.       _Version        =   393216
  94.       BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
  95.          NumButtons      =   13
  96.          BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  97.             Caption         =   "确定"
  98.             Key             =   "ok"
  99.             ImageIndex      =   1
  100.          EndProperty
  101.          BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  102.             Caption         =   "取消"
  103.             Key             =   "cancel"
  104.             ImageIndex      =   2
  105.          EndProperty
  106.          BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  107.             Style           =   3
  108.          EndProperty
  109.          BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  110.             Caption         =   "添加同级"
  111.             Key             =   "addnew"
  112.             ImageIndex      =   3
  113.          EndProperty
  114.          BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  115.             Caption         =   "添加下级"
  116.             Key             =   "child"
  117.             ImageIndex      =   4
  118.          EndProperty
  119.          BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  120.             Style           =   3
  121.          EndProperty
  122.          BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  123.             Caption         =   "修改"
  124.             Key             =   "modify"
  125.             ImageIndex      =   5
  126.          EndProperty
  127.          BeginProperty Button8 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  128.             Caption         =   "删除"
  129.             Key             =   "del"
  130.             ImageIndex      =   6
  131.          EndProperty
  132.          BeginProperty Button9 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  133.             Style           =   3
  134.          EndProperty
  135.          BeginProperty Button10 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  136.             Caption         =   "展开"
  137.             Key             =   "expand"
  138.             ImageIndex      =   7
  139.          EndProperty
  140.          BeginProperty Button11 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  141.             Caption         =   "收缩"
  142.             Key             =   "nexpand"
  143.             ImageIndex      =   8
  144.          EndProperty
  145.          BeginProperty Button12 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  146.             Style           =   3
  147.          EndProperty
  148.          BeginProperty Button13 {66833FEA-8583-11D1-B16A-00C0F0283628} 
  149.             Caption         =   "退出"
  150.             Key             =   "exit"
  151.             ImageIndex      =   9
  152.          EndProperty
  153.       EndProperty
  154.       BorderStyle     =   1
  155.    End
  156.    Begin MSComctlLib.ImageList ImageList1 
  157.       Left            =   645
  158.       Top             =   1725
  159.       _ExtentX        =   1005
  160.       _ExtentY        =   1005
  161.       BackColor       =   -2147483643
  162.       ImageWidth      =   32
  163.       ImageHeight     =   32
  164.       MaskColor       =   12632256
  165.       _Version        =   393216
  166.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  167.          NumListImages   =   9
  168.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  169.             Picture         =   "main_jbzl_bmgl.frx":000C
  170.             Key             =   ""
  171.          EndProperty
  172.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  173.             Picture         =   "main_jbzl_bmgl.frx":08E6
  174.             Key             =   ""
  175.          EndProperty
  176.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  177.             Picture         =   "main_jbzl_bmgl.frx":11C0
  178.             Key             =   ""
  179.          EndProperty
  180.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  181.             Picture         =   "main_jbzl_bmgl.frx":14DA
  182.             Key             =   ""
  183.          EndProperty
  184.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  185.             Picture         =   "main_jbzl_bmgl.frx":17F4
  186.             Key             =   ""
  187.          EndProperty
  188.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  189.             Picture         =   "main_jbzl_bmgl.frx":20CE
  190.             Key             =   ""
  191.          EndProperty
  192.          BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  193.             Picture         =   "main_jbzl_bmgl.frx":29A8
  194.             Key             =   ""
  195.          EndProperty
  196.          BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  197.             Picture         =   "main_jbzl_bmgl.frx":2CC2
  198.             Key             =   ""
  199.          EndProperty
  200.          BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  201.             Picture         =   "main_jbzl_bmgl.frx":2FDC
  202.             Key             =   ""
  203.          EndProperty
  204.       EndProperty
  205.    End
  206.    Begin MSComctlLib.TreeView TreeView1 
  207.       Height          =   3180
  208.       Left            =   0
  209.       TabIndex        =   7
  210.       Top             =   900
  211.       Width           =   3300
  212.       _ExtentX        =   5821
  213.       _ExtentY        =   5609
  214.       _Version        =   393217
  215.       HideSelection   =   0   'False
  216.       Indentation     =   617
  217.       LabelEdit       =   1
  218.       LineStyle       =   1
  219.       Sorted          =   -1  'True
  220.       Style           =   6
  221.       ImageList       =   "imlSmallIcons"
  222.       Appearance      =   1
  223.       OLEDragMode     =   1
  224.    End
  225.    Begin MSComctlLib.ImageList imlSmallIcons 
  226.       Left            =   0
  227.       Top             =   255
  228.       _ExtentX        =   1005
  229.       _ExtentY        =   1005
  230.       BackColor       =   -2147483643
  231.       ImageWidth      =   13
  232.       ImageHeight     =   13
  233.       MaskColor       =   12632256
  234.       _Version        =   393216
  235.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  236.          NumListImages   =   6
  237.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  238.             Picture         =   "main_jbzl_bmgl.frx":38B6
  239.             Key             =   "closed"
  240.          EndProperty
  241.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  242.             Picture         =   "main_jbzl_bmgl.frx":3A28
  243.             Key             =   "cylinder"
  244.          EndProperty
  245.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  246.             Picture         =   "main_jbzl_bmgl.frx":3B9A
  247.             Key             =   "leaf"
  248.          EndProperty
  249.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  250.             Picture         =   "main_jbzl_bmgl.frx":3D0C
  251.             Key             =   "open"
  252.          EndProperty
  253.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  254.             Picture         =   "main_jbzl_bmgl.frx":3E7E
  255.             Key             =   "smlBook"
  256.          EndProperty
  257.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  258.             Picture         =   "main_jbzl_bmgl.frx":4130
  259.             Key             =   ""
  260.          EndProperty
  261.       EndProperty
  262.    End
  263.    Begin VB.Label Label1 
  264.       BackStyle       =   0  'Transparent
  265.       Caption         =   "部门全称:"
  266.       Height          =   270
  267.       Index           =   4
  268.       Left            =   3465
  269.       TabIndex        =   15
  270.       Top             =   2220
  271.       Width           =   1380
  272.    End
  273.    Begin VB.Label Label1 
  274.       BackStyle       =   0  'Transparent
  275.       Caption         =   "部门编号:"
  276.       Height          =   270
  277.       Index           =   0
  278.       Left            =   3465
  279.       TabIndex        =   13
  280.       Top             =   945
  281.       Width           =   1380
  282.    End
  283.    Begin VB.Label Label1 
  284.       BackStyle       =   0  'Transparent
  285.       Caption         =   "本级编号:"
  286.       Height          =   270
  287.       Index           =   1
  288.       Left            =   3465
  289.       TabIndex        =   12
  290.       Top             =   1365
  291.       Width           =   1380
  292.    End
  293.    Begin VB.Label Label1 
  294.       BackStyle       =   0  'Transparent
  295.       Caption         =   "部门名称:"
  296.       Height          =   270
  297.       Index           =   2
  298.       Left            =   3465
  299.       TabIndex        =   11
  300.       Top             =   1785
  301.       Width           =   1380
  302.    End
  303.    Begin VB.Label Label1 
  304.       BackStyle       =   0  'Transparent
  305.       Caption         =   "部门主管:"
  306.       Height          =   270
  307.       Index           =   3
  308.       Left            =   3465
  309.       TabIndex        =   10
  310.       Top             =   2940
  311.       Width           =   1380
  312.    End
  313.    Begin VB.Label Label1 
  314.       BackStyle       =   0  'Transparent
  315.       Caption         =   "部门地址:"
  316.       Height          =   270
  317.       Index           =   5
  318.       Left            =   3465
  319.       TabIndex        =   9
  320.       Top             =   3360
  321.       Width           =   1380
  322.    End
  323.    Begin VB.Label Label1 
  324.       BackStyle       =   0  'Transparent
  325.       Caption         =   "部门电话:"
  326.       Height          =   270
  327.       Index           =   6
  328.       Left            =   3465
  329.       TabIndex        =   8
  330.       Top             =   3780
  331.       Width           =   1380
  332.    End
  333. End
  334. Attribute VB_Name = "main_jbzl_bmgl"
  335. Attribute VB_GlobalNameSpace = False
  336. Attribute VB_Creatable = False
  337. Attribute VB_PredeclaredId = True
  338. Attribute VB_Exposed = False
  339.  Dim rs1 As New ADODB.Recordset
  340. Dim i As Integer
  341. Dim blnTJ, blnAdd As Boolean
  342. Dim bmjc As Integer
  343. Dim bmbh As String
  344. Public lngOL As Long
  345. Public Sub tree_change()     '定义添加树状列表的函数
  346.   TreeView1.Nodes.Clear
  347.   Dim mNode As Node
  348.   rs1.Open "select * from 部门表 order by 部门编号,编码级次", Cnn, adOpenKeyset, adLockOptimistic
  349.   If rs1.RecordCount > 0 Then
  350.   rs1.MoveFirst
  351.    Do While rs1.EOF = False
  352.      Select Case rs1.Fields("编码级次")
  353.         Case 1
  354.           Set mNode = TreeView1.Nodes.Add()
  355.           mNode.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
  356.           mNode.Key = rs1.Fields("部门全称")
  357.         Case 2
  358.           Set mNode1 = TreeView1.Nodes.Add(mNode.index, tvwChild)
  359.           mNode1.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
  360.           mNode1.Key = rs1.Fields("部门全称")
  361.         Case 3
  362.           Set mNode2 = TreeView1.Nodes.Add(mNode1.index, tvwChild)
  363.           mNode2.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
  364.           mNode2.Key = rs1.Fields("部门全称")
  365.         Case 4
  366.           Set mNode3 = TreeView1.Nodes.Add(mNode2.index, tvwChild)
  367.           mNode3.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
  368.           mNode3.Key = rs1.Fields("部门全称")
  369.         Case 5
  370.           Set mNode4 = TreeView1.Nodes.Add(mNode3.index, tvwChild)
  371.           mNode4.text = "(" & rs1.Fields("本级编号") & ")" & rs1.Fields("部门名称")
  372.           mNode4.Key = rs1.Fields("部门全称")
  373.      End Select
  374.      rs1.MoveNext
  375.   Loop
  376.   End If
  377.   rs1.Close
  378. End Sub
  379. Sub tlbState(state As Boolean)
  380.   With Toolbar1
  381.     If state = True Then
  382.        .Buttons(1).Enabled = False
  383.        .Buttons(2).Enabled = False
  384.        For i = 4 To 11
  385.          .Buttons(i).Enabled = True
  386.        Next i
  387.        For i = 0 To Text1.UBound
  388.          Text1(i).Locked = True
  389.        Next i
  390.     Else
  391.        .Buttons(1).Enabled = True
  392.        .Buttons(2).Enabled = True
  393.        For i = 4 To 11
  394.          .Buttons(i).Enabled = False
  395.        Next i
  396.        For i = 0 To Text1.UBound
  397.          Text1(i).Locked = False
  398.        Next i
  399.      End If
  400.    End With
  401. End Sub
  402. Private Sub Form_Load()
  403.   Me.Caption = text
  404.   tree_change
  405.   tlbState True
  406.   If TreeView1.Nodes.Count > 0 Then TreeView1.Nodes(1).Selected = True
  407. End Sub
  408. Private Sub Text1_KeyDown(index As Integer, KeyCode As Integer, Shift As Integer)
  409.   Dim strPos As String
  410.   If KeyCode = vbKeyReturn And index = 2 Then
  411.      If blnAdd = False Then
  412.        If Text1(3) <> "" Then Text1(3) = Left(Text1(3), Len(Text1(3)) - lngOL) & "(" & Text1(1) & ")" & Text1(2)
  413.      Else
  414.        If blnTJ = True Then
  415.           If TreeView1.Nodes.Count > 0 Then
  416.             strPos = InStr(1, TreeView1.SelectedItem.Key, "", 1)
  417.             If strPos = 0 Then
  418.               Text1(3) = "(" & Text1(1) & ")" & Text1(2)
  419.             Else
  420.               Text1(3) = TreeView1.SelectedItem.Parent.FullPath & "" & "(" & Text1(1) & ")" & Text1(2)
  421.             End If
  422.           Else
  423.             Text1(3) = "(" & Text1(1) & ")" & Text1(2)
  424.           End If
  425.        Else
  426.           Text1(3) = TreeView1.SelectedItem.FullPath & "" & "(" & Text1(1) & ")" & Text1(2)
  427.        End If
  428.      End If
  429.      Text1(4).SetFocus
  430.    End If
  431.    If KeyCode = vbKeyReturn And index > 3 And index < 6 Then Text1(index + 1).SetFocus
  432. End Sub
  433. Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
  434.   rs1.Open "select * from 部门表 where 部门全称='" + TreeView1.SelectedItem.Key + "'", Cnn, adOpenKeyset, adLockOptimistic
  435.   If rs1.RecordCount > 0 Then
  436.     For i = 0 To 6
  437.       Text1(i) = rs1.Fields(i)
  438.     Next i
  439.   End If
  440.   rs1.Close
  441. End Sub
  442. Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
  443.   Select Case Button.Key
  444.     Case "ok"
  445.       tlbState True
  446.       If Len(Text1(0)) > 10 Then
  447.         MsgBox "部门编号超长!"
  448.         Exit Sub
  449.       End If
  450.       If blnAdd = True Then
  451.         rs1.Open "select * from 部门表", Cnn, adOpenKeyset, adLockOptimistic
  452.         rs1.AddNew
  453.         For i = 0 To 6
  454.           rs1.Fields(i) = Text1(i)
  455.         Next i
  456.         rs1.Fields("编码级次") = Len(Text1(0)) / 2
  457.         rs1.Update
  458.         rs1.Close
  459.       Else
  460.         rs1.Open "select * from 部门表 where 部门编号='" + Text1(0) + "'", Cnn, adOpenKeyset, adLockOptimistic
  461.         If rs1.RecordCount > 0 Then
  462.         For i = 0 To 6
  463.           rs1.Fields(i) = Text1(i)
  464.         Next i
  465.         rs1.Update
  466.         End If
  467.         rs1.Close
  468.       End If
  469.       tree_change
  470.     Case "cancel"
  471.       tlbState True
  472.     Case "addnew"
  473.       tlbState False
  474.       blnTJ = True
  475.       blnAdd = True
  476.       For i = 0 To Text1.UBound
  477.          Text1(i).text = ""
  478.       Next i
  479.       rs1.Open "select * from 部门表 where 部门全称='" + TreeView1.SelectedItem.Key + "'order by 编码级次", Cnn, adOpenKeyset, adLockOptimistic
  480.       If rs1.RecordCount > 0 Then
  481.          bmjc = rs1.Fields("编码级次")
  482.       End If
  483.       rs1.Close
  484.       rs1.Open "select * from 部门表 where 部门全称 like '" + Left(TreeView1.SelectedItem.Key, (bmjc - 1) * 2) + "'+'%'and 编码级次=" & bmjc & "", Cnn, adOpenKeyset, adLockOptimistic
  485.       If rs1.RecordCount > 0 Then
  486.          rs1.MoveLast
  487.          Text1(1) = Format(Val(rs1.Fields("本级编号")) + 1, "00")
  488.          Text1(0) = Left(rs1.Fields("部门编号"), Val(bmjc - 1) * 2) & Text1(1)
  489.       Else
  490.          Text1(1) = "01"
  491.          For i = 1 To bmjc
  492.             Text1(0) = Text1(0) & "01"
  493.          Next i
  494.       End If
  495.       rs1.Close
  496.       Text1(2).SetFocus
  497.     Case "child"
  498.       tlbState False
  499.       blnTJ = False
  500.       blnAdd = True
  501.       For i = 0 To Text1.UBound
  502.          Text1(i).text = ""
  503.       Next i
  504.       rs1.Open "select * from 部门表 where 部门全称= '" + TreeView1.SelectedItem.Key + "'order by 编码级次", Cnn, adOpenKeyset, adLockOptimistic
  505.       If rs1.RecordCount > 0 Then
  506.          rs1.MoveLast
  507.          bmjc = rs1.Fields("编码级次") + 1
  508.          bmbh = rs1.Fields("部门编号")
  509.       End If
  510.       rs1.Close
  511.       rs1.Open "select * from 部门表 where 部门全称 like '" + TreeView1.SelectedItem.Key + "'+'%'and 编码级次=" & bmjc & "", Cnn, adOpenKeyset, adLockOptimistic
  512.       If rs1.RecordCount > 0 Then
  513.          rs1.MoveLast
  514.          Text1(1) = Format(Val(rs1.Fields("本级编号")) + 1, "00")
  515.          Text1(0) = Left(rs1.Fields("部门编号"), Val(bmjc - 1) * 2) & Text1(1)
  516.       Else
  517.          Text1(1) = "01"
  518.          For i = 1 To bmjc
  519.             Text1(0) = bmbh & "01"
  520.          Next i
  521.       End If
  522.       rs1.Close
  523.       Text1(2).SetFocus
  524.     Case "modify"
  525.       blnAdd = False
  526.       tlbState False
  527.       lngOL = Len("(" & Text1(1) & ")" & Text1(2))
  528.       Text1(2).SetFocus
  529.     Case "del"
  530.       If TreeView1.SelectedItem.Children > 0 Then
  531.          MsgBox "此部门存在下级部门,不允许删除!"
  532.          Exit Sub
  533.       End If
  534.       Cnn.Execute ("delete from 部门表 where 部门全称='" + TreeView1.SelectedItem.Key + "'")
  535.       tree_change
  536.     Case "expand"
  537.      For i = 1 To TreeView1.Nodes.Count
  538.        TreeView1.Nodes(i).Expanded = True
  539.      Next i
  540.     Case "nexpand"
  541.      For i = 1 To TreeView1.Nodes.Count
  542.        TreeView1.Nodes(i).Expanded = False
  543.      Next i
  544.     Case "exit"
  545.       Unload Me
  546.   End Select
  547. End Sub