1. 程式人生 > >趙曉東-廊坊師範學院提高班十五期

趙曉東-廊坊師範學院提高班十五期

一、思路
結賬目的:為了給管理人員檢視,更加直觀。
含義:經過分析,我們可知道,這就是管理員看操作員一天的工作明細,即售卡,充值,退卡的情況。

1、 購卡:就是在student_info表總查詢沒有結賬的那些新註冊的學生卡號等資訊。

2、 充值:在recharge_info表中查詢未結賬的充值資訊。

3、 退卡:在cancelCard_info中查詢未結賬的退卡資訊。

4、 臨時使用者:在student_info表中查詢未結賬的,沒有退卡的臨時使用者。

5、 彙總:將前面所有的資訊彙總起來。用到了student_Info 、Recharge_Info 、cancelcard_Info 表。

6、 售卡張數=購卡選項卡的記錄總數

7、 退卡張數=退卡選項卡的記錄總數

8、 退卡金額=cancelcard_Info表中的金額進行累加

9、 總售卡數=售卡數-退卡數

10、 註冊和充值金額=student_Info 表中註冊時候的充值金額+Recharge_Info 表中的充值金額(註冊時的充值的錢和充值時充進去的錢其實都一樣)

11、 臨時收費=臨時收費選項卡記錄中的卡號上機所消費的錢的總和(Line_Info)(只是用來顯示)

12、應收金額=註冊和充值金額-退卡金額
二、程式碼:

Dim MsgText As String
Dim UserSQL As String
Dim StuSQL As String
Dim ReChargeSQL As String
Dim CancelCardSQL As String
Dim CheckDaySQL As String
Dim LineSQL As String
Dim mrcReCharge As ADODB.Recordset
Dim mrcCancelCard As ADODB.Recordset
Dim mrcCheckDay As ADODB.Recordset
Dim mrcLine As ADODB.Recordset
Dim mrcUser As ADODB.Recordset
Dim mrcStu As ADODB.Recordset
Dim Allcash1 As String '使用者記錄註冊和充值總金額
 


 Private Sub Form_Load()
 
    '窗體初始載入時,在下拉選單中載入userid(級別)
    UserSQL = "select * from User_Info where Level='操作員'"
    Set mrcUser = ExecuteSQL(UserSQL, MsgText)
      
    '在下拉選單中顯示所有的UserID
    Do While mrcUser.EOF = False
        comboUserID.AddItem mrcUser.Fields(0)    '操作員使用者名稱
        mrcUser.MoveNext
    Loop
    mrcUser.Close
'    Me.Left = (frmMDIForm1.Width - Me.Width) / 2
'    Me.Top = (frmMDIForm1.Height - Me.Height) / 2
End Sub

'顯示真實姓名
Private Sub comboUserID_Click()
    UserSQL = "select * from User_info where UserID='" & comboUserID.Text & "'"
    Set mrcUser = ExecuteSQL(UserSQL, MsgText)
    comboUserName.Text = Trim(mrcUser.Fields(3))    '顯示姓名
    mrcUser.Close
End Sub


Private Sub SSTab1_Click(PreviousTab As Integer)

