机房收费系统之结帐

      现在回想起来机房收费系统的结账部分也是很简单的,但是自己当时敲得时候似乎用了好久。我的理解是结账是管理员给操作员结的帐,对于管理员就不用给结了,这是自己的想法,当然每个人都可以有自己的想法。现在说一下大致思路。
      (1)实现两个combox的同步功能,实现选择了操作员用户名之后,显示操作员的真实姓名。   
Private Sub Form_Load()  
txtsql = "select * from User_Info where Level <>'一般用户'" '选择用户级别  
   Set mrc = ExecuteSQL(txtsql, msgtext)  
    Do While mrc.EOF = False  
    Combo1.AddItem Trim(mrc.Fields(0))    '通过循环进行添加  
    mrc.MoveNext  
    Loop  
    mrc.Close  
End Sub  
      combo1的单击事件:   
txtsql1 = "select * from User_Info where userID='" & Trim(Combo1.Text) & "'" '选择用户级别  
Set mrc1 = ExecuteSQL(txtsql1, msgtext1)  
Combo2.Text = Trim(mrc1.Fields(3))

      (2)购卡调用的是数据库student_Info,充值调用的是recharge_Info, 退卡调用的是cancel_Info, 临时用户调用的也是student_Info,需要注意的是这几个都需要满足status的状态是“未结账”,这些要select case语句实现各个选项卡的信息的变幻。
      (3) 汇总中的一些信息可以通过我们选项卡中的购卡,退卡的信息来确定。售卡张数是我们购卡中的行数,退卡张数是我们退卡中的行数,可以通过recordcount来实现。总售卡数=售卡数-退卡数。临时收费金额是临时用户充的钱。应收金额=注册充值金额-退卡金额。
        代码中income代表的是总共金额,outcome是退卡支出,tempmoney是临时用户充值金额。       
Private Sub SSTab1_Click(PreviousTab As Integer)
    Dim txtSQL As String
    Dim MsgText As String
    Dim mrc As ADODB.Recordset
    
    Select Case SSTab1.Tab
        Case 0
            txtSQL = "select * from student_Info where UserID = '" & Trim(comboUserId.Text) & "' and Ischeck = '未结账'"
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            SellCard = mrc.RecordCount  '售卡数
            
            With myFlexgrid1
                .Rows = 1
                .CellAlignment = 4
                .TextMatrix(0, 0) = "学号"
                .TextMatrix(0, 1) = "卡号"
                .TextMatrix(0, 2) = "购卡日期"
                .TextMatrix(0, 3) = "购卡时间"
                
                Do While Not mrc.EOF
                    .Rows = .Rows + 1
                    .CellAlignment = 4
                    .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1))
                    .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(0))
                    .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(12))
                    .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(13))
                    mrc.MoveNext
                Loop
                mrc.Close
            End With
        Case 1
            txtSQL = "select * from Recharge_Info where status = '未结账' and UserID = '" & Trim(comboUserId.Text) & "'"
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            
            With myFlexgrid2
                .Rows = 1
                .CellAlignment = 4
                .TextMatrix(0, 0) = "学号"
                .TextMatrix(0, 1) = "卡号"
                .TextMatrix(0, 2) = "充值金额"
                .TextMatrix(0, 3) = "充值日期"
                .TextMatrix(0, 4) = "充值时间"
                
                Do While Not mrc.EOF
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1))
                .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(2))
                .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(3))
                Income = Income + Val(mrc.Fields(3))
                .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(4))
                .TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(5))
                mrc.MoveNext
            Loop
            mrc.Close
            End With
        Case 2
            txtSQL = "select * from CancelCard_Info where status = '未结账' and UserID = '" & Trim(comboUserId.Text) & "'"
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            CancelCard = mrc.RecordCount  '退卡数
            
            With myFlexgrid3
                .Rows = 1
                .CellAlignment = 4
                .TextMatrix(0, 0) = "学号"
                .TextMatrix(0, 1) = "卡号"
                .TextMatrix(0, 2) = "退卡日期"
                .TextMatrix(0, 3) = "退卡时间"
                .TextMatrix(0, 4) = "退卡金额"
                
                Do While Not mrc.EOF
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(0))
                .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(1))
                .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(3))
                .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(4))
                .TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(2))
                OutCome = OutCome + Val(mrc.Fields(2))
                mrc.MoveNext
            Loop
            mrc.Close
            End With
        Case 3
            txtSQL = "select * from student_Info where type = '临时用户' and UserID = '" & Trim(comboUserId.Text) & "'"
            Set mrc = ExecuteSQL(txtSQL, MsgText)
            
            With myFlexgrid4
                .Rows = 1
                .CellAlignment = 4
                .TextMatrix(0, 0) = "学号"
                .TextMatrix(0, 1) = "卡号"
                .TextMatrix(0, 2) = "日期"
                .TextMatrix(0, 3) = "时间"
                
                Do While Not mrc.EOF
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1))
                .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(0))
                .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(12))
                .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(13))
                tempmoney = tempmoney + Val(mrc.Fields(7))
                mrc.MoveNext
            Loop
            mrc.Close
            End With
        Case 4
            txtSellnumber.Text = SellCard
            txtReturnnumber.Text = CancelCard
            txtRecharge.Text = Income
            txtReturnMoney.Text = OutCome
            txtTotalnumber.Text = Val(txtSellnumber.Text) - Val(txtReturnnumber.Text)
            txtShouldmoney = Val(txtRecharge.Text) - Val(txtReturnMoney.Text)
            txtTempmoney.Text = tempmoney
        Case 5
            Unload Me
    End Select   
End Sub
       结账感觉是整个系统最难理解的部分, 现在理解了,但是不知道为什么冥冥之中感觉没有这么简单一样,如果我理解的有什么问题还望大家指正。                                                               

你可能感兴趣的:(sql,数据库,vb)