机房收费系统之组合查询

来源:互联网 发布:淘宝查消费总额 编辑:程序博客网 时间:2024/04/27 13:15

     进行机房收费系统已经有一个星期多了,现在正在传说中本系统相对比较难部分——组合查询的门外徘徊。其实在还没有进入这道门的时候我就已经先给自己建了一道无法逾越的围墙。听说它比较难,所以我就知难而退,一直都不想碰这部分,可是时间一天天的过,我不能总是停留,所以又逼着自己往前走,经过数个番茄的时间,倒也让信息显示出来了,不知道是否正确。现在将它展示一下,希望大家批评指正。

 

     首先:将每行控件作为一个整体,以便控制。我将这个窗体,一共分为三个整体。如图:

它的代码如下:

 

 If Testtxt(Combo1.Text) And Testtxt(Combo2.Text) And Testtxt(Text1.Text) Then       '将窗体中的每一行看成一个整体,并对他进行整体的控制        dd(0) = True    End If        If Testtxt(Combo4.Text) And Testtxt(Combo5.Text) And Testtxt(Text2.Text) Then        dd(1) = True    End If        If Testtxt(Combo7.Text) And Testtxt(Combo8.Text) Then        dd(2) = True    End If


 

     其次:根据每一行的情况,写实现语句,代码如下:

If dd(0) = True And dd(1) = False And dd(2) = False Then   strTxtSQL = strTxtSQL & FileName(Combo1.Text) & Trim(Combo2.Text) & "'" & Trim(Text1.Text) & "'"          
        Select Case Combo3.Text            Case "与"                strTxtSQL = strTxtSQL & " and " & FileName(Combo1.Text) & Trim(Combo2.Text) & "'" & Trim(Text1.Text) & "'"            Case "或"                strTxtSQL = strTxtSQL & " or " & FileName(Combo1.Text) & Trim(Combo2.Text) & "'" & Trim(Text1.Text) & "'"        End Select    Else        If dd(0) = True And dd(1) = True And dd(2) = False Then            strTxtSQL = strTxtSQL & FileName(Combo4.Text) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'"                 Select Case Combo6.Text                Case "与"                    strTxtSQL = strTxtSQL & " and " & FileName(Combo4.Text) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'"                Case "或"                    strTxtSQL = strTxtSQL & " or " & FileName(Combo4.Text) & Trim(Combo5.Text) & "'" & Trim(Text2.Text) & "'"            End Select        Else            If dd(0) = True And dd(1) = True And dd(2) = True Then                strTxtSQL = strTxtSQL & FileName(Combo7.Text) & Trim(Combo8.Text) & "'" & Trim(Text2.Text) & "'"            End If        End If    End If    Set mrc = ExecuteSQL(strTxtSQL, strMsgtext) 


 

     最后:将查询到的记录集中的信息显示到Myflexgrid控件中。代码如下:

 

With MyFlexGrid                               '将查询到的记录集中的信息通过Myflexgrid控件显示出来        .Rows = 2        .CellAlignment = 4        .TextMatrix(1, 0) = "卡号"        .TextMatrix(1, 1) = "姓名"        .TextMatrix(1, 2) = "上机日期"        .TextMatrix(1, 3) = "上机时间"        .TextMatrix(1, 4) = "机房号"         Do While (Not mrc.EOF)            .Rows = .Rows + 1            .CellAlignment = 4            .TextMatrix(.Rows - 1, 0) = mrc.Fields(0)            .TextMatrix(.Rows - 1, 1) = mrc.Fields(1)            .TextMatrix(.Rows - 1, 2) = mrc.Fields(2)            .TextMatrix(.Rows - 1, 3) = mrc.Fields(3)            .TextMatrix(.Rows - 1, 4) = mrc.Fields(4)            mrc.MoveNext         Loop    End With


 

     这样的解决方式可能很不尽人意,但是做总比不做好,不管怎样写下来鼓励一下自己吧。

原创粉丝点击