机房收费系统--组合查询
来源:互联网 发布:c语言如何转换大小写 编辑:程序博客网 时间:2024/05/02 01:02
本来不打算再发表这些东西的,但是最近帮朝哥调了点机房,感觉这一部分还是有很多精华的,在几个地方思路很好。思路很重要,理清思路可以为后期的实现节省很多时间。毕竟不是自己想出来的,抄袭师哥师姐的东西总归运用不熟练。
下面是学生基本信息维护的代码。
这个透明代码好难写。。。
Private Sub cboField_Click(Index As Integer) If Trim(cboField(0).Text) = "性别" Or Trim(cboField(1).Text) = "性别" Or Trim(cboField(2).Text) = "性别" Then MsgBox "请在要查询的内容里输入男或女", vbOKOnly + vbExclamation, "提示" End IfEnd SubPrivate Sub cboField_KeyPress(Index As Integer, KeyAscii As Integer) KeyAscii = 0End SubPrivate Sub cboOperator_KeyPress(Index As Integer, KeyAscii As Integer) KeyAscii = 0End SubPrivate Sub cboRelation_KeyPress(Index As Integer, KeyAscii As Integer) KeyAscii = 0End SubPrivate Sub cmdClean_Click() '清空所有数据 cboField(0).Text = "" cboField(1).Text = "" cboField(2).Text = "" cboOperator(0).Text = "" cboOperator(1).Text = "" cboOperator(2).Text = "" Text1(0).Text = "" Text1(1).Text = "" Text1(2).Text = "" cboRelation(0).Text = "" cboRelation(1).Text = "" With MSHFlexGrid1 '添加表头 .CellAlignment = 4 .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) = "时间" End WithEnd SubPrivate Sub cboRelation_Click(Index As Integer) If Trim(cboRelation(0).Text) <> "" Then '第一个关系不为空时,第二行可用 cboField(1).Enabled = True cboOperator(1).Enabled = True Text1(1).Enabled = True cboRelation(1).Enabled = True End If If Trim(cboRelation(1).Text) <> "" Then '第二个关系不为空时,第三行可用 cboField(2).Enabled = True cboOperator(2).Enabled = True Text1(2).Enabled = True End IfEnd SubPrivate Sub cmdExit_Click() Unload MeEnd SubPrivate Sub cmdInquiry_Click() Dim txtSQL As String Dim Msgtext As String Dim mrc As ADODB.Recordset '一个条件时 If Trim(cboField(0).Text) = "" Or Trim(cboOperator(0).Text) = "" Or Trim(Text1(0).Text) = "" Then MsgBox "请将第一行选项填写完整", vbOKOnly + vbExclamation, "提示" Exit Sub Else txtSQL = "select * from student_info where " & Fieldname(cboField(0).Text) & cboOperator(0).Text & "'" & Trim(Text1(0).Text) & "'" End If '两个条件时 If cboRelation(0) <> "" Then '判断第一个关系是否选中 If cboField(1).Text = "" Or cboOperator(1).Text = "" Or Text1(1).Text = "" Then MsgBox "请将第二行选项填写完整", vbOKOnly + vbExclamation, "提示" Exit Sub Else txtSQL = "select * from student_info where " & Fieldname(cboField(0).Text) & cboOperator(0).Text & "'" & Trim(Text1(0).Text) & "'" _ & " " & Relationname(cboRelation(0).Text) & " " & Fieldname(cboField(1).Text) & cboOperator(1).Text & "'" & Trim(Text1(1).Text) & "'" End If End If '三个条件时 If cboRelation(1) <> "" Then '判断第二个关系是否选中 If cboField(2).Text = "" Or cboOperator(2).Text = "" Or Text1(2).Text = "" Then MsgBox "请将第三行选项填写完整", vbOKOnly + vbExclamation, "提示" Exit Sub Else txtSQL = "select * from student_info where " & Fieldname(cboField(0).Text) & cboOperator(0).Text & "'" & Trim(Text1(0).Text) & "'" _ & " " & Relationname(cboRelation(0).Text) & " " & Fieldname(cboField(1).Text) & cboOperator(1).Text & "'" & Trim(Text1(1).Text) & "'" _ & " " & Relationname(cboRelation(1).Text) & " " & Fieldname(cboField(2).Text) & cboOperator(2).Text & "'" & Trim(Text1(2).Text) & "'" End If End If With MSHFlexGrid1 '添加表头 .CellAlignment = 4 .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) = "时间" End With Set mrc = ExecuteSQL(txtSQL, Msgtext) Do While Not mrc.EOF '表内添加信息 With MSHFlexGrid1 .Rows = .Rows + 1 .CellAlignment = 4 .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1)) .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(2)) .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(0)) .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(7)) .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(3)) .TextMatrix(.Rows - 1, 8) = Trim(mrc.Fields(10)) .TextMatrix(.Rows - 1, 9) = Trim(mrc.Fields(8)) .TextMatrix(.Rows - 1, 10) = Trim(mrc.Fields(14)) .TextMatrix(.Rows - 1, 11) = Trim(mrc.Fields(12)) .TextMatrix(.Rows - 1, 12) = Trim(mrc.Fields(13)) End With Call AdjustColWidth(frmBasicInfoMaintain, MSHFlexGrid1) mrc.MoveNext Loop mrc.CloseEnd SubPrivate Sub cmdModify_Click() '选中表内数据 Dim txtSQL As String Dim Msgtext As String Dim mrc As ADODB.Recordset With MSHFlexGrid1 If .RowSel = 0 Then '没有选中时 MsgBox "请选择数据", vbOKOnly + vbExclamation, "提示" Exit Sub Else If .RowSel > 0 Then '查询选中数据 txtSQL = "select * from student_Info where cardno='" & Trim(.TextMatrix(.RowSel, 0)) & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) End If End If End With frmModifySI.ShowEnd SubPrivate Sub Form_Load() Dim a, b, c For a = 0 To 2 '字段名里添加信息 With cboField(a) .AddItem "" .AddItem "卡号" .AddItem "学号" .AddItem "姓名" .AddItem "性别" .AddItem "系别" .AddItem "年级" .AddItem "班级" End With Next a For b = 0 To 2 '操作符里添加信息 With cboOperator(b) .AddItem "" .AddItem "=" .AddItem "<>" .AddItem "<" .AddItem ">" End With Next b For c = 0 To 1 '操作符里添加信息 With cboRelation(c) .AddItem "" .AddItem "与" .AddItem "或" End With Next c cboField(1).Enabled = False cboOperator(1).Enabled = False Text1(1).Enabled = False cboField(2).Enabled = False cboOperator(2).Enabled = False Text1(2).Enabled = False cboRelation(1).Enabled = FalseEnd Sub '定义一个过程,保证可以从数据库选择正确的字段Public Function Fieldname(strFieldname As String) As String Select Case strFieldname Case "卡号" Fieldname = "cardno" Case "学号" Fieldname = "studentno" Case "姓名" Fieldname = "studentname" Case "性别" Fieldname = "sex" Case "系别" Fieldname = "department" Case "年级" Fieldname = "grade" Case "班级" Fieldname = "class" End SelectEnd FunctionPublic Function Relationname(strRelationname As String) As String Select Case strRelationname Case "与" Relationname = "and" Case "或" Relationname = "or" End SelectEnd Function
0 0
- 机房收费系统组合查询
- 机房收费系统---组合查询
- 机房收费系统@组合查询
- 机房收费系统---组合查询
- 机房收费系统--组合查询
- 【机房收费系统】组合查询
- 【机房收费系统】组合查询
- 机房收费系统-组合查询
- 【机房收费系统】组合查询
- 【机房收费系统】组合查询
- 机房收费系统-组合查询
- 组合查询--机房收费系统
- 机房收费系统--组合查询
- 机房收费系统--组合查询
- 机房收费系统-组合查询
- 机房收费系统-组合查询
- 机房收费系统之组合查询
- 机房收费系统之组合查询
- github 开源项目
- s:list标签
- secureCRT常用快捷键
- 15、Android数据存储——SharedPreferences及SDCard
- 使用 Python 创建你自己的 Shell (上)
- 机房收费系统--组合查询
- HTML5-CSS总结
- NS2中无线网络模拟之三(AODV路由分析)
- eclipse内存监测工具 DDMS --> Heap
- 15.1、SQLiteDatabase
- Solaris+Oracle启动实例及切换多实例
- js jquery父页面 子页面互相调用
- Redis 的 5 个常见使用场景
- tcp长连接和保活时间