充值窗體 機房收費系統
阿新 • • 發佈:2019-02-05
宣告:這個文章上個星期寫已發表結果誤刪了,從回收站沒法還原,只能從新發表了,見諒。
首先我們先對這個窗體進行下分析。
(1)檢測卡號和金錢的輸入
1.1 首先輸入卡號(檢查輸入卡號是否存在。若不存在,提示沒有該卡號請重新輸入,從student表中調去資訊判斷卡號是否存在,若該卡號存在,下一步)
1.2 輸入充值金額,
從basicdata表中調去資料 充值金額不能小於最小充值金額,
(2)單機確定按鈕 充值成功 文字框(下圖)顯示本次充值的資訊,根據資訊我們可以得知
2.1 在recharge表中顯示本次的充值記錄,
2.2 在student表中更新金額總數
(3)文字框顯示充值資訊
程式碼如下:
- PrivateSub CmdOK_Click()
- Dim txtsql AsString
- Dim msgtext AsString
- Dim mrc As adodb.Recordset
- Dim mrcc As adodb.Recordset
- Dim mrcc1 As adodb.Recordset
- Dim Number AsString'獲取學號
- Dim lastcash AsInteger'上次餘額
-
Dim leastcash
- Dim nowcash AsInteger' 最新餘額
- '檢查輸入
- IfNot Testtxt(CardIdtxt.Text) Then
- MsgBox "請輸入卡號!", vbOKOnly + vbExclamation, "警告!"
- CardIdtxt.SetFocus
- ExitSub
- EndIf
- IfNot Testtxt(Rechargetxt.Text) Then
- MsgBox "請輸入金額!", vbOKOnly + vbExclamation, "警告!"
-
Rechargetxt.SetFocus
- ExitSub
- EndIf
- IfNot IsNumeric(Rechargetxt.Text) Then
- MsgBox "請輸入數字!", vbOKOnly + vbExclamation, "警告!"
- Rechargetxt.SetFocus
- ExitSub
- EndIf
- '判斷卡號是否註冊
- txtsql = "select * from student_info where cardno= '" & Trim(CardIdtxt.Text) & "' "
- Set mrcc = ExecuteSQL(txtsql, msgtext)
- If mrcc.EOF Then
- MsgBox "該卡號沒有註冊,請重新輸入!", vbOKOnly + vbExclamation, "警告!"
- CardIdtxt.Text = ""
- CardIdtxt.SetFocus
- ExitSub
- Else
- Number = Trim(mrcc.Fields(1))
- lastcash = Val(Trim(CStr(mrcc.Fields(7))))
- mrcc.Close
- EndIf
- '獲取最新金額,與輸入的金額做比較
- txtsql = "select * from BasicData_Info "
- Set mrcc1 = ExecuteSQL(txtsql, msgtext)
- mrcc1.MoveLast
- leastcash = Val(Trim(CStr(mrcc1.Fields(5))))
- mrcc1.Close
- If Val(Trim(Rechargetxt.Text)) < leastcash Then
- MsgBox "輸入金額不得小於" & leastcash & "元!", vbOKOnly + vbExclamation, "警告!"
- Rechargetxt.Text = ""
- Rechargetxt.SetFocus
- ExitSub
- EndIf
- '更新recharge表中的資料
- txtsql = "select * from ReCharge_info "
- Set mrc = ExecuteSQL(txtsql, msgtext)
- mrc.AddNew
- mrc.Fields(1) = Number
- mrc.Fields(2) = Trim(CardIdtxt.Text)
- mrc.Fields(3) = Trim(Rechargetxt.Text)
- mrc.Fields(4) = Format(Date, "yyyy-mm-dd")
- mrc.Fields(5) = Time
- mrc.Fields(6) = "Username"
- mrc.Fields(7) = "未結賬"
- mrc.Update
- mrc.Close
- '更新student表中的最新餘額
- txtsql = "select * from student_info where cardno= '" & Trim(CardIdtxt.Text) & "' "
- Set mrcc = ExecuteSQL(txtsql, msgtext)
- mrcc.Fields(7).Value = lastcash + Val(Rechargetxt.Text)
- a = mrcc.Fields(7)
- mrcc.Update
- mrcc.Close
- bsp;
- '顯示充值資訊
- Showtxt.Text = "充值卡號:" & Trim(CardIdtxt.Text) & vbCrLf _
- & "上次餘額 " & lastcash & vbCrLf _
- & "最新餘額 " & a & vbCrLf _
- & "衝卡日期" & Date & vbCrLf _
- & "衝卡時間" & Time & vbCrLf _
- & "充值教師" & Username &
- MsgBox "充值成功!", vbOKOnly + vbExclamation, "警告!"
- CardIdtxt.Text = ""
- Rechargetxt.Text = ""
- Showtxt.Text = ""
- d Sub