机房收费系统问题集(4)——指定时间段数据查询+组合查询

2024-08-26 11:08

本文主要是介绍机房收费系统问题集(4)——指定时间段数据查询+组合查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

    最近一直处在“攻坚”阶段,指定时间段数据查询和组合查询两座大山终于拿下,现在整理一下,也不枉我的苦心经营了......奋斗

(1)指定时间段数据查询

首先添加DTPicker控件,这是个非常强大的控件,早知道有它,我肯定赚到好多时间......



然后在你需要的地方画出来,它刚刚画出来的样式虽然很普通,但是,运行后,你会大吃一惊的


既能选择你想要的时间,又能立马回到今天,有木有很强大吐舌头

重点是两个时间段内的数据查询,写入下面的代码,哈哈,尽情的查吧

<pre name="code" class="vb"><strong><span style="font-family:KaiTi_GB2312;font-size:18px;">Private Sub cmdchaxun_Click()
Dim txtsql As String
Dim msgtext As String
Dim mrc As ADODB.Recordset
Dim startdate As Date
Dim enddate As Datestartdate = DTPicker1.Value
enddate = DTPicker2.Valuetxtsql = "select * from Recharge_Info where date >='" & startdate & "' and date <='" & enddate & "'"
Set mrc = executesql(txtsql, msgtext)
'比较两个日期的大小
If DateDiff("d", CDate(startdate), CDate(enddate)) < 0 ThenMsgBox "起始日期不能小于终止日期!", vbOKOnly + vbExclamation, "警告"Exit Sub
End IfIf mrc.EOF ThenMsgBox "没有数据!", vbOKOnly + vbExclamation, "警告"Exit Sub
End IfWith myflexgrid.CellAlignment = 4.Rows = 1.TextMatrix(0, 0) = "卡号".TextMatrix(0, 1) = "充值金额".TextMatrix(0, 2) = "充值日期".TextMatrix(0, 3) = "充值时间".TextMatrix(0, 4) = "充值教师".TextMatrix(0, 5) = "结账状态"
Do While Not mrc.EOF.CellAlignment = 4.Rows = .Rows + 1.TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(2)).TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(3)).TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(4)).TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(5)).TextMatrix(.Rows - 1, 4) = Trim(username)If IsNull(mrc.Fields(7)) = False Then.TextMatrix(.Rows - 1, 5) = Trim(mrc.Fields(7))Else.TextMatrix(.Rows - 1, 5) = ""End Ifmrc.MoveNextLoop
End With
mrc.Close</span></strong>


 
在代码中间用到了三个函数:DateDiff函数、IsNull函数和CDate函数 

DateDiff函数:表达式:DateDiff(timeinterval,date1,date2 [, firstdayofweek [,                                      firstweekofyear]])                     

              允许数据类型::timeinterval 表示相隔时间的类型,代码为:                     

              年份 yy、yyyy 季度 qq、q                     

              月份 mm、m                    

              每年的某一日 dy、y                     

              日期 dd、d                     

              星期 wk、ww                    

              工作日 dw                     

              小时 hh                     

              分钟 mi、n                     

              秒 ss、s                     

              毫秒 ms

IsNull函数:IsNull是一个内部函数,判断参数对象是否为空(指出表达式是否不包含任何有效数据),若是,返回true,否则返回false. 

CDate函数:CDate(date)返回表达式,此表达式已被转换为 Date 子类型的 Variant。

           CDate 根据系统的区域设置识别日期格式。如果数据的格式不能被日期设置识别,则不能判断                年、月、日的正确顺序。另外,如果长日期格式包含表示星期几的字符串,则不能被识别。

(2)组合查询

    在机房收费系统中有三个用到组合查询的窗体:学生基本信息维护,学生上机统计信息查询,操作员工作记录,现在以学生基本信息维护为例

首先在模块中将人类语言转换成计算机可以懂的语言,以便于查询

<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">Public Function FiledName(StrFiledName As String) As StringSelect Case StrFiledNameCase "卡号"FiledName = "cardno"Case "学号"FiledName = "studentno"Case "姓名"FiledName = "studentname"Case "性别"FiledName = "sex"Case "学院"FiledName = "department"Case "年级"FiledName = "grade"Case "班级"FiledName = "class"End Select</span></strong>
<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">End Function
</span></strong>

再在模块中添加判断是否为空的代码(学生信息管理系统中也用到了)

<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">Public Function testtxt(txt As String) As Boolean
'判断输入内容是否为空
If Trim(txt) = "" Thentesttxt = False
Elsetesttxt = True
End If
End Function
</span></strong>

