⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmanage.frm

📁 人事管理系统vb版,用于一般中小企业
💻 FRM
📖 第 1 页 / 共 3 页
字号:
Private Sub cmdEdit_Click(Index As Integer)
On Error GoTo errNext
    With adoMainLink
        Select Case Index
        Case 1: '添加
            dgdFind.Enabled = False
            For intCount = 0 To 3
                txtUser(intCount).Text = ""
            Next
            With adoEditLink
                If .State = adStateOpen Then .Close
                .Open "select * from 隶属部门 order by 层次,部门编号,id", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
                cboUser.Clear
                cboUser.AddItem "无上层", 0
                cboUser.ListIndex = 0
                intCount = 1
                If .EOF = False Then
                    .MoveLast
                    ReDim intSum(.RecordCount) As Integer
                    .MoveFirst
                    Do Until .EOF
                        cboUser.AddItem .Fields("隶属部门"), intCount
                        intSum(intCount) = CInt(.Fields("层次"))
                        intCount = intCount + 1
                        .MoveNext
                    Loop
                End If
            End With
            blnAddNew = True
            cmdEdit(1).Enabled = False
            cmdEdit(2).Enabled = False
            cmdEdit(3).Enabled = True
            cmdEdit(4).Enabled = True
        Case 2: '删除
            If .EOF = False Then
                Dim intID As Integer
                Dim strTemp As String
                strBM = Trim(.Fields("隶属部门")) & ""
                intID = Trim(.Fields("id")) & ""
                If MsgBox("确认要删除部门[" & strBM & "]?", vbOKCancel + vbInformation, App.Title) = vbOK Then
                    If MsgBox("如果删除部门[" & strBM & "],则隶属于此部门的所有人员都将同时被清除,确认吗?", vbOKCancel + vbInformation, App.Title) = vbCancel Then
                        Exit Sub
                    End If
                    'dgdFind.Visible = False
                    adoConn.BeginTrans
                    .Delete
                    .MoveNext
                    With adoEditLink
                        If .State = adStateOpen Then .Close
                        .Open "select id,上层部门,层次 from 隶属部门 where 上层部门='" & strBM & "'", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
                        Do Until .EOF
                            .Fields("上层部门") = ""
                            .Fields("层次") = "1"
                            .Update
                            .MoveNext
                        Loop
                        .Close
                        .Open "select 员工编号,姓名,隶属部门 from 员工详细资料 where 隶属部门=" & intID & "", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
                        intCount = 0
                        If .EOF = False Then
                            .MoveLast
                            intCount = .RecordCount
                            .MoveFirst
                            Do Until .EOF
                                strTemp = strTemp & "编号[" & .Fields("员工编号") & "]" & "姓名[" & .Fields("姓名") & "] "
                                .MoveNext
                            Loop
                            .Close
                            .Open "delete from 员工详细资料 where 隶属部门=" & intID & "", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
                        End If
                    End With
                    adoConn.CommitTrans
                    ricBox.Text = ricBox.Text & "时间: " & Now & " 内容: 删除部门[" & strBM & "],删除隶属此部门的员工" & intCount & "人." & vbCrLf & "被删除人员名单:--------------------------------------------" & vbCrLf & strTemp & vbCrLf & vbTab & "        --------------------------------------------" & vbCrLf
                    .Requery
                    If blnInfo = True Then
                        Call ManageView
                        Call frmInfo.AddTreeView
                        Call frmInfo.ManageLoad(1)
                    Else
                        Call ManageView
                    End If
                    Call dgdFind_RowColChange(0, 0)
                    'dgdFind.Visible = True
                    MsgBox "删除成功!", vbOKOnly + vbInformation, App.Title
                End If
            Else
                MsgBox "未找到要删除的记录!"
                Exit Sub
            End If
        Case 3: '保存,先进行层次扫描,判断各属性的正确位置,再进行保存工作.
            If Len(Trim(txtUser(0).Text)) = 0 Then
                MsgBox "未输入部门名称!", vbCritical
                txtUser(0).SetFocus
                Exit Sub
            End If
            If Len(Trim(txtUser(3).Text)) = 0 Then
                MsgBox "未输入部门编号!", vbCritical
                txtUser(3).SetFocus
                Exit Sub
            End If
            For intCount = 0 To cboUser.ListCount - 1
                If Trim(txtUser(0).Text) = Trim(cboUser.List(intCount)) Then
                    MsgBox Trim(txtUser(0).Text) & "已在隶属部门中存在,请重新输入!", vbExclamation
                    txtUser(0).Text = ""
                    txtUser(0).SetFocus
                    Exit Sub
                End If
            Next
            If txtUser(1).Text > 5 Then MsgBox "部门层次不能超过5层!", vbExclamation: Exit Sub
            If blnAddNew = True Then
                .AddNew
                strBM = Trim(txtUser(0).Text)
            Else
                If strManage <> Trim(txtUser(0).Text) Then
                    If MsgBox("如果修改部门名称,则所有属于此部门的员工的隶属" & vbCrLf & "部门都将同时被更改,确认要修改吗(Y/N)?", vbInformation + vbOKCancel, App.Title) = vbCancel Then Exit Sub
                End If
            End If
            .Fields("隶属部门") = Trim(txtUser(0).Text)
            .Fields("部门编号") = Trim(txtUser(3).Text)
            If Trim(cboUser.Text) <> "无上层" Then
                .Fields("上层部门") = Trim(cboUser.Text)
                .Fields("层次") = Trim(txtUser(1).Text)
            Else
                .Fields("上层部门") = ""
                .Fields("层次") = "1"
            End If
            .Fields("部门职责") = Trim(txtUser(2).Text)
            .Update
            If blnAddNew = True Then
                blnAddNew = False
                ricBox.Text = ricBox.Text & "时间: " & Now & " 内容: 添加部门[" & strBM & "]." & vbCrLf
            Else
                ricBox.Text = ricBox.Text & "时间: " & Now & " 内容: 保存部门[" & strManage & "]为[" & strBM & "]." & vbCrLf
            End If
            If blnInfo = True And blnAddNew = True Then
                Call frmInfo.AddTreeView
            ElseIf blnInfo = True And blnAddNew = False Then
                Call frmInfo.AddTreeView
                Call frmInfo.ManageLoad(1)
                Call ManageView
            Else
                Call ManageView
            End If

            .Requery
            dgdFind.Enabled = True
            cmdEdit(1).Enabled = True
            cmdEdit(4).Enabled = False
            MsgBox "保存成功!", vbOKOnly + vbInformation, App.Title
        Case 4: '取消
            blnAddNew = False
            dgdFind.Enabled = True
            cmdEdit(1).Enabled = True
            cmdEdit(4).Enabled = False
            Call dgdFind_RowColChange(0, 0)
        End Select
        If blnAddNew = False Then
            cmdEdit(2).Enabled = Not .EOF
            cmdEdit(3).Enabled = Not .EOF
        End If
    End With
    Exit Sub