Dim MsgText As String
Dim StuSQL As String
Dim ReChargeSQL As String
Dim CancelCardSQL As String
Dim mrcReCharge As ADODB.Recordset
Dim mrcCancelCard As ADODB.Recordset
Dim mrcStu As ADODB.Recordset
Dim Rcharge As Integer
Dim Tuicharge As Integer
Dim RchargeMoney As Integer
Dim TuichargeMoney As Integer

    '購卡
    If SSTab1.Caption = "購卡" Then
        MSFlexGrid1.Rows = 1
        MSFlexGrid1.Cols = 6
        StuSQL = "select * from student_Info where UserID='" & comboUserID.Text & "' and Ischeck='未結賬'"
        Set mrcStu = ExecuteSQL(StuSQL, MsgText)
        MSFlexGrid1.Rows = mrcStu.RecordCount + 1
    
        With MSFlexGrid1
            .Rows = 1
            .CellAlignment = 4      '居中
            .TextMatrix(0, 0) = "學號"  'studentid
            .TextMatrix(0, 1) = "卡號"  'cardid
            .TextMatrix(0, 2) = "日期"  'date
            .TextMatrix(0, 3) = "時間"  'time
            .TextMatrix(0, 4) = "使用狀態"
            .TextMatrix(0, 5) = "結賬情況"
        While mrcStu.EOF = False
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = Trim(mrcStu.Fields(1)) 'studentno
            .TextMatrix(.Rows - 1, 1) = Trim(mrcStu.Fields(0)) 'cardno
            .TextMatrix(.Rows - 1, 2) = Trim(mrcStu.Fields(12)) 'date
            .TextMatrix(.Rows - 1, 3) = Trim(mrcStu.Fields(13)) 'time
            .TextMatrix(.Rows - 1, 4) = Trim(mrcStu.Fields(10))
            .TextMatrix(.Rows - 1, 5) = Trim(mrcStu.Fields(11))
            mrcStu.MoveNext
        Wend
        End With
    End If
 
    '充值
    If SSTab1.Caption = "充值" Then
        MSFlexGrid2.Rows = 1
        MSFlexGrid2.Cols = 5
        ReChargeSQL = "select * from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未結賬" & "'"
        Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
        With MSFlexGrid2
            .CellAlignment = 5
            .TextMatrix(0, 0) = "卡號"
            .TextMatrix(0, 1) = "學號"
            .TextMatrix(0, 2) = "充值金額"
            .TextMatrix(0, 3) = "日期"
            .TextMatrix(0, 4) = "時間"
        Do While Not mrcReCharge.EOF
            .Rows = .Rows + 1
            .TextMatrix(.Rows - 1, 0) = mrcReCharge.Fields(2)
            .TextMatrix(.Rows - 1, 1) = mrcReCharge.Fields(1)
            .TextMatrix(.Rows - 1, 2) = mrcReCharge.Fields(3)
            .TextMatrix(.Rows - 1, 3) = mrcReCharge.Fields(4)
            .TextMatrix(.Rows - 1, 4) = mrcReCharge.Fields(5)
            mrcReCharge.MoveNext
        Loop
        End With
    End If
    
    '退卡
    '把所有資訊彙總到表格
    CancelCardSQL = "select * from CancelCard_Info where status='未結賬'and UserID='" & comboUserID.Text & "'"
    Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
    cancelcash = 0
    With MSFlexGrid3
        .Rows = 1
        .CellAlignment = 4      '居中
        .TextMatrix(0, 0) = "學號"  'studentid
        .TextMatrix(0, 1) = "卡號"  'cardid
        .TextMatrix(0, 2) = "日期"  'cash
        .TextMatrix(0, 3) = "時間"  'date
        .TextMatrix(0, 4) = "退卡金額"
        .TextMatrix(0, 5) = "結賬情況"
        
        While Not mrcCancelCard.EOF
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = Trim(mrcCancelCard.Fields(0))  'studentno
            .TextMatrix(.Rows - 1, 1) = Trim(mrcCancelCard.Fields(1))   'cardno
            .TextMatrix(.Rows - 1, 2) = Trim(mrcCancelCard.Fields(3))   'date
            .TextMatrix(.Rows - 1, 3) = Trim(mrcCancelCard.Fields(4))   'time
            .TextMatrix(.Rows - 1, 4) = Trim(mrcCancelCard.Fields(2))   'cancelcash
            .TextMatrix(.Rows - 1, 5) = Trim(mrcCancelCard.Fields(6))   'cancelcash
            cancelcash = cancelcash + mrcCancelCard.Fields(2)
            mrcCancelCard.MoveNext
        Wend
    End With
    
    '臨時使用者
    StuSQL = "select * from student_Info where status='使用' and UserID='" & comboUserID.Text & "'and type='臨時使用者'and Ischeck='未結賬'"
    Set mrcStu = ExecuteSQL(StuSQL, MsgText)
    TmpCash = 0
    With MSFlexGrid4
        .Rows = 1
        .CellAlignment = 4      '居中
        .TextMatrix(0, 0) = "學號"  'studentid
        .TextMatrix(0, 1) = "卡號"  'cardid
        .TextMatrix(0, 2) = "日期"  'date
        .TextMatrix(0, 3) = "時間"  'time
        .TextMatrix(0, 4) = "結賬情況"  'time
        While mrcStu.EOF = False
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = Trim(mrcStu.Fields(1))  'studentno
            .TextMatrix(.Rows - 1, 1) = Trim(mrcStu.Fields(0))   'cardno
            .TextMatrix(.Rows - 1, 2) = Trim(mrcStu.Fields(12))    'date
            .TextMatrix(.Rows - 1, 3) = Trim(mrcStu.Fields(13))   'time
            .TextMatrix(.Rows - 1, 4) = Trim(mrcStu.Fields(11))
            TmpCash = mrcStu.Fields(7)
            mrcStu.MoveNext
        Wend
    End With
    
    If MSFlexGrid4.Rows = 1 Then
        rechargecash = "0"
    Else
        ReChargeSQL = "select * from ReCharge_Info where status='未結賬' and UserID='" & comboUserID.Text & "'"
        Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
        Do While Not mrcReCharge.EOF
            rechargecash = rechargecash + mrcReCharge.Fields(3)
            mrcReCharge.MoveNext
        Loop
    End If
    
    '彙總
    If SSTab1.Caption = "彙總" Then
        '計算售卡張數
        StuSQL = "select * from student_info where UserID = '" & Trim(comboUserID.Text) & "'and ischeck = '" & "未結賬" & "'"
        Set mrcStu = ExecuteSQL(StuSQL, MsgText)
        txtSCard.Text = mrcStu.RecordCount
   
        '計算退卡張數
        CancelCardSQL = "select * from CancelCard_info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未結賬" & "'"
        Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
        txtBCard.Text = mrcCancelCard.RecordCount
        '總售卡數=售卡張數-退卡張數
        txtAllSCard = txtSCard - txtBCard
        
        '計算充值金額(不區分固定還是臨時使用者)
        ReChargeSQL = "select sum(addmoney) from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未結賬" & "'"
        Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)

        If IsNull(mrcReCharge.Fields(0)) Then       '無記錄
            txtChargeMoney.Text = "0"
        Else
            txtChargeMoney.Text = mrcReCharge.Fields(3)
        End If

        '計算退卡金額
        CancelCardSQL = "select sum(CancelCash) from CancelCard_Info where UserID = '" & Trim(comboUserID.Text) & "'and status = '" & "未結賬" & "'"
        Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)

        If IsNull(mrcCancelCard.Fields(0)) Then       '無記錄
            txtBMoney.Text = "0"
        Else
            txtBMoney.Text = mrcCancelCard.Fields(0)
        End If

        '計算臨時收費金額
        ReChargeSQL = "select sum(addmoney) from ReCharge_Info where UserID = '" & Trim(comboUserID.Text) & "'and status = '未使用'"
        Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)

        If IsNull(mrcReCharge.Fields(0)) Then       '無記錄
            txtTemporaryMoney.Text = "0"
        Else
            txtTemporaryMoney.Text = mrcReCharge.Fields(0)
        End If

        '計算應收金額
        txtAllCollectMoney.Text = Val(txtChargeMoney.Text) - Val(txtBMoney.Text)
        mrcStu.Close         '關閉釋放空間
        mrcReCharge.Close
        mrcCancelCard.Close
    End If
    
    '退出
    If SSTab1.Caption = "退出" Then
        Unload Me
    End If
