一、思路
结账目的:为了给管理人员查看,更加直观。
含义:经过分析,我们可知道,这就是管理员看操作员一天的工作明细,即售卡,充值,退卡的情况。
1、 购卡:就是在student_info表总查询没有结账的那些新注册的学生卡号等信息。
2、 充值:在recharge_info表中查询未结账的充值信息。
3、 退卡:在cancelCard_info中查询未结账的退卡信息。
4、 临时用户:在student_info表中查询未结账的,没有退卡的临时用户。
5、 汇总:将前面所有的信息汇总起来。用到了student_Info 、Recharge_Info 、cancelcard_Info 表。
6、 售卡张数=购卡选项卡的记录总数
7、 退卡张数=退卡选项卡的记录总数
8、 退卡金额=cancelcard_Info表中的金额进行累加
9、 总售卡数=售卡数-退卡数
10、 注册和充值金额=student_Info 表中注册时候的充值金额+Recharge_Info 表中的充值金额(注册时的充值的钱和充值时充进去的钱其实都一样)
11、 临时收费=临时收费选项卡记录中的卡号上机所消费的钱的总和(Line_Info)(只是用来显示)
12、应收金额=注册和充值金额-退卡金额
二、代码:
Dim MsgText As String
Dim UserSQL As String
Dim StuSQL As String
Dim ReChargeSQL As String
Dim CancelCardSQL As String
Dim CheckDaySQL As String
Dim LineSQL As String
Dim mrcReCharge As ADODB.Recordset
Dim mrcCancelCard As ADODB.Recordset
Dim mrcCheckDay As ADODB.Recordset
Dim mrcLine As ADODB.Recordset
Dim mrcUser As ADODB.Recordset
Dim mrcStu As ADODB.Recordset
Dim Allcash1 As String '用户记录注册和充值总金额
Private Sub Form_Load()
'窗体初始加载时,在下拉菜单中加载userid(级别)
UserSQL = "select * from User_Info where Level='操作员'"
Set mrcUser = ExecuteSQL(UserSQL, MsgText)
'在下拉菜单中显示所有的UserID
Do While mrcUser.EOF = False
comboUserID.AddItem mrcUser.Fields(0) '操作员用户名
mrcUser.MoveNext
Loop
mrcUser.Close
' Me.Left = (frmMDIForm1.Width - Me.Width) / 2
' Me.Top = (frmMDIForm1.Height - Me.Height) / 2
End Sub
'显示真实姓名
Private Sub comboUserID_Click()
UserSQL = "select * from User_info where UserID='" & comboUserID.Text & "'"
Set mrcUser = ExecuteSQL(UserSQL, MsgText)
comboUserName.Text = Trim(mrcUser.Fields(3)) '显示姓名
mrcUser.Close
End Sub
Private Sub SSTab1_Click(PreviousTab As Integer)
Dim MsgText As String
Dim StuSQL As String
Dim ReChargeSQL As String
Dim CancelCardSQL As String
Dim mrcReCharge As ADODB.Recordset
Dim mrcCancelCard As ADODB.Recordset
Dim mrcStu As ADODB.Recordset
Dim Rcharge As Integer
Dim Tuicharge As Integer
Dim RchargeMoney As Integer
Dim TuichargeMoney As Integer
'购卡
If SSTab1.Caption = "购卡" Then
MSFlexGrid1.Rows = 1
MSFlexGrid1.Cols = 6
StuSQL = "select * from student_Info where UserID='" & comboUserID.Text & "' and Ischeck='未结账'"
Set mrcStu = ExecuteSQL(StuSQL, MsgText)
MSFlexGrid1.Rows = mrcStu.RecordCount + 1
With MSFlexGrid1
.Rows = 1
.CellAlignment = 4 '居中
.TextMatrix(0, 0) = "学号" 'studentid
.TextMatrix(0, 1) = "卡号" 'cardid
.TextMatrix(0, 2) = "日期" 'date
.TextMatrix(0, 3) = "时间" 'time
.TextMatrix(0, 4) = "使用状态"
.TextMatrix(0, 5) = "结账情况"
While mrcStu.EOF = False
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Trim(mrcStu.Fields(1)) 'studentno
.TextMatrix(.Rows - 1, 1) = Trim(mrcStu.Fields(0)) 'cardno
.TextMatrix(.Rows - 1, 2) = Trim(mrcStu.Fields(12)) 'date
.TextMatrix(.Rows - 1, 3) = Trim(mrcStu.Fields(13)) 'time
.TextMatrix(.Rows - 1, 4) = Trim(mrcStu.Fields(10))
.TextMatrix(.Rows - 1, 5) = Trim(mrcStu.Fields(11))
mrcStu.MoveNext
Wend
End With
End If
'充值
If SSTab1.Caption = "充值" Then
MSFlexGrid2.Rows = 1
MSFlexGrid2.Cols = 5
ReChargeSQL = "select * from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
With MSFlexGrid2
.CellAlignment = 5
.TextMatrix(0, 0) = "卡号"
.TextMatrix(0, 1) = "学号"
.TextMatrix(0, 2) = "充值金额"
.TextMatrix(0, 3) = "日期"
.TextMatrix(0, 4) = "时间"
Do While Not mrcReCharge.EOF
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 0) = mrcReCharge.Fields(2)
.TextMatrix(.Rows - 1, 1) = mrcReCharge.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrcReCharge.Fields(3)
.TextMatrix(.Rows - 1, 3) = mrcReCharge.Fields(4)
.TextMatrix(.Rows - 1, 4) = mrcReCharge.Fields(5)
mrcReCharge.MoveNext
Loop
End With
End If
'退卡
'把所有信息汇总到表格
CancelCardSQL = "select * from CancelCard_Info where status='未结账'and UserID='" & comboUserID.Text & "'"
Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
cancelcash = 0
With MSFlexGrid3
.Rows = 1
.CellAlignment = 4 '居中
.TextMatrix(0, 0) = "学号" 'studentid
.TextMatrix(0, 1) = "卡号" 'cardid
.TextMatrix(0, 2) = "日期" 'cash
.TextMatrix(0, 3) = "时间" 'date
.TextMatrix(0, 4) = "退卡金额"
.TextMatrix(0, 5) = "结账情况"
While Not mrcCancelCard.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Trim(mrcCancelCard.Fields(0)) 'studentno
.TextMatrix(.Rows - 1, 1) = Trim(mrcCancelCard.Fields(1)) 'cardno
.TextMatrix(.Rows - 1, 2) = Trim(mrcCancelCard.Fields(3)) 'date
.TextMatrix(.Rows - 1, 3) = Trim(mrcCancelCard.Fields(4)) 'time
.TextMatrix(.Rows - 1, 4) = Trim(mrcCancelCard.Fields(2)) 'cancelcash
.TextMatrix(.Rows - 1, 5) = Trim(mrcCancelCard.Fields(6)) 'cancelcash
cancelcash = cancelcash + mrcCancelCard.Fields(2)
mrcCancelCard.MoveNext
Wend
End With
'临时用户
StuSQL = "select * from student_Info where status='使用' and UserID='" & comboUserID.Text & "'and type='临时用户'and Ischeck='未结账'"
Set mrcStu = ExecuteSQL(StuSQL, MsgText)
TmpCash = 0
With MSFlexGrid4
.Rows = 1
.CellAlignment = 4 '居中
.TextMatrix(0, 0) = "学号" 'studentid
.TextMatrix(0, 1) = "卡号" 'cardid
.TextMatrix(0, 2) = "日期" 'date
.TextMatrix(0, 3) = "时间" 'time
.TextMatrix(0, 4) = "结账情况" 'time
While mrcStu.EOF = False
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Trim(mrcStu.Fields(1)) 'studentno
.TextMatrix(.Rows - 1, 1) = Trim(mrcStu.Fields(0)) 'cardno
.TextMatrix(.Rows - 1, 2) = Trim(mrcStu.Fields(12)) 'date
.TextMatrix(.Rows - 1, 3) = Trim(mrcStu.Fields(13)) 'time
.TextMatrix(.Rows - 1, 4) = Trim(mrcStu.Fields(11))
TmpCash = mrcStu.Fields(7)
mrcStu.MoveNext
Wend
End With
If MSFlexGrid4.Rows = 1 Then
rechargecash = "0"
Else
ReChargeSQL = "select * from ReCharge_Info where status='未结账' and UserID='" & comboUserID.Text & "'"
Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
Do While Not mrcReCharge.EOF
rechargecash = rechargecash + mrcReCharge.Fields(3)
mrcReCharge.MoveNext
Loop
End If
'汇总
If SSTab1.Caption = "汇总" Then
'计算售卡张数
StuSQL = "select * from student_info where UserID = '" & Trim(comboUserID.Text) & "'and ischeck = '" & "未结账" & "'"
Set mrcStu = ExecuteSQL(StuSQL, MsgText)
txtSCard.Text = mrcStu.RecordCount
'计算退卡张数
CancelCardSQL = "select * from CancelCard_info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
txtBCard.Text = mrcCancelCard.RecordCount
'总售卡数=售卡张数-退卡张数
txtAllSCard = txtSCard - txtBCard
'计算充值金额(不区分固定还是临时用户)
ReChargeSQL = "select sum(addmoney) from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
If IsNull(mrcReCharge.Fields(0)) Then '无记录
txtChargeMoney.Text = "0"
Else
txtChargeMoney.Text = mrcReCharge.Fields(3)
End If
'计算退卡金额
CancelCardSQL = "select sum(CancelCash) from CancelCard_Info where UserID = '" & Trim(comboUserID.Text) & "'and status = '" & "未结账" & "'"
Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
If IsNull(mrcCancelCard.Fields(0)) Then '无记录
txtBMoney.Text = "0"
Else
txtBMoney.Text = mrcCancelCard.Fields(0)
End If
'计算临时收费金额
ReChargeSQL = "select sum(addmoney) from ReCharge_Info where UserID = '" & Trim(comboUserID.Text) & "'and status = '未使用'"
Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
If IsNull(mrcReCharge.Fields(0)) Then '无记录
txtTemporaryMoney.Text = "0"
Else
txtTemporaryMoney.Text = mrcReCharge.Fields(0)
End If
'计算应收金额
txtAllCollectMoney.Text = Val(txtChargeMoney.Text) - Val(txtBMoney.Text)
mrcStu.Close '关闭释放空间
mrcReCharge.Close
mrcCancelCard.Close
End If
'退出
If SSTab1.Caption = "退出" Then
Unload Me
End If
End Sub
Private Sub cmdAmount_Click()
Dim MsgText As String
Dim StuSQL As String
Dim ReChargeSQL As String
Dim CancelCardSQL As String
Dim checkWeekSQL As String
Dim CheckDaySQL As String
Dim LineSQL As String
Dim mrcStu As ADODB.Recordset '代表学生表(student_info)
Dim mrcReCharge As ADODB.Recordset '代表充值表(recharge_info)
Dim mrcCancelCard As ADODB.Recordset '代表退卡表(cancelcard_info)
Dim mrcCheckDay As ADODB.Recordset '代表日结账单(checkday_info)
Dim mrcLine As ADODB.Recordset '代表line表(Line_info)
Dim remaincash As String
Dim rechargecash As String
Dim consumecash As String
Dim cancelcash As String
Dim allcash As String
If comboUserID.Text = "" Then
MsgBox "请选择操作员后再结账!", vbOKOnly + vbExclamation, "提示"
Exit Sub
End If
'更新学生表
StuSQL = "select * from student_info where UserID = '" & Trim(comboUserID.Text) & "'and ischeck = '" & "未结账" & "'"
Set mrcStu = ExecuteSQL(StuSQL, MsgText)
Do While Not mrcStu.EOF
mrcStu!ischeck = "结账"
mrcStu.Update
mrcStu.MoveNext
Loop
mrcStu.Close
'更新充值表
ReChargeSQL = "select * from ReCharge_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
Do While Not mrcReCharge.EOF
mrcReCharge!Status = "结账"
mrcReCharge.Update
mrcReCharge.MoveNext
Loop
mrcReCharge.Close
'更新退卡表
CancelCardSQL = "select * from CancelCard_Info where UserID='" & Trim(comboUserID.Text) & "' and status = '" & "未结账" & "'"
Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
Do While Not mrcCancelCard.EOF
mrcCancelCard!Status = "结账"
mrcCancelCard.Update
mrcCancelCard.MoveNext
Loop
mrcCancelCard.Close
'更新日结账单表
'计算上期充值卡余额(remaincash)
txtSQL = "select max(date) from checkWeek_Info" 'max(date)就是最近的一天
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF Then
Exit Sub
MaxDate = mrc.Fields(0)
CheckDaySQL = "select * from CheckDay_Info where date ='" & MaxDate & "'"
Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
If IsNull(mrcCheckDay.Fields(0)) Then
remaincash = "0"
Exit Sub
Else
remaincash = mrcCheckDay.Fields(0)
End If
End If
'更新当天充值金额,充值金额是今天的值班的任意个操作员充值的金额,并且是已经结了账的,如果今天充值了某些金额,但是没有结账,则在计算日结账单时,不计入)
ReChargeSQL = "select sum(addmoney) from ReCharge_info where status = '结账' and date = '" & Date & "'" '代表今天
Set mrcReCharge = ExecuteSQL(ReChargeSQL, MsgText)
If IsNull(mrcReCharge.Fields(0)) = True Then
rechargecash = "0"
Else
rechargecash = mrcReCharge.Fields(0)
End If
'从line表计算当日消费金额
LineSQL = "select sum(consume) from Line_Info where offdate='" & Date & "'"
Set mrcLine = ExecuteSQL(LineSQL, MsgText)
If IsNull(mrcLine.Fields(0)) Then
consumecash = "0"
Else
consumecash = mrcLine.Fields(0)
End If
'更新计算当天的退卡金额(cancelcash)这样没结账的操作员就不会算到这里面了
CancelCardSQL = "select sum(cancelcash) from CancelCard_Info where date='" & Date & "'and status = '结账'"
Set mrcCancelCard = ExecuteSQL(CancelCardSQL, MsgText)
If IsNull(mrcCancelCard.Fields(0)) Then
cancelcash = "0"
Else
cancelcash = mrcCancelCard.Fields(0)
End If
'往表里更新
CheckDaySQL = "select * from CheckDay_info "
Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
'判断是不是当天已经结过帐了
CheckDaySQL = "select * from CheckDay_info where date='" & Date & "'"
Set mrcCheckDay = ExecuteSQL(CheckDaySQL, MsgText)
If mrcCheckDay.EOF = False Then
mrcCheckDay!remaincash = Val(remaincash)
mrcCheckDay!rechargecash = Val(rechargecash)
mrcCheckDay!consumecash = Val(consumecash)
mrcCheckDay!cancelcash = Val(cancelcash)
mrcCheckDay!allcash = Val(remaincash) + Val(rechargecash) - Val(cancelcash) - Val(consumecash)
mrcCheckDay!Date = Date
mrcCheckDay.Update
mrcCheckDay.Close
Else
mrcCheckDay.AddNew
mrcCheckDay!remaincash = Val(remaincash)
mrcCheckDay!rechargecash = Val(rechargecash)
mrcCheckDay!consumecash = Val(consumecash)
mrcCheckDay!cancelcash = Val(cancelcash)
mrcCheckDay!allcash = Val(remaincash) + Val(rechargecash) - Val(cancelcash)
mrcCheckDay!Date = Date
mrcCheckDay.Update
mrcCheckDay.Close
End If
'更新周结账单(只需要删除周结账单表里的东西,然后将日结账单里所有的内容都跟新进去)
checkWeekSQL = "delete checkWeek_info"
Set mrccheckWeek = ExecuteSQL(checkWeekSQL, MsgText)
checkWeekSQL = "insert into checkWeek_info select * from CheckDay_info"
Set mrccheckWeek = ExecuteSQL(checkWeekSQL, MsgText)
'清空文本框显示的信息
txtSCard.Text = "0"
txtBCard.Text = "0"
txtChargeMoney.Text = "0"
txtTemporaryMoney.Text = "0"
txtBMoney.Text = "0"
txtAllSCard.Text = "0"
txtAllCollectMoney.Text = "0"
MsgBox "结账成功!", 64, "提示"
End Sub