WorkEvent.frm
上传用户:cntx88
上传日期:2022-08-07
资源大小:169k
文件大小:7k
- VERSION 5.00
- Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
- Begin VB.Form WorkEvent
- Caption = "添加考勤记录"
- ClientHeight = 5430
- ClientLeft = 60
- ClientTop = 450
- ClientWidth = 3705
- LinkTopic = "Form1"
- LockControls = -1 'True
- ScaleHeight = 5430
- ScaleWidth = 3705
- StartUpPosition = 3 '窗口缺省
- Begin VB.Frame Frame1
- Caption = "添加考勤记录"
- Height = 5175
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 3495
- Begin VB.CommandButton Command2
- Cancel = -1 'True
- Caption = "取消添加"
- Height = 495
- Left = 240
- TabIndex = 9
- Top = 4440
- Width = 3015
- End
- Begin VB.CommandButton Command1
- Caption = "添加记录"
- Default = -1 'True
- Height = 495
- Left = 240
- TabIndex = 8
- Top = 3720
- Width = 3015
- End
- Begin VB.ComboBox TypeCombo
- Height = 300
- ItemData = "WorkEvent.frx":0000
- Left = 240
- List = "WorkEvent.frx":0002
- TabIndex = 7
- Top = 3000
- Width = 3015
- End
- Begin MSComCtl2.DTPicker DTPicker1
- Height = 375
- Left = 240
- TabIndex = 5
- Top = 2160
- Width = 3015
- _ExtentX = 5318
- _ExtentY = 661
- _Version = 393216
- Format = 72613889
- CurrentDate = 38011
- End
- Begin VB.TextBox EvtTime
- Appearance = 0 'Flat
- Height = 270
- Left = 240
- TabIndex = 4
- Top = 1320
- Width = 3015
- End
- Begin VB.TextBox User
- Appearance = 0 'Flat
- Height = 270
- Left = 240
- TabIndex = 1
- Top = 600
- Width = 3015
- End
- Begin VB.Label Label4
- Caption = "考勤类别"
- Height = 255
- Left = 240
- TabIndex = 10
- Top = 2760
- Width = 1455
- End
- Begin VB.Label Label3
- Caption = "考勤记录时间"
- Height = 255
- Left = 240
- TabIndex = 6
- Top = 1920
- Width = 1575
- End
- Begin VB.Label Label2
- Caption = "考勤时间(【分仲】【天】)"
- Height = 255
- Left = 240
- TabIndex = 3
- Top = 1080
- Width = 3015
- End
- Begin VB.Label Label1
- Caption = "员工ID号"
- Height = 255
- Left = 240
- TabIndex = 2
- Top = 360
- Width = 1455
- End
- End
- End
- Attribute VB_Name = "WorkEvent"
- 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