机房收费系统之周结账单

         在做系统的过程中,应该说报表这块儿,尤其是周结账和日结账这块是最繁琐的了,我用了3、4天吧,拿下了这块儿。

         首先看一下这个周结账单

        

           这个窗体的控件我也找了很长时间才找到,显示时间的是DTpicker,日历是monthview。

          首先实例化报表       

     Dim WithEvents report As grproLibCtl.GridppReport '实例化报表

         在报表中初始化日期、用户名

      

Private Sub report_initialize() '初始化数据
    report.ParameterByName("username").AsString = username
    report.ParameterByName("datestart").AsString = Format(startDate.Value, "yyyy-mm-dd")
    report.ParameterByName("dateend").AsString = Format(endDate.Value, "yyyy-mm-dd")

End Sub

 

          下面看一下我的周结账单是如何计算的

Private Sub cmdUpdate_Click()
    Dim strMsg As String
    Dim strSqlRe As String
    Dim mrcRe As ADODB.Recordset
    Dim strSqlCan As String
    Dim mrcCan As ADODB.Recordset
    Dim strSqlWeek As String
    Dim mrcWeek  As ADODB.Recordset
    Dim strSQLL As String
    Dim mrcL As ADODB.Recordset
    Dim Toconsume As Long
    Dim consume As Long
    Dim dateIndex As Date
    Dim datestart As Date
    Dim dateend As Date
    Dim Toremain As Integer
    Dim Torecharge As Integer
    Dim Tocancel As Integer
    Dim remain As Integer
    Dim charge As Integer
    Dim cancel As Integer
    Dim all As Long
    'GRDisplayViewer1.Refresh
    
    datestart = Format(startDate.Value, "yyyy-mm-dd")
    dateend = Format(endDate.Value, "yyyy-mm-dd")
    
                 '删除周表中的数据
    strSqlWeek = "delete from checkweek_info "
    Set mrcWeek = executeSQL(strSqlWeek, strMsg)

    For dateIndex = datestart To dateend
        remain = 0
        Recharge = 0
        consume = 0
        cancel = 0
        all = 0
        '上期充值卡余额计算
        If dateIndex = datestart Then
            remain = 0
            Call Form_Load
        Else
        
            '先算总的recharge
            strSqlRe = "select sum(addmoney) as rechargecash from recharge_info where date<='" & Format(dateIndex - 1, "yyyy-mm-dd") & "'"
            Set mrcRe = executeSQL(strSqlRe, strMsg)
            If Not IsNull(mrcRe!rechargecash) Then
                Recharge = mrcRe!rechargecash
                mrcRe.Close
            End If
        
            '总的cancelcard
            strSqlCan = "select sum(cancelcash) as cancel from cancelcard_info where date<='" & Format(dateIndex - 1, "yyyy-mm-dd") & "'"
            Set mrcCan = executeSQL(strSqlCan, strMsg)
            If Not IsNull(mrcCan!cancel) Then
               cancel = mrcCan!cancel
               mrcCan.Close
            End If
            '总的consume
            strSQLL = "select sum(consume) as consumecash from line_info where offdate<= '" & Format(dateIndex - 1, "yyyy-mm-dd") & "'"
            Set mrcL = executeSQL(strSQLL, strMsg)
            If Not IsNull(mrcL!consumeCash) Then
                consume = mrcL!consumeCash
                mrcL.Close
            End If
            '上期充值卡余额
            remain = Recharge - consume - cancel
            '本期充值金额
            strSqlRe = "select sum(addmoney) as rechargecash from recharge_info where date='" & Format(dateIndex, "yyyy-mm-dd") & "'"
            Set mrcRe = executeSQL(strSqlRe, strMsg)
            If Not IsNull(mrcRe!rechargecash) Then
                Torecharge = mrcRe!rechargecash
                mrcRe.Close
            End If
            '本期退卡
            strSqlCan = "select sum(cancelcash) as cancel from cancelcard_info where date='" & Format(dateIndex, "yyyy-mm-dd") & "'"
            Set mrcCan = executeSQL(strSqlCan, strMsg)
            If Not IsNull(mrcCan!cancel) Then
                Tocancel = mrcCan!cancel
                mrcCan.Close
            End If
            '本期消费
            strSQLL = "select sum(consume) as consumecash from line_info where offdate= '" & Format(dateIndex, "yyyy-mm-dd") & "'"
            Set mrcL = executeSQL(strSQLL, strMsg)
            If Not IsNull(mrcL!consumeCash) Then
                Toconsume = mrcL!consumeCash
                mrcL.Close
            End If
            '本期充值卡余额
            all = remain + Torecharge - Toconsume - Tocancel
            strSqlWeek = "select * from checkweek_info "
            Set mrcWeek = executeSQL(strSqlWeek, strMsg)
            mrcWeek.AddNew
            mrcWeek.Fields("remaincash") = remain
            mrcWeek.Fields("rechargecash") = Torecharge
            mrcWeek.Fields("consumecash") = Toconsume
            mrcWeek.Fields("cancelcash") = Tocancel
            mrcWeek.Fields("allcash") = all
            mrcWeek.Fields("date") = Format(dateIndex, "yyyy-mm-dd")
            mrcWeek.Update
            mrcWeek.Close
        End If
    Next
    Call Form_Load
    End Sub

