QueryCur.frm
上传用户:cntx88
上传日期:2022-08-07
资源大小:169k
文件大小:12k
- VERSION 5.00
- Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
- Begin VB.Form QueryCur
- Caption = "查询报销记录"
- ClientHeight = 4725
- ClientLeft = 60
- ClientTop = 450
- ClientWidth = 7830
- LinkTopic = "Form1"
- ScaleHeight = 4725
- ScaleWidth = 7830
- StartUpPosition = 3 '窗口缺省
- Begin VB.Frame Frame1
- Caption = "报销记录查询【忽略的字段留空】"
- Height = 4455
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 7575
- Begin VB.CheckBox Check1
- Caption = "不限定日期"
- Height = 255
- Left = 5160
- TabIndex = 17
- Top = 1200
- Width = 2055
- End
- Begin VB.CommandButton Command2
- Caption = "放弃退出"
- Height = 495
- Left = 4080
- TabIndex = 15
- Top = 3720
- Width = 3135
- End
- Begin VB.CommandButton Command1
- Caption = "确定提交"
- Height = 495
- Left = 360
- TabIndex = 14
- Top = 3720
- Width = 3135
- End
- Begin VB.ComboBox Combo2
- Height = 300
- Left = 240
- TabIndex = 13
- Text = "Combo2"
- Top = 1800
- Width = 2175
- End
- Begin VB.TextBox Text4
- Height = 1095
- Left = 240
- MultiLine = -1 'True
- TabIndex = 6
- Text = "QueryCur.frx":0000
- Top = 2400
- Width = 7095
- End
- Begin VB.ComboBox Combo1
- Height = 300
- Left = 2760
- TabIndex = 5
- Text = "Combo1"
- Top = 600
- Width = 2175
- End
- Begin MSComCtl2.DTPicker DTPicker1
- Height = 255
- Left = 2760
- TabIndex = 4
- Top = 1200
- Width = 2175
- _ExtentX = 3836
- _ExtentY = 450
- _Version = 393216
- Format = 27066369
- CurrentDate = 38012
- End
- Begin VB.TextBox Text3
- Height = 270
- Left = 240
- TabIndex = 3
- Text = "Text3"
- Top = 1200
- Width = 2175
- End
- Begin VB.TextBox Text2
- Height = 270
- Left = 5160
- TabIndex = 2
- Text = "Text2"
- Top = 600
- Width = 2175
- End
- Begin VB.TextBox Text1
- Height = 270
- Left = 240
- TabIndex = 1
- Text = "Text1"
- Top = 600
- Width = 2175
- End
- Begin VB.Label Label7
- Caption = "报销说明"
- Height = 255
- Left = 240
- TabIndex = 16
- Top = 2160
- Width = 1815
- End
- Begin VB.Label Label6
- Caption = "报销部门"
- Height = 255
- Left = 240
- TabIndex = 12
- Top = 1560
- Width = 1815
- End
- Begin VB.Label Label5
- Caption = "报销人ID编号"
- Height = 255
- Left = 240
- TabIndex = 11
- Top = 960
- Width = 1815
- End
- Begin VB.Label Label4
- Caption = "报销日期"
- Height = 255
- Left = 2760
- TabIndex = 10
- Top = 960
- Width = 1815
- End
- Begin VB.Label Label3
- Caption = "报销金额"
- Height = 255
- Left = 5160
- TabIndex = 9
- Top = 360
- Width = 1815
- End
- Begin VB.Label Label2
- Caption = "报销类别"
- Height = 255
- Left = 2760
- TabIndex = 8
- Top = 360
- Width = 1815
- End
- Begin VB.Label Label1
- Caption = "报销单号"
- Height = 255
- Left = 240
- TabIndex = 7
- Top = 360
- Width = 1815
- End
- End
- End
- Attribute VB_Name = "QueryCur"
- 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 FilterEmpty As Boolean
- Dim rsFilter As String
- Dim i As Integer
- Dim resultcount As Long
-
- If (Not IsNumeric(Text2.Text)) And (Text2.Text <> "") Then '判断用户输入数据完整性和有效性
- MsgBox "报销金额必须是数字!", vbCritical
- Text2.SetFocus
- Exit Sub
- End If
-
- If DbHandle.DbConnection Then
- FilterEmpty = True '设置查询条件为"空"
- If Text1.Text <> "" Then '判断每个输入控件,如果用户改动就构造搜索条件字符串
- If FilterEmpty Then
- rsFilter = "CUR_ID='" & Text1.Text & "'"
- Else
- rsFilter = rsFilter & " AND CUR_ID='" & Text1.Text & "'"
- End If
- FilterEmpty = False
- End If
- If Text2.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "CUR_MONEY=" & Val(Text2.Text)
- Else
- rsFilter = rsFilter & " AND CUR_MONEY=" & Val(Text2.Text)
- End If
- FilterEmpty = False
- End If
- If Text3.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "CUR_USER='" & Text3.Text & "'"
- Else
- rsFilter = rsFilter & " AND CUR_USER='" & Text3.Text & "'"
- End If
- FilterEmpty = False
- End If
- If Text4.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "CUR_REMARK='" & Text4.Text & "'"
- Else
- rsFilter = rsFilter & " AND CUR_REMARK='" & Text4.Text & "'"
- End If
- FilterEmpty = False
- End If
- If DTPicker1.Enabled Then
- If FilterEmpty Then
- rsFilter = "CUR_DATE='" & DTPicker1.Value & "'"
- Else
- rsFilter = rsFilter & " AND CUR_DATE='" & DTPicker1.Value & "'"
- End If
- FilterEmpty = False
- End If
- If Combo1.ListIndex <> -1 Then
- If FilterEmpty Then
- rsFilter = "CUR_TYPE=" & Combo1.ListIndex
- Else
- rsFilter = rsFilter & " AND CUR_TYPE=" & Combo1.ListIndex
- End If
- FilterEmpty = False
- End If
- If Combo2.ListIndex <> -1 Then
- If FilterEmpty Then
- rsFilter = "CUR_PART=" & Combo2.ListIndex
- Else
- rsFilter = rsFilter & " AND CUR_PART=" & Combo2.ListIndex
- End If
- FilterEmpty = False
- End If
- sql = "SELECT CUR_ID,CUR_MONEY,CUR_USER,CUR_DATE,CUR_REMARK,PART_NAME,CURTYPE_NAME FROM TBL_CUR,TBL_PART,TBL_CURTYPE WHERE " '报销记录查询
- If FilterEmpty Then '构造完整的SQL语句(静态语句+动态条件)
- sql = sql & "CUR_PART=PART_ID AND CUR_TYPE=CURTYPE_ID"
- Else
- sql = sql & rsFilter & " AND CUR_PART=PART_ID AND CUR_TYPE=CURTYPE_ID"
- End If
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Open sql, DbFinance
- resultcount = DbHandle.resultcount(rs)
- QueryCur2.Cls '设置电子表格的列头
- QueryCur2.MSFlexGrid1.Cols = 7
- QueryCur2.MSFlexGrid1.Rows = resultcount + 1
- QueryCur2.MSFlexGrid1.Row = 0
- QueryCur2.MSFlexGrid1.Col = 0
- QueryCur2.MSFlexGrid1.Text = "报销单号"
- QueryCur2.MSFlexGrid1.Col = 1
- QueryCur2.MSFlexGrid1.Text = "报销类别"
- QueryCur2.MSFlexGrid1.Col = 2
- QueryCur2.MSFlexGrid1.Text = "报销金额"
- QueryCur2.MSFlexGrid1.Col = 3
- QueryCur2.MSFlexGrid1.Text = "报销人ID"
- QueryCur2.MSFlexGrid1.Col = 4
- QueryCur2.MSFlexGrid1.Text = "报销日期"
- QueryCur2.MSFlexGrid1.Col = 5
- QueryCur2.MSFlexGrid1.Text = "报销部门"
- QueryCur2.MSFlexGrid1.Col = 6
- QueryCur2.MSFlexGrid1.Text = "报销说明"
- For i = 0 To 6 '平均分配每个列的宽
- QueryCur2.MSFlexGrid1.ColWidth(i) = QueryCur2.MSFlexGrid1.Width / 7 - 50
- Next i
- For i = 1 To resultcount '循环将报销记录信息放入电子表格
- QueryCur2.MSFlexGrid1.Row = i
- QueryCur2.MSFlexGrid1.Col = 0
- QueryCur2.MSFlexGrid1.Text = rs("CUR_ID")
- QueryCur2.MSFlexGrid1.Col = 1
- QueryCur2.MSFlexGrid1.Text = rs("CURTYPE_NAME")
- QueryCur2.MSFlexGrid1.Col = 2
- QueryCur2.MSFlexGrid1.Text = Trim(Str(rs("CUR_MONEY")))
- QueryCur2.MSFlexGrid1.Col = 3
- QueryCur2.MSFlexGrid1.Text = rs("CUR_USER")
- QueryCur2.MSFlexGrid1.Col = 4
- QueryCur2.MSFlexGrid1.Text = rs("CUR_DATE")
- QueryCur2.MSFlexGrid1.Col = 5
- QueryCur2.MSFlexGrid1.Text = rs("PART_NAME")
- QueryCur2.MSFlexGrid1.Col = 6
- QueryCur2.MSFlexGrid1.Text = rs("CUR_REMARK")
- rs.MoveNext
- Next i
- QueryCur2.Show 1 '显示查询结构窗体
- rs.Close '查询结束,释放资源
- Set rs = Nothing
- DbHandle.DbClose
- Else '数据库连接失败,退出
- MsgBox "数据库错误!", vbExclamation
- DbHandle.DbClose
- End
- End If
- End Sub
- Private Sub Command2_Click()
- Unload Me '返回主窗体
- 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_CURTYPE" '把报销类别表中所有静态记录提取出来
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = ""
- rs.Open sql, DbFinance
-
- Do While rs.EOF = False '循环加入下拉列表中去
- Combo1.AddItem (rs("CURTYPE_NAME"))
- Combo1.ItemData(Combo1.NewIndex) = rs("CURTYPE_ID")
- rs.MoveNext
- Loop
- rs.Close '释放资源
- Set rs = Nothing
- DbHandle.DbClose
- Else '数据库连接失败,退出
- MsgBox "数据库错误!", vbExclamation
- DbHandle.DbClose
- End
- End If
- If DbHandle.DbConnection Then
- sql = "TBL_PART" '把部门表中所有静态记录提取出来
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = ""
- rs.Open sql, DbFinance
-
- Do While rs.EOF = False '循环加入下拉列表中去
- Combo2.AddItem (rs("PART_NAME"))
- Combo2.ItemData(Combo2.NewIndex) = rs("PART_ID")
- rs.MoveNext
- Loop
- rs.Close '释放资源
- Set rs = Nothing
- DbHandle.DbClose
- Else '数据库连接失败,退出
- MsgBox "数据库错误!", vbExclamation
- DbHandle.DbClose
- End
- End If
- Text1.Text = "" '初始化窗体元素属性
- Text2.Text = ""
- Text3.Text = ""
- Text4.Text = ""
- Text4.MaxLength = 100
- Combo1.Text = ""
- Combo2.Text = ""
- End Sub