还记得当时敲的时候上机和下机可是让我想了老长时间了,现在回想起来,当时还真是好笑,就知道着急,就没想分析分析,后来通过系统的分析,感觉还真是简单啊,现在来回顾一下我的上下机。
下面先看看上机的流程图:
具体步骤:
1、判断卡号不能为空
2、判断卡号是否注册
3、判断卡号是否已经退卡(如果退卡后把表删除不用考虑次判断)
4、判断余额是否充足
5、判断是否上机
6、如果上机,把上机信息显示出来
7、如果没上机在文本框中显示信息
8、增加信息到online info中
9、显示上机人数
下机的流程图
具体步骤:
1、判断文本框是否为空
2、判断输入的是否是数字
3、判断此卡号是否注册
4、判断该卡号是否可以使用(是否已被退卡)
5、判断该卡号是否正在上机
6、计算消费时间、金额
7 、计算余额(账户余额=原账户余额-消费金额)
8、显示下机信息
9、更新学生信息表的余额
10、更新上机记录表(line表)
11、删除在线表中的信息
由于上机比较简单就不做代码展示了,现在看看下机的代码展示:
Dim mrcOnline As ADODB.Recordset Dim mrcStudent As ADODB.Recordset Dim mrcBasicData As ADODB.Recordset Dim mrcLine As ADODB.Recordset Dim OnlineSQL As String, studentSQL As String, BasicDataSQL As String, LineSQL As String Dim OnMsgtext As String, stuMsgtext As String, BMsgtext As String, LMsgtext As String Dim intLineTime As Integer '用于存储实际在线时间 Dim intConsumeTime As Integer Dim curConsume As Single '用于存储真正花费钱的时间 Dim curBalance As Single '用于存储用户的余额 Dim fixedunit As Single '用于存储固定用户的单位金额 Dim temunit As Single '用于存储临时用户的单位金额 '判断卡号框是否为空 If txtCardno.Text = "" Then MsgBox "请输入卡号!", vbOKOnly, "警告" txtCardno.SetFocus Exit Sub Else '判断卡号输入的是否是数字 If Not IsNumeric(txtCardno.Text) Then MsgBox "卡号请输入数字!", vbOKOnly, "警告" txtCardno.Text = "" txtCardno.SetFocus Exit Sub Else '判断此卡号是否存在 studentSQL = "select * from student_Info where cardno = '" & Trim(txtCardno.Text) & "'" Set mrcStudent = ExecuteSQL(studentSQL, stuMsgtext) If mrcStudent.EOF Then MsgBox "该卡号尚未注册!请重新输入!", vbOKOnly, "警告" txtCardno.SetFocus Exit Sub Else '判断该卡号是否可以使用(是否已被退卡) If mrcStudent.Fields(10) = "不使用" Then MsgBox "该卡号已经退卡,不能下机!", vbOKOnly, "警告" txtCardno.SetFocus Exit Sub Else '判断该卡号是否正在上机 OnlineSQL = "select * from Online_Info where cardno = '" & Trim(txtCardno.Text) & "'" Set mrcOnline = ExecuteSQL(OnlineSQL, OnMsgtext) ' If mrcOnline.EOF Then MsgBox "该卡号没有上机!", vbOKOnly, "警告" Exit Sub txtCardno.SetFocus End If End If End If End If End If '查询基本数据表,获得设定的基本数据 BasicDataSQL = "select * from BasicData_Info " Set mrcBasicData = ExecuteSQL(BasicDataSQL, BMsgtext) '计算消费时间 '实际在线时间 intLineTime = (Date - DateValue(mrcOnline!onDate)) * 1440 + (Hour(Time) - _ Hour(TimeValue(mrcOnline!OnTime))) * 60 + (Minute(Time) - _ Minute(TimeValue(mrcOnline!OnTime))) '把固定用户、临时用单位时间的费用分别赋给费用 fixedunit = Val(mrcBasicData.Fields(0)) '把固定用户的金额赋给变量 temunit = Val(mrcBasicData.Fields(1)) '把临时用户的金额赋给变量 '判断实际在线时间是否小于准备时间,若小于则消费时间为0 If intLineTime <= Val(Trim(mrcBasicData.Fields(4))) Then txtResumeCash.Text = 0 Else '判断实际在线时间是否小于最低消费时间,若小于消费为0 If intLineTime <= Val(Trim(mrcBasicData.Fields(3))) Then txtResumeCash.Text = 0 Else '实际在线时间大于最低消费时间则按单位时间算,分固定用户和临时用户 If intLineTime >= Val(Trim(mrcBasicData!LeastTime)) And intLineTime < Val(Trim(mrcBasicData!UnitTime)) And Trim(mrcStudent.Fields(14)) = "固定用户" Then txtResumeCash.Text = fixedunit Else If intLineTime >= Val(Trim(mrcBasicData!LeastTime)) And intLineTime < Val(Trim(mrcBasicData!UnitTime)) And Trim(mrcStudent.Fields(14)) = "临时用户" Then txtcostmoney.Text = temunit Else '当实际在线时间大于单位时间,就按有几个单位时间算,分固定用户和临时用户 If intLineTime > Val(Trim(mrcBasicData!LeastTime)) And Trim(mrcStudent.Fields(14)) = "固定用户" Then curConsume = intLineTime / Val(Trim(mrcBasicData!UnitTime)) txtResumeCash.Text = Val(curConsume) * Val(fixedunit) Else If intLineTime > Val(Trim(mrcBasicData!LeastTime)) And Trim(mrcStudent.Fields(14)) = "临时用户" Then curConsume = intLineTime / Val(Trim(mrcBasicData!UnitTime)) txtResumeCash.Text = Val(curConsume) * Val(temunit) End If End If End If End If End If End If '计算余额(账户余额=原账户余额-消费金额) curBalance = mrcStudent!cash - Val(txtResumeCash.Text) '下机信息显示 txtoffDate.Text = Date txtoffTime.Text = Time txtStudentNo.Text = Trim(mrcOnline.Fields(2)) txtName.Text = Trim(mrcOnline.Fields(3)) txtDepartment.Text = Trim(mrcOnline.Fields(4)) txtType.Text = Trim(mrcOnline.Fields(1)) txtSex.Text = Trim(mrcOnline.Fields(5)) txtonDate.Text = Trim(mrcOnline.Fields(6)) txtOnTime.Text = Trim(mrcOnline.Fields(7)) txtResumeTime.Text = intLineTime txtCash.Text = curBalance MsgBox "下机成功!欢迎下次再来!", vbOKOnly, "提示" '更新学生信息表的余额 mrcStudent.Fields(7) = curBalance mrcStudent.Update mrcStudent.Close '更新上机记录表(line表) LineSQL = "select * from Line_Info" Set mrcLine = ExecuteSQL(LineSQL, LMsgtext) mrcLine.AddNew mrcLine.Fields(1) = Trim(txtCardno.Text) mrcLine.Fields(2) = Trim(txtStudentNo.Text) mrcLine.Fields(3) = Trim(txtName.Text) mrcLine.Fields(4) = Trim(txtDepartment.Text) mrcLine.Fields(5) = Trim(txtSex.Text) mrcLine.Fields(6) = Trim(txtonDate.Text) mrcLine.Fields(7) = Trim(txtOnTime.Text) mrcLine.Fields(8) = Trim(txtoffDate.Text) mrcLine.Fields(9) = Trim(txtoffTime.Text) mrcLine.Fields(10) = Trim(Val(txtResumeTime.Text)) mrcLine.Fields(11) = Trim(Val(txtResumeCash.Text)) mrcLine.Fields(12) = Trim(Val(txtCash.Text)) mrcLine.Fields(13) = "正常下机" mrcLine.Fields(14) = Trim(Winsock1.LocalHostName) mrcLine.Update '删除在线表中的信息 OnlineSQL = "select * from online_Info where cardno = '" & Trim(txtCardno.Text) & "'" Set mrcOnline = ExecuteSQL(OnlineSQL, OnMsgtext) mrcOnline.Delete mrcOnline.Update Label15.Caption = Str(Label15.Caption - 1)