本文主要是介绍第一次机房收费系统之上下机,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言: 首先,学生上机需要在主界面上显示学生的信息,然后在online表和line表中添加记录,下机需要计算好上机时间和消费金额,更新line表和student表,删除online表中对应的记录。
流程图如下:
上机:
Dim txtsql As StringDim msgtext As StringDim mrc As ADODB.RecordsetDim mrc1 As ADODB.Recordsettxtdowntime.Text = ""txtdowndate.Text = ""txtpaytime.Text = ""txtpay.Text = ""'判断是否输入卡号If Not Testtxt(txtcardid.Text) ThenLabel1.Visible = TrueLabel1.Caption = "请输入卡号!"Exit SubEnd IfIf Not IsNumeric(txtcardid.Text) ThenLabel1.Visible = Truetxtcardid.Text = ""txtcardid.SetFocusLabel1.Caption = "卡号请输入数字!"Exit SubEnd If'查询卡号txtsql = "select * from student_info where cardno='" & Trim(txtcardid.Text) & "'"Set mrc = ExecuteSQL(txtsql, msgtext)If mrc.RecordCount = 0 ThenLabel1.Visible = Truetxtcardid.Text = ""txtcardid.SetFocusLabel1.Caption = "卡号不存在!"Exit SubElseIf Trim(mrc!Status) = "不使用" Then '查询是否注册Label1.Visible = TrueLabel1.Caption = "此卡尚未注册!"Exit SubEnd IfEnd Ifmrc.Close'查询是否上机txtsql = "select * from online_info where cardno='" & Trim(txtcardid.Text) & "'"Set mrc = ExecuteSQL(txtsql, msgtext)If mrc.RecordCount = 1 ThenLabel1.Visible = TrueLabel1.Caption = "此卡正在上机!"txttype.Text = Trim(mrc.Fields(1))txtsid.Text = Trim(mrc.Fields(2))txtname.Text = Trim(mrc.Fields(3))txtdepartment.Text = Trim(mrc.Fields(4))txtsex.Text = Trim(mrc.Fields(5))txtupdate.Text = Trim(mrc.Fields(6))txtuptime.Text = Trim(mrc.Fields(7))Exit SubEnd Ifmrc.Close'查询余额txtsql = "select * from student_info where cardno='" & Trim(txtcardid.Text) & "'"Set mrc = ExecuteSQL(txtsql, msgtext)txtsql = "select * from basicdata_info"Set mrc1 = ExecuteSQL(txtsql, msgtext)If Val(Trim(mrc!cash)) < Val(Trim(mrc1!limitcash)) ThenLabel1.Visible = TrueLabel1.Caption = "余额不足,请充值!"Exit SubEnd Ifmrc.Closemrc1.Close'显示学生信息txtsql = "select * from student_info where cardno='" & Trim(txtcardid.Text) & "'"Set mrc = ExecuteSQL(txtsql, msgtext)txtname.Text = Trim(mrc.Fields(2))txtsex.Text = Trim(mrc.Fields(3))txtsid.Text = Trim(mrc.Fields(1))txtdepartment.Text = Trim(mrc.Fields(4))txttype.Text = Trim(mrc.Fields(14))txtcash.Text = Trim(mrc.Fields(7))txtuptime.Text = timetxtupdate.Text = Datemrc.Close'向online表中添加数据txtsql = "select * from online_info "Set mrc = ExecuteSQL(txtsql, msgtext)mrc.AddNewmrc.Fields(0) = txtcardid.Textmrc.Fields(1) = txttype.Textmrc.Fields(2) = txtsid.Textmrc.Fields(3) = txtname.Textmrc.Fields(4) = txtdepartment.Textmrc.Fields(5) = txtsex.Textmrc.Fields(6) = txtupdate.Textmrc.Fields(7) = txtuptime.Textmrc.Fields(8) = GetThisComputerNamemrc.Fields(9) = Nowmrc.Updatelblshangji.Caption = mrc.RecordCountmrc.Close'向line表中添加数据txtsql = "select * from line_info"Set mrc = ExecuteSQL(txtsql, msgtext)mrc.AddNewmrc.Fields(1) = txtcardid.Textmrc.Fields(2) = txtsid.Textmrc.Fields(3) = txtname.Textmrc.Fields(4) = txtdepartment.Textmrc.Fields(5) = txtsex.Textmrc.Fields(6) = txtupdate.Textmrc.Fields(7) = txtuptime.Textmrc.Fields(14) = GetThisComputerNamemrc.Fields(13) = "正常上机"mrc.Fields(12) = txtcash.Textmrc.Updatemrc.CloseMsgBox "成功上机", vbOKOnly + vbExclamation, "提示"Label1.Visible = False
下机:
Dim txtsql As StringDim msgtext As StringDim mrc As ADODB.RecordsetDim mrc1 As ADODB.RecordsetDim umrc As ADODB.Recordset'判断是否输入卡号If Not Testtxt(txtcardid.Text) ThenLabel1.Visible = TrueLabel1.Caption = "请输入卡号!"Exit SubEnd IfIf Not IsNumeric(txtcardid.Text) ThenLabel1.Visible = TrueLabel1.Caption = "卡号请输入数字!"txtcardid.Text = ""txtcardid.SetFocusExit SubEnd If'查询卡号txtsql = "select * from student_info where cardno='" & Trim(txtcardid.Text) & "'"Set mrc = ExecuteSQL(txtsql, msgtext)If mrc.RecordCount = 0 ThenLabel1.Visible = TrueLabel1.Caption = "卡号不存在!"txtcardid.Text = ""txtcardid.SetFocusExit SubElseIf Trim(mrc!Status) = "不使用" Then '查询是否注册Label1.Visible = TrueLabel1.Caption = "此卡尚未注册!"Exit SubEnd IfEnd Ifmrc.Close'查询是否上机txtsql = "select * from online_info where cardno='" & Trim(txtcardid.Text) & "'"Set mrc = ExecuteSQL(txtsql, msgtext)If mrc.RecordCount = 0 ThenLabel1.Visible = TrueLabel1.Caption = "此卡没有上机!"Exit SubEnd Ifmrc.Close'显示数据txtdowntime.Text = timetxtdowndate.Text = Datetxtsql = "select * from online_info where cardno='" & txtcardid.Text & "'"Set mrc = ExecuteSQL(txtsql, msgtext)txtcardid.Text = Trim(mrc.Fields(0))txttype.Text = Trim(mrc.Fields(1))txtsid.Text = Trim(mrc.Fields(2))txtname.Text = Trim(mrc.Fields(3))txtdepartment.Text = Trim(mrc.Fields(4))txtsex.Text = Trim(mrc.Fields(5))txtupdate.Text = Trim(mrc.Fields(6))txtuptime.Text = Trim(mrc.Fields(7))'计算上机时间txtpaytime.Text = DateDiff("n", txtupdate, txtdowndate) + DateDiff("n", txtuptime, txtdowntime)mrc.Close'计算消费金额txtsql = "select * from student_info where cardno='" & Trim(txtcardid.Text) & "'"Set mrc = ExecuteSQL(txtsql, msgtext)txtsql = "select * from basicdata_info "Set mrc1 = ExecuteSQL(txtsql, msgtext)If Val(txtpaytime.Text) < Trim(mrc1!LeastTime) Thentxtpay.Text = 0txtcash.Text = Trim(mrc.Fields(7))ElseIf Trim(mrc!Type) = "固定用户" Thentxtpay.Text = Round(Val(txtpaytime.Text) / Trim(mrc1!unittime) * Trim(mrc1!Rate))txtcash.Text = Trim(mrc!cash - txtpay.Text)Elsetxtpay.Text = Round(Val(txtpaytime.Text) / Trim(mrc1!unittime) * Trim(mrc1!TmpRate))txtcash.Text = Trim(mrc!cash - txtpay.Text)End IfEnd Ifmrc.Closemrc1.Close'更新两个表txtsql = "select * from online_info where cardno='" & txtcardid.Text & "'"Set mrc = ExecuteSQL(txtsql, msgtext)txtsql = "select * from line_info where cardno='" & txtcardid.Text & "'and ondate='" & Trim(mrc!ondate) & "'and ontime='" & Trim(mrc!OnTime) & "'"Set mrc1 = ExecuteSQL(txtsql, msgtext)mrc1.Fields(8) = Datemrc1.Fields(9) = timemrc1.Fields(10) = Trim(txtpaytime.Text)mrc1.Fields(11) = Trim(txtpay.Text)mrc1.Fields(12) = Trim(txtcash.Text)mrc1.Fields(13) = "正常下机"mrc1.Updatemrc.Deletemrc.Closemrc1.Closetxtsql = "select * from online_info "Set mrc = ExecuteSQL(txtsql, msgtext)lblshangji.Caption = mrc.RecordCountmrc.Closetxtsql = "select * from student_info where cardno='" & txtcardid.Text & "'"Set mrc = ExecuteSQL(txtsql, msgtext)mrc.Fields(7) = Trim(txtcash.Text)mrc.Updatemrc.Close
这篇关于第一次机房收费系统之上下机的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!