ChangeEvent.frm
上传用户:cntx88
上传日期:2022-08-07
资源大小:169k
文件大小:7k
- VERSION 5.00
- Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
- Begin VB.Form ChangeEvent
- Caption = "定位考勤记录"
- ClientHeight = 4500
- ClientLeft = 60
- ClientTop = 450
- ClientWidth = 3780
- LinkTopic = "Form1"
- ScaleHeight = 4500
- ScaleWidth = 3780
- StartUpPosition = 3 'Windows Default
- Begin VB.Frame Frame1
- Caption = "定位预修改的考勤记录"
- Height = 4215
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 3495
- Begin VB.CommandButton Command2
- Cancel = -1 'True
- Caption = "取消修改"
- Height = 495
- Left = 240
- TabIndex = 7
- Top = 3480
- Width = 3015
- End
- Begin VB.CommandButton Command1
- Caption = "定位考勤记录"
- Default = -1 'True
- Height = 495
- Left = 240
- TabIndex = 6
- Top = 2880
- Width = 3015
- End
- Begin VB.ComboBox TypeCombo
- Height = 300
- Left = 240
- TabIndex = 5
- Top = 2280
- Width = 3015
- End
- Begin MSComCtl2.DTPicker DTPicker1
- Height = 375
- Left = 240
- TabIndex = 3
- Top = 1440
- Width = 3015
- _ExtentX = 5318
- _ExtentY = 661
- _Version = 393216
- Format = 662831105
- CurrentDate = 38011
- 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 = 8
- Top = 2040
- Width = 1455
- End
- Begin VB.Label Label3
- Caption = "考勤记录时间"
- Height = 255
- Left = 240
- TabIndex = 4
- Top = 1200
- Width = 1575
- End
- Begin VB.Label Label1
- Caption = "员工ID号"
- Height = 255
- Left = 240
- TabIndex = 2
- Top = 360
- Width = 1455
- End
- End
- End
- Attribute VB_Name = "ChangeEvent"
- 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
- Dim i As Integer
-
- If TypeCombo.ListIndex = -1 Then '列表框必须选定考勤类别
- MsgBox "考勤类别不能为空!", vbCritical
- TypeCombo.SetFocus
- Exit Sub
- End If
- If User.Text = "" Then '文本框必须输入员工ID
- MsgBox "员工ID不能为空!", vbCritical
- User.SetFocus
- Exit Sub
- End If
- If DbHandle.DbConnection Then
- sql = "TBL_WORK" '查看数据库中是否存在预想修改的数据库记录
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = "WORK_ID='" & User.Text & "' AND WORK_DATE='" & DTPicker1.Value & "' AND WORK_TYPE=" & Str(TypeCombo.ListIndex + 1)
- rs.Open sql, DbFinance
- If DbHandle.resultcount(rs) <> 1 Then '不存在显示错误窗体,并且关闭数据库退出
- MsgBox "错误,不存在的考勤记录!", vbExclamation
- User.SetFocus
- rs.Close
- Set rs = Nothing
- DbHandle.DbClose
- Exit Sub
- End If
- ChangeEvent2.TypeCombo.Clear '存在考勤记录,设置修改考勤记录对话框的窗体元素属性
- For i = 0 To TypeCombo.ListCount - 1 '设置考勤类别下拉列表
- ChangeEvent2.TypeCombo.AddItem (TypeCombo.List(i))
- ChangeEvent2.TypeCombo.ItemData(ChangeEvent2.TypeCombo.NewIndex) = TypeCombo.ItemData(i)
- Next i
- ChangeEvent2.TypeCombo.ListIndex = TypeCombo.ListIndex '设置默认值为记录中各个字段的原始值
- ChangeEvent2.User.Text = rs("WORK_ID")
- ChangeEvent2.EvtTime.Text = rs("WORK_TIME")
- ChangeEvent2.DTPicker1.Value = DTPicker1.Value
- ChangeEvent2.Cancel = True '修改考勤记录对话框是否按确定退出
- ChangeEvent2.Show 1 '显示模式修改考勤记录对话框
- If ChangeEvent2.Cancel Then '如果修改考勤记录对话框是按确定退出就修改当前考勤记录
- rs("WORK_ID") = ChangeEvent2.User.Text
- rs("WORK_DATE") = ChangeEvent2.DTPicker1.Value
- rs("WORK_TIME") = Val(ChangeEvent2.EvtTime.Text)
- rs("WORK_TYPE") = ChangeEvent2.TypeCombo.ItemData(ChangeEvent2.TypeCombo.ListIndex)
- rs.Update
- MsgBox "考勤记录成功修改!"
- End If
- rs.Close '关闭数据库结果集,返回主窗体
- 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
-
- 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