然后设置操作符,卡号,学号可以有“<”和“>”,可是姓名,性别,系别,年级不能有,于是乎,在每个字段的click事件下添加下面的代码:

<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">Private Sub Comboziduan1_Click()Combocaozuo1.Clear '添加后就没有重复的操作符了Select Case Comboziduan1.TextCase "卡号"Combocaozuo1.AddItem "="Combocaozuo1.AddItem "<"Combocaozuo1.AddItem ">"Combocaozuo1.AddItem "<>"Case "学号"Combocaozuo1.AddItem "="Combocaozuo1.AddItem "<"Combocaozuo1.AddItem ">"Combocaozuo1.AddItem "<>"Case "姓名"Combocaozuo1.AddItem "="Combocaozuo1.AddItem "<>"Case "性别"MsgBox "请输入“男”或“女”!", vbOKOnly + vbExclamation, "提示"Combocaozuo1.AddItem "="Combocaozuo1.AddItem "<>"Case "系别"Combocaozuo1.AddItem "="Combocaozuo1.AddItem "<>"Case "年级"Combocaozuo1.AddItem "="Combocaozuo1.AddItem "<>"Case "班级"Combocaozuo1.AddItem "="Combocaozuo1.AddItem "<>"End Select
End Sub</span></strong>

再在“查询”的按钮的click事件中添加下面的代码:

<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">Private Sub cmdchaxun_Click()Dim txtsql As StringDim msgtext As StringDim mrc As ADODB.Recordsettxtsql = "select * from student_Info where "'判断字段是否为空If Not testtxt(Trim(Comboziduan1.Text)) ThenMsgBox "请选择字段名!", vbOKOnly + vbExclamation, "警告"Comboziduan1.SetFocusExit SubEnd If'判断操作符是否为空If Not testtxt(Trim(Combocaozuo1.Text)) ThenMsgBox "请选择操作符!", vbOKOnly + vbExclamation, "警告"Combocaozuo1.SetFocusExit SubEnd If'判断查询内容是否为空If Not testtxt(Trim(txtchaxun1.Text)) ThenMsgBox "请输入要查询的内容!", vbOKOnly + vbExclamation, "警告"txtchaxun1.SetFocusExit SubEnd Iftxtsql = txtsql & FiledName(Comboziduan1.Text) & " " & Combocaozuo1.Text & "'" & txtchaxun1.Text & "'"'开始组合If Trim(Combozuhe1.Text <> "") ThenIf Trim(Comboziduan2.Text) = "" Or Trim(Combocaozuo2.Text) = "" Or Trim(txtchaxun2.Text) = "" ThenMsgBox "您选择了第一个组合关系,请输入完整的信息后再查询!", vbOKOnly + vbExclamation, "提示"Exit SubElsetxtsql = txtsql & FiledName(Combozuhe1.Text) & " " & FiledName(Comboziduan2.Text) & Combocaozuo2.Text & "'" & Trim(txtchaxun2.Text) & "'"End IfEnd IfIf Trim(Combozuhe2.Text) <> "" ThenIf Trim(Comboziduan3.Text) = "" Or Trim(Combocaozuo3.Text) = "" Or Trim(txtchaxun3.Text) = "" ThenMsgBox "您选择了第二个组合关系,请输入完整的信息后再查询!", vbOKOnly + vbExclamation, "警告"Exit SubElsetxtsql = txtsql & FiledName(Combozuhe2.Text) & " " & FiledName(Comboziduan3.Text) & Combocaozuo3.Text & "'" & Trim(txtchaxun3.Text) & "'"End IfEnd If'开始查询Set mrc = executesql(txtsql, msgtext)If mrc.EOF ThenMsgBox "没有您要查找的学生,请重新查询!", vbOKOnly + vbExclamation, "警告"ElseWith myflexgrid.Rows = 1.CellAlignment = 4.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) = "类型"End WithDo While Not mrc.EOFWith myflexgrid.Rows = .Rows + 1.CellAlignment = 4.TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(0)).TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(1)).TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(2)).TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(3)).TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(4)).TextMatrix(.Rows - 1, 5) = Trim(mrc.Fields(5)).TextMatrix(.Rows - 1, 6) = Trim(mrc.Fields(6)).TextMatrix(.Rows - 1, 7) = Trim(mrc.Fields(7)).TextMatrix(.Rows - 1, 8) = Trim(mrc.Fields(8)).TextMatrix(.Rows - 1, 9) = Trim(mrc.Fields(10)).TextMatrix(.Rows - 1, 10) = Trim(mrc.Fields(12)).TextMatrix(.Rows - 1, 11) = Trim(mrc.Fields(13)).TextMatrix(.Rows - 1, 12) = Trim(mrc.Fields(14))End Withmrc.MoveNextLoopEnd If </span></strong>
<strong><span style="font-family:KaiTi_GB2312;font-size:18px;">mrc.Close  
End Sub</span></strong>
    OK,大功告成,查询一下吧,是不是感觉超厉害(其实代码中我还有不懂的地方,还在摸索中奋斗,希望大家多多提建议,共同加油!!!)

    没有做不到,只有想不到,怀着全心全意为人民服务的赤诚之心,没有做不好的事情!!!小伙伴们,好好加油!!!




