1. 程式人生 > >機房收費系統——學生基本資訊維護

機房收費系統——學生基本資訊維護

這個窗體是一個簡單的組合查詢窗體,之所以它簡單是因為它沒有涉及到時間控制元件,所以可以節省不少程式碼量,但是它有一個難點就是把選中修改,把修改後的資訊返還到這個窗體中,所以這個窗體也涉及到另外一個窗體!

程式碼展示:

學生基本資訊維護

Public TmpCardno As String 'TmpCardno稱它為“臨時卡號”,是您選擇的那行資料的列的值
Public tmpload As String 'tmpLoad是在“修改資訊窗體”新增的子窗體

Public Function field(strfield As String) As String

    Select Case strfield
        Case "卡號"
            field = "cardno"
        Case "學號"
            field = "studentNo"
        Case "姓名"
            field = "studentName"
        Case "性別"
            field = "sex"
        Case "系別"
            field = "department"
        Case "年級"
            field = "grade"
        Case "班級"
            field = "class"
     
        End Select

End Function

Public Function RelationName(strRelationName As String) As String
    Select Case strRelationName
        Case "與"
            RelationName = "and"
        Case "或"
            RelationName = "or"
        End Select
        
End Function
Private Sub cmdCheck_Click()
    Dim txtsql As String
    Dim msgtext As String
    Dim mrc As ADODB.Recordset '定義資料集物件
    '在Student_info 這張表中獲得整行記錄
    txtsql = "select * from student_Info where "
    
    If Trim(comboField(0).Text) = "" Or Trim(ComboOpSign(0).Text) = "" Or Trim(txtInquriryContent(0).Text) = "" Then
        MsgBox "請將選項內容填寫完整!", vbOKOnly, "提示"
    Exit Sub
    
    Else

    txtsql = txtsql & " " & field(comboField(0).Text) & " " & ComboOpSign(0).Text & " '" & Trim(txtInquriryContent(0).Text) & "'"
    
    
    If ComboCombineRelation(0).Text <> "" Then
        If Trim(comboField(1).Text) = "" Or Trim(ComboOpSign(1).Text) = "" Or Trim(txtInquriryContent(1).Text) = "" Then
            MsgBox "請將第二行選項內容填寫完整!", vbOKOnly, "提示"
            Exit Sub
        Else
        
        txtsql = txtsql & " " & RelationName(ComboCombineRelation(0).Text) & " " & field(comboField(1).Text) & " " & ComboOpSign(1).Text & "'" & Trim(txtInquriryContent(1).Text) & "'"
        
            If ComboCombineRelation(1).Text <> "" Then
                If comboField(2).Text = "" Or ComboOpSign(2).Text = "" Or txtInquriryContent(2).Text = "" Then
                MsgBox "請將第三行內容填寫完整", vbOKOnly, "溫馨提示"
                Exit Sub
                Else
                
                txtsql = txtsql & " " & RelationName(ComboCombineRelation(1).Text) & " " & field(comboField(2).Text) & " " & ComboOpSign(2).Text & "'" & Trim(txtInquriryContent(2).Text) & "'"
                
                End If
            End If
        End If
    End If
End If
    Set mrc = ExecuteSQL(txtsql, msgtext)
    If mrc.EOF Then
        MsgBox "無資料,請重新填寫", vbInformation
        comboField(0).SetFocus
        comboField(0).Text = ""
        MSHFlexGrid1.Clear
    Else
        With MSHFlexGrid1
        .Rows = 1
        .CellAlignment = 4
        .TextMatrix(0, 0) = "學號"
        .TextMatrix(0, 1) = "姓名"
        .TextMatrix(0, 2) = "卡號"
        .TextMatrix(0, 3) = "金額"
        .TextMatrix(0, 4) = "系別"
        .TextMatrix(0, 5) = "年級"
        .TextMatrix(0, 6) = "班級"
        .TextMatrix(0, 7) = "性別"
        .TextMatrix(0, 8) = "狀態"
        .TextMatrix(0, 9) = "備註"
        .TextMatrix(0, 10) = "型別"
        .TextMatrix(0, 11) = "日期"
        .TextMatrix(0, 12) = "時間"
          
        Do While Not mrc.EOF
        .Rows = .Rows + 1
        .CellAlignment = 4
        .TextMatrix(.Rows - 1, 0) = Trim(mrc.fields(1))
        .TextMatrix(.Rows - 1, 1) = Trim(mrc.fields(2))
        .TextMatrix(.Rows - 1, 2) = Trim(mrc.fields(0))
        .TextMatrix(.Rows - 1, 3) = Trim(mrc.fields(7))
        .TextMatrix(.Rows - 1, 4) = Trim(mrc.fields(4))
        .TextMatrix(.Rows - 1, 5) = Trim(mrc.fields(5))
        .TextMatrix(.Rows - 1, 6) = Trim(mrc.fields(6))
        .TextMatrix(.Rows - 1, 7) = Trim(mrc.fields(3))
        .TextMatrix(.Rows - 1, 8) = Trim(mrc.fields(10))
        .TextMatrix(.Rows - 1, 9) = Trim(mrc.fields(8))
        .TextMatrix(.Rows - 1, 10) = Trim(mrc.fields(14))
        .TextMatrix(.Rows - 1, 11) = Trim(mrc.fields(12))
        .TextMatrix(.Rows - 1, 12) = Trim(mrc.fields(13))
        
        mrc.MoveNext
       
        Loop
    End With
    End If
