概述
转眼间两个多月过去了,依稀的记得当时刚进入机房收费系统的状态。心里更多的是一种抵触,是一种恐惧,主要原因在于自己对于未来的困难没有任何的可遇见性,脑袋里的知识储备极少。坎坎坷坷,经历了两个多月,两次的项目验收,多达六次的项目延期,总结博客数十篇,画了不下十张的流程图……自己的内心依然说不出个一五一十。直到项目结束,才渐渐清晰的大脑。下面就来总结下本次这充满坎坷而又美好的旅程。
正文
机房收费系统是一个小型的完整系统,别看他小,五张俱全,完全可以收拾住小白们。下面一一展现。重点总结机房收费系统的三大难点。
- 上下机:
(1)上机:这个稍显简单一些,毕竟没有什么计算,我们只需要思路清晰就好,跟以往不一样的是需要调用多张表:student_Info表——这个很关键,因为所有卡注册后的信息都在这个表里,上机首先要查它,看上机的人是否已经注册,判断其是否退卡;Basicdata_Info表——我们的基本信息表,有价格,收费标准都在其中,我们需要判断用户的卡内余额是否充足;Online_Info表——在线统计表,用途在于判断该用户是否已经在线;Line_Info表——上下机记录统计表,我们必须将上机的记录更新到该表,以备后续的调用。
个人感受:上机方面没有特别的难点,就是调用的数据表较多而已,其实不难想象,上机关系到后续的一系列计算等等,信息当然要全面。
(2)下机:这个稍显复杂,不仅牵扯到数据表,并且还需要进行简单的计算。首先调用Online_Info表——判断下机账号是否正在上机,否则无从谈起;Basicdata_Info表——有计算就一定少不了它;Student_Info 表——将计算的信息更新到学生表中;Line_Info表——将下机的信息更新到上下机记录表中去。
重点代码:
time1 = Trim(DateDiff("n", txtOnTime.Text, Time)) '把时间差转换为分钟
time2 = Trim(DateDiff("n", txtOnData.Text, Date)) '把日期差转换为分钟
txtSQL = "select * from BasicData_Info" '从数据表中获取基本数据
Set mrc1 = ExecuteSQL(txtSQL, Msgtext)
If Val(time1) + Val(time2) < mrc1.Fields(4) Then '上机时间小于准备时间,则消费时间为0
time3 = "0"
Else
time3 = Val(time1) + Val(time2) - Val(mrc1.Fields(4)) '否则则是上机时间减去准备时间
End If
txtConsumeTime.Text = Val(time3) '更新消费时间
If mrc.Fields(1) = "固定用户" Then
txtConsume.Text = Int(mrc1.Fields(0) / 60 * Val(txtConsumeTime.Text)) '计算固定用户金额
Else '计算临时用户金额
txtConsume.Text = Int(mrc1.Fields(1) / 60 * Val(txtConsumeTime.Text))
mrc1.Close
End If
txtSQL = "select * from student_Info where cardno= '" & Trim(txtNo.Text) & "'and status='" & "使用" & "'" '得出余额
Set mrc3 = ExecuteSQL(txtSQL, Msgtext)
txtCash.Text = Val(Trim(mrc3.Fields(7)) - Val(txtConsume.Text))
mrc3.Fields(7) = Val(txtCash.Text)
mrc3.Update
mrc3.Close
txtSQL = "select * from Line_Info where cardno= '" & Trim(txtNo.Text) & "'and ondate='" & Trim(txtOnData.Text) & "'and ontime='" & Trim(txtOnTime.Text) & "'" '增加上机记录
Set mrc6 = ExecuteSQL(txtSQL, Msgtext)
If Not mrc6.EOF Then
mrc6.Fields(8) = Trim(txtDownData.Text)
mrc6.Fields(9) = Trim(txtDownData.Text)
mrc6.Fields(10) = Trim(txtConsumeTime.Text)
mrc6.Fields(11) = Val(txtConsume.Text)
mrc6.Fields(12) = Trim(txtCash.Text)
mrc6.Fields(13) = "正常下机"
mrc6.Update
mrc6.Close
End If
个人感受:计算是难点,逻辑性很强,需要我们将每个表的用途搞清楚。多问几个为什么需要将某些信息更新到这个表中,而不更新到其他表中,后面到底干什么用,等等。
- 组合查询:顾名思义就是查询自己想要的信息。关键点是多条件查询,还要组合等等。首先会用到的是Student_Info表——它是从注册开始就必不可少的表,很多的信息都在这张表上。
重点代码
StutxtSQL = "select*from student_info where"
'在student_Info这张表中获得整行记录。其中*表示整行记录,也可以换成你需要查询的具体记录。
If Trim(Combo1.Text) = "" Or Trim(Combo2.Text) = "" Or Trim(Text1.Text) = "" Then
MsgBox "请将选项内容填写完整!", vbOKOnly, "提示"
Combo1.SetFocus
Exit Sub
Else
StutxtSQL = StutxtSQL & " " & field(Combo1.Text) & "" & Combo2.Text & "'" & Trim(Text1.Text) & "'"
If Combo7.Text <> "" Then
If Combo3.Text = "" Or Combo4.Text = "" Or Text2.Text = "" Then
MsgBox "请将第二行选项内容填写完整!", vbOKOnly, "提示"
Exit Sub
Else
StutxtSQL = StutxtSQL & " " & field(Combo7.Text) = "" Or field(Combo3.Text) & "" & Combo4.Text & "'" & Trim(Text2.Text) & "'"
If Combo8.Text <> "" Then
If Combo5.Text = "" Or Combo6.Text = "" Or Text3.Text = "" Then
MsgBox "请将第三行选项内容填写完整!", vbOKOnly, "提示"
Exit Sub
Else
StutxtSQL = StutxtSQL & " " & field(Combo8.Text) & "" & field(bombo5.Text) & "" & Trim(Combo6.Text) & "" & Trim(Text3.Text) & "'"
End If
End If
End If
End If
Set Stumrc = ExecuteSQL(StutxtSQL, StuMsgtext)
个人感受:难点在于用严密的逻辑,运用各种条件查询想要的信息。小白同志们最难的就是想的不全面,大家懂的。
- 结账:最让我头疼的地方,哈哈哈。首先需要我们汇总各种信息,那么我们就需要将每种信息所对应的数据表搞清楚,并且清楚所汇总的信息。
关键字:准确
数据表:
Student_Info表——这里怎么可以没有他呢?购卡信息和余额都在该表上;Recharge_Info表——充值信息表,汇总充值信息及计算其他余额所必不可少的表;Cancelcard_Info表——退卡表汇总退卡信息,特别是退卡金额的汇总;Line_Info、Online_Info表、Basicdata_Info表这些都是必不可少的,这里不一一介绍(前面有阐述)。
结账项中每个单项对应的关系:
到底是什么卡???汇总的主要是什么???每个单项都是什么???相互之间有些什么关系???结账的关键,这些不搞清楚,否则我们无从下手,更不知道调用什么数据表。下面我仅谈我自己的理解。
1.购卡:对应的是注册窗体,关键点在于临时用户还是固定用户,其他信息没有特别的地方,而结账窗体中又有相应的临时用户,因此推断:该购卡主要统计的是固定用户的信息
2.充值:这个较为简单,顾名思义,就是充值的相关信息的汇总
3.退卡:退卡信息的汇总
4.临时用户:就是注册窗体中临时用户部分的汇总。
重点代码
txtSQL = "select*from student_info where userid='" & cmbUserid.Text & "'" & "and ischeck='未结账'" & "and type='固定用户'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
txtCardAmount.Text = mrc.RecordCount
With myflexgrid1
.CellAlignment = 5
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "日期"
.TextMatrix(0, 3) = "时间"
.TextMatrix(0, 4) = "金额"
.Rows = 1
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 5
.TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1))
.TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(0))
.TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(12))
.TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(13))
.TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(15))
txtfixedcash.Text = Val(txtfixedcash.Text) + Val(Trim(mrc.Fields(15)))
mrc.MoveNext
Loop
End With
mrc.Close
End If
If SSTab.Caption = "充值" Then
myflexgrid2.Clear
txtRecharge.Text = "0"
txtSQL = "select * from recharge_info where userid='" & cmbUserid.Text & "'" & "and status='未结账'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
With myflexgrid2
.CellAlignment = 4
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "充值金额"
.TextMatrix(0, 3) = "日期"
.TextMatrix(0, 4) = "时间"
.Rows = 1
Do While Not mrc.EOF
.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(3))
.TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(4))
.TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(5))
txtRecharge.Text = Val(txtRecharge.Text) + Val(Trim(mrc.Fields(3)))
mrc.MoveNext
Loop
End With
mrc.Close
End If
If SSTab.Caption = "退卡" Then
myflexgrid3.Clear
txtExitCash.Text = "0"
txtSQL = "select * from cancelcard_info where userid='" & cmbUserid.Text & "'" & " and status='未结账'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
txtExitCardAmount.Text = mrc.RecordCount
With myflexgrid3
.CellAlignment = 4
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "退卡金额"
.TextMatrix(0, 3) = "日期"
.TextMatrix(0, 4) = "时间"
.Rows = 1
Do While Not mrc.EOF
.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))
txtExitCash.Text = Val(txtExitCash.Text) + Val(Trim(mrc.Fields(2)))
mrc.MoveNext
Loop
End With
mrc.Close
End If
If SSTab.Caption = "临时用户" Then
myflexgrid4.Clear
txtTemCash.Text = "0"
txtSQL = "select * from student_Info where userID='" & cmbUserid.Text & "'" & " and Ischeck='未结账' and type='临时用户'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
With myflexgrid4 '设置myflexgrid
.CellAlignment = 4
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "日期"
.TextMatrix(0, 3) = "时间"
.TextMatrix(0, 4) = "金额"
.Rows = 1
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1))
.TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(0))
.TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(12))
.TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(13))
.TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(15))
mrc.MoveNext
Loop
End With
mrc.Close
End If
If SSTab.Caption = "退出" Then
Unload Me
End If
If SSTab.Caption = "汇总" Then
If txtCash.Text = "0" Then '限制重复结账
txtSQL = "select*from student_info where userID='" & cmbUserid.Text & "'" & "and status='使用'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
mrc.Close
txtCash.Text = Val(txtTemCash.Text) + Val(txtRecharge.Text) + Val(txtfixedcash.Text) - Val(txtExitCash.Text)
End If
End If
End Sub
个人感受:汇总是结账的难点,调用的表多,计算错综复杂,稍有不慎就会有重复的情况。
总结
机房收费系统还是非常的有魅力的,其实还远远不止我总结的这点东西,越研究越有意思,目前我也远远没有达到全部都搞懂的境地,后面,有待进一步的学习。