第一次机房收费系统—组合查询
来源:互联网 发布:单片机3.3v转5v 编辑:程序博客网 时间:2024/05/18 01:25
今天总结组合查询,组合查询无非涉及到两个语句!敲机房给我的一点想法就是,有的代码自己还不确定是否在这个世界上时候存在,其实它是存在的,恐于自己怕浪费时间,功能还没有实现。还是太将就了,所以小伙伴们做得时候有想法一定要大胆尝试哦!找到每个窗体后面最基本最简单的那个道理。加油!
组合查询:
先放两张有代表性的组合查询的图片:
1.学生信息管理系统:(组合查询)
2.机房收费系统:(组合查询)
比较:
1.学生信息管理系统:
大家可以明显的看出学生组合查询的条件有三个,分别是学号查询、姓名查询、班号查询。这三个条件任意组合,三者之间的关系只能为“与”。
2.部分代码展示:
Private Sub cmdInquire_Click() Dim txtSQL As String Dim MsgText As String Dim sMeg As String Dim dd(4) As Boolean Dim mrc As ADODB.Recordset '组合 SQL 语句 txtSQL = "select * from student_Info where" ' 判断是否选择学号查询方式 If Check1.Value Then If Trim(txtSID.Text) = "" Then sMeg = "学号不能为空" MsgBox sMeg, 48, "警告" txtSID.SetFocus Exit Sub Else '判断输入学号是否为数字 If Not IsNumeric(Trim(txtSID.Text)) Then MsgBox "请输入数字!", 48, "警告" Exit Sub txtSID.SetFocus End If dd(0) = True '组合查询语句 txtSQL = txtSQL & " student_ID='" & Trim(txtSID.Text) & "'" End If End If '判断是否选择姓名查询方式 If Check2.Value Then '判断是否输入姓名 If Trim(txtName.Text) = "" Then sMeg = "用户未输入姓名!" MsgBox sMeg, 48, "警告" txtName.SetFocus Exit Sub Else dd(1) = True If dd(0) Then '组合查询语句 txtSQL = txtSQL & "and student_Name='" & txtName.Text & "'" Else txtSQL = txtSQL & " student_Name='" & txtName.Text & "'" End If End If End If '判断是否选择班号查询方式 If Check3.Value Then '判断是否输入班号 If Trim(txtClassno.Text) = "" Then sMeg = "未输入班号!" MsgBox sMeg, 48, "警告" txtClassno.SetFocus Exit Sub Else dd(2) = True If dd(0) Or dd(1) Then '组合查询语句 txtSQL = txtSQL & " and class_No='" & txtClassno.Text & "'" Else txtSQL = txtSQL & " class_No='" & txtClassno.Text & "'" End If End If End If '判断是否设置查询方式 If Not (dd(0) Or dd(1) Or dd(3)) Then MsgBox "请选择查询方式!", 48, "警告" Exit Sub End If ' 查询所有满足条件的内容 txtSQL = txtSQL & " order by student_ID" ' 执行查询语句 Set mrc = ExecuteSQL(txtSQL, MsgText) '将查询内容显示在表格控件中 With myFlexgrid .rows = 2 .CellAlignment = 4 .TextMatrix(1, 0) = "性别" .TextMatrix(1, 1) = "班号" .TextMatrix(1, 2) = "学号" .TextMatrix(1, 3) = "姓名" .TextMatrix(1, 4) = "出生日期" .TextMatrix(1, 5) = "联系电话" .TextMatrix(1, 6) = "入校时间" .TextMatrix(1, 7) = "家庭住址" ' 判断是否移动到数据集对象的最后一条 MsgBox txtSQL MsgBox MsgText Do While Not mrc.EOF .rows = .rows + 1 .CellAlignment = 4 .TextMatrix(.rows - 1, 0) = mrc.Fields(2) .TextMatrix(.rows - 1, 1) = mrc.Fields(4) .TextMatrix(.rows - 1, 2) = mrc.Fields(0) .TextMatrix(.rows - 1, 3) = mrc.Fields(1) .TextMatrix(.rows - 1, 4) = Format(mrc.Fields(3), "yyyy-mm-dd") .TextMatrix(.rows - 1, 5) = mrc.Fields(5) .TextMatrix(.rows - 1, 6) = Format(mrc.Fields(6), "yyyy-mm-dd") .TextMatrix(.rows - 1, 7) = mrc.Fields(7) '移动到下一条记录 mrc.MoveNext Loop End With mrc.CloseEnd Sub
Private Sub Check1_Click() If Check1.Value = 1 Then txtSID.Enabled = True txtSID.Visible = True Else txtSID.Text = "" txtSID.Enabled = False txtSID.Visible = False End If '检查其他的复选框是否选中 If Check2.Value = 0 Then txtName.Text = "" txtName.Enabled = False txtName.Visible = False End If If Check3.Value = 0 Then txtClassno.Text = "" txtClassno.Enabled = False txtClassno.Visible = False End If End Sub
机房收费系统
1.从上图可以看出
一组查询包含三个控件的查询内容,组合关系分别为“与”“或”。如果第一个组合关系选中,第二行必须有查询条件,同样第二组组合查询选中,第三行必须有组合查询条件。
2.思路图:
3.部分代码展示
Private Sub CmdFind_Click()Dim txtSql As StringDim msgText As StringDim mrc As ADODB.RecordsettxtSql = "select * from line_Info where "'在line_Info这张表中获得整行记录。其中*表示整行记录,也可以换成你需要查询的具体记录。 If Trim(Combo1.Text) = "" Or Trim(Combo4.Text) = "" Or Trim(Text1.Text) = "" Then MsgBox "请将选项内容填写完整!", vbOKOnly, "提示" Exit SubElse txtSql = txtSql & " " & field(Combo1.Text) & " " & Combo4.Text & "'" & Trim(Text1.Text) & "'" If Combo7.Text <> "" Then '判断第一个组合关系是否选中 If Trim(Combo2.Text) = "" Or Trim(Combo5.Text) = "" Or Trim(Text2.Text) = "" Then '如果选中,判断第二行内容是否填写完整,且符合要求 MsgBox "请将第二行选项内容填写完整!", vbOKOnly, "提示" Exit Sub Else txtSql = txtSql & " " & field(Combo7.Text) & " " & field(Combo2.Text) & " " & Combo5.Text & "'" & Trim(Text2.Text) & "'" '将前两行的条件联系起来,完成SQL语句 If Combo8.Text <> "" Then '判断第二个组合关系是否选中 If Combo3.Text = "" Or Combo6.Text = "" Or Text3.Text = "" Then '如果选中,判断第二行内容是否填写完整,且符合要求 MsgBox "请将第三行选项内容填写完整!", vbOKOnly, "提示" Exit Sub Else txtSql = txtSql & " " & field(Combo8.Text) & " " & field(Combo3.Text) & " " & Trim(Combo6.Text) & "'" & Trim(Text3.Text) & "'" '将三行的条件联系起来,完成SQL语句 End If End If End If End IfEnd If
总结:找到组合查询最简单做基本的那个语句。然后按照你的思路进行代码描述,进行信息的输入与输出。
txtSQL = "select * from 表名称 where" txtSQL = txtSQL & " " & field(组合关系) & " " & field(某行条件中运算符前的内容) & " " & 该行条件中的运算符号 & "'" & 运算符后的内容 & "'"
注意:我们看机房组合查询字段名,由于个别字段名的特殊原因,操作符是有限制的,假如字段名里面有性别、卡号、姓名、备注之类的字段名,操作符只能是“= <>”。字段名为日期和时间时,查询的内容需要有合适要求。当然代码可以进行限制。特别值得注意,未来的我们不能在这上面有任何一点马虎。
解决代码:
Select Case Combo1.Text Case "姓名", "卡号", "备注", "性别" Combo4.Clear Combo4.AddItem "=" Combo4.AddItem "<>" Case "上机日期", "下机日期", "上机时间", "下机时间", "余额", "消费金额" Combo4.Clear Combo4.AddItem "=" Combo4.AddItem "<>" Combo4.AddItem "<" Combo4.AddItem ">" End Select
1.快速清除所有文本框、combox、以及MSFlexGrid1 内容
Dim ctl As Control '定义一个变量,把控件装载到里面 For Each ctl In Controls '删除所有text文本框内容 If TypeOf ctl Is TextBox Then ctl.Text = "" Next ctl '删除所有combobox文本框内容 For Each ctl In Controls If TypeOf ctl Is ComboBox Then ctl.Text = "" Next ctl MSFlexGrid1.Clear
If Combo3.Text = "上机日期" Or Combo3.Text = "下机日期" Then DTPicker3.Format = dtpCustom DTPicker3.CustomFormat = Format("yyyy-MM-dd") DTPicker3.Visible = True Text3.Visible = False Text3.Text = DTPicker1.Value Else If Combo3.Text = "上机时间" Or Combo3.Text = "下机时间" Then DTPicker3.Format = dtpTime DTPicker3.Visible = True Text3.Visible = False Text3.Text = DTPicker1.Value Else DTPicker3.Visible = False Text3.Visible = True End If End If
阅读全文
1 0
- 第一次机房收费系统—组合查询
- [第一次机房收费系统]组合查询
- 【Cumputer】《第一次机房收费系统》总结三 组合查询
- 机房收费系统——组合查询
- 机房收费系统——组合查询
- 组合查询——机房收费系统
- 【机房收费系统——组合查询】
- 机房收费系统——组合查询
- 机房收费系统——组合查询
- 【机房收费系统】——组合查询
- 【机房收费系统】——组合查询
- 机房收费系统——组合查询
- 机房收费系统——组合查询
- 机房收费系统——组合查询
- 【机房收费系统】——组合查询
- 机房收费系统——组合查询
- 机房收费系统—组合查询
- 机房收费系统—组合查询
- 学习Spring Cloud第十课(Ribbon脱离Eureka使用)
- 关于PDO预处理语句bindParam的坑应对策略
- 【08-Redis大量数据插入】
- Xcode9学习笔记82
- 《七点三刻》024期 世界互联网大会乌镇举行/美国通过税改法案/马云再爆金句……
- 第一次机房收费系统—组合查询
- Mac 给新人的入手指南
- catalan
- [jzoj]1330. 迎接仪式(转化模型+DP)
- maven——我的食用姿势
- WIN10下 python+eclipse+jdk+PyDev(离线) 搭建java,python,C/C++开发环境
- 抽象类的作用
- JSON怎样添加注释
- ios-Runloop简单介绍