天天看点

机房收费系统之结账

总体来说这个窗体很难,就是要调用的东西有点多但是只要把每一个都弄清楚,就好弄很多了。

这个是加载的代码,实现的是查询操作员是谁,但是有个思考问题那么怎么能让我点的是谁下面的text 里面就是谁呢

Private Sub Form_Load()

    Dim txtSQL As String
        Dim Msgtext As String
        Dim mrc As ADODB.Recordset       '查询操作员
        Dim mrc1 As ADODB.Recordset
        txtSQL = "select * from User_info where Level='操作员'"
        Set mrc = ExecuteSQL(txtSQL, Msgtext)
            Do While mrc.EOF = False
                comboUserID.AddItem mrc.Fields(0)
                mrc.MoveNext
            Loop
            mrc.Close
  
End Sub
           

代码写在哪里很重要,你想的是 点击选择这个操作员,然后就能出现对应的操作员姓名,下面的代码就可以实现了。

Private Sub comboUserID_Click()
         Dim txtSQL As String
         Dim Msgtext As String
         Dim mrc1 As ADODB.Recordset
       txtSQL = "select * from user_info where userID='" & comboUserID.Text & "'" '用ID获取操作员姓名
              Set mrc1 = ExecuteSQL(txtSQL, Msgtext)
              
              Text1.Text = mrc1.Fields(3)
              mrc1.Close
            
End Sub
           

最后就是重头戏,关于SSTab里面的东西加载的数据,怎么弄呢

别慌也别急,满满分析,有购卡,充值,退卡,还有临时用户,就这4个,我觉得退出有点多余,我就不要了。

下面的代码要仔细的看哟。

Private Sub SSTab1_Click(PreviousTab As Integer)
    MSFGBuyCard.Clear
    MSFGBuyCard.Rows = 1
    
      Dim txtSQL As String
      Dim Msgtext As String
      Dim mrcGK As ADODB.Recordset     '购卡
      Dim mrcCZ As ADODB.Recordset     '充值
      Dim mrcTK As ADODB.Recordset     '退卡
      Dim mrcLSYH As ADODB.Recordset   '临时用户
    '购卡
    With MSFGBuyCard
        txtSQL = "select * from student_info where userID='" & comboUserID.Text & "'"
        Set mrcGK = ExecuteSQL(txtSQL, Msgtext)
         .Rows = 1
        .CellAlignment = 4
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "日期"
        .TextMatrix(0, 3) = "时间"
        .TextMatrix(0, 4) = "金额"
        Do While mrcGK.EOF = False
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrcGK.Fields(0))
                .TextMatrix(.Rows - 1, 1) = Trim(mrcGK!studentno)
                .TextMatrix(.Rows - 1, 2) = Trim(mrcGK!Date)
                .TextMatrix(.Rows - 1, 3) = Trim(mrcGK!Time)
                .TextMatrix(.Rows - 1, 4) = Trim(mrcGK!cash)
            mrcGK.MoveNext
            Loop
    End With
        
    '充值
     With MSFGRecharege
       .Rows = 1
        .CellAlignment = 4
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "充值金额"
        .TextMatrix(0, 3) = "日期"
        .TextMatrix(0, 4) = "时间"
        .TextMatrix(0, 5) = "方式"
         txtSQL = "select * from recharge_info where userID='" & comboUserID.Text & "'"
         Set mrcCZ = ExecuteSQL(txtSQL, Msgtext)
            Do While mrcCZ.EOF = False
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrcCZ!cardno)
                .TextMatrix(.Rows - 1, 1) = Trim(mrcCZ!studentno)
                .TextMatrix(.Rows - 1, 2) = Trim(mrcCZ!addmoney)
                .TextMatrix(.Rows - 1, 3) = Trim(mrcCZ!Date)
                .TextMatrix(.Rows - 1, 4) = Trim(mrcCZ!Time)
                .TextMatrix(.Rows - 1, 5) = Trim(mrcCZ!Status)
            mrcCZ.MoveNext
            Loop
         End With
        
     '退卡
         
  With MSFGCancelCard
  .Rows = 1
        .CellAlignment = 4
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "日期"
        .TextMatrix(0, 3) = "时间"
        .TextMatrix(0, 4) = "退卡金额"
         txtSQL = "select * from cancelcard_info where userID='" & comboUserID.Text & "'"
         Set mrcTK = ExecuteSQL(txtSQL, Msgtext)
            Do While mrcTK.EOF = False
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrcTK!cardno)
                .TextMatrix(.Rows - 1, 1) = Trim(mrcTK!studentno)
                .TextMatrix(.Rows - 1, 2) = Trim(mrcTK!Date)
                .TextMatrix(.Rows - 1, 3) = Trim(mrcTK!Time)
                .TextMatrix(.Rows - 1, 4) = Trim(mrcTK!cancelcash)
            mrcTK.MoveNext
            Loop
    End With
      '临时用户
      With MSFlexGrid4
       .Rows = 1
        .CellAlignment = 4
        .TextMatrix(0, 0) = "学号"
        .TextMatrix(0, 1) = "卡号"
        .TextMatrix(0, 2) = "日期"
        .TextMatrix(0, 3) = "时间"
         txtSQL = "select * from student_info where userID='" & comboUserID.Text & "'and type='临时用户'"
         Set mrcLSYH = ExecuteSQL(txtSQL, Msgtext)
            Do While mrcLSYH.EOF = False
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrcLSYH!cardno)
                .TextMatrix(.Rows - 1, 1) = Trim(mrcLSYH!studentno)
                .TextMatrix(.Rows - 1, 2) = Trim(mrcLSYH!Date)
                .TextMatrix(.Rows - 1, 3) = Trim(mrcLSYH!Time)
            mrcLSYH.MoveNext
            Loop
         End With
      
