您的位置:首页 > 其它

机房收费系统令我头疼的收费问题

2012-10-11 09:03 232 查看
转眼间又到周日了,一周的生活很快结束了,回想自己一周的经历,主要有以下几个:

1、 每天的两个小时英语

2、 每天三或者四个番茄时间自考书

3、 每天上下的时间学生收费系统

一天之后总共19个番茄,出去英语四个番茄、自考四个剩下的10个番茄都给力机房收费系统,这周对于收费系统可谓是呕心沥血啊。在这机房收费系统中对于上机下机中的收费问题可是费了好大的周折才弄清楚,写完代码。

对于收费问题,当我们刷卡上机时,系统显示卡号,学生信息、刷卡时间以及卡的余额(此处需要使用表(student_Info)中该卡的余额),然后可以立刻将主窗体中得到的上机信息更新到数据表(Online_Info)中。这都没有问题,上机完成,接下来就是下机了。

此时考虑问题

上机要求:

消费/半小时

递增时间/m

至少上机时间/m

准备时间/m

最少金额/RMB

固定用户

10

20

10

2

5

临时用户

15

看上去是听少,就几点。但是细细想起来还是真够麻烦的。这个过程中用到的数据库有student_Info、Online_Info、Line_Info.

从数据表online_Info中获取上机日期(txtoffdate)以及上机日期(txtofftime),然后传到主窗体的上机日期(txtondate)上机时间(txtontime)在计算上机时间(time)的时候就应该考虑上机的要求了。

上机时间(time)=上机时间(time)-准备时间(time)

上机时间太短,不能让改卡下机,或者有信息提示。

此时应该考虑上机计算的时间(time)和0的比较如果小于0则消费金额为0,剩余金额是原来金额(这个金额是student_Info中的cash这个取值之后然后更新)

如果上机计算的时间(time)和0的比较如果大于0,剩余金额就应该按照上机要就计算消费了。

1................固定用户下:(上机时间/30)*消费。


1.1................当上机时间不足半小时:


1.1.1................不足半小时的情况下而且消费时间大于递增时间,消费金额为半小时费用。


1.1.2................不足半小时的情况下而且消费时间也小于半小时,金额为0。


1.2................当上机时间超过半小时此时还得考虑余数(加入上机时间为50分钟,每半小时收费固定金额那么省下的20分钟该如何收取,社该20分钟为余数)问题,


1.2.1................如果余数大于递增时间。


1.2.2................如果余数小于递增时间。

2................临时用户下:(上机时间/60)*消费

此时考虑的应该和固定用户一样就不重复写了。

写完之后总有种不真实的感觉,是不是我想得有些复杂了,还是思路正确,代码实现的过程中走了弯路。

下面是代码实现。

'获取student_Info表中的cash

txtslq = "select * from student_Info where cardno='" & Trim(txtcardNo.Text) & "'" & "and status='" & "使用" & "'"
    Set Mrc = ExecuteSQL(txtSQL, MsgText)
    txtcash.Text = Mrc!cash
    Mrc.Close

'online_Info 数据表中的数据信息,同步到文本框中去

txtSQLon = "select * from online_info where cardno='" & Trim(txtcardNo.Text) & "'"
    Set Mrcon = ExecuteSQL(txtSQLon, MsgText)
    txtcardNo.Text = Mrcon!cardno
    txtType.Text = Mrcon!cardtype
    txtStudentNo.Text = Mrcon!studentNo
    txtStudentname.Text = Mrcon!studentname
    txtDepartment.Text = Mrcon!department
    txtSex.Text = Mrcon!sex
    txtOnDate.Text = Mrcon!ondate
    txtOnTime.Text = Mrcon!ontime
    txtOffDate.Text = Date
    txtOffTime.Text = Hour(Time) & ":" & Minute(Time)
    Mrcon.Close

'计算消费时间(刷卡下机时间-准备时间-开始刷卡上机时间)

'准备时间在Basic_Info 表中获得