Private Sub Form_Load()
    Dim strSQL As String
    Dim strMsg As String
    Dim mrc As ADODB.Recordset
    Dim strSqlRe As String
    Dim mrcRe As ADODB.Recordset
    Dim strSqlCan As String
    Dim mrcCan As ADODB.Recordset
    Dim strSqlWeek As String
    Dim mrcWeek  As ADODB.Recordset
    Dim strSQLL As String
    Dim mrcL As ADODB.Recordset
    Dim Toconsume As Long
    Dim consume As Long
    Dim remain As Integer
    Dim Recharge As Integer
    Dim cancel As Integer
    Dim all As Integer
    Dim Toremain As Integer
    Dim Torecharge As Integer
    Dim Tocancel As Integer
    
    MonthViewStart.Visible = False
    MonthViewEnd.Visible = False

    strSQL = "select * from checkweek_info where date between '" & Format(startDate.Value, "yyyy-mm-dd") & "' and '" & Format(endDate.Value, "yyyy-mm-dd") & "'"
    Set mrc = executeSQL(strSQL, strMsg)
    strSQL = strSQL & "order by date"
    Set report = New grproLibCtl.GridppReport
    GRDisplayViewer1.Stop
    report.LoadFromFile (App.Path & "\周结账单.grf")
    

    report.DetailGrid.Recordset.ConnectionString = connectstring()
    report.DetailGrid.Recordset.QuerySQL = strSQL
    GRDisplayViewer1.report = report
    GRDisplayViewer1.Start
    
    strSqlRe = "select sum(addmoney) as rechargecash from recharge_info where date<='" & Format(startDate.Value - 1, "yyyy-mm-dd") & "'"
    Set mrcRe = executeSQL(strSqlRe, strMsg)
    If Not IsNull(mrcRe!rechargecash) Then
        Recharge = mrcRe!rechargecash
        mrcRe.Close
    End If

    '总的cancelcard
    strSqlCan = "select sum(cancelcash) as cancel from cancelcard_info where date<='" & Format(startDate.Value - 1, "yyyy-mm-dd") & "'"
    Set mrcCan = executeSQL(strSqlCan, strMsg)
    If Not IsNull(mrcCan!cancel) Then
       cancel = mrcCan!cancel
       mrcCan.Close
    End If
    '总的consume
    strSQLL = "select sum(consume) as consumecash from line_info where offdate<= '" & Format(startDate.Value - 1, "yyyy-mm-dd") & "'"
    Set mrcL = executeSQL(strSQLL, strMsg)
    If Not IsNull(mrcL!consumeCash) Then
        consume = mrcL!consumeCash
        mrcL.Close
    End If
    '上期充值卡余额
    remain = Recharge - consume - cancel
    '本期充值金额
    strSqlRe = "select sum(addmoney) as rechargecash from recharge_info where date='" & Format(startDate.Value, "yyyy-mm-dd") & "'"
    Set mrcRe = executeSQL(strSqlRe, strMsg)
    If Not IsNull(mrcRe!rechargecash) Then
        Torecharge = mrcRe!rechargecash
        mrcRe.Close
    End If
    '本期退卡
    strSqlCan = "select sum(cancelcash) as cancel from cancelcard_info where date='" & Format(startDate.Value, "yyyy-mm-dd") & "'"
    Set mrcCan = executeSQL(strSqlCan, strMsg)
    If Not IsNull(mrcCan!cancel) Then
        Tocancel = mrcCan!cancel
        mrcCan.Close
    End If
    '本期消费
    strSQLL = "select sum(consume) as consumecash from line_info where offdate= '" & Format(startDate.Value, "yyyy-mm-dd") & "'"
    Set mrcL = executeSQL(strSQLL, strMsg)
    If Not IsNull(mrcL!consumeCash) Then
        Toconsume = mrcL!consumeCash
        mrcL.Close
    End If
    '本期充值卡余额
    all = remain + Torecharge - Toconsume - Tocancel
    strSqlWeek = "select * from checkweek_info "
    Set mrcWeek = executeSQL(strSqlWeek, strMsg)
    mrcWeek.AddNew
    mrcWeek.Fields("remaincash") = remain
    mrcWeek.Fields("rechargecash") = Torecharge
    mrcWeek.Fields("consumecash") = Toconsume
    mrcWeek.Fields("cancelcash") = Tocancel
    mrcWeek.Fields("allcash") = all
    mrcWeek.Fields("date") = Format(startDate.Value, "yyyy-mm-dd")
    mrcWeek.Update


End Sub

         我的方法很麻烦,这是我使劲想出来的,大家有好的方法可以给我一个连接哦,让我借鉴一下。 

         

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值