机房收费系统——学生基本信息维护(组合查询,选中整行)

简介: 机房收费系统——学生基本信息维护(组合查询,选中整行)

前言

机房的小难点之一就是组合查询,刚开始完全没有思路,看了看他人的博客,就感觉豁然开朗其实是很简单的,流程图一画出来就简单多了,剩下的就是代码设计。

定义函数,使text属性中字符与数据库相对应

Public Function Field(i As String) As String
    '定义函数,使text属性中的字符与数据库相对应
    Select Case i
        Case "卡号"
    Field = "cardno"
        Case "学号"
    Field = "studentno"
        Case "姓名"
    Field = "studentname"
        Case "性别"
    Field = "sex"
        Case "系别"
    Field = "depart"
        Case "年级"
    Field = "grade"
        Case "班级"
    Field = "class"
        Case "与"
    Field = "and"
        Case "或"
    Field = "or"
  End Select
End Function

组合查询代码

Private Sub cmdContent_Click()
    Dim txtSQL, Msgtext As String
    Dim mrc_stu As ADODB.Recordset
    txtSQL = "select * from student_info where"
    If Combo1.Text = "" Or Combo4.Text = "" Or txtContent1.Text = "" Then
        MsgBox "请输入要查询的内容", 0 + 48, "警告"
        Exit Sub
    Else
        txtSQL = txtSQL & " " & Field(Combo1.Text) & "" & Combo4.Text & " '" & Trim(txtContent1.Text) & "'"
        If Combo7.Text <> "" Then
            If Combo2.Text = "" Or Combo5.Text = "" Or txtContent2.Text = "" Then
                MsgBox "请将第二行内容补充完整", 0 + 48, "警告"
                Exit Sub
            Else
                txtSQL = txtSQL & " " & Field(Combo7.Text) & " " & Field(Combo2.Text) & " " & Combo5.Text & " '" & Trim(txtContent2.Text) & "'"
                    If Combo8.Text <> "" Then
                        If Combo3.Text = "" Or Combo6.Text = "" Or txtContent3.Text = "" Then
                        MsgBox "请将第三行内容补充完整", 0 + 48, "警告"
                        Exit Sub
                        Else
                        txtSQL = txtSQL & " " & Field(Combo8.Text) & " " & Field(Combo3.Text) & "" & Combo6.Text & " '" & Trim(txtContent3.Text) & "'"
                        End If
                    End If
            End If
        End If
    End If
    Set mrc_stu = ExecuteSQL(txtSQL, Msgtext)
    If mrc_stu.EOF Then
        MsgBox "没有数据", 0 + 48, "警告"
        txtContent1.Text = ""
        txtContent2.Text = ""
        txtContent3.Text = ""
        txtContent1.SetFocus
        myflexgrid.Clear
        Exit Sub
    Else
        With myflexgrid
            .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) = "性别"
            .TextMatrix(0, 8) = "状态"
            .TextMatrix(0, 9) = "备注"
            .TextMatrix(0, 10) = "类型"
            .TextMatrix(0, 11) = "日期"
            .TextMatrix(0, 12) = "时间"
        Do While Not mrc_stu.EOF
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = Trim(mrc_stu.Fields(2))
            .TextMatrix(.Rows - 1, 1) = Trim(mrc_stu.Fields(1))
            .TextMatrix(.Rows - 1, 2) = Trim(mrc_stu.Fields(0))
            .TextMatrix(.Rows - 1, 3) = Trim(mrc_stu.Fields(7))
            .TextMatrix(.Rows - 1, 4) = Trim(mrc_stu.Fields(4))
            .TextMatrix(.Rows - 1, 5) = Trim(mrc_stu.Fields(5))
            .TextMatrix(.Rows - 1, 6) = Trim(mrc_stu.Fields(6))
            .TextMatrix(.Rows - 1, 7) = Trim(mrc_stu.Fields(3))
            .TextMatrix(.Rows - 1, 8) = Trim(mrc_stu.Fields(10))
            .TextMatrix(.Rows - 1, 9) = Trim(mrc_stu.Fields(8))
            .TextMatrix(.Rows - 1, 10) = Trim(mrc_stu.Fields(14))
            .TextMatrix(.Rows - 1, 11) = Trim(mrc_stu.Fields(12))
            .TextMatrix(.Rows - 1, 12) = Trim(mrc_stu.Fields(13))
            mrc_stu.MoveNext
            Loop
        End With
    End If