txtsqlB = "select * from basicdata_Info "
                Set MrcB = ExecuteSQL(txtsqlB, MsgText)
                    Dim Rate
                    Dim tmpRate
                    Dim preparetime
                    Dim unitTime
                    Dim leasttime
                    Rate = MrcB!Rate
                    tmpRate = MrcB!tmpRate
                    unitTime = MrcB!unitTime
                    preparetime = MrcB!preparetime
                    leasttime = MrcB!leasttime
                    
                MrcB.Close

'计算消费时间

txtconsumeTime.Text = DateDiff("n", CDate(txtOnDate.Text), CDate(txtOffDate.Text))
                    txtconsumeTime.Text = txtconsumeTime.Text + DateDiff("n", CDate(txtOnTime.Text), CDate(txtOffTime.Text))
                    txtconsumeTime.Text = txtconsumeTime.Text - preparetime
                    If txtconsumeTime.Text < 0 Then
                        txtconsumeTime.Text = 0
                        txtconsume.Text = 0
                    Else
                        If txtconsumeTime.Text - leasttime < 0 Then
                            MsgBox "对不起您的上机时间太短不允许下机", , "提示"
                            Exit Sub
                        Else

’有消费时间,计算消费金额

’先要看改用户是不是固定的或者是临时用户

If Trim(txtType.Text) = "固定用户" Then
                                txtconsume.Text = Int(txtconsumeTime.Text / 30) * Val(Rate)
                                If Val(((Val(txtconsumeTime.Text) + 30) Mod 30) * 60) > Val(Trim(unitTime)) Then
                                    txtconsume.Text = Val(Trim(txtconsume.Text)) + Val(Trim(Rate))
                                End If
                            Else
                                txtconsume.Text = Int(txtconsumeTime.Text / 60) * Val(tmpRate)
                                  If Val((txtconsume.Text Mod 60) * 60) > Val(Trim(unitTime)) Then
                                    txtconsume.Text = txtconsume.Text + Trim(tmpRate)
                                End If
                            End If
                        End If
                    End If
                    txtcash.Text = txtcash.Text - txtconsume.Text


’删除online_Info 中该学生的上机记录

txtSQLon = "select * from online_Info where cardno='" & Trim(txtcardNo.Text) & "'"
    Set Mrcon = ExecuteSQL(txtSQLon, MsgText)
    Mrcon.Delete
    Mrcon.Close

‘所有该学生的信息都显示在主窗体的各个文本框中,然后添加到line_Info中

txtSQL = "select * from line_Info "
        Set Mrc = ExecuteSQL(txtSQL, MsgText)
        Mrc.AddNew
        
        Mrc!cardno = Trim(txtcardNo.Text)
        Mrc!studentNo = Trim(txtStudentNo.Text)
        Mrc!studentname = Trim(txtStudentname.Text)
        Mrc!department = Trim(txtDepartment.Text)
        Mrc!sex = Trim(txtSex.Text)
        Mrc!ondate = Trim(txtOnDate.Text)
        Mrc!ontime = Trim(txtOnTime.Text)
        Mrc!offDate = Trim(txtOffDate.Text)
        Mrc!offTime = Trim(txtOffTime.Text)
        Mrc!consumetime = Trim(txtconsumeTime.Text)
        Mrc!consume = Trim(txtconsume.Text)
        Mrc!cash = Trim(txtcash.Text)
        Mrc!Status = "正常下机"
        Mrc!computer = Trim(VBA.Environ("computername"))
    Mrc.Update
    Mrc.Close

’更新student_info表中cash数据

txtSQL = "select * from student_Info where cardno='" & Trim(txtcardNo.Text) & "'" & "and status='" & "ʹÓÃ" & "'"
    Set Mrc = ExecuteSQL(txtSQL, MsgText)
    Mrc!cash = txtcash.Text
    Mrc.Update
    Mrc.Close
    MsgBox "下机成功,欢迎下次光临", , "提示"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: