QueryCur.frm
上传用户:cntx88
上传日期:2022-08-07
资源大小:169k
文件大小:12k
源码类别:

企业管理

开发平台:

Visual Basic

  1. VERSION 5.00
  2. Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
  3. Begin VB.Form QueryCur 
  4.    Caption         =   "查询报销记录"
  5.    ClientHeight    =   4725
  6.    ClientLeft      =   60
  7.    ClientTop       =   450
  8.    ClientWidth     =   7830
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   4725
  11.    ScaleWidth      =   7830
  12.    StartUpPosition =   3  '窗口缺省
  13.    Begin VB.Frame Frame1 
  14.       Caption         =   "报销记录查询【忽略的字段留空】"
  15.       Height          =   4455
  16.       Left            =   120
  17.       TabIndex        =   0
  18.       Top             =   120
  19.       Width           =   7575
  20.       Begin VB.CheckBox Check1 
  21.          Caption         =   "不限定日期"
  22.          Height          =   255
  23.          Left            =   5160
  24.          TabIndex        =   17
  25.          Top             =   1200
  26.          Width           =   2055
  27.       End
  28.       Begin VB.CommandButton Command2 
  29.          Caption         =   "放弃退出"
  30.          Height          =   495
  31.          Left            =   4080
  32.          TabIndex        =   15
  33.          Top             =   3720
  34.          Width           =   3135
  35.       End
  36.       Begin VB.CommandButton Command1 
  37.          Caption         =   "确定提交"
  38.          Height          =   495
  39.          Left            =   360
  40.          TabIndex        =   14
  41.          Top             =   3720
  42.          Width           =   3135
  43.       End
  44.       Begin VB.ComboBox Combo2 
  45.          Height          =   300
  46.          Left            =   240
  47.          TabIndex        =   13
  48.          Text            =   "Combo2"
  49.          Top             =   1800
  50.          Width           =   2175
  51.       End
  52.       Begin VB.TextBox Text4 
  53.          Height          =   1095
  54.          Left            =   240
  55.          MultiLine       =   -1  'True
  56.          TabIndex        =   6
  57.          Text            =   "QueryCur.frx":0000
  58.          Top             =   2400
  59.          Width           =   7095
  60.       End
  61.       Begin VB.ComboBox Combo1 
  62.          Height          =   300
  63.          Left            =   2760
  64.          TabIndex        =   5
  65.          Text            =   "Combo1"
  66.          Top             =   600
  67.          Width           =   2175
  68.       End
  69.       Begin MSComCtl2.DTPicker DTPicker1 
  70.          Height          =   255
  71.          Left            =   2760
  72.          TabIndex        =   4
  73.          Top             =   1200
  74.          Width           =   2175
  75.          _ExtentX        =   3836
  76.          _ExtentY        =   450
  77.          _Version        =   393216
  78.          Format          =   27066369
  79.          CurrentDate     =   38012
  80.       End
  81.       Begin VB.TextBox Text3 
  82.          Height          =   270
  83.          Left            =   240
  84.          TabIndex        =   3
  85.          Text            =   "Text3"
  86.          Top             =   1200
  87.          Width           =   2175
  88.       End
  89.       Begin VB.TextBox Text2 
  90.          Height          =   270
  91.          Left            =   5160
  92.          TabIndex        =   2
  93.          Text            =   "Text2"
  94.          Top             =   600
  95.          Width           =   2175
  96.       End
  97.       Begin VB.TextBox Text1 
  98.          Height          =   270
  99.          Left            =   240
  100.          TabIndex        =   1
  101.          Text            =   "Text1"
  102.          Top             =   600
  103.          Width           =   2175
  104.       End
  105.       Begin VB.Label Label7 
  106.          Caption         =   "报销说明"
  107.          Height          =   255
  108.          Left            =   240
  109.          TabIndex        =   16
  110.          Top             =   2160
  111.          Width           =   1815
  112.       End
  113.       Begin VB.Label Label6 
  114.          Caption         =   "报销部门"
  115.          Height          =   255
  116.          Left            =   240
  117.          TabIndex        =   12
  118.          Top             =   1560
  119.          Width           =   1815
  120.       End
  121.       Begin VB.Label Label5 
  122.          Caption         =   "报销人ID编号"
  123.          Height          =   255
  124.          Left            =   240
  125.          TabIndex        =   11
  126.          Top             =   960
  127.          Width           =   1815
  128.       End
  129.       Begin VB.Label Label4 
  130.          Caption         =   "报销日期"
  131.          Height          =   255
  132.          Left            =   2760
  133.          TabIndex        =   10
  134.          Top             =   960
  135.          Width           =   1815
  136.       End
  137.       Begin VB.Label Label3 
  138.          Caption         =   "报销金额"
  139.          Height          =   255
  140.          Left            =   5160
  141.          TabIndex        =   9
  142.          Top             =   360
  143.          Width           =   1815
  144.       End
  145.       Begin VB.Label Label2 
  146.          Caption         =   "报销类别"
  147.          Height          =   255
  148.          Left            =   2760
  149.          TabIndex        =   8
  150.          Top             =   360
  151.          Width           =   1815
  152.       End
  153.       Begin VB.Label Label1 
  154.          Caption         =   "报销单号"
  155.          Height          =   255
  156.          Left            =   240
  157.          TabIndex        =   7
  158.          Top             =   360
  159.          Width           =   1815
  160.       End
  161.    End
  162. End
  163. Attribute VB_Name = "QueryCur"
  164. Attribute VB_GlobalNameSpace = False
  165. Attribute VB_Creatable = False
  166. Attribute VB_PredeclaredId = True
  167. Attribute VB_Exposed = False
  168. Option Explicit
  169. Private Sub Check1_Click()
  170.     If Check1.Value Then        '设置是否把日期作为搜索条件
  171.         DTPicker1.Enabled = False
  172.     Else
  173.         DTPicker1.Enabled = True
  174.     End If
  175. End Sub
  176. Private Sub Command1_Click()
  177.     Dim sql As String
  178.     Dim rs As New ADODB.Recordset
  179.     Dim FilterEmpty As Boolean
  180.     Dim rsFilter As String
  181.     Dim i As Integer
  182.     Dim resultcount As Long
  183.     
  184.     If (Not IsNumeric(Text2.Text)) And (Text2.Text <> "") Then      '判断用户输入数据完整性和有效性
  185.         MsgBox "报销金额必须是数字!", vbCritical
  186.         Text2.SetFocus
  187.         Exit Sub
  188.     End If
  189.     
  190.     If DbHandle.DbConnection Then
  191.         FilterEmpty = True      '设置查询条件为"空"
  192.         If Text1.Text <> "" Then        '判断每个输入控件,如果用户改动就构造搜索条件字符串
  193.             If FilterEmpty Then
  194.                 rsFilter = "CUR_ID='" & Text1.Text & "'"
  195.             Else
  196.                 rsFilter = rsFilter & " AND CUR_ID='" & Text1.Text & "'"
  197.             End If
  198.             FilterEmpty = False
  199.         End If
  200.         If Text2.Text <> "" Then
  201.             If FilterEmpty Then
  202.                 rsFilter = "CUR_MONEY=" & Val(Text2.Text)
  203.             Else
  204.                 rsFilter = rsFilter & " AND CUR_MONEY=" & Val(Text2.Text)
  205.             End If
  206.             FilterEmpty = False
  207.         End If
  208.         If Text3.Text <> "" Then
  209.             If FilterEmpty Then
  210.                 rsFilter = "CUR_USER='" & Text3.Text & "'"
  211.             Else
  212.                 rsFilter = rsFilter & " AND CUR_USER='" & Text3.Text & "'"
  213.             End If
  214.             FilterEmpty = False
  215.         End If
  216.         If Text4.Text <> "" Then
  217.             If FilterEmpty Then
  218.                 rsFilter = "CUR_REMARK='" & Text4.Text & "'"
  219.             Else
  220.                 rsFilter = rsFilter & " AND CUR_REMARK='" & Text4.Text & "'"
  221.             End If
  222.             FilterEmpty = False
  223.         End If
  224.         If DTPicker1.Enabled Then
  225.             If FilterEmpty Then
  226.                 rsFilter = "CUR_DATE='" & DTPicker1.Value & "'"
  227.             Else
  228.                 rsFilter = rsFilter & " AND CUR_DATE='" & DTPicker1.Value & "'"
  229.             End If
  230.             FilterEmpty = False
  231.         End If
  232.         If Combo1.ListIndex <> -1 Then
  233.             If FilterEmpty Then
  234.                 rsFilter = "CUR_TYPE=" & Combo1.ListIndex
  235.             Else
  236.                 rsFilter = rsFilter & " AND CUR_TYPE=" & Combo1.ListIndex
  237.             End If
  238.             FilterEmpty = False
  239.         End If
  240.         If Combo2.ListIndex <> -1 Then
  241.             If FilterEmpty Then
  242.                 rsFilter = "CUR_PART=" & Combo2.ListIndex
  243.             Else
  244.                 rsFilter = rsFilter & " AND CUR_PART=" & Combo2.ListIndex
  245.             End If
  246.             FilterEmpty = False
  247.         End If
  248.         sql = "SELECT CUR_ID,CUR_MONEY,CUR_USER,CUR_DATE,CUR_REMARK,PART_NAME,CURTYPE_NAME FROM TBL_CUR,TBL_PART,TBL_CURTYPE WHERE "        '报销记录查询
  249.         If FilterEmpty Then     '构造完整的SQL语句(静态语句+动态条件)
  250.             sql = sql & "CUR_PART=PART_ID AND CUR_TYPE=CURTYPE_ID"
  251.         Else
  252.             sql = sql & rsFilter & " AND CUR_PART=PART_ID AND CUR_TYPE=CURTYPE_ID"
  253.         End If
  254.         rs.CursorType = adOpenDynamic
  255.         rs.LockType = adLockOptimistic
  256.         rs.Open sql, DbFinance
  257.         resultcount = DbHandle.resultcount(rs)
  258.         QueryCur2.Cls       '设置电子表格的列头
  259.         QueryCur2.MSFlexGrid1.Cols = 7
  260.         QueryCur2.MSFlexGrid1.Rows = resultcount + 1
  261.         QueryCur2.MSFlexGrid1.Row = 0
  262.         QueryCur2.MSFlexGrid1.Col = 0
  263.         QueryCur2.MSFlexGrid1.Text = "报销单号"
  264.         QueryCur2.MSFlexGrid1.Col = 1
  265.         QueryCur2.MSFlexGrid1.Text = "报销类别"
  266.         QueryCur2.MSFlexGrid1.Col = 2
  267.         QueryCur2.MSFlexGrid1.Text = "报销金额"
  268.         QueryCur2.MSFlexGrid1.Col = 3
  269.         QueryCur2.MSFlexGrid1.Text = "报销人ID"
  270.         QueryCur2.MSFlexGrid1.Col = 4
  271.         QueryCur2.MSFlexGrid1.Text = "报销日期"
  272.         QueryCur2.MSFlexGrid1.Col = 5
  273.         QueryCur2.MSFlexGrid1.Text = "报销部门"
  274.         QueryCur2.MSFlexGrid1.Col = 6
  275.         QueryCur2.MSFlexGrid1.Text = "报销说明"
  276.         For i = 0 To 6      '平均分配每个列的宽
  277.             QueryCur2.MSFlexGrid1.ColWidth(i) = QueryCur2.MSFlexGrid1.Width / 7 - 50
  278.         Next i
  279.         For i = 1 To resultcount    '循环将报销记录信息放入电子表格
  280.             QueryCur2.MSFlexGrid1.Row = i
  281.             QueryCur2.MSFlexGrid1.Col = 0
  282.             QueryCur2.MSFlexGrid1.Text = rs("CUR_ID")
  283.             QueryCur2.MSFlexGrid1.Col = 1
  284.             QueryCur2.MSFlexGrid1.Text = rs("CURTYPE_NAME")
  285.             QueryCur2.MSFlexGrid1.Col = 2
  286.             QueryCur2.MSFlexGrid1.Text = Trim(Str(rs("CUR_MONEY")))
  287.             QueryCur2.MSFlexGrid1.Col = 3
  288.             QueryCur2.MSFlexGrid1.Text = rs("CUR_USER")
  289.             QueryCur2.MSFlexGrid1.Col = 4
  290.             QueryCur2.MSFlexGrid1.Text = rs("CUR_DATE")
  291.             QueryCur2.MSFlexGrid1.Col = 5
  292.             QueryCur2.MSFlexGrid1.Text = rs("PART_NAME")
  293.             QueryCur2.MSFlexGrid1.Col = 6
  294.             QueryCur2.MSFlexGrid1.Text = rs("CUR_REMARK")
  295.             rs.MoveNext
  296.         Next i
  297.         QueryCur2.Show 1        '显示查询结构窗体
  298.         rs.Close        '查询结束,释放资源
  299.         Set rs = Nothing
  300.         DbHandle.DbClose
  301.     Else        '数据库连接失败,退出
  302.         MsgBox "数据库错误!", vbExclamation
  303.         DbHandle.DbClose
  304.         End
  305.     End If
  306. End Sub
  307. Private Sub Command2_Click()
  308.     Unload Me       '返回主窗体
  309. End Sub
  310. Private Sub Form_Load()
  311.     Dim sql As String
  312.     Dim rs As New ADODB.Recordset
  313.     
  314.     Me.Left = (Screen.Width - Me.ScaleWidth) / 2        '窗体居中显示
  315.     Me.Top = (Screen.Height - Me.ScaleHeight) / 2
  316.     If DbHandle.DbConnection Then
  317.         sql = "TBL_CURTYPE"     '把报销类别表中所有静态记录提取出来
  318.         rs.CursorType = adOpenDynamic
  319.         rs.LockType = adLockOptimistic
  320.         rs.Filter = ""
  321.         rs.Open sql, DbFinance
  322.         
  323.         Do While rs.EOF = False     '循环加入下拉列表中去
  324.             Combo1.AddItem (rs("CURTYPE_NAME"))
  325.             Combo1.ItemData(Combo1.NewIndex) = rs("CURTYPE_ID")
  326.             rs.MoveNext
  327.         Loop
  328.         rs.Close        '释放资源
  329.         Set rs = Nothing
  330.         DbHandle.DbClose
  331.     Else        '数据库连接失败,退出
  332.         MsgBox "数据库错误!", vbExclamation
  333.         DbHandle.DbClose
  334.         End
  335.     End If
  336.     If DbHandle.DbConnection Then
  337.         sql = "TBL_PART"     '把部门表中所有静态记录提取出来
  338.         rs.CursorType = adOpenDynamic
  339.         rs.LockType = adLockOptimistic
  340.         rs.Filter = ""
  341.         rs.Open sql, DbFinance
  342.         
  343.         Do While rs.EOF = False     '循环加入下拉列表中去
  344.             Combo2.AddItem (rs("PART_NAME"))
  345.             Combo2.ItemData(Combo2.NewIndex) = rs("PART_ID")
  346.             rs.MoveNext
  347.         Loop
  348.         rs.Close        '释放资源
  349.         Set rs = Nothing
  350.         DbHandle.DbClose
  351.     Else       '数据库连接失败,退出
  352.         MsgBox "数据库错误!", vbExclamation
  353.         DbHandle.DbClose
  354.         End
  355.     End If
  356.     Text1.Text = ""     '初始化窗体元素属性
  357.     Text2.Text = ""
  358.     Text3.Text = ""
  359.     Text4.Text = ""
  360.     Text4.MaxLength = 100
  361.     Combo1.Text = ""
  362.     Combo2.Text = ""
  363. End Sub