作者:血玉残阳 | 来源:互联网 | 2024-12-13 12:33
前言:在十一结束的时候,机房收费系统的基本功能终于完成了,但因为自考的缘故,也没有一直写博客总结,今天就趁着闲暇时间完成总结,完美收官。
机房收费系统的上下机是最基本的功能,简单来说,收费、统计等功能都是建立在上下机以及相连的数据库表之上的,没有上下机,其他都是空谈。
上机:上机很简单,流程就是操作员给要上机的用户上机,在用户名处输入学号,然后点击上机,将上机的用户从学生表中找出,并将部分数据传递给Online表中,从而完成上机。
流程图:
代码部分:
Private Sub cmdOnline_Click()Dim mrcbd As ADODB.RecordsetDim mrcol As ADODB.Recordset'下机按钮可用cmdOffline.Enabled = True'若卡号框为空If txtCardID.Text = "" ThenLabel14.Caption = "请输入卡号!"txtCardID.SetFocusExit SubElseIf Not IsNumeric(Trim(txtCardID.Text)) ThenLabel14.Caption = "请输入数字!"txtCardID.Text = ""txtCardID.SetFocusExit SubEnd IfEnd If'查询学生表中卡号列txtSQL = "select * from student_info where cardno='" & Trim(txtCardID.Text) & "'"Set mrcs = ExecuteSQL(txtSQL, MsgText)'第一次判断是否有用户If mrcs.EOF ThenLabel14.Caption = "没有该用户,请注册或核实信息是否正确!"txtCardID.SetFocustxtCardID.Text = ""Exit SubElse'第二次判断是否用户正在上机txtSQL = "select * from online_info where cardno='" & Trim(txtCardID.Text) & "'"Set mrcol = ExecuteSQL(txtSQL, MsgText)'如果用户正在上机If mrcol.EOF = False ThenLabel14.Caption = "该用户正在上机!"txtCardID.Text = mrcs!cardnotxtType.Text = mrcs!TypetxtSID.Text = mrcs!studentnotxtName.Text = mrcs!studentnametxtFaculty.Text = mrcs!departmenttxtGender.Text = mrcs!sextxtOnlineDate.Text = mrcs!DatetxtOnlineTime.Text = mrcs!TimelblUserName.Caption = UserNametxtBalance.Text = mrcs!cashExit SubElse'第三次判断用户余额是否充足'该处一定要用where来判断是对哪一列数据的对比txtSQL = "select * from student_info where cardno='" & Trim(txtCardID.Text) & "'"Set mrcs = ExecuteSQL(txtSQL, MsgText)txtSQL = "select * from basicdata_info "Set mrcbd = ExecuteSQL(txtSQL, MsgText)If Val(mrcs.Fields(7))
下机则是将要下机的用户从界面中"取消登陆的状态",从数据库Online表中删掉,再添加到line表中,并且通过Basicdata表中的计费数据,进行计算。之后根据用户所消费的金额,从余额中扣除金钱,从而更新学生表
下机代码:
Private Sub cmdOffline_Click()Dim mrcol As ADODB.RecordsetDim mrcl As ADODB.RecordsetDim mrcoloff As ADODB.RecordsetDim offlinetime As IntegerDim mrcbd As ADODB.RecordsetDim costtime As StringDim costday As StringDim alltime As StringDim unittime As String'判断是否输入卡号If txtCardID.Text = "" ThenLabel14.Caption = "请输入卡号!"txtCardID.SetFocusExit SubEnd If'查询online表中的卡号列txtSQL = "select * from online_info where cardno='" & Trim(txtCardID.Text) & "'"Set mrcol = ExecuteSQL(txtSQL, MsgText)'判断该用户是否正在上机If mrcol.EOF ThenLabel14.Caption = "该用户尚未上机!"txtCardID.SetFocustxtCardID.Text = ""Exit SubElse'消费时间计算costday = DateDiff("n", mrcol!ondate, Date)costtime = DateDiff("n", mrcol!OnTime, Time)alltime = Val(costday) + Val(costtime)txtSQL = "select * from basicdata_info "Set mrcbd = ExecuteSQL(txtSQL, MsgText)'判断是什么类型用户,从而进行计费If Trim(mrcol!cardtype) = "固定用户" ThentxtCostMoney = alltime / 60 * mrcbd!RateElsetxtCostMoney = alltime / 60 * mrcbd!tmprateEnd If'判断是否超过准备时间If costtime End Sub
总结:上下机其实就是对数据表中,信息的增加、修改或删除。
难点:下机消费时间与金额的计算,以及对之后表的更新,这期间逻辑一定要十分清晰。