QueryFixed.frm
上传用户:cntx88
上传日期:2022-08-07
资源大小:169k
文件大小:14k
- VERSION 5.00
- Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
- Begin VB.Form QueryFixed
- Caption = "查询固定资产"
- ClientHeight = 6105
- ClientLeft = 60
- ClientTop = 450
- ClientWidth = 7140
- LinkTopic = "Form1"
- LockControls = -1 'True
- ScaleHeight = 6105
- ScaleWidth = 7140
- StartUpPosition = 3 '窗口缺省
- Begin VB.Frame Frame2
- Height = 1095
- Left = 120
- TabIndex = 17
- Top = 4800
- Width = 6855
- Begin VB.CommandButton Command2
- Cancel = -1 'True
- Caption = "放弃查询"
- Height = 615
- Left = 3720
- TabIndex = 21
- Top = 240
- Width = 2895
- End
- Begin VB.CommandButton Command1
- Caption = "执行查询"
- Default = -1 'True
- Height = 615
- Left = 240
- TabIndex = 20
- Top = 240
- Width = 2895
- End
- End
- Begin VB.Frame Frame1
- Caption = "固定资产查询【不作为条件的字段留空】"
- Height = 4575
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 6855
- Begin VB.CheckBox Check1
- Caption = "不限定日期"
- Height = 255
- Left = 4680
- TabIndex = 22
- Top = 2280
- Width = 1215
- End
- Begin VB.TextBox Text7
- Appearance = 0 'Flat
- Height = 270
- Left = 2520
- TabIndex = 19
- Text = "Text7"
- Top = 1440
- Width = 1815
- End
- Begin VB.TextBox Text6
- Appearance = 0 'Flat
- Height = 1335
- Left = 240
- MaxLength = 100
- TabIndex = 15
- Text = "Text6"
- Top = 3000
- Width = 6375
- End
- Begin VB.TextBox Text5
- Appearance = 0 'Flat
- Height = 270
- Left = 4800
- TabIndex = 13
- Text = "Text5"
- Top = 1440
- Width = 1815
- End
- Begin MSComCtl2.DTPicker DTPicker1
- Height = 255
- Left = 2520
- TabIndex = 11
- Top = 2280
- Width = 1815
- _ExtentX = 3201
- _ExtentY = 450
- _Version = 393216
- Format = 27066369
- CurrentDate = 38012
- End
- Begin VB.ComboBox PartCombo
- Height = 300
- Left = 240
- TabIndex = 10
- Text = "Combo1"
- Top = 2280
- Width = 1815
- End
- Begin VB.TextBox Text4
- Appearance = 0 'Flat
- Height = 270
- Left = 240
- TabIndex = 7
- Text = "Text4"
- Top = 1440
- Width = 1815
- End
- Begin VB.TextBox Text3
- Appearance = 0 'Flat
- Height = 270
- Left = 4800
- TabIndex = 6
- Text = "Text3"
- Top = 600
- Width = 1815
- End
- Begin VB.TextBox Text2
- Appearance = 0 'Flat
- Height = 270
- Left = 2520
- TabIndex = 4
- Text = "Text2"
- Top = 600
- Width = 1815
- End
- Begin VB.TextBox Text1
- Appearance = 0 'Flat
- Height = 270
- Left = 240
- TabIndex = 1
- Text = "Text1"
- Top = 600
- Width = 1815
- End
- Begin VB.Label Label9
- Caption = "经手人ID"
- Height = 255
- Left = 2520
- TabIndex = 18
- Top = 1200
- Width = 1335
- End
- Begin VB.Label Label8
- Caption = "资产说明"
- Height = 255
- Left = 240
- TabIndex = 16
- Top = 2760
- Width = 2055
- End
- Begin VB.Label Label7
- Caption = "联系电话"
- Height = 255
- Left = 4800
- TabIndex = 14
- Top = 1200
- Width = 1455
- End
- Begin VB.Label Label6
- Caption = "购买日期"
- Height = 255
- Left = 2520
- TabIndex = 12
- Top = 2040
- Width = 1455
- End
- Begin VB.Label Label5
- Caption = "购买部门"
- Height = 255
- Left = 240
- TabIndex = 9
- Top = 2040
- Width = 1215
- End
- Begin VB.Label Label4
- Caption = "单价(元)"
- Height = 255
- Left = 240
- TabIndex = 8
- Top = 1200
- Width = 1335
- End
- Begin VB.Label Label3
- Caption = "资产数目"
- Height = 255
- Left = 4800
- TabIndex = 5
- Top = 360
- Width = 1335
- End
- Begin VB.Label Label2
- Caption = "资产名称"
- Height = 255
- Left = 2520
- TabIndex = 3
- Top = 360
- Width = 1575
- End
- Begin VB.Label Label1
- Caption = "资产编号"
- Height = 255
- Left = 240
- TabIndex = 2
- Top = 360
- Width = 1575
- End
- End
- End
- Attribute VB_Name = "QueryFixed"
- 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(Text3.Text)) And (Text3.Text <> "") Then '判断用户输入数据完整性和有效性
- MsgBox "资产数目必须是数字!", vbCritical
- Text3.SetFocus
- Exit Sub
- End If
- If (Not IsNumeric(Text4.Text)) And (Text4.Text <> "") Then
- MsgBox "资产单价必须是数字!", vbCritical
- Text4.SetFocus
- Exit Sub
- End If
-
- If DbHandle.DbConnection Then
- FilterEmpty = True '设置查询条件为"空"
- If Text1.Text <> "" Then '判断每个输入控件,如果用户改动就构造搜索条件字符串
- If FilterEmpty Then
- rsFilter = "FIXED_ID='" & Text1.Text & "'"
- Else
- rsFilter = rsFilter & " AND FIXED_ID='" & Text1.Text & "'"
- End If
- FilterEmpty = False
- End If
- If Text2.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "FIXED_NAME='" & Text2.Text & "'"
- Else
- rsFilter = rsFilter & " AND FIXED_NAME='" & Text2.Text & "'"
- End If
- FilterEmpty = False
- End If
- If Text3.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "FIXED_NUM=" & Val(Text3.Text)
- Else
- rsFilter = rsFilter & " AND FIXED_NUM=" & Val(Text3.Text)
- End If
- FilterEmpty = False
- End If
- If Text4.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "FIXED_MONEY=" & Val(Text4.Text)
- Else
- rsFilter = rsFilter & " AND FIXED_MONEY=" & Val(Text4.Text)
- End If
- FilterEmpty = False
- End If
- If Text5.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "FIXED_PHONE='" & Text5.Text & "'"
- Else
- rsFilter = rsFilter & " AND FIXED_PHONE='" & Text5.Text & "'"
- End If
- FilterEmpty = False
- End If
- If Text6.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "FIXED_REMARK='" & Text6.Text & "'"
- Else
- rsFilter = rsFilter & " AND FIXED_REMARK='" & Text6.Text & "'"
- End If
- FilterEmpty = False
- End If
- If Text7.Text <> "" Then
- If FilterEmpty Then
- rsFilter = "FIXED_USER='" & Text7.Text & "'"
- Else
- rsFilter = rsFilter & " AND FIXED_USER='" & Text7.Text & "'"
- End If
- FilterEmpty = False
- End If
- If DTPicker1.Enabled Then
- If FilterEmpty Then
- rsFilter = "FIXED_DATE='" & DTPicker1.Value & "'"
- Else
- rsFilter = rsFilter & " AND FIXED_DATE='" & DTPicker1.Value & "'"
- End If
- FilterEmpty = False
- End If
- If PartCombo.ListIndex <> -1 Then
- If FilterEmpty Then
- rsFilter = "FIXED_PART=" & PartCombo.ListIndex
- Else
- rsFilter = rsFilter & " AND FIXED_PART=" & PartCombo.ListIndex
- End If
- FilterEmpty = False
- End If
- sql = "SELECT FIXED_ID,FIXED_NAME,FIXED_NUM,FIXED_MONEY,FIXED_USER,FIXED_DATE,FIXED_PHONE,FIXED_REMARK,PART_NAME FROM TBL_FIXED,TBL_PART WHERE "
- If FilterEmpty Then '构造完整的SQL语句(静态语句+动态条件)
- sql = sql & "FIXED_PART=PART_ID"
- Else
- sql = sql & rsFilter & " AND FIXED_PART=PART_ID"
- End If
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Open sql, DbFinance
- resultcount = DbHandle.resultcount(rs)
- QueryFixed2.Cls '设置电子表格的列头
- QueryFixed2.MSFlexGrid1.Cols = 9
- QueryFixed2.MSFlexGrid1.Rows = resultcount + 1
- QueryFixed2.MSFlexGrid1.Row = 0
- QueryFixed2.MSFlexGrid1.Col = 0
- QueryFixed2.MSFlexGrid1.Text = "资产编号"
- QueryFixed2.MSFlexGrid1.Col = 1
- QueryFixed2.MSFlexGrid1.Text = "资产名称"
- QueryFixed2.MSFlexGrid1.Col = 2
- QueryFixed2.MSFlexGrid1.Text = "资产数目"
- QueryFixed2.MSFlexGrid1.Col = 3
- QueryFixed2.MSFlexGrid1.Text = "资产单价"
- QueryFixed2.MSFlexGrid1.Col = 4
- QueryFixed2.MSFlexGrid1.Text = "经手人ID"
- QueryFixed2.MSFlexGrid1.Col = 5
- QueryFixed2.MSFlexGrid1.Text = "联系电话"
- QueryFixed2.MSFlexGrid1.Col = 6
- QueryFixed2.MSFlexGrid1.Text = "购买部门"
- QueryFixed2.MSFlexGrid1.Col = 7
- QueryFixed2.MSFlexGrid1.Text = "购买日期"
- QueryFixed2.MSFlexGrid1.Col = 8
- QueryFixed2.MSFlexGrid1.Text = "资产说明"
- For i = 0 To 8 '平均分配每个列的宽
- QueryFixed2.MSFlexGrid1.ColWidth(i) = QueryFixed2.MSFlexGrid1.Width / 9 - 50
- Next i
- For i = 1 To resultcount '循环将报销记录信息放入电子表格
- QueryFixed2.MSFlexGrid1.Row = i
- QueryFixed2.MSFlexGrid1.Col = 0
- QueryFixed2.MSFlexGrid1.Text = rs("FIXED_ID")
- QueryFixed2.MSFlexGrid1.Col = 1
- QueryFixed2.MSFlexGrid1.Text = rs("FIXED_NAME")
- QueryFixed2.MSFlexGrid1.Col = 2
- QueryFixed2.MSFlexGrid1.Text = Trim(Str(rs("FIXED_NUM")))
- QueryFixed2.MSFlexGrid1.Col = 3
- QueryFixed2.MSFlexGrid1.Text = Trim(Str(rs("FIXED_MONEY")))
- QueryFixed2.MSFlexGrid1.Col = 4
- QueryFixed2.MSFlexGrid1.Text = rs("FIXED_USER")
- QueryFixed2.MSFlexGrid1.Col = 5
- QueryFixed2.MSFlexGrid1.Text = rs("FIXED_PHONE")
- QueryFixed2.MSFlexGrid1.Col = 6
- QueryFixed2.MSFlexGrid1.Text = rs("PART_NAME")
- QueryFixed2.MSFlexGrid1.Col = 7
- QueryFixed2.MSFlexGrid1.Text = rs("FIXED_DATE")
- QueryFixed2.MSFlexGrid1.Col = 8
- QueryFixed2.MSFlexGrid1.Text = rs("FIXED_REMARK")
- rs.MoveNext
- Next i
- QueryFixed2.Show 1 '显示查询结构窗体
- rs.Close '查询结束,释放资源
- 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_PART" '把部门信息表中所有静态记录提取出来
- rs.CursorType = adOpenDynamic
- rs.LockType = adLockOptimistic
- rs.Filter = ""
- rs.Open sql, DbFinance
-
- Do While rs.EOF = False '循环加入下拉列表中去
- PartCombo.AddItem (rs("PART_NAME"))
- PartCombo.ItemData(PartCombo.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 = ""
- Text5.Text = ""
- Text6.Text = ""
- Text7.Text = ""
- Text7.MaxLength = 100
- PartCombo.Text = ""
- End Sub