• 机房收费系统系列四:上下机


    在机房收费系统中,上下机这边花了不少的时间去做它,主要原因是没有理清思路,一股脑的就做起来了,上机挺好做的,到了下机,做完以后傻眼了,这才发现不对着呢……为了避免这种情况,在做上下机的时候首先理清思路,不要着急着写代码,磨刀不误砍柴工,下面说说我对上下机的认识.

    上机

    首先是上机的流程图


    然后是针对每个流程进行的分析和部分代码。如果对流程分析清楚,代码就好写了。

    1、卡号是否为空

    2、卡号是否存在(student_Info表)

    3、卡号的状态是否为”使用”(student_Info表)

    <strong><span style="font-size:18px;">'检查卡号是否能正常使用
        txtSQL = "select * from student_Info where cardno='" & Trim(txtcardno.Text) & "'"
        Set mrc = executesql(txtSQL, msgText)
        
        If mrc.EOF Then
            MsgBox "此卡尚未注册!", vbOKOnly + vbExclamation, "警告"
            txtcardno.Text = ""
            txtcardno.SetFocus
            mrc.Close
            Exit Sub
        Else
           status = Trim(mrc.Fields(10))
           If mrc.EOF = False And "未使用" = status Then
              MsgBox "该卡没有注册!", vbOKOnly + vbExclamation, "警告!"
              txtcardno.Text = ""
              txtcardno.SetFocus
              mrc.Close
              Exit Sub
               
           End If
        End If</span></strong>

    4、检查是否正在上机

    <span style="font-size:18px;"><strong> txtSQL = "select * from OnLine_Info where cardno='" & Trim(txtcardno.Text) & "'"
      Set mrcc = executesql(txtSQL, msgText</strong>)</span>
    5、没有上机,检查卡内余额是否小于最少上机金额(student_Info表)
    <strong><span style="font-size:18px;"> '如果卡号能用且没有上机,检查余额
          If Not mrc.Fields(7) > frmbasicctsding.txtlimitcash Then          '坚持是否余额是否大于最少金额
              MsgBox "余额不足,请充值!", vbOKOnly + vbExclamation, "警告"
              mrc.Close
              Exit Sub
          End If
    6、满足上述条件,就可以上机,显示主界面显示上机信息和登录人数
    '显示登录人数
      onflag = onflag + 1
      Label19.Caption = onflag
      '断开数据库连接
      mrc.Close
    7、将这条正在上机的记录添加到OnLine_Info表中

    8、将上机记录添加到Line_Info表中


    下机

    下机的流程图


    1、检查是否正在上机

    2、更新Line_Info表中的数据(更新下机日期和下机时间)   

    <strong><span style="font-size:18px;"> '判断卡号是否在上机
        txtSQL = "select * from OnLine_Info where cardno='" & Trim(txtcardno.Text) & "'"
        Set mrc = executesql(txtSQL, msgText)
        
        If mrc.EOF = True Then
            Label14.Caption = "该卡号还没上机!"
            mrc.Close
            Exit Sub</span></strong>

    3、删除OnLine_Info表中的数据

    4、计算消费的时间

    <strong><span style="font-size:24px;"> '计算上机消耗的时间
        txtoffdate.Text = Format(Date, "yyyy-mm-dd")
        txtofftime.Text = Format(Time, "hh:mm")
          
        Usetime = Abs(DateDiff("n", txtofftime, txtontime)) ’每天一结账,结账的时候强制用户下机
        txtconsumetime.Text = Usetime</span></strong>

    5、计算消费的金额

     '计算消费的金额
     '如果消费的时间小于最少时间,消费金额为1元
       If txtconsumetime.Text <= Leasttime Then
            txtconsume.Text = 1
            'txtcash.Text = mrc.Fields(7) - Trim(txtconsume.Text)
       ElseIf Usetime <= pretime Then
      '第一种情况 消费时间小于准备时间,消费金额为0
            Usecash = 0
            txtconsume.Text = Usecash
       Else
         '递增时间段消费的金钱,以半小时的费用为计算基础
          Unitcash = Format((Halfcash / 30) * Unittime, "0.0")
           
         '第二种情况 当消费时间小于最小上机时间 按一个递增时间段收费
          If Usetime <= Leasttime Then
             Usecash = Unitcash
             txtconsume.Text = Unitcash
          Else
            '第三种情况  最后求出的UnitNumber为递增时间段的个数
             Usetime = Usetime - pretime
             UnitNumber = Usetime Mod Unittime
               
             If UnitNumber = 0 Then
                 UnitNumber = Int(Usetime / Unittime)
             Else
                 UnitNumber = Int(Usetime / Unittime) + 1
             End If
            Usecash = Format(UnitNumber * Unitcash, "0.0")
            txtconsume.Text = Usecash
                                 
            End If
        End If
    计算现有金额:

    <strong>  <span style="font-size:18px;">  txtSQL = "select * from student_Info where cardno='" & txtcardno & "'"
        Set mrc = executesql(txtSQL, msgText)
          
        '获得原来的余额
        Totalcash = mrc.Fields(7)
        '计算消费后的余额
        Totalcash = Totalcash - Val(Trim(txtconsume.Text))
        '更新余额
        mrc.Fields(7).Value = Totalcash
        mrc.Update
        mrc.Close
        txtcash.Text = Totalcash</span></strong>
    6、将这些信息更新到主界面对应的文本框中,上机人数也要更新。

    7、更新基本信息表(student_Info表)

            上下机这里主要是逻辑上的思考,把思路理清以后就能做好。在机房收费系统中,不仅仅是上下机,结账,组合查询等等都体现了逻辑的重要性,对要实现的功能有个全局把握,再把它分解,这样一点点的进行,就可以把它做好。



  • 相关阅读:
    B/S架构
    RPC远程过程调用详解
    Ubuntu18.04安装MongoDB
    Python2.X SQLAlchemy @@tx_isolation警告
    Excel单元格内自动换行自动行高,打印预览出现内容缺失解决方案
    Winform应用的多语言设置
    单例模式创建窗口
    相似命名的字符串高效拼接
    利用dynamic动态创建对象
    设置全局快捷键
  • 原文地址:https://www.cnblogs.com/chenxiaochan/p/7237646.html
Copyright © 2020-2023  润新知