QueryEvent.frm
上传用户:cntx88
上传日期:2022-08-07
资源大小:169k
文件大小:8k
- VERSION 5.00
- Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
- Begin VB.Form QueryEvent
- Caption = "查询"
- ClientHeight = 4545
- ClientLeft = 60
- ClientTop = 450
- ClientWidth = 3765
- LinkTopic = "Form1"
- ScaleHeight = 4545
- ScaleWidth = 3765
- StartUpPosition = 3 'Windows Default
- Begin VB.Frame Frame1
- Caption = "查询考勤记录【忽略的字段留空】"
- Height = 4335
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 3495
- Begin VB.CheckBox Check1
- Caption = "不限定日期"
- Height = 255
- Left = 1800
- TabIndex = 9
- Top = 1920
- Width = 1335
- End
- Begin VB.CommandButton Command2
- Cancel = -1 'True
- Caption = "取消"
- Height = 495
- Left = 240
- TabIndex = 7
- Top = 3600
- Width = 3015
- End
- Begin VB.CommandButton Command1
- Caption = "查询"
- Default = -1 'True
- Height = 495
- Left = 240
- TabIndex = 6
- Top = 3000
- Width = 3015
- End
- Begin VB.ComboBox TypeCombo
- Height = 300
- Left = 240
- TabIndex = 5
- Top = 2520
- 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 = 2280
- 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 = "QueryEvent"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub Check1_Click()
- If Check1.Value Then '设置是否把日期作为搜索条件
- DTPicker1.Enabled = False
- Else
- DTPicker1.Enabled = True
- End If
- End Sub
- Private Sub Command1_Click()
- Dim sql As String
- Dim rs As New ADODB.Recordset
- Dim i As Integer
- Dim rsFilter As String
- Dim FilterEmpty As Boolean
- Dim resultcount As Long
-
- If DbHandle.DbConnection Then '考勤记录查询
- sql = "SELECT WORK_ID,WORK_DATE,WORK_TIME,TYPE_NAME FROM TBL_WORK,TBL_TYPE WHERE "
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- FilterEmpty = True '设置查询条件为"空"
- rsFilter = ""
- If User.Text <> "" Then '判断每个输入控件,如果用户改动就构造搜索条件字符串
- If FilterEmpty Then
- rsFilter = "WORK_ID='" & User.Text & "'"
- Else
- rsFilter = rsFilter & " AND WORK_ID='" & User.Text & "'"
- End If
- FilterEmpty = False
- End If
- If DTPicker1.Enabled Then
- If FilterEmpty Then
- rsFilter = "WORK_DATE='" & DTPicker1.Value & "'"
- Else
- rsFilter = rsFilter & " AND WORK_DATE='" & DTPicker1.Value & "'"
- End If
- FilterEmpty = False
- End If
- If TypeCombo.ListIndex <> -1 Then
- If FilterEmpty Then
- rsFilter = "WORK_TYPE=" & Str(TypeCombo.ListIndex + 1)
- Else
- rsFilter = rsFilter & " AND WORK_TYPE=" & Trim(Str(TypeCombo.ListIndex + 1))
- End If
- FilterEmpty = False
- End If
- If rsFilter <> "" Then '构造完整的SQL语句(静态语句+动态条件)
- sql = sql & "TYPE_ID = WORK_TYPE AND " & rsFilter
- Else
- sql = sql & "TYPE_ID = WORK_TYPE"
- End If
-
- rs.Open sql, DbFinance
- resultcount = DbHandle.resultcount(rs)
- QueryEvent2.Cls '设置电子表格的列头
- QueryEvent2.MSFlexGrid1.Cols = 4
- QueryEvent2.MSFlexGrid1.Rows = resultcount + 1
- QueryEvent2.MSFlexGrid1.Row = 0
- QueryEvent2.MSFlexGrid1.Col = 0
- QueryEvent2.MSFlexGrid1.Text = "员工ID号"
- QueryEvent2.MSFlexGrid1.Col = 1
- QueryEvent2.MSFlexGrid1.Text = "考勤日期"
- QueryEvent2.MSFlexGrid1.Col = 2
- QueryEvent2.MSFlexGrid1.Text = "持续时间"
- QueryEvent2.MSFlexGrid1.Col = 3
- QueryEvent2.MSFlexGrid1.Text = "考勤类别"
- For i = 0 To 3 '平均分配每个列的宽
- QueryEvent2.MSFlexGrid1.ColWidth(i) = QueryEvent2.MSFlexGrid1.Width / 4 - 50
- Next i
- For i = 1 To resultcount '循环将考勤记录信息放入电子表格
- QueryEvent2.MSFlexGrid1.Row = i
- QueryEvent2.MSFlexGrid1.Col = 0
- QueryEvent2.MSFlexGrid1.Text = rs("WORK_ID")
- QueryEvent2.MSFlexGrid1.Col = 1
- QueryEvent2.MSFlexGrid1.Text = rs("WORK_DATE")
- QueryEvent2.MSFlexGrid1.Col = 2
- QueryEvent2.MSFlexGrid1.Text = Trim(Str(rs("WORK_TIME")))
- QueryEvent2.MSFlexGrid1.Col = 3
- QueryEvent2.MSFlexGrid1.Text = rs("TYPE_NAME")
- rs.MoveNext
- Next i
- QueryEvent2.Show 1 '显示查询结构窗体
- rs.Close '查询结束,释放资源
- DbHandle.DbClose
- 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