上机
上机流程图
这里个人觉得就是数据表的增删改查,没有思路的看官可以参考我的全码
'上机 Private Sub cmdonline_Click(Index As Integer) Dim mrc As adodb.Recordset Dim txtsql As String Dim msgtext As String '是否输入学号 If Not testtxt(cardno.Text) Then MsgBox "请输入学号!",vbOKOnly + vbExclamation,"警告" cardno.SetFocus Exit Sub Else '验证用户是否已上机 txtsql = "select * from onLine_Info where cardno='" & Trim(cardno.Text) & "'" Set mrc1 = Executesql(txtsql,msgtext) If mrc1.EOF = False Then MsgBox "该帐号已经上机,不允许重复登录!","警告" cardno.Text = "" studentName.Text = "" dept.Text = "" sex.Text = "" class.Text = "" grade.Text = "" status.Text = "" style.Text = "" Else '验证学号是否存在 txtsql = "select * from student_Info where cardno ='" & cardno.Text & "'" Set mrc = Executesql(txtsql,msgtext) If mrc.EOF = True Then MsgBox txtsql MsgBox msgtext MsgBox "此用户名不存在,请重新输入!","警告" cardno.SetFocus Else '验证余额是否充足 If Val(mrc.Fields(7)) < 5 Then MsgBox "余额不足,请先充值","警告" cardno.Text = "" Exit Sub Else cardno.Text = mrc.Fields(0) studentName.Text = mrc.Fields(2) dept.Text = mrc.Fields(4) sex.Text = mrc.Fields(3) class.Text = mrc.Fields(6) grade.Text = mrc.Fields(5) status.Text = mrc.Fields(10) style.Text = mrc.Fields(14) ondate.Text = Date ontime.Text = Time havemoney = mrc.Fields(7) '更新上机人数 txtsql = "select * from onLine_Info" Set mrc1 = Executesql(txtsql,msgtext) txtsql = "select * from User_Info" Set mrc2 = Executesql(txtsql,msgtext) mrc1.AddNew mrc1.Fields(0) = Trim(cardno.Text) mrc1.Fields(1) = Trim(style.Text) mrc1.Fields(2) = Trim(cardno.Text) mrc1.Fields(3) = Trim(studentName.Text) mrc1.Fields(4) = Trim(dept.Text) mrc1.Fields(5) = Trim(sex.Text) mrc1.Fields(6) = Date mrc1.Fields(7) = Time mrc1.Fields(8) = "" mrc1.Fields(9) = "" mrc.Fields(9) = mrc2.Fields(0) mrc1.Update onlineNumber.Caption = mrc1.RecordCount nowtime.Caption = Time MsgBox "上机成功!","提示" mrc1.Close txtsql = "select * from Line_info " Set mrc4 = Executesql(txtsql,msgtext) '更新上机记录表 mrc4.AddNew mrc4.Fields(1) = Trim(cardno.Text) mrc4.Fields(2) = Trim(cardno.Text) mrc4.Fields(3) = Trim(studentName.Text) mrc4.Fields(4) = Trim(dept.Text) mrc4.Fields(5) = Trim(sex.Text) mrc4.Fields(6) = Trim(ondate.Text) mrc4.Fields(7) = Trim(ontime.Text) mrc4.Fields(13) = "上机" mrc4.Fields(14) = VBA.Environ("computername") mrc4.Update mrc4.Close End If End If End If End If End Sub
下机
简单来说,下机的流程就是要删除上机表中的数据外,而且还要把上机的数据记录下来。
下机的难点在于多表的使用,消费时间,消费余额、金额的计算等等。
流程图
全部参考代码如下,希望能帮你建立下机的全局逻辑。
Private Sub cmddown_Click() '下机 '判断是否输入了学号 Dim msgtext As String Dim txtsql As String Dim mrc As adodb.Recordset Dim txtdate As String Dim txttime As String Dim intconsumetime As String Dim inttime As String Dim intstyle As String Dim cash As String Dim unittime As String Dim rate As String Dim mrc6 As adodb.Recordset If cardno.Text = "" Then MsgBox "请输入学号!","警告" Else '判断该用户是否上机 txtsql = "select * from OnLine_Info where cardno='" & Trim(cardno.Text) & "'" Set mrc = Executesql(txtsql,msgtext) If mrc.EOF = True Then MsgBox "该卡号未上机,请重新确认","警告" cardno.Text = "" studentName.Text = "" dept.Text = "" sex.Text = "" class.Text = "" grade.Text = "" status.Text = "" style.Text = "" ondate.Text = "" ontime.Text = "" Else '显示上机帐号数据 txtsql = "select * from student_Info" Set mrc1 = Executesql(txtsql,msgtext) txtsql = "select * from BasicData_Info" Set mrc2 = Executesql(txtsql,msgtext) style.Text = mrc.Fields(1) cardno.Text = mrc.Fields(0) studentName.Text = mrc.Fields(3) dept.Text = mrc.Fields(4) sex.Text = mrc.Fields(5) ondate.Text = Format(Trim(mrc.Fields(6)),"yyyy-mm-dd") ontime.Text = Format(Trim(mrc.Fields(7)),"hh:mm:ss") class.Text = mrc1.Fields(6) grade.Text = mrc1.Fields(5) status.Text = mrc1.Fields(10) txtupdate.Text = Format(Date,"yyyy-mm-dd") uptime.Text = Format(Time,"hh:mm:ss") '下机结算:时间,金额 txtdate = DateDiff("n",ondate,txtupdate) txttime = DateDiff("n",ontime,uptime) txtconsumetime.Text = Int(txttime) + Int(txtdate) intcousumetime = txtconsumetime.Text If intcousumetime < mrc2.Fields(4) Then '判断消费时间是否小于准备时间 txtconsumetime = "0" spendmoney.Text = "0" havemoney.Text = Trim(mrc.Fields(7)) End If If intcousumetime < mrc2.Fields(3) Then '判断消费时小于最小上机时间时消费金额为1 txtconsumetime = "0" spendmoney.Text = "1" havemoney.Text = Trim(mrc.Fields(7)) - Trim(spendmoney.Text) MsgBox "下机成功!",vbonly + vbExclamation,"提示" Else '判断临时用户的消费金额 If mrc1.Fields(14) = "临时用户" Then spendmoney.Text = (Int(intcousumetime / 60) + 1) * Trim(mrc2.Fields(1)) havemoney.Text = Trim(mrc1.Fields(7)) - Trim(spendmoney.Text) Else '判断固定用户的消费金额 spendmoney.Text = (Int(intcousumetime / 60) + 1) * Trim(mrc2.Fields(0)) havemoney.Text = Trim(mrc1.Fields(7)) - Trim(spendmoney.Text) If havemoney.Text < 0 Then recharge.Show MsgBox "下机失败,请先充值!","提示" End If MsgBox "下机成功!","提示" End If '更新上机记录 mrc.Delete mrc.Update mrc.Close '更新历史上机记录 txtsql = "select * from Line_info where cardno='" & Trim(cardno.Text) & "'" Set mrc4 = Executesql(txtsql,msgtext) mrc4.AddNew mrc4.Fields(1) = Trim(cardno.Text) mrc4.Fields(2) = Trim(cardno.Text) mrc4.Fields(3) = Trim(studentName.Text) mrc4.Fields(4) = Trim(dept.Text) mrc4.Fields(5) = Trim(sex.Text) mrc4.Fields(6) = Trim(ondate.Text) mrc4.Fields(7) = Trim(ontime.Text) mrc4.Fields(8) = Trim(txtupdate.Text) mrc4.Fields(9) = Trim(uptime.Text) mrc4.Fields(10) = Trim(txtconsumetime.Text) mrc4.Fields(11) = Trim(spendmoney.Text) mrc4.Fields(12) = Trim(havemoney.Text) mrc4.Fields(13) = "下机" mrc4.Fields(14) = VBA.Environ("computername") mrc4.Update mrc4.Close End If '更新学生表学生信息(余额) txtsql = "select * from student_Info where cardno='" & Trim(cardno.Text) & "'" Set mrc6 = Executesql(txtsql,msgtext) mrc6.Fields(7) = Trim(havemoney.Text) mrc6.Fields(9) = UserName mrc6.Fields(10) = "正常" mrc6.Fields(11) = "结账" mrc6.Fields(12) = Date mrc6.Fields(13) = Time mrc6.Update mrc6.Close End If '更新上机人数 txtsql = "select * from online_info" Set mrc5 = Executesql(txtsql,msgtext) onlineNumber.Caption = "当前上机人数为:" & mrc5.RecordCount mrc5.Close '显示当前时间 nowtime.Caption = Time End If '清空文本框 style.Text = "" cardno.Text = "" studentName = "" dept.Text = "" sex.Text = "" ondate.Text = "" ontime.Text = "" class.Text = "" grade.Text = "" status.Text = "" txtupdate.Text = "" uptime.Text = "" spendmoney.Text = "" txtconsumetime = "" havemoney = "" End Sub
结语
这个专栏针对的读者主要是没有思路的读者,所以我贴源码意在提供思路,部分代码参考。