前言:
一遍遍的说理清逻辑是多么的重要,刚开始的时候毫无头绪更不想开始,画出流程图梳理清晰自己的思路,上下机并没有想象中的那么难,现在就总结下上下机部分;
内容:
- 上机:整个上机过程总的来说就是查询数据库,进行条件限制判断,更新数据表,就过程的思路有以下流程图;
- 下机:下机相对而言就复杂了点,关于消费时间的计算判断,和消费金额的计算;
1、 时间转换
txtTime1 = Trim(DateDiff("n", Trim(txtOnTime.Text), Trim(Time)))
txtdate = DateDiff("n", txtOnDate.Text, Date)
txtTime.Text = Int(txtTime1) + Int(txtdate)
2、消费时间计算
- 没有达到准备时间,不收费
If Val(txtTime.Text) < PrepareTime Then
MsgBox "没有达到上机准备时间,不收取费用!", 48, "提示"
txtTime = 0
txtUsedcash.Text = 0
Exit Sub
End If
- 达到准备时间,进行消费时间判断
If (Val(txtTime.Text) - Val(leastTime.Text)) < PrepareTime.Text Then
txtTime1 = 0
txtTime.Text = Val(time1) '更新消费时间
txtUsedcash.Text = 0
Else
'上机时间
txtTime1 = Val(txtTime.Text) - Val(leastTime.Text) - Val(PrepareTime.Text)
txtTime.Text = Val(txtTime1) '更新消费时间
mrc.Update
mrc.Close
End If
3、消费金额计算
If Val(txtTime.Text) > PrepareTime Then
Select Case Trim(txtType.Text)
Case "固定用户"
money = Round(Val(txtTime.Text) / unitTime * Rate)
If money > 1# Then '消费金额小于1的时候0不显示
txtUsedcash.Text = Str(money)
Else
txtUsedcash.Text = "0" & Str(money)
End If
txtRemaincash.Text = mrc.Fields(7)
mrc.Fields(7) = Val(txtRemaincash.Text) - money
txtRemaincash.Text = mrc.Fields(7)
mrc.Update
Case "临时用户"
money = Round(Val(txtTime.Text) / unitTime * temRate, 2)
If money > 1# Then
txtUsedcash.Text = Str(money)
Else
txtUsedcash.Text = "0" & Str(money)
End If
txtRemaincash.Text = mrc.Fields(7)
mrc.Fields(7) = Val(txtRemaincash.Text) - money
txtRemaincash.Text = mrc.Fields(7)
mrc.Update
mrc.Close
End Select
End If