End Sub
    
Private Sub cmdDelete_Click()
MSHFlexGrid1.Clear


    If Not (mrc.EOF Or mrc.BOF) Then
        mrc.fields(0) = Trim(txtCardNo.Text)
        mrc.fields(1) = Trim(txtSID.Text)
        mrc.fields(2) = Trim(txtName.Text)
        mrc.fields(3) = Trim(comboSex.Text)
        mrc.fields(4) = Trim(txtDept.Text)
        mrc.fields(5) = Trim(txtGrade.Text)
        mrc.fields(6) = Trim(txtClass.Text)
        mrc.fields(7) = Trim(txtmoney.Text)
        mrc.fields(8) = Trim(txtexplain.Text)
        mrc.fields(10) = Trim(txtstate.Text)
        mrc.fields(14) = Trim(Combotype.Text)
        mrc.Update
        mrc.Close
    End If
    Me.Hide
    
    '修改資訊後,重新載入到基本資訊維護窗體的查詢結果中
    
End Sub

'End Function
Private Sub cmdModify_Click()
'TmpCardno = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 0) '選擇一行資料
    frmeditstuinfo.txtSID.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 0)
    frmeditstuinfo.txtClass.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 6)
    frmeditstuinfo.txtName.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 1)
    frmeditstuinfo.txtCardNo.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 2)
    frmeditstuinfo.comboSex.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 7)
    frmeditstuinfo.txtmoney.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 3)
    frmeditstuinfo.txtDept.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 4)
    frmeditstuinfo.txtexplain.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 9)
    frmeditstuinfo.txtGrade.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 5)
    frmeditstuinfo.Combotype.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 10)
    frmeditstuinfo.txtstate.Text = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 8)
            
    frmeditstuinfo.Show '顯示修改資訊窗體
    MsgBox "請先選擇資料,再進行修改!", , "溫馨提示"
    
    Exit Sub
    
End Sub


Private Sub Form_Load()
     comboField(0).AddItem "卡號"
     comboField(0).AddItem "學號"
     comboField(0).AddItem "姓名"
     comboField(0).AddItem "性別"
     comboField(0).AddItem "系別"
     comboField(0).AddItem "年級"
     comboField(0).AddItem "班級"
     
     comboField(1).AddItem "卡號"
     comboField(1).AddItem "學號"
     comboField(1).AddItem "姓名"
     comboField(1).AddItem "性別"
     comboField(1).AddItem "系別"
     comboField(1).AddItem "年級"
     comboField(1).AddItem "班級"
     
     comboField(2).AddItem "卡號"
     comboField(2).AddItem "學號"
     comboField(2).AddItem "姓名"
     comboField(2).AddItem "性別"
     comboField(2).AddItem "系別"
     comboField(2).AddItem "年級"
     comboField(2).AddItem "班級"
     
     ComboOpSign(0).AddItem "="
    
    
     ComboOpSign(0).AddItem "<>"
     
     ComboOpSign(1).AddItem "="
     
     
     ComboOpSign(1).AddItem "<>"
     
     ComboOpSign(2).AddItem "="
    
    
     ComboOpSign(2).AddItem "<>"
     
     ComboCombineRelation(0).AddItem "與"
     ComboCombineRelation(0).AddItem "或"
     
     ComboCombineRelation(1).AddItem "與"
     ComboCombineRelation(1).AddItem "或"
    
     
End Sub



Private Sub MSHFlexGrid1_Click()
MSHFlexGrid1.SelectionMode = flexSelectionByRow '單擊時選擇整行
MSHFlexGrid1.FocusRect = flexFocusNone '在當前但願的周圍畫一個焦點框
MSHFlexGrid1.HighLight = flexHighlightWithFocus  '該值決定了所選定的單元是否突出顯示

 
End Sub