End Sub
           

最后就是结账了,汇总里面。也是很简单,把对应的内容查询出来,然后填到对应的Text里面,就OK了

我的命名有点low比,凑活着看一下吧,肯定可以看得懂,哈哈

Private Sub Cmdover_Click()
        Dim txtSQL As String
        Dim Msgtext As String
        Dim mrc As ADODB.Recordset    '售卡
        Dim mrc1 As ADODB.Recordset    '退卡金额
        Dim mrc2 As ADODB.Recordset   '退卡张数
        Dim mrc3 As ADODB.Recordset   '充值金额
        Dim mrc4 As ADODB.Recordset   '临时金额
        
        
        '售卡数量
        txtSQL = "select * from student_info where userID='" & Trim(comboUserID.Text) & "'"
        Set mrc = ExecuteSQL(txtSQL, Msgtext)
        
        If mrc.RecordCount = 0 Then
            TxtSK.Text = "0"
        Else
            TxtSK.Text = mrc.RecordCount
        End If
        
        '退卡金额
        
        txtSQL = "select sum(cancelCash) from cancelCard_info where userID='" & Trim(comboUserID.Text) & "'"
         Set mrc1 = ExecuteSQL(txtSQL, Msgtext)
        If IsNull(Trim(mrc1.Fields(0))) Then
                TxtTKJE.Text = "0"
        Else
                TxtTKJE.Text = Val(mrc1.Fields(0))
        End If
        
        '退卡张数
        txtSQL = "select * from cancelcard_info where UserID='" & Trim(comboUserID.Text) & "'"
            Set mrc2 = ExecuteSQL(txtSQL, Msgtext)
        If mrc2.RecordCount = 0 Then
            TxtTK.Text = "0"
        Else
            TxtTK.Text = mrc2.RecordCount
        End If
 
        
        '总售卡数    = 售卡张数-退卡张数
        
        TxtZSKS.Text = Val(TxtSK.Text) - Val(TxtTK.Text)
        
        '充值金额
        txtSQL = "select sum(addmoney) from recharge_info where userID='" & Trim(comboUserID.Text) & "'"
        Set mrc3 = ExecuteSQL(txtSQL, Msgtext)
        
        If IsNull(Trim(mrc3.Fields(0))) Then
            TxtCZ.Text = "0"
        Else
            TxtCZ.Text = Val(mrc3.Fields(0))
        End If
        
        '应收金额  =充值金额-退卡金额
        
        TxtXJ.Text = Val(TxtCZ.Text) - Val(TxtTKJE.Text)
        
       '临时金额
       
        txtSQL = "select sum(cash) from student_info where UserID='" & Trim(comboUserID.Text) & "'and type='" & "临时用户" & "'"
        Set mrc4 = ExecuteSQL(txtSQL, Msgtext)
        If IsNull(Trim(mrc4.Fields(0))) Then
            TxtLS.Text = "0"
        Else
        TxtLS.Text = Val(mrc4.Fields(0))
        End If
        
        
End Sub
           

有什么问题,欢迎下面留言。

继续阅读