机房收费系统中管理员可以对操作员进行结账操作。
窗体界面:
结账用到了SSTab选项卡,SSTab的添加:添加SSTab选项卡
每一个选项下面对应的连接数据库和想要查询的内容都是不一样的。
代码展示:
Private Sub SSTab1_Click(PreviousTab As Integer)
Dim txtSQL As String
Dim MsgText As String
Dim mrc As Recordset
Select Case SSTab1.Tab
Case 0 '显示购卡
MSHFlexGrid1.Rows = 1
With MSHFlexGrid1
.CellAlignment = 4
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "日期"
.TextMatrix(0, 3) = "时间"
End With
'连接数据库 student 表
txtSQL = "select * from student_info where UserID='" & Trim(ComboUserID.Text) & "'and Ischeck='" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Do While Not mrc.EOF
With MSHFlexGrid1
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(12)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(13)
'移动到下一条记录
mrc.MoveNext
End With
Loop
mrc.Close
Case 1 '显示充值
MSHFlexGrid2.Rows = 1
With MSHFlexGrid2
.CellAlignment = 4
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "充值金额"
.TextMatrix(0, 3) = "日期"
.TextMatrix(0, 4) = "时间"
End With
'连接数据库 Recharge 表
txtSQL = "select * from Recharge_info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Do While Not mrc.EOF
With MSHFlexGrid2
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(4)
.TextMatrix(.Rows - 1, 4) = mrc.Fields(5)
'移动到下一条记录
mrc.MoveNext
End With
Loop
mrc.Close
Case 2 '显示退卡
MSHFlexGrid3.Rows = 1
With MSHFlexGrid3
.CellAlignment = 4
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "退卡金额"
.TextMatrix(0, 3) = "日期"
.TextMatrix(0, 4) = "时间"
End With
'连接数据库 CancelCard 表
txtSQL = "select * from CancelCard_info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Do While Not mrc.EOF
With MSHFlexGrid3
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2) '退卡金额
.TextMatrix(.Rows - 1, 3) = mrc.Fields(3) '日期
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4) '时间
'移动到下一条记录
mrc.MoveNext
End With
Loop
mrc.Close
Case 3 '显示临时用户
MSHFlexGrid4.Rows = 1
With MSHFlexGrid4
.CellAlignment = 4
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "日期"
.TextMatrix(0, 3) = "时间"
End With
'连接数据库 sutdent表 临时用户
txtSQL = "select * from student_info where UserID='" & Trim(ComboUserID.Text) & "' and type='" & Trim(Label11.Caption) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Do While Not mrc.EOF
With MSHFlexGrid4
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(1) '学号
.TextMatrix(.Rows - 1, 1) = mrc.Fields(0) '卡号
.TextMatrix(.Rows - 1, 2) = mrc.Fields(12) '日期
.TextMatrix(.Rows - 1, 3) = mrc.Fields(13) '时间
'移动到下一条记录
mrc.MoveNext
End With
Loop
mrc.Close
Case 4 '显示汇总
Dim mrcStu As ADODB.Recordset '连接student表
Dim mrcCancel As ADODB.Recordset '连接cancelCard表
Dim mrcRe As ADODB.Recordset '连接Rechange表
'连接student表
txtSQL = "select * from student_info where UserID='" & Trim(ComboUserID.Text) & "'and Ischeck='" & "未结账" & "'"
Set mrcStu = ExecuteSQL(txtSQL, MsgText)
txtSellCardSum.Text = mrcStu.RecordCount '售卡张数
'连接数据库 CancelCard 表
txtSQL = "select * from CancelCard_info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"
Set mrcCancel = ExecuteSQL(txtSQL, MsgText)
txtBackCardSum.Text = mrcCancel.RecordCount '退卡张数
'退卡金额
If mrcCancel.EOF = True Then
txtBackCardMoney.Text = "0"
Else
txtBackCardMoney.Text = Val(mrcCancel.Fields(2))
End If
'连接数据库 Recharge 表
txtSQL = "select sum(addmoney) from Recharge_info where UserID='" & Trim(ComboUserID.Text) & "'and status='" & "未结账" & "'"
Set mrcRe = ExecuteSQL(txtSQL, MsgText)
' mrcRe.Open
'充值金额
If IsNull(Trim(mrcRe.Fields(0))) Then
txtRecharge.Text = "0"
Else
txtRecharge.Text = Val(mrcRe.Fields(0))
End If
'计算总售卡数与应收金额
txtSellCardActual.Text = Val(txtSellCardSum.Text) - Val(txtBackCardSum.Text) '总售卡张数
txtCollectMoney.Text = Val(txtRecharge.Text) - Val(txtBackCardMoney.Text) '应收金额
Case 5 '退出
Unload Me
End Select
End Sub
汇总选项卡下面还有一个结账的控件
结账的时候需要连接学生表、充值表和退卡表,综合上机的时间和卡里余额进行结账。
代码展示:
Private Sub cmdAccounts_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrcStu As ADODB.Recordset '连接student表
Dim mrcCancel As ADODB.Recordset '连接cancelCard表
Dim mrcRe As ADODB.Recordset '连接Rechange表
'连接student表
txtSQL = "select * from student_info where UserID='" & Trim(ComboUserID.Text) & "'"
Set mrcStu = ExecuteSQL(txtSQL, MsgText)
Do While Not mrcStu.EOF
mrcStu!Ischeck = "结账"
mrcStu.Update
mrcStu.MoveNext
Loop
mrcStu.Close
'连接数据库 CancelCard 表
txtSQL = "select * from CancelCard_info where UserID='" & Trim(ComboUserID.Text) & "'"
Set mrcCancel = ExecuteSQL(txtSQL, MsgText)
Do While Not mrcCancel.EOF
mrcCancel!Status = "结账"
mrcCancel.Update
mrcCancel.MoveNext
Loop
mrcCancel.Close
'连接数据库 Recharge 表
txtSQL = "select * from Recharge_info where UserID='" & Trim(ComboUserID.Text) & "'"
Set mrcRe = ExecuteSQL(txtSQL, MsgText)
Do While Not mrcRe.EOF
mrcRe!Status = "结账"
mrcRe.Update
mrcRe.MoveNext
Loop
mrcRe.Close
MsgBox "结账成功", 64, "温馨提示"
Exit Sub
End Sub
感谢阅读~