Private Sub MSHFlexGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim tmpselect As Boolean
tmpselect = True

End Sub

Private Sub txtInquriryContent_KeyPress(Index As Integer, KeyAscii As Integer)
Dim ctemp As String
    ctemp = "#$%^&*"   '禁止輸入的字元
    If InStr(1, ctemp, Chr(KeyAscii)) <> 0 Then
        KeyAscii = 0
    End If
End Sub

修改學生資訊

Private Sub cmdOk_Click()
    Dim txtsql As String
    Dim msgtext As String
    Dim mrc As ADODB.Recordset
    
    txtCardNo.Enabled = False
    
    txtsql = "select * from student_info where cardno= '" & Trim(txtCardNo.Text) & "'"
    Set mrc = ExecuteSQL(txtsql, msgtext)
    
    If mrc.EOF And mrc.BOF = True Then
        mrc.fields(0) = Trim(txtCardNo.Text)
        mrc.fields(1) = Trim(txtSID.Text)
        mrc.fields(2) = Trim(txtName.Text)
        mrc.fields(3) = Trim(comboSex.Text)
        mrc.fields(4) = Trim(txtDept.Text)
        mrc.fields(5) = Trim(txtGrade.Text)
        mrc.fields(6) = Trim(txtClass.Text)
        mrc.fields(7) = Trim(txtmoney.Text)
        mrc.fields(8) = Trim(txtexplain.Text)
        mrc.fields(10) = Trim(txtstate.Text)
        mrc.fields(14) = Trim(Combotype.Text)
        mrc.Update

        Do While Not mrc.EOF
        With MSHFlexGrid1
        .Rows = .Rows + 1
        .CellAlignment = 4
        .TextMatrix(.Rows - 1, 0) = Trim(mrc.fields(1))
        .TextMatrix(.Rows - 1, 1) = Trim(mrc.fields(2))
        .TextMatrix(.Rows - 1, 2) = Trim(mrc.fields(0))
        .TextMatrix(.Rows - 1, 3) = Trim(mrc.fields(7))
        .TextMatrix(.Rows - 1, 4) = Trim(mrc.fields(4))
        .TextMatrix(.Rows - 1, 5) = Trim(mrc.fields(5))
        .TextMatrix(.Rows - 1, 6) = Trim(mrc.fields(6))
        .TextMatrix(.Rows - 1, 7) = Trim(mrc.fields(3))
        .TextMatrix(.Rows - 1, 8) = Trim(mrc.fields(10))
        .TextMatrix(.Rows - 1, 9) = Trim(mrc.fields(8))
        .TextMatrix(.Rows - 1, 10) = Trim(mrc.fields(14))
        .TextMatrix(.Rows - 1, 11) = Trim(mrc.fields(12))
        .TextMatrix(.Rows - 1, 12) = Trim(mrc.fields(13))

        mrc.MoveNext

     
    End With
       Loop
        MsgBox "無任何修改", 0 + 48, "警告"
    End If
    
    Me.Hide
    
End Sub

Public Sub tmpload()
    Dim txtsql As String
    Dim msgtext As String
    Dim mrc As ADODB.Recordset
    
     txtsql = "select * from student_info where cardno= '" & Trim(txtCardNo.Text) & "'"
     Set mrc = ExecuteSQL(txtsql, msgtext)
     
     If mrc.EOF Then
        MsgBox "載入資訊不存在,請確認後重新操作", 0 + 48, "警告"
    Else
        txtSID.Text = mrc!studentNo
        txtName.Text = mrc!studentname
        comboSex.Text = mrc!sex
        txtDept.Text = mrc!department
        txtGrade.Text = mrc!grade
        txtClass.Text = mrc!Class
        txtCardNo.Text = mrc!cardno
        txtmoney.Text = mrc!cash
        txtstate.Text = mrc!status
        txtexplain.Text = mrc!explain
        Combotype.Text = mrc!Type
        mrc.Close
        
    End If
    
        
End Sub

Private Sub txtSID_KeyPress(KeyAscii As Integer)
Dim ctemp As String
    ctemp = "#$%^&*"   '禁止輸入的字元
    If InStr(1, ctemp, Chr(KeyAscii)) <> 0 Then
        KeyAscii = 0
    End If
Select Case KeyAscii
    Case 48 To 57 '只能輸入數字
    Case 65 To 90 '只能輸入大小寫字母
    Case 97 To 122 ' 只能輸入退格
    Case 8
    Case Else
    KeyAscii = 0
End Select
End Sub

看完程式碼之後,你學會了嗎?有什麼創新的地方嗎?