机房收费系统之组合查询

来源:互联网 发布:移动数据功能是什么 编辑:程序博客网 时间:2024/06/01 10:54

神器的逻辑

      好像谈到整个机房收费系统,我们谈之色变的不是整个项目有很多窗体,而是窗体模块的执行顺序(流程);我们把大部分时间都用来思考某个功能实现的过程;相比较来看,只要我们有了逻辑思路,敲代码仅仅是小菜一碟,哈哈;不过....前提你要绞尽脑汁的去思考,不然事后优化也会消耗大部分时间,尽量一次性考虑的全面一些;

      组合查询,这个名词我们应该不陌生了,原来在学生中我们也遇到过,不过那个时候我们应用的是CheckBox控件当做筛选判断工具,而这次却换为了combobox控件,不过两者的原理也差不太多,等到实现功能后自己可以比较两者之间的区别;当然还是要先把机房的组合查询搞定,执行流程图走一波....


现在这么来看思维逻辑是不是清晰多了,有些时候不要依靠自己的大脑,多用一些纸和图来理清自己的思路;

    最后就展示自己依附于流程图实现的代码模块了;

If Trim(Combo1(0).Text = "") Or Trim(Combo2(0).Text = "") Or Trim(Text1.Text = "") Then        MsgBox "请输入完整的查询条件!", vbOKOnly, "提示"        Exit Sub    End If        txtsql = "select * from worklog_info where "    txtsql = txtsql & filedname(Combo1(0).Text) & Trim(Combo2(0).Text) & "'" & Trim(Text1.Text) & "'"    If Trim(Combo3(0).Text <> "") Then        If Trim(Combo1(1).Text = "") Or Trim(Combo2(1).Text = "") Or Trim(Text2.Text = "") Then            MsgBox "请输入完整的第二个查询条件,否则请不要选择第二个查询!", vbOKOnly, "提示"            Exit Sub        Else            txtsql = txtsql & filedname(Combo3(0).Text) & " " & filedname(Combo1(1).Text) & Trim(Combo2(1).Text) & "'" & Trim(Text2.Text) & "'"            Combo1(0).Locked = True            Combo2(0).Locked = True            Text1.Locked = True        End If    ElseIf Trim(Combo3(1).Text <> "") Then        If Trim(Combo1(2).Text) = "" Or Trim(Combo2(2).Text) = "" Or Trim(Text3.Text) = "" Then            MsgBox "请输入完整的第三个查询条件!", vbOKOnly, "提示"            Exit Sub        Else            txtsql = txtsql & "" & filedname(Combo3(1).Text) & " " & filedname(Combo1(2).Text) & Trim(Combo2(2).Text) & "'" & Trim(Text3.Text) & "'"            Combo1(1).Locked = True            Combo2(1).Locked = True            Text2.Locked = True        End If    End If    Set mrc = ExecuteSQL(txtsql, msgtext)        With MSHFlexGrid1            .Rows = 1            .TextMatrix(0, 0) = "教师"            .TextMatrix(0, 1) = "级别"            .TextMatrix(0, 2) = "注册日期"            .TextMatrix(0, 3) = "注册时间"            .TextMatrix(0, 4) = "注销日期"            .TextMatrix(0, 5) = "注销时间"            .TextMatrix(0, 6) = "机器名"            .TextMatrix(0, 7) = "状态"        If Not (mrc.BOF Or mrc.EOF) Then            Do While Not mrc.EOF                .Rows = .Rows + 1                .CellAlignment = 4                .TextMatrix(.Rows - 1, 0) = mrc.Fields(1)                .TextMatrix(.Rows - 1, 1) = mrc.Fields(2)                .TextMatrix(.Rows - 1, 2) = mrc.Fields(3)                .TextMatrix(.Rows - 1, 3) = mrc.Fields(4)                .TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(5)) & ""                .TextMatrix(.Rows - 1, 5) = Trim(mrc.Fields(6)) & ""                .TextMatrix(.Rows - 1, 6) = mrc.Fields(7)                .TextMatrix(.Rows - 1, 7) = mrc.Fields(8)                mrc.MoveNext            Loop            MsgBox "筛选条件信息显示完毕!", vbOKOnly, "提示!"        Else            MsgBox "筛选条件中未找到任何信息!", vbOKOnly, "提示"        End If    End With    mrc.CloseEnd Sub

当然这个代码中有很多自己修补Bug的地方,同时也欢迎大家指正;后面还有自己优化的部分。

     组合查询材料:三个筛选条件+两个逻辑运算符号;

     过程:选择其一条件即可完成操作---解决选择运算符号后并不输入查询条件;

     补充:点击逻辑运算符号后自动锁定上一个查询条件并且将下一个条件变为可选框;---补充空白逻辑运算符

    If Not Trim(Combo3(0).Text) = "" Then        SelectCase Index    Else        Combo1(1).Enabled = False        Combo2(1).Enabled = False        Text2.Enabled = False    End If    If Not Trim(Combo3(1).Text) = "" Then        SelectCase Index    Else        Combo1(2).Enabled = False        Combo2(2).Enabled = False        Text3.Enabled = False    End If

     优化:case语句辅助筛选查询条件(汉字映射到数据库字段名)

Public Function filedname(a As String) As String    Select Case a        Case "卡号"            filedname = "cardno"        Case "姓名"            filedname = "studentname"        Case "上机日期"            filedname = "ondate"        Case "上机时间"            filedname = "ontime"        Case "下机日期"            filedname = "offdate"        Case "下机时间"            filedname = "offtime"        Case "消费金额"            filedname = "consumetime"        Case "余额"            filedname = "cash"        Case "与"            filedname = "and"        Case "或"            filedname = "or"    End SelectEnd Function

以上就是组合查询窗体的主要执行过程和代码,本篇博客也要告一段落了,总而言之,(手和脑)+工具(图)一定要相互结合,才可以发挥出最好的实力,提高自己的效率和窗体的质量;