mrc_stu.Close
End Sub

修改命令

单击选中整行

MSHFlexGrid控件右击属性页

添加标识

Private Sub myflexgrid_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    '判断鼠标所在行,并添加*
    With myflexgrid
        If .MouseRow Then
            .TextMatrix(.MouseRow, 13) = "*"
            Exit Sub
        End If
    End With
End Sub

如图:


修改命令

Private Sub cmdRevise_Click()
    Dim n As Integer
    Dim m As Integer
    If myflexgrid.TextMatrix(myflexgrid.RowSel, 13) <> "*" Then
            MsgBox "请选择数据", 0 + 48, "警告"
            Exit Sub
        Else
            SetParent frmRSInformation.hWnd, frmmenu.hWnd
            frmRSInformation.Show
            With frmSNDefend.myflexgrid
                frmRSInformation.txtSID.Text = .TextMatrix(.RowSel, 0)
                frmRSInformation.txtName.Text = .TextMatrix(.RowSel, 1)
                frmRSInformation.txtCardNo.Text = .TextMatrix(.RowSel, 2)
                frmRSInformation.txtMoney.Text = .TextMatrix(.RowSel, 3)
                frmRSInformation.txtDept.Text = .TextMatrix(.RowSel, 4)
                frmRSInformation.txtGrade.Text = .TextMatrix(.RowSel, 5)
                frmRSInformation.txtClass.Text = .TextMatrix(.RowSel, 6)
                frmRSInformation.cboSex.Text = .TextMatrix(.RowSel, 7)
                frmRSInformation.txtStatus.Text = .TextMatrix(.RowSel, 8)
                frmRSInformation.txtExplain.Text = .TextMatrix(.RowSel, 9)
                frmRSInformation.cboType.Text = .TextMatrix(.RowSel, 10)
            End With
        End If
End Sub
目录
相关文章
|
10月前
EXCEL导入程序中(针对excel单元格合并等导致的一行多条数据重复解决办法)
EXCEL导入程序中(针对excel单元格合并等导致的一行多条数据重复解决办法)
103 0
|
3月前
【word】论文、报告:①插入图表题注,交叉引用②快速插入图表目录③删改后一键更新
【word】论文、报告:①插入图表题注,交叉引用②快速插入图表目录③删改后一键更新
108 0
|
8月前
|
存储 JSON 搜索推荐
授人以渔-在 SAP MM 物料显示界面上看到一个字段,如何查找哪张数据库表的哪个字段进行的存储的试读版
授人以渔-在 SAP MM 物料显示界面上看到一个字段,如何查找哪张数据库表的哪个字段进行的存储的试读版
52 1
|
8月前
|
存储 JSON BI
如何查询 SAPGUI 屏幕上某个字段对应的数据库表存储的试读版
如何查询 SAPGUI 屏幕上某个字段对应的数据库表存储的试读版
55 0
|
10月前
第一次机房收费系统指点击查询按钮重复出现查询结果
第一次机房收费系统指点击查询按钮重复出现查询结果
35 0
|
NoSQL Shell 测试技术
第十五章《键的管理》
第十五章《键的管理》
第十五章《键的管理》
成功解决在excel表格中仅在某列内插入一个空白单元格,使其下部的数据整体下移一格
成功解决在excel表格中仅在某列内插入一个空白单元格,使其下部的数据整体下移一格
成功解决在excel表格中仅在某列内插入一个空白单元格,使其下部的数据整体下移一格
|
数据库 索引 程序员
excel导入功能中去掉重复数据—解决思路
excel导入功能中去掉重复数据—解决思路 今天客户提出一个问题,能否在产品中2个子系统中的实现所有的excel导入功能过滤掉已有的数据。 我思考了一番,想到了3种大概的解决思路: 1、在插入每条数据的时候,查到对应的表找出是否存在对应的数据,如存在就跳过。
1995 0
|
数据库 索引
存在逻辑删除的表字段上建立唯一索引的巧办法 (逻辑删除与唯一索引)
设计数据库唯一索引时,经常会碰到唯一删除的键值,导致很难处理,这里就简单介绍一种巧办法,帮你快速解决该问题
1745 0
存在逻辑删除的表字段上建立唯一索引的巧办法 (逻辑删除与唯一索引)