(四)充值-機房收費系統
阿新 • • 發佈:2019-02-12
Private Sub cmdOK_Click()
Dim mrc As ADODB.Recordset
Dim mrcc As ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
Dim a As String
Dim b As String
'任務一:不允許不輸入
If txtCardNo.Text = "" Or txtCash.Text = "" Then
MsgBox "請輸入姓名和充值金額"
Else
'任務二: 如何能充值,卡號存在,並在使用狀態
txtSQL = "select * from student_info where cardNo = '" & Trim(txtCardNo.Text) & "'"
Set mrcc = ExecuteSQL(txtSQL, MsgText)
If mrcc.EOF Then ' 游標可以移動到這一行所以資料庫中沒有相應的卡號
MsgBox "卡號不存在,請重新輸入卡號", vbOKOnly + vbExclamation, "提示"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
Else
'任務三:查詢卡是否在使用狀態
txtSQL = "select * from student_info where cardNo = '" & Trim(txtCardNo.Text) & "' and status = '" & "使用" & "'"
Set mrcc = ExecuteSQL(txtSQL, MsgText)
If mrcc.EOF Then ' 游標可以移動到這一行所以資料庫中沒有相應的卡號
MsgBox "該卡已退卡,請啟用,或重新輸入卡號。", vbOKOnly + vbExclamation, "提示"
txtCardNo.Text = ""
txtCardNo.SetFocus
Exit Sub
Else
'任務四;查詢需要的學號
a = mrcc.Fields(1)
b = mrcc.Fields(7)
'任務五:不能少於最小金額
If Val(txtCash.Text) <= Val(frmBasicData.txtMinCash.Text) Then
MsgBox "充值金額不能少於最小金額!", vbOKOnly + vbExclamation, "警告"
txtCash.Text = ""
txtCash.SetFocus
Else
'任務六:把值附到充值表中
txtSQL = "select * from ReCharge_info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.AddNew
mrc.Fields(1) = Trim(a)
mrc.Fields(2) = Trim(txtCardNo.Text)
mrc.Fields(4) = Date
mrc.Fields(5) = Time
mrc.Fields(6) = UserName
mrc.Fields(7) = "未結賬"
mrc.Fields(3) = Trim(txtCash.Text)
mrc.Update
'任務六:顯示資訊
' 充值之前的錢數需要記錄,一共有多少錢金額需要記錄,時間日期,老師
txtShow.Text = "充值卡號:" & mrc.Fields(2) & vbCrLf & vbCrLf & "上次卡內的餘額:" & b & vbCrLf & vbCrLf & "現在卡內的餘額:" & b + mrc.Fields(3) & vbCrLf & vbCrLf & "充值日期:" & mrc.Fields(4) & vbCrLf & vbCrLf & "充值時間:" & mrc.Fields(5) & vbCrLf & vbCrLf & "充值老師:" & UserName & vbCrLf
mrc.Close
'任務七:把資訊新增到學生表中,更新相應資訊
txtSQL = "select * from student_info where cardno = '" & Trim(txtCardNo.Text) & "'"
Set mrcc = ExecuteSQL(txtSQL, MsgText)
mrcc.Fields(7) = Val(Val(Trim(b)) + Val(Trim(txtCash.Text)))
mrcc.Update
mrcc.Close
MsgBox "儲存成功", vbOKOnly + vbExclamation, "警告"
txtShow.Text = ""
txtCardNo.Text = ""
txtCash.Text = ""
End If
End If
End If
End If