登高而望远,感觉机房收费系统也是如此,刚开始敲机房的时候就觉得会有很多细节去考虑和添加,自己也尽量边敲边完善,但毕竟身在此山中,云深不知处。有很多东西是当时所不曾考虑到的,所以越到后面问题所暴露出来的也就越多,下面是自己对部分细节的优化:
1、临时用户下机相当于退卡
txtSQL = "select * from student_Info where type ='临时用户' and cardno ='" & Trim(txtCardNo.Text) & "'" '如果是临时用户下机相当于退卡 Set mrc5 = ExecuteSQL(txtSQL, MsgText) If Not (mrc5.BOF And mrc5.EOF) Then mrc5.Fields(10) = Trim("不使用") mrc5.Update
If Trim(CStr(mrc.Fields(10))) = "不使用" Then '注销的卡号如果再次使用需要重新激活 a = MsgBox("此卡已注销,是否重新激活?!", vbYesNo + vbQuestion, "提示") If a = vbYes Then txtSQL = "update student_Info set status= '" & Trim("使用") & "' where cardno = '" & txtCardNo.Text & "'" Else txtCardNo.Text = "" txtCardNo.SetFocus Exit Sub
txtSQL = "select * from User_Info where UserID ='" & UserName & "'" '根据用户名来判断用户等级 Set mrc1 = ExecuteSQL(txtSQL, MsgText) If Not (mrc1.BOF And mrc1.EOF) Then strLevel = mrc1.Fields(2) '给正在值班老师表增加一行记录 txtSQL = "select * from OnWork_info" Set mrc2 = ExecuteSQL(txtSQL, MsgText) mrc2.AddNew mrc2.Fields(0) = UserName mrc2.Fields(1) = strLevel mrc2.Fields(2) = Format(Date, "yyyy-mm-dd") mrc2.Fields(3) = Format(Time, "hh:mm:ss") mrc2.Fields(4) = Trim(VBA.Environ("computername")) mrc2.Update '给值班记录表添加记录 txtSQL = "select * from worklog_info" Set mrcc = ExecuteSQL(txtSQL, MsgText) mrcc.AddNew mrcc.Fields(1) = UserName mrcc.Fields(2) = strLevel mrcc.Fields(3) = Format(Date, "yyyy-mm-dd") mrcc.Fields(4) = Format(Time, "hh:mm:ss") mrcc.Fields(7) = Trim(VBA.Environ("computername")) mrcc.Fields(8) = Trim(True) mrcc.Update
</pre><pre>3、全部学生下机,开始的时候完全没思路,后来问的贾文静同学,用了一个循环。
Private Sub AllStudent_Click() Dim i, j As Single '定义一个循环 With myflexgrid If myflexgrid.Rows < 2 Then '如果表格行数小于2的话... MsgBox "暂无学生上机" Else With myflexgrid i = myflexgrid.Rows - 1 'i=记录数 For j = i To 1 Step -1 '从 j = i 到 1 步长 -1 myflexgrid.RowSel = j '选中j行 Call viewdata 'Call了一个选中下机过程 Next j MsgBox "恭喜您,全部下机成功!", vbOKOnly + vbInformation, "恭喜您" End With End If End With End Sub
myflexgrid.SelectionMode = flexSelectionByRow '单击的时候选择的是整行 myflexgrid.FocusRect = flexFocusNone '在当前单元的周围画一个焦点框 myflexgrid.HighLight = flexHighlightWithFocus '该值决定了所选定的单元是否突出显示 .RemoveItem .RowSel '移除所选的那行5、根据用户不同的等级来限制用户的管理权限
Private Sub MDIForm_Load() Dim mrcc As ADODB.Recordset Dim txtSQL As String Dim MsgText As String Dim strLevel As String '定义变量 txtSQL = "select * from User_Info where UserID ='" & UserName & "'" '根据用户名来判断用户等级 Set mrcc = ExecuteSQL(txtSQL, MsgText) strLevel = mrcc!Level Select Case Trim(strLevel) Case "管理员" Case "操作员" '如果是操作员,则管理员那一栏不可用 administrator.Enabled = False Case "一般用户" '如果是一般用户,则管理员和操作员两栏不可用 administrator.Enabled = False operator.Enabled = False End Select End Sub6、如果有些地方实在是不好解决的话,在不伤大雅的情况下还是可以用下On Error GoTo进行错误跳转的。