【前言】
对于机房收费系统的管理员下结账功能这一部分,重要的需要理清楚逻辑思路,逻辑很重要。具体的部分在下面作出具体解释。
【正文】
整体思路:
一、对于SSTab1中需要显示信息的购卡、充值、退卡、临时用户这四部分中,不受操作员用户名限制的基本信息可以先在窗体Load事件中实现。同时在窗体加载过程中,对于操作员的用户名和真实姓名的信息也是在窗体加载时显示出来。具体如下:
'在combobox框中显示数据库中关于操作员的信息 txtSQL = "select * from user_info where level='" & "操作员" & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) Do While mrc.EOF = False comboUserID.AddItem mrc.Fields(0) mrc.MoveNext Loop '购卡基本信息 MfgBuyCard.TextMatrix(0, 0) = "学号" MfgBuyCard.TextMatrix(0, 1) = "卡号" MfgBuyCard.TextMatrix(0, 2) = "日期" MfgBuyCard.TextMatrix(0, 3) = "时间" '充值基本信息 MfgRecharge.TextMatrix(0, 0) = "学号" MfgRecharge.TextMatrix(0, 1) = "卡号" MfgRecharge.TextMatrix(0, 2) = "充值金额" MfgRecharge.TextMatrix(0, 3) = "日期" MfgRecharge.TextMatrix(0, 4) = "时间" '退卡基本信息 MfgCancelCard.TextMatrix(0, 0) = "学号" MfgCancelCard.TextMatrix(0, 1) = "卡号" MfgCancelCard.TextMatrix(0, 2) = "日期" MfgCancelCard.TextMatrix(0, 3) = "时间" MfgCancelCard.TextMatrix(0, 4) = "退卡金额" '临时用户基本信息 MfgTemporary.TextMatrix(0, 0) = "学号" MfgTemporary.TextMatrix(0, 1) = "卡号" MfgTemporary.TextMatrix(0, 2) = "日期" MfgTemporary.TextMatrix(0, 3) = "时间"
二、在购卡、充值、退卡、临时用户这四部分中信息的基本内容就收到操作员的影响,不同的操作员在这四部分中显示的信息是不同的,因此,对于这一部分,我定义了一个过程:
Private Sub viewdata() Dim mrcBC As ADODB.Recordset Dim mrcRC As ADODB.Recordset Dim mrccc As ADODB.Recordset '购卡具体信息 txtSQL = "select * from student_Info where Ischeck ='未结账' and UserID='" & Trim(comboUserID.Text) & "'" Set mrcBC = ExecuteSQL(txtSQL, Msgtext) With MfgBuyCard While mrcBC.EOF = False .Rows = .Rows + 1 .TextMatrix(.Rows - 1, 0) = mrcBC.Fields(1) .TextMatrix(.Rows - 1, 1) = mrcBC.Fields(0) .TextMatrix(.Rows - 1, 2) = mrcBC.Fields(12) .TextMatrix(.Rows - 1, 3) = mrcBC.Fields(13) mrcBC.MoveNext Wend End With '充值基本信息 txtSQL = "select studentno,cardno,addmoney,date,time from recharge_Info where status ='未结账' and UserID='" & Trim(comboUserID.Text) & "'" Set mrcRC = ExecuteSQL(txtSQL, Msgtext) With MfgRecharge While mrcRC.EOF = False .Rows = .Rows + 1 .TextMatrix(.Rows - 1, 0) = mrcRC.Fields(0) .TextMatrix(.Rows - 1, 1) = mrcRC.Fields(1) .TextMatrix(.Rows - 1, 2) = mrcRC.Fields(2) .TextMatrix(.Rows - 1, 3) = mrcRC.Fields(3) .TextMatrix(.Rows - 1, 4) = mrcRC.Fields(4) mrcRC.MoveNext Wend End With '退卡基本信息 txtSQL = "select studentno,cardno,date,time,cancelcash from cancelcard_info where status='未结账' and userid ='" & Trim(comboUserID.Text) & "'" Set mrccc = ExecuteSQL(txtSQL, Msgtext) With MfgCancelCard While mrcRC.EOF = False .Rows = .Rows + 1 .TextMatrix(.Rows - 1, 0) = mrcRC.Fields(0) .TextMatrix(.Rows - 1, 1) = mrcRC.Fields(1) .TextMatrix(.Rows - 1, 2) = mrcRC.Fields(2) .TextMatrix(.Rows - 1, 3) = mrcRC.Fields(3) .TextMatrix(.Rows - 1, 4) = mrcRC.Fields(4) mrccc.MoveNext Wend End With '临时用户基本信息 'txtSQL = "select * from student_Info where Ischeck ='未结账' and UserID='" & Trim(comboUserID.Text) & "'" '注意与下列语句的区别 txtSQL = "select studentno,cardno,date,time from student_Info where ischeck ='未结账' and type ='临时用户' and userid='" & Trim(comboUserID.Text) & "'" Set mrcBC = ExecuteSQL(txtSQL, Msgtext) With MfgTemporary While mrcBC.EOF = False .Rows = .Rows + 1 .TextMatrix(.Rows - 1, 0) = mrcBC.Fields(0) .TextMatrix(.Rows - 1, 1) = mrcBC.Fields(1) .TextMatrix(.Rows - 1, 2) = mrcBC.Fields(2) .TextMatrix(.Rows - 1, 3) = mrcBC.Fields(3) mrcBC.MoveNext Wend End With
具体信息在该过程中实现后,在选出不同的操作员的时候直接调用该过程就可以,减少了代码的重复性:
Private Sub comboName_click() txtSQL = "select * from user_info where username='" & Trim(comboName.Text) & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) comboUserID.Text = mrc.Fields(0) Call viewdata End Sub Private Sub comboUserID_click() txtSQL = "select * from user_info where userid='" & Trim(comboUserID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) comboName.Text = mrc.Fields(3) Call viewdata End Sub
具体结账部分的思路:
在SSTab1中的结账部分,显示的内容也不算难,重要的就是理清思路,理解每一个文本框中需要显示的内容一切也都不是问题。其内容主要有售卡张数、退卡张数、充值金额、临时收费金额、退卡金额、总售卡数、应收金额,对于总售卡数来说,即为售卡张数减去退卡张数;应收金额等于充值金额减去退卡金额,刚开始认为临时用户的收费金额应当算到应收金额中,但是后来想了想,临时收费金额在充值金额中已经被算上了,因此在这里不用再次算入其中。(希望大家可以提出不同的见解,我们一起进行讨论)
''''''''''''''结账部分显示的内容 '售卡张数 txtSQL = "select * from student_info where ischeck ='未结账' and UserID='" & Trim(comboUserID.Text) & "'" '售卡张数 Set mrc = ExecuteSQL(txtSQL, Msgtext) txtCradNumber = mrc.RecordCount '退卡张数 txtSQL = "select * from cancelcard_info where status='未结账'and UserID='" & Trim(comboUserID.Text) & "'" '退卡张数 Set mrc = ExecuteSQL(txtSQL, Msgtext) txtBackCardNumber = mrc.RecordCount '总售卡数 txtAllCardNumber.Text = Val(txtCradNumber.Text) - Val(txtBackCardNumber) '充值金额 Dim recharge As Variant txtSQL = "select sum(addmoney)from recharge_info where status='未结账' and UserID='" & Trim(comboUserID.Text) & "'" '充值金额 Set mrc = ExecuteSQL(txtSQL, Msgtext) If mrc.BOF And mrc.EOF Then recharge = 0 Else If IsNull(Trim(mrc.Fields(0))) Then recharge = 0 Else recharge = mrc.Fields(0) End If End If txtRechargeCash.Text = recharge '退卡金额 txtSQL = "select sum(cancelcash)from cancelcard_info where status='未结账' and UserID='" & Trim(comboUserID.Text) & "'" '退卡金额 Set mrc = ExecuteSQL(txtSQL, Msgtext) If mrc.BOF And mrc.EOF Then recharge = 0 Else If IsNull(Trim(mrc.Fields(0))) Then recharge = 0 Else recharge = mrc.Fields(0) End If End If txtCancelCash.Text = recharge '临时收费金额 Dim temporaryCash As Variant txtSQL = "select sum(cash)from student_info where ischeck ='未结账'and type ='临时用户' and UserID='" & Trim(comboUserID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) If mrc.BOF And mrc.EOF Then temporaryCash = 0 Else If IsNull(Trim(mrc.Fields(0))) Then temporaryCash = 0 Else temporaryCash = mrc.Fields(0) End If End If txtTemporaryCash.Text = temporaryCash '应收金额 Dim consume As Variant, cancelcash As Variant '''''''''充值金额 txtSQL = "select sum(cash)from student_info where ischeck='未结账' and UserID='" & Trim(comboUserID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) If mrc.BOF And mrc.EOF Then recharge = 0 Else If IsNull(Trim(mrc.Fields(0))) Then recharge = 0 Else recharge = mrc.Fields(0) End If End If txtAllCash.Text = recharge ''''''''''退卡金额 txtSQL = "select sum(cancelcash)from cancelcard_info where status='未结账' and UserID='" & Trim(comboUserID.Text) & "'" Set mrc = ExecuteSQL(txtSQL, Msgtext) If mrc.BOF And mrc.EOF Then cancelcash = 0 Else If IsNull(Trim(mrc.Fields(0))) Then cancelcash = 0 Else cancelcash = mrc.Fields(0) End If End If txtAllCash.Text = txtAllCash.Text - cancelcash
【总结】
一、逻辑思路对于我们来说很重要,我们应该着力去培养
二、在写代码的时候要细心,有时候一个微小的错误都会浪费很多时间
三、自己的代码调试能力还不够,希望自己可以在以后中着重培养