这篇关于机房收费系统问题集(4)——指定时间段数据查询+组合查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1108392

相关文章

Python数据验证神器Pydantic库的使用和实践中的避坑指南

《Python数据验证神器Pydantic库的使用和实践中的避坑指南》Pydantic是一个用于数据验证和设置的库,可以显著简化API接口开发,文章通过一个实际案例,展示了Pydantic如何在生产环... 目录1️⃣ 崩溃时刻:当你的API接口又双叒崩了!2️⃣ 神兵天降:3行代码解决验证难题3️⃣ 深度

MySQL中between and的基本用法、范围查询示例详解

《MySQL中betweenand的基本用法、范围查询示例详解》BETWEENAND操作符在MySQL中用于选择在两个值之间的数据,包括边界值,它支持数值和日期类型,示例展示了如何使用BETWEEN... 目录一、between and语法二、使用示例2.1、betwphpeen and数值查询2.2、be

MySQL快速复制一张表的四种核心方法(包括表结构和数据)

《MySQL快速复制一张表的四种核心方法(包括表结构和数据)》本文详细介绍了四种复制MySQL表(结构+数据)的方法,并对每种方法进行了对比分析,适用于不同场景和数据量的复制需求,特别是针对超大表(1... 目录一、mysql 复制表(结构+数据)的 4 种核心方法(面试结构化回答)方法 1:CREATE

Springboot3统一返回类设计全过程(从问题到实现)

《Springboot3统一返回类设计全过程(从问题到实现)》文章介绍了如何在SpringBoot3中设计一个统一返回类,以实现前后端接口返回格式的一致性,该类包含状态码、描述信息、业务数据和时间戳,... 目录Spring Boot 3 统一返回类设计:从问题到实现一、核心需求:统一返回类要解决什么问题?

详解C++ 存储二进制数据容器的几种方法

《详解C++存储二进制数据容器的几种方法》本文主要介绍了详解C++存储二进制数据容器,包括std::vector、std::array、std::string、std::bitset和std::ve... 目录1.std::vector<uint8_t>(最常用)特点:适用场景:示例:2.std::arra

maven异常Invalid bound statement(not found)的问题解决

《maven异常Invalidboundstatement(notfound)的问题解决》本文详细介绍了Maven项目中常见的Invalidboundstatement异常及其解决方案,文中通过... 目录Maven异常:Invalid bound statement (not found) 详解问题描述可

idea粘贴空格时显示NBSP的问题及解决方案

《idea粘贴空格时显示NBSP的问题及解决方案》在IDEA中粘贴代码时出现大量空格占位符NBSP,可以通过取消勾选AdvancedSettings中的相应选项来解决... 目录1、背景介绍2、解决办法3、处理完成总结1、背景介绍python在idehttp://www.chinasem.cna粘贴代码,出

MyBatis-Plus使用动态表名分表查询的实现

《MyBatis-Plus使用动态表名分表查询的实现》本文主要介绍了MyBatis-Plus使用动态表名分表查询,主要是动态修改表名的几种常见场景,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录1. 引入依赖2. myBATis-plus配置3. TenantContext 类:租户上下文

SpringBoot整合Kafka启动失败的常见错误问题总结(推荐)

《SpringBoot整合Kafka启动失败的常见错误问题总结(推荐)》本文总结了SpringBoot项目整合Kafka启动失败的常见错误,包括Kafka服务器连接问题、序列化配置错误、依赖配置问题、... 目录一、Kafka服务器连接问题1. Kafka服务器无法连接2. 开发环境与生产环境网络不通二、序

SpringSecurity中的跨域问题处理方案

《SpringSecurity中的跨域问题处理方案》本文介绍了跨域资源共享(CORS)技术在JavaEE开发中的应用,详细讲解了CORS的工作原理,包括简单请求和非简单请求的处理方式,本文结合实例代码... 目录1.什么是CORS2.简单请求3.非简单请求4.Spring跨域解决方案4.1.@CrossOr