errNext:
    dgdFind.Visible = True
    Call ErrMsg(Err.Number, Err.Description)
End Sub

Private Sub cmdEnd_Click()
    Unload Me
End Sub

Public Sub dgdFind_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    On Error GoTo errNext
    If adoMainLink.EOF = True Or blnAddNew = True Then Exit Sub
    With adoEditLink
        If .State = adStateOpen Then .Close
        strManage = Trim(adoMainLink.Fields("隶属部门")) & ""
        .Open "select * from 隶属部门 where 隶属部门='" & strManage & "'", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
        For intCount = 0 To 3
            txtUser(intCount).Text = Trim(.Fields(lblUser(intCount).Caption) & "")
        Next
        strLevel = .Fields("层次")
        strUpManage = .Fields("上层部门") & ""
        cboUser.Visible = False
        cboUser.Clear
        cboUser.AddItem "无上层", 0
        cboUser.ListIndex = 0
        intCount = 1
        .Close
        .Open "select id,隶属部门,上层部门,层次 from 隶属部门 where 隶属部门<>'" & strManage & "'", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
        If .EOF = False Then
            .MoveLast
            ReDim intSum(.RecordCount) As Integer
            .MoveFirst
            Do Until .EOF
                cboUser.AddItem .Fields("隶属部门"), intCount
                If Trim(.Fields("隶属部门")) = strUpManage Then cboUser.ListIndex = intCount
                intSum(intCount) = CInt(.Fields("层次"))
                intCount = intCount + 1
                .MoveNext
            Loop
        .MoveFirst
        End If
        cboUser.Visible = True
        Call cboUser_Click
    End With
    tvwManage.Nodes(adoMainLink.AbsolutePosition + 1).Selected = True
    Exit Sub
errNext:
    cboUser.Visible = True
    Call ErrMsg(Err.Number, Err.Description)
End Sub

Private Sub Form_Load()
    On Error Resume Next
    cboFind.ListIndex = 0
    tvwManage.ImageList = MDIMain.iltPic
    stbManage.TabPicture(0) = MDIMain.iltPic.ListImages(7).Picture
    blnAddNew = False
    With adoMainLink
        If .State = adStateOpen Then .Close
        .Open "select * from 隶属部门  order by 层次,部门编号,id", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
        Set dgdFind.DataSource = adoMainLink
        cmdEdit(2).Enabled = Not .EOF
        cmdEdit(3).Enabled = Not .EOF
        Call ManageView
        If .EOF = False Then .AbsolutePosition = gintManageTake
    End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If adoEditLink.State = adStateOpen Then adoEditLink.Close
    Set adoEditLink = Nothing
End Sub

Private Sub tvwManage_NodeClick(ByVal Node As MSComctlLib.Node)
    On Error Resume Next
    Set nodName = Node
    If Node.Key = "A" Then Exit Sub
    With adoMainLink
        If intManage <> .RecordCount Then Call cmdFind_Click(1)
        .AbsolutePosition = nodName.Index - 1
    End With
End Sub

Private Sub cmdFind_Click(Index As Integer)
    On Error Resume Next
    With adoMainLink
        If .State = adStateOpen Then .Close
        If Index = 0 Then
            .Open "select * from 隶属部门 where " & cboFind.Text & " like '%" & txtFind.Text & "%' order by 层次,部门编号,id", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
        Else
            .Open "select * from 隶属部门 order by 层次,部门编号,id", adoConn, adOpenDynamic, adLockPessimistic, adCmdText
        End If
        Set dgdFind.DataSource = adoMainLink
    End With
End Sub

Private Sub txtFind_Change()
    Call cmdFind_Click(0)
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -