1. 程式人生 > >機房收費系統之學生上機狀態檢視

機房收費系統之學生上機狀態檢視

作為程式設計師,我們在設計軟體編寫程式碼時最重要的一點為程式碼量的大小和巧用思維。我在編寫學生上機狀態檢視這個窗體時遇見兩個比較棘手的問題:使全部學生下機和選擇學生下機,這兩個功能的實現甚是煞費腦筋,不過最終採用了三點將這兩個功能實現出出來。

但是是哪三個關鍵點呢?第一:呼叫MDI窗體的下機按鈕,省去大量連線資料庫表和計算消費餘額的程式碼

                                        第二:採用陣列,使選擇下機的資料行能夠連續排列

                                        第三:定義tmpselect的運用

Dim tmpselect As Boolean



Private Sub msflexgrid1_mouseup(button As Integer, shift As Integer, x As Single, y As Single)

    tmpselect = True
End Sub
Rem:所有學生下線
Private Sub allstudentoutline_Click()
    Dim txtsqlonline As String
    Dim msgtextonline As String
    Dim mrconline As ADODB.Recordset
   
    Dim i As Integer
    
    txtsqlonline = "select * from online_info"
    Set mrconline = executesql(txtsqlonline, msgtextonline)
    If MSFlexGrid1.Text = "" Then
            MsgBox "請先顯示資料!", vbOKOnly + vbInformation, "溫馨提示"
    Else
    
            If mrconline.EOF = False Then
                    For i = 1 To MSFlexGrid1.Rows - 1
                             frmMDI.txtcardno.Text = MSFlexGrid1.TextMatrix(i, 0)
                             frmMDI.cmdclose.Value = True
                    Next
                    MsgBox "所有學生均已下機!", vbOKOnly + vbInformation, "溫馨提示"
                    MSFlexGrid1.Clear
            End If
    End If
            
End Sub



Private Sub msflexgrid1_click()
If tmpselect = True Then
            MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, 10) = "√"
End If
End Sub

Private Sub MSFlexGrid1_DblClick()
    MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, 10) = ""
End Sub



Rem:選擇學生下線
Private Sub optionstudentoutline_Click()
    Dim a(9999) As String
    Dim i As Integer
    Dim j As Integer
    
    
    If MSFlexGrid1.Text = "" Then
            MsgBox "請先顯示資料!", vbOKOnly + vbInformation, "溫馨提示"
            Exit Sub
    Else
            If MSFlexGrid1.RowSel = 0 Then
                    MsgBox "請先選擇資料!", vbOKOnly + vbInformation, "溫馨提示"
            End If
            
            With MSFlexGrid1
            For i = 1 To .Rows - 1
                    j = 0
                    If j > .Row Then
                    Exit Sub
                    End If
            
                    If .TextMatrix(i, 10) = "√" Then
                        a(j) = i
                        frmMDI.txtcardno.Text = MSFlexGrid1.TextMatrix(i, 0)
                        frmMDI.cmdclose.Value = True
                    Else
                        MsgBox "請先勾選資料!", vbOKOnly + vbInformation, "溫馨提示"
                        Exit Sub
                    End If
            Next
            End With
            MsgBox "所選擇的學生均已下機!", vbOKOnly + vbInformation, "溫馨提示"
    End If
End Sub

陣列思維的運用是建立在李光小師傅和閆偉強的分享的部落格的基礎上的,如果沒有這兩篇部落格,或許我會消耗些較為更多的時間。