End Sub

Private Sub cmdAmount_Click()

Dim MsgText As String
Dim StuSQL As String
Dim ReChargeSQL As String
Dim CancelCardSQL As String
Dim checkWeekSQL As String
Dim CheckDaySQL As String
Dim LineSQL As String
Dim mrcStu As ADODB.Recordset          '代表學生表(student_info)
Dim mrcReCharge As ADODB.Recordset     '代表充值表(recharge_info)
Dim mrcCancelCard As ADODB.Recordset   '代表退卡表(cancelcard_info)
Dim mrcCheckDay As ADODB.Recordset     '代表日結賬單(checkday_info)
Dim mrcLine As ADODB.Recordset         '代表line表(Line_info)
Dim remaincash As String
Dim rechargecash As String
Dim consumecash As String
Dim cancelcash As String
Dim allcash As String

    If comboUserID.Text = "" Then
        MsgBox "請選擇操作員後再結賬!", vbOKOnly + vbExclamation, "提示"
        Exit Sub
    End If

    '更新學生表
    StuSQL = "select * from student_info where UserID = '" & Trim(comboUserID.Text) & "'and ischeck = '" & "未結賬" & "'"
    Set mrcStu = ExecuteSQL(StuSQL, MsgText)
    Do While Not mrcStu.EOF
        mrcStu!ischeck = "結賬"
        mrcStu.Update
        mrcStu.MoveNext
    Loop
    mrcStu.Close

    '更新充值表
    ReChargeSQL = "select * from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未結賬" & "'"
    Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
    Do While Not mrcReCharge.EOF
        mrcReCharge!Status = "結賬"
        mrcReCharge.Update
        mrcReCharge.MoveNext
    Loop
        mrcReCharge.Close
    
    '更新退卡表
    CancelCardSQL = "select * from CancelCard_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未結賬" & "'"
        Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
        Do While Not mrcCancelCard.EOF
        mrcCancelCard!Status = "結賬"
        mrcCancelCard.Update
        mrcCancelCard.MoveNext
    Loop
    mrcCancelCard.Close

    '更新日結賬單表
    '計算上期充值卡餘額(remaincash)
    txtSQL = "select max(date) from checkWeek_Info"   'max(date)就是最近的一天
    Set mrc = ExecuteSQL(txtSQL, MsgText)
    If mrc.BOF Then
    Exit Sub
    MaxDate = mrc.Fields(0)
    
    CheckDaySQL = "select * from CheckDay_Info where date ='" & MaxDate & "'"
    Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
        If IsNull(mrcCheckDay.Fields(0)) Then
            remaincash = "0"
            Exit Sub
        Else
            remaincash = mrcCheckDay.Fields(0)
        End If
    End If
    
    '更新當天充值金額,充值金額是今天的值班的任意個操作員充值的金額,並且是已經結了賬的,如果今天充值了某些金額,但是沒有結賬,則在計算日結賬單時,不計入)
    ReChargeSQL = "select sum(addmoney) from ReCharge_info where status = '結賬' and date  = '" & Date & "'" '代表今天
    Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
    If IsNull(mrcReCharge.Fields(0)) = True Then
        rechargecash = "0"
    Else
        rechargecash = mrcReCharge.Fields(0)
    End If

    '從line表計算當日消費金額
    LineSQL = "select sum(consume) from Line_Info where offdate='" & Date & "'"
    Set mrcLine = ExecuteSQL(LineSQL, MsgText)
    If IsNull(mrcLine.Fields(0)) Then
        consumecash = "0"
    Else
        consumecash = mrcLine.Fields(0)
    End If

   '更新計算當天的退卡金額(cancelcash)這樣沒結賬的操作員就不會算到這裡面了
   CancelCardSQL = "select sum(cancelcash) from CancelCard_Info where date='" & Date & "'and status = '結賬'"
   Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
   If IsNull(mrcCancelCard.Fields(0)) Then
       cancelcash = "0"
   Else
       cancelcash = mrcCancelCard.Fields(0)
   End If

    '往表裡更新
    CheckDaySQL = "select * from CheckDay_info "
    Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
    
    '判斷是不是當天已經結過帳了
    CheckDaySQL = "select * from CheckDay_info where date='" & Date & "'"
    Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
    If mrcCheckDay.EOF = False Then
        mrcCheckDay!remaincash = Val(remaincash)
        mrcCheckDay!rechargecash = Val(rechargecash)
        mrcCheckDay!consumecash = Val(consumecash)
        mrcCheckDay!cancelcash = Val(cancelcash)
        mrcCheckDay!allcash = Val(remaincash) + Val(rechargecash) - Val(cancelcash) - Val(consumecash)
        mrcCheckDay!Date = Date
        mrcCheckDay.Update
        mrcCheckDay.Close
     Else
        mrcCheckDay.AddNew
        mrcCheckDay!remaincash = Val(remaincash)
        mrcCheckDay!rechargecash = Val(rechargecash)
        mrcCheckDay!consumecash = Val(consumecash)
        mrcCheckDay!cancelcash = Val(cancelcash)
        mrcCheckDay!allcash = Val(remaincash) + Val(rechargecash) - Val(cancelcash)
        mrcCheckDay!Date = Date
        mrcCheckDay.Update
        mrcCheckDay.Close
      End If
    
    '更新周結賬單(只需要刪除周結賬單表裡的東西,然後將日結賬單裡所有的內容都跟新進去)
    checkWeekSQL = "delete checkWeek_info"
    Set mrccheckWeek = ExecuteSQL(checkWeekSQL, MsgText)

    checkWeekSQL = "insert into checkWeek_info select * from CheckDay_info"
    Set mrccheckWeek = ExecuteSQL(checkWeekSQL, MsgText)

    '清空文字框顯示的資訊
    txtSCard.Text = "0"
    txtBCard.Text = "0"
    txtChargeMoney.Text = "0"
    txtTemporaryMoney.Text = "0"
    txtBMoney.Text = "0"
    txtAllSCard.Text = "0"
    txtAllCollectMoney.Text = "0"
    MsgBox "結賬成功!", 64, "提示"
   
End Sub