机房收费系统—查询并导出Excel表

15:30

时间过的很快,但是自己的进度确实有够慢的,很多同学已经开始进入到软工了,自己还为机房收费系统苦恼着。虽然进度很慢,但是每每解决一个问题都很兴奋。

开始都说,只要参考学生信息管理系统敲就行了,但是压根就没有思路,但是现在,只要解决一个,下一个就会有些思路,久而久之,突然感觉有很多相似的窗体,进度要赶,但是自己真正理解了感觉收获更多。

以下是收取金额查询窗体:

Private Sub CmdOK_Click()
    Dim mrc As ADODB.Recordset
    Dim Msgtext As String
    Dim TxtSQL As String
    
    '收取金额查询
        TxtSQL = "select * from ReCharge_Info where date >='" & DTPicker1.Value & "'" & " And date <= '" & DTPicker2.Value & "'"
        Set mrc = ExecuteSQL(TxtSQL, Msgtext)
        
        If Not mrc.EOF = False Then
            MsgBox "无记录!", vbOKOnly + vbExclamation, "警告"
        Else
        
        With MyFlexGrid
        .Rows = 2
        .CellAlignment = 4
        .TextMatrix(1, 0) = "卡号"
        .TextMatrix(1, 1) = "充值金额"
        .TextMatrix(1, 2) = "充值日期"
        .TextMatrix(1, 3) = "充值时间"
        .TextMatrix(1, 4) = "充值教师"
        .TextMatrix(1, 5) = "结账状态"
        
        Do While Not mrc.EOF
            .Rows = .Rows + 1
            .CellAlignment = 4
            .TextMatrix(.Rows - 1, 0) = mrc!cardno
            .TextMatrix(.Rows - 1, 1) = mrc!addmoney
            .TextMatrix(.Rows - 1, 2) = mrc!Date
            .TextMatrix(.Rows - 1, 3) = mrc!Time
            .TextMatrix(.Rows - 1, 4) = mrc!UserID
            .TextMatrix(.Rows - 1, 5) = mrc!Status
            
            mrc.MoveNext
        Loop
        End With
        End If
        mrc.Close
End Sub

导出Excel表:

Private Sub CmdExcel_Click()
    Dim app As Excel.Application
    Dim book As Excel.Workbook
    Dim sheet As Excel.Worksheet
    
    Set app = New Excel.Application
    Set book = app.Workbooks.Add
    Set sheet = book.Worksheets.Add
    
    Dim row As Single
    Dim col As Single
    
    With MyFlexGrid
    
        For row = 0 To .Rows - 1
            For col = 0 To .col - 1
                sheet.Cells(row + 1, col + 1).Value = .TextMatrix(row, col)
                Next col
            Next row
       End With
       
       app.Visible = True
       Exit Sub
End Sub

同样,金额退还信息查询的窗体的代码也就很容易的就可以敲出来了,其他的导出Excel表当然也很容易的完成的。

可能这个窗体的代码很早就完成了,都说很简单,敲完再看确实不难,但是真正自己完成它还是很开心的。



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