📄 员工.frm
字号:
Width = 975
End
Begin VB.Label lblInfo
Caption = "学 历:"
Height = 255
Index = 4
Left = 120
TabIndex = 42
Top = 1884
Width = 975
End
End
Begin VB.Menu m1
Caption = "管理操作(&F)"
Begin VB.Menu m10
Caption = "档案查询"
End
Begin VB.Menu m1bar0
Caption = "-"
End
Begin VB.Menu m11
Caption = "增加档案"
End
Begin VB.Menu m12
Caption = "修改档案"
End
Begin VB.Menu m13
Caption = "删除档案"
End
Begin VB.Menu m1bar1
Caption = "-"
End
Begin VB.Menu m14
Caption = "保存档案"
End
Begin VB.Menu m1bar2
Caption = "-"
End
Begin VB.Menu m15
Caption = "退出"
End
End
Begin VB.Menu m2
Caption = "视图查看(&V)"
Begin VB.Menu m21
Caption = "基本资料"
End
Begin VB.Menu m22
Caption = "联系资料"
End
Begin VB.Menu m23
Caption = "其他资料"
End
Begin VB.Menu m24
Caption = "总览全局"
End
End
End
Attribute VB_Name = "yuangong"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdAdd_Click()
strCheck = "增加"
SSTab1.Tab = 1
Call LockInput(False)
Call ClearInput
Call LockButton(True)
End Sub
Private Sub cmdCancel_Click()
If strCheck = "增加" Or strCheck = "修改" Then
Call ClearInput
Call LockButton(False)
Call LockInput(True)
strCheck = "" '清空strCheck标志,以备运行后面关闭窗体
Else
Unload Me
End If
End Sub
Private Sub cmdDel_Click()
If MsgBox("确定要删除【" & txtInfo(1).Text & "】的档案吗?", vbYesNo, "警告") = vbYes Then
sql = "Select * from [员工档案] where [姓名]='" & txtInfo(1).Text & "'"
rs.Open sql, conn, 1, 3
rs.Delete
rs.Update
MsgBox "成功地将【" & txtInfo(1).Text & "】的档案删除了!", vbOKOnly + vbInformation, App.Title
rs.Close
Set rs = Nothing
Call ClearInput
Call ShowList
Else
Exit Sub
End If
End Sub
Private Sub cmdSearch_Click()
yuangongchaxun.Show 1
Call ShowInfo
End Sub
Private Sub cmdModify_Click()
strCheck = "修改"
Call LockInput(False)
Call LockButton(True)
End Sub
Private Sub cmdSave_Click()
If strCheck = "增加" Then
Call CheckInput
If FoundErr = True Then
FoundErr = False
Exit Sub
End If
sql = "Select * from [员工档案] where [编号]='" & txtInfo(9).Text & "'"
rs.Open sql, conn, 1, 3
If rs.EOF = False Then
MsgBox "员工编号【" & txtInfo(9).Text & "】已经存在!"
rs.Close
Set rs = Nothing
txtInfo(9).Text = ""
txtInfo(9).SetFocus
Exit Sub
Else
rs.AddNew
For i = 1 To 37
rs.Fields(i) = txtInfo(i).Text
Next i
rs.Fields("登记日期") = Date
rs.Fields("修改日期") = Date
rs.Update
MsgBox ("添加成功!")
End If
End If
If strCheck = "修改" Then
Call CheckInput
If FoundErr = True Then
FoundErr = False
Exit Sub
End If
sql = "Select * from [员工档案] where [id]=" & ID
rs.Open sql, conn, 1, 3
If rs.EOF Then
MsgBox "员工编号【" & txtInfo(9).Text & "】已经存在!"
txtInfo(9).SetFocus
txtInfo(9).SelStart = 0
txtInfo(9).SelLength = Len(txtInfo(9).Text)
rs.Close
Set rs = Nothing
Exit Sub
End If
For i = 1 To 37
rs.Fields(i) = txtInfo(i).Text
Next i
rs.Fields("修改日期") = Date
rs.Update
Call LockInput(True)
MsgBox ("修改成功!")
End If
strCheck = "" '清空strCheck标志,以备以后继续查询使用,而不是转化为跳格键功能
Call LockButton(False)
rs.Close
Set rs = Nothing
Call ShowList
End Sub
Private Sub Form_Load()
Me.Height = 5700
Me.Refresh
Call CheckLogin(Me)
Call SetCenter(Me)
Call yuangongSet(Me)
Call LockInput(True)
'打开数据库,总览全局显示员工档案
Call OpenDB
Call ShowList
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call Closewindow(UnloadMode, Cancel, Me)
End Sub
'过程--锁定输入
Sub LockInput(YesNo As Boolean)
For i = 1 To 37
txtInfo(i).Locked = YesNo
Next i
End Sub
'过程--清空输入
Sub ClearInput()
For i = 1 To 37
txtInfo(i).Text = ""
Next i
txtInfo(1).SetFocus
End Sub
'过程--禁用按钮
Sub LockButton(YesNo As Boolean)
'按钮
cmdAdd.Enabled = Not (YesNo)
cmdModify.Enabled = Not (YesNo)
cmdDel.Enabled = Not (YesNo)
cmdSearch.Enabled = Not (YesNo)
cmdSave.Enabled = YesNo
'菜单
m10.Enabled = Not (YesNo)
m11.Enabled = Not (YesNo)
m12.Enabled = Not (YesNo)
m13.Enabled = Not (YesNo)
m14.Enabled = YesNo
End Sub
'过程--显示记录内容
Sub ShowInfo()
If WhereField = "姓名" And Keywords <> "" Then
sql = "Select * from [员工档案] where [姓名]='" & Keywords & " '"
ElseIf WhereField = "编号" And Keywords <> "" Then
sql = "Select * from [员工档案] where [编号]='" & Keywords & "'"
Else
Exit Sub
End If
rs.Open sql, conn, 1, 1
If rs.EOF Then
If WhereField = "姓名" Then
MsgBox "没有找到员工姓名为【" & Keywords & "】的记录!"
ElseIf WhereField = "编号" Then
MsgBox "没有找到员工编号名为【" & Keywords & "】的记录!"
End If
rs.Close
Set rs = Nothing
Exit Sub
Else
For i = 1 To 37
txtInfo(i).Text = rs.Fields(i)
Next i
JoinDate.Caption = rs.Fields("登记日期")
ModifyDate.Caption = rs.Fields("修改日期")
'判断员工是否有照片
If Len(rs.Fields("照片")) > 0 Then
lblPhoto.ForeColor = RGB(0, 0, 255)
lblPhoto.Caption = "查看照片"
Else
lblPhoto.ForeColor = RGB(0, 0, 0)
lblPhoto.Caption = "添加照片"
End If
'将当前记录的编号给变量ID,为以后的修改使用
ID = rs("id")
Call LockInput(True)
Call LockButton(False)
End If
rs.Close
Set rs = Nothing
End Sub
'过程--显示总览全局信息
Sub ShowList()
sql = "Select * from [员工档案] order by id"
rs.Open sql, conn, 1, 1
SumFields = rs.Fields.Count - 3 '该表的字段总数(减3因为其中有3个不显示字段,如ID,有无照片,照片这三字段)
'读取所有员工档案信息
If rs.EOF Then
MsgBox "没有员工档案,请增加后再查看!", vbInformation + vbOKOnly, App.Title
rs.Close
Set rs = Nothing
Exit Sub
Else
'初始化MSFlexGrid
ListInfo.Clear '清空列表,防止增加或修改调用时重复显示
ListInfo.BackColor = &HC0FFFF '设置网格背景颜色
ListInfo.Cols = SumFields
ListInfo.Row = 0
'设置第一行的各列标题
For i = 0 To SumFields - 1
ListInfo.Col = i
ListInfo.Text = rs.Fields(i + 1).Name
Next i
'设置第一行的各列标题文字格式
For i = 0 To SumFields - 1
ListInfo.Col = i
ListInfo.CellAlignment = 4
ListInfo.CellFontName = "黑体"
ListInfo.CellFontSize = 10
ListInfo.CellForeColor = RGB(0, 0, 200)
ListInfo.BackColorFixed = RGB(200, 200, 200)
'设置标题宽度,防止部分长文字不显示
j = TextWidth(ListInfo.Text) + 200
If j > ListInfo.ColWidth(i) Then
ListInfo.ColWidth(i) = j
End If
Next i
'循环开始--显示所有记录
rs.MoveLast
ListInfo.Rows = rs.RecordCount + 1 '设置总行数,其中标题占一行
rs.MoveFirst
ListInfo.Row = 0
While Not rs.EOF
ListInfo.Row = ListInfo.Row + 1 '增加一行,用于写入内容
For i = 1 To SumFields
ListInfo.Col = i - 1
'读入内容
If Not IsNull(rs.Fields(i).Value) Then
ListInfo.Text = rs.Fields(i).Value
Else
ListInfo.Text = ""
End If
Next i
rs.MoveNext
Wend
'循环结束--显示所有记录
'设置网格每行的高度为270 Twip
For j = 0 To ListInfo.Row
ListInfo.RowHeight(j) = 270
Next j
End If
rs.Close
Set rs = Nothing
End Sub
'过程--检查输入
Sub CheckInput()
If Trim(txtInfo(1).Text) = "" Then
MsgBox "姓名不能为空!"
txtInfo(1).SetFocus
FoundErr = True
ElseIf Trim(txtInfo(2).Text) = "" Then
MsgBox "性别不能为空!"
txtInfo(2).SetFocus
FoundErr = True
ElseIf Trim(txtInfo(3).Text) = "" Then
MsgBox "出生日期不能为空!"
txtInfo(3).SetFocus
FoundErr = True
ElseIf Trim(txtInfo(9).Text) = "" Then
MsgBox "编号不能为空!"
txtInfo(9).SetFocus
FoundErr = True
ElseIf Trim(txtInfo(10).Text) = "" Then
MsgBox "部门不能为空!"
txtInfo(10).SetFocus
FoundErr = True
ElseIf Trim(txtInfo(11).Text) = "" Then
MsgBox "职务不能为空!"
txtInfo(11).SetFocus
FoundErr = True
ElseIf Trim(txtInfo(14).Text) = "" Then
MsgBox "基本工资不能为空!"
txtInfo(14).SetFocus
FoundErr = True
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call CloseDB
End Sub
Private Sub lblPhoto_Click()
If lblPhoto.Caption <> "" Then
zhaopian.Show 1
End If
End Sub
Private Sub m10_Click()
Call cmdSearch_Click
End Sub
Private Sub m11_Click()
Call cmdAdd_Click
End Sub
Private Sub m12_Click()
Call cmdModify_Click
End Sub
Private Sub m13_Click()
Call cmdDel_Click
End Sub
Private Sub m14_Click()
Call cmdSave_Click
End Sub
Private Sub m15_Click()
Unload Me
End Sub
Private Sub m21_Click()
SSTab1.Tab = 0
End Sub
Private Sub m22_Click()
SSTab1.Tab = 1
End Sub
Private Sub m23_Click()
SSTab1.Tab = 2
End Sub
Private Sub m24_Click()
SSTab1.Tab = 3
End Sub
Private Sub txtInfo_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{TAB}"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -