📄 form1.frm
字号:
VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form frmkaoqin
Caption = "添加考勤记录"
ClientHeight = 4350
ClientLeft = 60
ClientTop = 450
ClientWidth = 5430
LinkTopic = "Form1"
ScaleHeight = 4350
ScaleWidth = 5430
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Cancel = -1 'True
Caption = "取 消"
Height = 495
Left = 3240
TabIndex = 9
Top = 3360
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "添 加"
Default = -1 'True
Height = 495
Left = 1080
TabIndex = 8
Top = 3360
Width = 1215
End
Begin VB.ComboBox TypeCombo
Height = 300
ItemData = "Form1.frx":0000
Left = 1800
List = "Form1.frx":0002
TabIndex = 7
Top = 2640
Width = 3015
End
Begin VB.TextBox EvtTime
Appearance = 0 'Flat
Height = 270
Left = 1800
TabIndex = 3
Top = 1200
Width = 3015
End
Begin VB.TextBox User
Appearance = 0 'Flat
Height = 270
Left = 1800
TabIndex = 1
Top = 480
Width = 3015
End
Begin MSComCtl2.DTPicker DTPicker1
Height = 375
Left = 1800
TabIndex = 5
Top = 1920
Width = 3015
_ExtentX = 5318
_ExtentY = 661
_Version = 393216
Format = 21364737
CurrentDate = 39518
End
Begin VB.Label Label4
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "考勤类别"
Height = 180
Left = 480
TabIndex = 6
Top = 2640
Width = 720
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "考勤记录时间"
Height = 180
Left = 480
TabIndex = 4
Top = 1920
Width = 1080
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "考勤时间"
Height = 180
Left = 480
TabIndex = 2
Top = 1200
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "员工ID号"
Height = 180
Left = 480
TabIndex = 0
Top = 480
Width = 720
End
End
Attribute VB_Name = "frmkaoqin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
Dim sql As String
Dim rs As New ADODB.Recordset
If TypeCombo.ListIndex = -1 Then '验证用户输入数据完整性和有效性
MsgBox "考勤类别不能为空!", vbCritical
TypeCombo.SetFocus
Exit Sub
End If
If User.Text = "" Then
MsgBox "员工ID不能为空!", vbCritical
User.SetFocus
Exit Sub
End If
If EvtTime.Text = "" Then
MsgBox "考勤时间长度不能为空!", vbCritical
EvtTime.SetFocus
Exit Sub
End If
If Not IsNumeric(EvtTime.Text) Then
MsgBox "考勤时间必须是数字!", vbCritical
EvtTime.SetFocus
Exit Sub
End If
If DbHandle.DbConnection Then
sql = "TBL_USER" '查询职工表中是否存在和输入职工的ID号相同的记录
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Filter = "USER_ID='" & User.Text & "'"
rs.Open sql, DbFinance
If DbHandle.resultcount(rs) <> 1 Then '不存在提示错误,要求用户更正职工ID
MsgBox "错误,不存在的ID号!", vbExclamation
User.SetFocus
rs.Close
Set rs = Nothing
DbHandle.DbClose
Exit Sub
End If
rs.Close '存在职工,则在考勤表中新建考勤记录
sql = "TBL_WORK"
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Filter = ""
rs.Open sql, DbFinance
rs.AddNew
rs("WORK_ID") = User.Text '职工ID
rs("WORK_DATE") = DTPicker1.Value '考勤记录日期
rs("WORK_TIME") = Val(EvtTime.Text) '考勤项目时间
rs("WORK_TYPE") = TypeCombo.ItemData(TypeCombo.ListIndex) '考勤类别
rs.Update '添加记录,显示成功信息
rs.Close
MsgBox "考勤记录成功添加!"
Unload Me
Else '数据库连接出错
MsgBox "数据库错误!", vbExclamation
DbHandle.DbClose
End
End If
End Sub
Private Sub Command2_Click()
Me.Hide '返回主窗体
End Sub
Private Sub Form_Load()
Dim sql As String
Dim rs As New ADODB.Recordset
Me.Left = (Screen.Width - Me.ScaleWidth) / 2 '窗体居中显示
Me.Top = (Screen.Height - Me.ScaleHeight) / 2
If DbHandle.DbConnection Then
sql = "TBL_TYPE" '操作考勤类别,将所有静态记录提取
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Filter = ""
rs.Open sql, DbFinance
'将记录信息添加到下拉列表中,并且把TYPE_ID属性和字串关联
Do While rs.EOF = False
TypeCombo.AddItem (rs("TYPE_NAME"))
TypeCombo.ItemData(TypeCombo.NewIndex) = rs("TYPE_ID")
rs.MoveNext
Loop
rs.Close '释放资源
Set rs = Nothing
DbHandle.DbClose
Else '数据库连接失败,退出
MsgBox "数据库错误!", vbExclamation
DbHandle.DbClose
End
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
DbHandle.DbClose '当窗体关闭时关闭数据库连接
End Sub
Private Sub Label1_Click()
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -