到现在机房收费基本完成,相对之前的学生管理系统,有了一些小难度,个人感觉尤其在结账部分,由于涉及的表比较多,这更需要我们理清思路,保持清晰的思路,才是我们尽快完成王道!
在这一部分内容中涉及到一个之前我们运用较少的控件SSTab,这一部分的内容是自己在网上找的相关内容,再加上美红姐博客学习,使自己对这个控件有了很好的认识。
结账部分主要是运用到多个表中记录的查询,以及结账后对表中记录的更新,这些简单的操作更能使我们对SQL语句有一个很好的利用,如果在之前的学习中对SQL没有很好的认识,也没有关系,只是在学习过程中多百度一下就好啦。
售卡——根据选择操作员的编号,在student表中选择由其办理的卡号(未结账),避免结账之后的卡号重复被计算,造成账目的混乱。
<strong><span style="font-weight: bold;"> </span>txtSQL = "select * from student_Info where userID = '" & ComUserID.Text & "'" & " " & "and Ischeck = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF And mrc.EOF Then
MsgBox "没有工作记录,请重新选择!", vbOKOnly + vbExclamation, "友好提示"
Exit Sub
End If
With MSHFlexGrid1
.Rows = 1
.ColAlignment = 4
.CellAlignment = 4
.TextMatrix(0, 0) = "学号"
.TextMatrix(0, 1) = "卡号"
.TextMatrix(0, 2) = "日期"
.TextMatrix(0, 3) = "时间"
Do While Not mrc.EOF
.Rows = .Rows + 1
.ColAlignment = 4
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(1))
.TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(0))
.TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(12))
.TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(13))
mrc.MoveNext
Loop
End With
Call AdjustColWidth(frmCheckout, MSHFlexGrid1) '这一部分是调用自己写模块中的内容,目的使mshflexgrid1中内容居中
mrc.Close<strong>
</strong></strong>
在其之后的充值,退卡,以及临时用户和其大同小异,故就举售卡一例
汇总
看起来比较复杂吧,但是要踏实坐下来也没有什么特别复杂的内容,统计每个表中符合条件的记录一共有多少条,这时候可以用上SQL语句中的count,还有统计金额的问题,也可以适用sum,使统计更高效完成。
<strong><strong>'售卡张数
txtSQL = "select count(cardno) from student_Info where userID = '" & ComUserID.Text & "'" & " " & "and Ischeck = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF And mrc.EOF Then
Register = 0
Else
If IsNull(Trim(mrc.Fields(0))) Then
Register = 0
Else
Register = mrc.Fields(0)
End If
End If
txtshouka.Text = Register
'退卡张数
txtSQL = "select count(cardNo) from CancelCard_Info where userID = '" & ComUserID.Text & "'" & " " & "and status = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF And mrc.EOF Then
Backcard = 0
Else
If IsNull(Trim(mrc.Fields(0))) Then
Backcard = 0
Else
Backcard = mrc.Fields(0)
End If
End If
txttuika.Text = Backcard
'充值金额
txtSQL = "select sum(addmoney) from ReCharge_Info where userID = '" & ComUserID.Text & "'" & " " & "and status = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF And mrc.EOF Then
Charge = 0
Else
If IsNull(Trim(mrc.Fields(0))) Then
Charge = 0
Else
Charge = mrc.Fields(0)
End If
End If
txtchongka.Text = Charge
'退卡金额
txtSQL = "select sum(CancelCash)from CancelCard_Info where userID = '" & ComUserID.Text & "'" & " " & "and status = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF And mrc.EOF Then
Refund = 0
Else
If IsNull(Trim(mrc.Fields(0))) Then
Refund = 0
Else
Refund = mrc.Fields(0)
End If
End If
txttuiyue.Text = Refund
'临时金额
txtSQL = "select cardno from student_Info where userID = '" & ComUserID.Text & "'" & " " & "and Ischeck = '" & "未结账" & "'" & " " & "and type = '" & "临时用户" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF And mrc.EOF Then
temPorary = 0
Else
i = mrc.RecordCount
For j = 1 To i
cardid = mrc.Fields(0)
txtSQL1 = "select sum(cash) from line_Info where Ischeck = '" & "未结账" & "'" & _
" " & "and cardno = '" & cardid & "'"
Set mrcc = ExecuteSQL(txtSQL1, MsgText1)
If mrcc.BOF And mrcc.EOF Then
temPorary = 0
Else
If IsNull(mrcc.Fields(0)) Then
mrcc.Fields(0) = 0
End If
temPorary = mrcc.Fields(0) + temPorary
End If
mrc.MoveNext
Next
End If
txtlinshi.Text = temPorary
<span style="color:#ffffff;"> </strong></span></strong>
随后就是真正的结账内容了,单击结账按钮,需要完成表内容的更新,以及对消费金额,总的金额收入,还有总的售卡的统计等内容。
结账
<strong><strong>Private Sub cmdCheckout_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
Dim strSQL As String
Dim strMsg As String
Dim strMrc As ADODB.Recordset
Dim lastmoney As Single
'更新学生表
txtSQL = "select * from student_Info where userID = '" & ComUserID.Text & "'" & " " & "and Ischeck = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Do While mrc.EOF = False
mrc!IsCheck = "已结账"
mrc.MoveNext
Loop
mrc.Close
'更新充值表
txtSQL = "select * from ReCharge_Info where userID = '" & ComUserID.Text & "'" & " " & "and status = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Do While mrc.EOF = False
mrc!Status = "已结账"
mrc.MoveNext
Loop
mrc.Close
'更新退卡表
txtSQL = "select * from CancelCard_Info where userID = '" & ComUserID.Text & "'" & " " & "and status = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
Do While mrc.EOF = False
mrc!Status = "已结账"
mrc.MoveNext
Loop
mrc.Close
'消费金额
txtSQL = "select sum(consume)from line_Info where userID = '" & ComUserID.Text & "'" & " " & "and status = '" & "未结账" & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.BOF And mrc.EOF Then
Charge = 0
Else
If IsNull(Trim(mrc.Fields(0))) Then
Consume = 0
Else
Consume = mrc.Fields(0)
End If
End If
txtConsume.Text = Consume
'总售卡张数
txtzongshouka.Text = Register - Backcard
'总的收费金额
Total = Charge - Refund
txtyingshou.Text = Total
strSQL = "select * from CheckDay_Info "
Set strMrc = ExecuteSQL(strSQL, strMsg)
strMrc.MoveLast
lastmoney = strMrc.Fields(4)
strMrc.AddNew
strMrc.Fields(0) = lastmoney
strMrc.Fields(1) = Charge
strMrc.Fields(2) = Consume
strMrc.Fields(3) = Refund
strMrc.Fields(4) = Total
strMrc.Fields(5) = Date
strMrc.Update
strMrc.Close
MsgBox "结账成功!", vbOKOnly + vbInformation, "恭喜您"
Call notuse '这个过程使结账之后的文本框变为不可用,避免用户随意的改变(其实改也没关系,添加到数据库的数据还是查询内容为主,就是为了避免给用户一个误以为可以改动的错觉)
End Sub</strong></strong>
到现在为止,结账过程基本过程完成。当然需要不断的后续改进和优化,时刻保持为人民服务的原则,让程序可以做的更加完美。
【总结】
其实结账部分早就该完成,但是当我看到结账界面的复杂,我就有点恐惧了,现在做完之后,这些东西比想象中要简单多,做事情的时候千万别让“感觉很难”阻挡了脚步,无论是怎样的问题只需要我们脚踏实地的去做,一切都OK!