First time off the machine room

Compared with the computer room, the off-machine involves more tables, and the data update involved is more complicated. It requires multiple visits to the database to add, delete, modify, and check, so the flowchart is particularly important here. I’m not off the computer in one day. Finished, with the flow chart, I have a good connection to the idea of ​​writing the code before.

I personally think that the difficulty of getting off the computer is that there are too many data, the corresponding relationship is difficult to clarify, and it is easy to confuse. My own solution is to display all the information on the page first, whether it is the length of time or the amount of the computer, first Calculate the statistics, and then consider the interaction with the database after it is displayed on the interface. The advantage of this is that it is not easy to make mistakes in the data.

im mrca As ADODB.Recordset            '用来存储OnLine_info 的sql语句
Dim txtSQLa As String               '用来接收返回的结果
        txtSQLa = "exec proc_OnLine_info @cardno = '" & txtCardName.Text & "'"        '连接Online表判断是否已经上机
        Set mrca = ExecuteSQL(txtSQLa, MsgText)
        If mrca.EOF Then
            MsgBox "卡号未上机或不存在", vbOKCancel + vbExclamation, "警告"
            Exit Sub
        Else
            txtCardName.Text = mrca.Fields(0)
            txtType.Text = mrca.Fields(1)
            txtSID.Text = mrca.Fields(2)
            txtName.Text = mrca.Fields(3)
            txtDepartment.Text = mrca.Fields(4)
            ComboSex.Text = mrca.Fields(5)
            txtUpDate.Text = Trim(mrca.Fields(6))
            txtUpTime.Text = mrca.Fields(7)
            txtComputername.Text = mrca.Fields(8)
            txtDownDate.Text = Date  '下机日期,也就是现在的当前日期
            txtDownTime.Text = Time '下机时间
            
            
            consumtime = DateDiff("n", mrca.Fields(9), Now) '计算消费时间,这里比较的数据库中的日期和时间在一起
            txtConTime.Text = Val(consumtime)
        End If
        
Dim mrcb As ADODB.Recordset            '用来存储student_info 的sql语句
Dim txtSQLb As String               '用来接收返回的结果
Dim usertype As String          '用来记录用户的类型
Dim Cash As String      '用来记录余额

        txtSQLb = "exec proc_sutdentinfo_select @cardno = '" & txtCardName.Text & "'"
        Set mrcb = ExecuteSQL(txtSQLb, MsgText)
            usertype = Trim(mrcb.Fields(10))                '将用户类型记录
            Cash = Trim(mrcb.Fields(9))             '记录消费前账户余额
            
            
            
Dim mrcc As ADODB.Recordset            '用来存储BasicData_Info 的sql语句
Dim txtSQLc As String               '用来接收BasicData_Info返回的结果
Dim Rate As String          '记录固定用户每小时费用
Dim tmpRate As String      '记录临时用户每小时费用
Dim listTime As String   '记录最小时间

    txtSQLc = "exec proc_BasicData_select"
    Set mrcc = ExecuteSQL(txtSQLc, MsgText)             '将设定的基本数据赋值给变量
        Rate = mrcc.Fields(0)
        tmpRate = mrcc.Fields(1)
        listTime = mrcc.Fields(3)
    mrcc.Close
    If txtConTime.Text > listTime Then              '如果上机时间大于设置的最小时间
        If usertype = "固定用户" Then
            txtConMoney.Text = Int((Rate * txtConTime.Text) / 60 + 1)
        Else
            txtConMoney.Text = Int((tmpRate * txtConTime.Text) / 60 + 1)
        End If
        txtBalance.Text = Cash - txtConMoney.Text            '计算下机后的余额
    Else
        txtConMoney.Text = 0
        txtBalance.Text = Cash
    End If
        mrcb.Fields(9) = Trim(Cash)           '将余额更新到学生表
        mrcb.Update
        mrcb.Close
        
Dim mrcd As ADODB.Recordset            '用来更新line_info表存储记录
Dim txtSQLd As String               '用来接收返回的结果
Dim onlineMsgText As String     '接受信息
    txtSQLd = "delete OnLine_Info where cardno = '" & txtCardName.Text & "'"        '上机成功后将上机表的信息删除
    Set mrcd = ExecuteSQL(txtSQLd, onlineMsgText)
  
Dim mrc2 As ADODB.Recordset            '用来更新line_info表存储记录
Dim txtSQL2 As String               '用来接收返回的结果

    txtSQL2 = "exec proc_deplane @cardno = '" & txtCardName.Text & "'"        '使用查询将所需要更新字段进行更新
    Set mrc2 = ExecuteSQL(txtSQL2, MsgText)
        mrc2.Fields(0) = Date
        mrc2.Fields(1) = Time
        mrc2.Fields(2) = Trim(txtConTime.Text)
        mrc2.Fields(3) = Trim(txtConMoney.Text)
        mrc2.Fields(4) = "正常下机"
        mrc2.Update
        mrc2.Close
    MsgBox "下机成功", vbOKCancel + vbExclamation, "提示"
    Label9.Caption = Label9.Caption - 1

Special attention should be paid to the following points:

1: When updating the log on the computer, how to write the SQL statement is very important. You cannot simply use the student ID as a condition, because an account will involve multiple log on and off computers. 2: Operation time and price calculation. Don't make decimals, start from the actual situation and see how to calculate it. 3: Pay attention to the corresponding relationship when using stored procedures and don't mess up.

 

 

 

Guess you like

Origin blog.csdn.net/hlzdbk/article/details/113882959