VB版机房管理系统-组合查询

前端之家收集整理的这篇文章主要介绍了VB版机房管理系统-组合查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

刚开始接触组合查询的时候,脑子里一团浆糊,因为逻辑关系没有理清楚,理清楚以后问题也就不大了


① 在7、8为空的时候,进行第一行查询,且1、4、a不能为空

② 在7不为空,8为空的时候的时候,进行第一、二行组合查询,且1、4、a和2、5、b不能为空

③ 在7、8不为空的时候,三行组合查询,且所有项不能为空

PS:在7为空的时候,第二行往下的选项,都不能进行操作(同理,8也是)

代码如下:

Private Sub cmdOK_Click()

    txtsql = "select * from line_Info where "
    '第一行查询
    If Trim(Combo1.Text = "") Then
        MsgBox "请输入字段名",vbOKCancel + vbExclamation,"提示"
        Combo1.SetFocus
        Exit Sub
    ElseIf Trim(Combo4.Text = "") Then
            MsgBox "请输入操作符","提示"
            Combo4.SetFocus
            Exit Sub
    ElseIf Trim(txt1.Text = "") Then
                MsgBox "请输入要查询内容","提示"
                txt1.SetFocus
                Exit Sub
    Else
            
        txtsql = txtsql & " " & FiledName(Combo1.Text) & " " & Combo4.Text & "'" & Trim(txt1.Text) & "'"


        '第二行查询
            If Trim(Combo7.Text) <> "" Then
            
            If Trim(Combo2.Text = "") Then
                MsgBox "请输入字段名","提示"
                Combo2.SetFocus
                Exit Sub
            ElseIf Trim(Combo5.Text = "") Then
                    MsgBox "请输入操作符","提示"
                    Combo5.SetFocus
                    Exit Sub
            ElseIf Trim(txt2.Text = "") Then
                        MsgBox "请输入要查询内容","提示"
                        txt2.SetFocus
                        Exit Sub
            Else
                  txtsql = txtsql & " " & FiledName(Combo7.Text) & " " & FiledName(Combo2.Text) & " " & Combo5.Text & "'" & Trim(txt2.Text) & "'"
                        
        '第三行查询
                If Trim(Combo8.Text) <> "" Then
                
                    If Trim(Combo3.Text = "") Then
                        MsgBox "请输入字段名","提示"
                        Combo3.SetFocus
                        Exit Sub
                    ElseIf Trim(Combo6.Text = "") Then
                            MsgBox "请输入操作符","提示"
                            Combo6.SetFocus
                            Exit Sub
                    ElseIf Trim(txt3.Text = "") Then
                                MsgBox "请输入要查询内容","提示"
                                txt3.SetFocus
                                Exit Sub
                    Else
                         txtsql = txtsql & " " & Trim(FiledName(Combo8.Text)) & " " & Trim(FiledName(Combo3.Text)) & " " & Trim(Combo6.Text) & "'" & Trim(txt3.Text) & "'"
                         
                    End If
                End If
            End If
        End If
     End If
    
    Set mrc = Executesql(txtsql,msgtext)
    If mrc.EOF = True Then
        MsgBox "该条件的数据不存在"
        txtInquiryContent.Clear
        Combo1.Text = ""
        Combo2.Text = ""
        Combo3.Text = ""
        Combo4.Text = ""
        Combo5.Text = ""
        Combo6.Text = ""
        Combo7.Text = ""
        Combo8.Text = ""
        txt1.Text = ""
        txt2.Text = ""
        txt3.Text = ""
    Else
        With txtInquiryContent
            .Rows = 2           'rows:行
            .CellAlignment = 1  'CellAlingment:排列
            .ColWidth(0) = 1400 'width:宽度
            .ColWidth(1) = 1400
            .ColWidth(2) = 1400
            .ColWidth(3) = 1400
            .ColWidth(4) = 1400
            .ColWidth(5) = 1400
            .ColWidth(6) = 1400
            .ColWidth(7) = 1400
            .ColWidth(8) = 1400
            .TextMatrix(0,0) = "卡号"
            .TextMatrix(0,1) = "姓名"
            .TextMatrix(0,2) = "上机日期"
            .TextMatrix(0,3) = "上机时间"
            .TextMatrix(0,4) = "下机日期"
            .TextMatrix(0,5) = "下机时间"
            .TextMatrix(0,6) = "消费金额"
            .TextMatrix(0,7) = "余额"
            .TextMatrix(0,8) = "备注"
            
            Do While Not mrc.EOF
            .Rows = .Rows + 1
            .CellAlignment = 1
            .ColWidth(0) = 1400
            .ColWidth(1) = 1400
            .ColWidth(2) = 1400
            .ColWidth(3) = 1400
            .ColWidth(4) = 1400
            .ColWidth(5) = 1400
            .ColWidth(6) = 1400
            .ColWidth(7) = 1400
            .ColWidth(8) = 1400
            
            .TextMatrix(.Rows - 2,0) = mrc!cardno      'mrc.Fields(1)
            .TextMatrix(.Rows - 2,1) = mrc!studentname 'Fields(3)
            .TextMatrix(.Rows - 2,2) = mrc!ondate      'mrc.Fields(6)
            .TextMatrix(.Rows - 2,3) = mrc!OnTime      'mrc.Fields(7)
            .TextMatrix(.Rows - 2,4) = mrc!offdate & ""     'mrc.Fields(8) & ""
            .TextMatrix(.Rows - 2,5) = mrc!offtime & ""     'mrc.Fields(9) & ""
            .TextMatrix(.Rows - 2,6) = mrc!Consume & ""     'mrc.Fields(11) & ""
            .TextMatrix(.Rows - 2,7) = mrc!Cash & ""        'mrc.Fields(12) & ""
            .TextMatrix(.Rows - 2,8) = mrc!Status & ""      'mrc.Fields(13) & ""
             mrc.MoveNext
        Loop
    End With
    mrc.Close
 End If
End Sub

猜你在找的VB相关文章