一、登陆和登出
① 登陆
Sub Main() Dim flogin As New frmlogin flogin.Show vbModal 'flogin显示模式窗口' If Not flogin.ok Then '判断是否登陆成功' End End If flogin.Hide '登陆成功,登陆窗体隐藏,主窗体显示' MDIFrmmain.Show End Sub
Public ok As Boolean '判断是否登录成功' Dim meCount As Integer '判断登陆次数' Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long '登录按钮' Private Sub cmdOK_Click() Dim txtSQL, worklogSQL, OnWorkSQL As String Dim mrc, mrcworklog, mrcOnWork As ADODB.Recordset Dim MsgString As String If Trim(txtusername = "") Then MsgBox "用户名不能为空,请重新输入。", vbOKOnly + vbExclamation txtusername.SetFocus Else If Trim(txtpassword = "") Then MsgBox "密码不能为空,请重新输入。", vbOKOnly + vbExclamation txtpassword.SetFocus Else txtSQL = "select * from User_Info where userID = '" & txtusername.Text & "'" Set mrc = ExecuteSQL(txtSQL, MsgString) If mrc.EOF Then MsgBox "未查到用户名,请重新输入。", vbOKOnly + vbExclamation mrc.Close txtusername.SetFocus Else If Trim(txtpassword.Text) <> Trim(mrc.Fields(1)) Then MsgBox "密码输入错误,请重新输入。", vbOKOnly + vbExclamation txtpassword.SetFocus txtpassword.Text = "" Else worklogSQL = "select * from worklog_Info" Set mrcworklog = ExecuteSQL(worklogSQL, MsgString) mrcworklog.AddNew mrcworklog.Fields(1) = Trim(mrc.Fields(0)) mrcworklog.Fields(2) = Trim(mrc.Fields(2)) mrcworklog.Fields(3) = Date mrcworklog.Fields(4) = Time mrcworklog.Fields(7) = VBA.Environ("computername") mrcworklog.Fields(8) = "False" mrcworklog.Update OnWorkSQL = "select * from OnWork_Info where UserID ='" & txtusername.Text & "'" Set mrcOnWork = ExecuteSQL(OnWorkSQL, MsgString) If mrcOnWork.EOF Then '如果正在值班老师表中没有找到登陆ID,就添加进去' mrcOnWork.AddNew mrcOnWork.Fields(0) = Trim(txtusername.Text) mrcOnWork.Fields(1) = Trim(mrc.Fields(2)) mrcOnWork.Fields(2) = Date mrcOnWork.Fields(3) = Time mrcOnWork.Fields(4) = VBA.Environ("computername") mrcOnWork.Update Else '有就覆盖' mrcOnWork.Fields(0) = Trim(txtusername.Text) mrcOnWork.Fields(1) = Trim(mrc.Fields(2)) mrcOnWork.Fields(2) = Date mrcOnWork.Fields(3) = Time mrcOnWork.Fields(4) = VBA.Environ("computername") mrcOnWork.Update End If ok = True mrc.Close mrcworklog.Close ' mrcOnWork.Close Me.Hide '记录登陆的账号' UserName = Trim(txtusername.Text) '记录账号登陆时间' LoginD = Date LoginT = Time End If End If End If End If meCount = meCount + 1 If meCount = 3 Then MsgBox "登陆次数已用尽", 0, "温馨提示" Unload Me End If End Sub Private Sub Form_Load() Dim sBuffer As String Dim lSize As Long sBuffer = Space(255) lSize = Len(sBuffer) Call GetUserName(sBuffer, lSize) If lSize > 0 Then txtusername.Text = "" Else txtusername.Text = vbNullString End If ok = False meCount = 0 '累计登陆次数清0' End Sub
② 登出
登出有两个位置
'退出按钮' Private Sub Quit_Click() Dim worklogSQL, OnWorkSQL, MsgText As String Dim mrcworklog, mrcOnWork As ADODB.Recordset If MsgBox("确定要退出系统吗?", vbYesNo) = vbYes Then worklogSQL = "select * from worklog_Info where UserID='" & UserName & "'and LoginTime='" & LoginT & "'and LoginDate='" & LoginD & "'" Set mrcworklog = ExecuteSQL(worklogSQL, MsgText) ' If Not mrcworklog.EOF Then mrcworklog.Fields(5) = Date mrcworklog.Fields(6) = Time mrcworklog.Update mrcworklog.Close '从OnWork表中删除上机记录' OnWorkSQL = "delete from OnWork_Info where UserID='" & UserName & "'" Set mrcOnWork = ExecuteSQL(OnWorkSQL, MsgText) End Else Cancel = 1 End If End Sub
'点击右上角X提示是否退出系统' Public Sub MDIForm_unLoad(Cancel As Integer) Dim worklogSQL, OnWorkSQL, MsgText As String Dim mrcworklog, mrcOnWork As ADODB.Recordset If MsgBox("确定要退出系统吗?", vbYesNo) = vbYes Then worklogSQL = "select * from worklog_Info where UserID='" & UserName & "'and LoginTime='" & LoginT & "'and LoginDate='" & LoginD & "'" Set mrcworklog = ExecuteSQL(worklogSQL, MsgText) ' If Not mrcworklog.EOF Then mrcworklog.Fields(5) = Date mrcworklog.Fields(6) = Time mrcworklog.Update mrcworklog.Close '从OnWork表中删除上机记录 OnWorkSQL = "delete from OnWork_Info where UserID='" & UserName & "'" Set mrcOnWork = ExecuteSQL(OnWorkSQL, MsgText) End Else Cancel = 1 End If End Sub
二、组合查询
① 上机统计信息
Public Function FiledName(a As String) As String Select Case a Case "卡号" FiledName = "cardno" Case "姓名" FiledName = "StudentName" Case "上机日期" FiledName = "ondate" Case "上机时间" FiledName = "ontime" Case "下机日期" FiledName = "offdate" Case "下机时间" FiledName = "offtime" Case "消费金额" FiledName = "consume" Case "余额" FiledName = "cash" Case "与" FiledName = " And " Case "或" FiledName = " Or " End Select End Function
'查询按钮' Private Sub cmdInquiry_Click() Dim txtSQL, MsgText As String Dim dd(4) As Boolean Dim mrc As ADODB.Recordset On Error GoTo Linemod_Error txtSQL = "select * from Line_Info where " If Trim(comboField1.Text <> "") Or Trim(comboOpSign1.Text <> "") Or Trim(InquiryContent1.Text <> "") Then If Trim(comboField1.Text = "") Or Trim(comboOpSign1.Text = "") Or Trim(InquiryContent1.Text = "") Then MsgBox "第一条查询条件不可空缺!", 0, "系统提示" Exit Sub Else dd(0) = True txtSQL = txtSQL & FiledName(comboField1.Text) & Trim(comboOpSign1.Text) & "'" & Trim(InquiryContent1.Text) & "'" End If End If If Trim(comboField2.Text <> "") Or Trim(comboOpSign2.Text <> "") Or Trim(InquiryContent2.Text <> "") Then If Trim(comboField2.Text = "") Or Trim(comboOpSign2.Text = "") Or Trim(InquiryContent2.Text = "") Then MsgBox "请把第二条查询条件填写完整!", 0, "系统提示" Exit Sub Else dd(1) = True If Not dd(0) Then txtSQL = txtSQL & FiledName(comboField2.Text) & Trim(comboOpSign2.Text) & "'" & Trim(InquiryContent2.Text) & "'" Else If comboCombineRelation1.Text = "" Then MsgBox "请选择第一条组合关系!", 0, "系统提示" Exit Sub Else txtSQL = txtSQL & " " & FiledName(comboCombineRelation1.Text) & " " & FiledName(comboField2.Text) & " " & Trim(comboOpSign2.Text) & " " & "'" & Trim(InquiryContent2.Text) & "'" End If End If End If End If If Trim(comboField3.Text <> "") Or Trim(comboOpSign3.Text <> "") Or Trim(InquiryContent3.Text <> "") Then If Trim(comboField3.Text = "") Or Trim(comboOpSign3.Text = "") Or Trim(InquiryContent3.Text = "") Then MsgBox "请把第三条查询条件填写完整!", 0, "系统提示" Exit Sub Else dd(2) = True If Not dd(1) Then txtSQL = txtSQL & FiledName(comboField3.Text) & Trim(comboOpSign3.Text) & "'" & Trim(InquiryContent3.Text) & "'" Else If comboCombineRelation2.Text = "" Then MsgBox "请选择第二条组合关系!", 0, "系统提示" Exit Sub Else txtSQL = txtSQL & " " & FiledName(comboCombineRelation2.Text) & " " & FiledName(comboField2.Text) & Trim(comboOpSign2.Text) & " " & "'" & Trim(InquiryContent2.Text) & "'" If dd(0) And dd(1) Then txtSQL = txtSQL & " " & FiledName(comboCombineRelation1.Text) & " " & FiledName(comboField1.Text) & " " & Trim(comboOpSign1.Text) & " " & "'" & Trim(InquiryContent1.Text) & "'" End If End If End If End If End If If dd(0) = True And dd(1) = False And dd(2) = True Then dd(3) = True MsgBox "不可跨行查询!", 0, "系统提示" Exit Sub End If If Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then MsgBox "请设置查询方式!", vbOKOnly + vbExclamation, "警告" Exit Sub End If Set mrc = ExecuteSQL(txtSQL, MsgText) With MSHFlexGrid1 .rows = 1 .TextMatrix(0, 0) = "编号" .TextMatrix(0, 1) = "卡号" .TextMatrix(0, 2) = "姓名" .TextMatrix(0, 3) = "上机日期" .TextMatrix(0, 4) = "上机时间" .TextMatrix(0, 5) = "下机日期" .TextMatrix(0, 6) = "下机时间" .TextMatrix(0, 7) = "消费金额" .TextMatrix(0, 8) = "余额" If Not (mrc.BOF Or mrc.EOF) Then For i = 0 To n Do While Not mrc.EOF i = i + 1 .rows = .rows + 1 .CellAlignment = 4 .TextMatrix(.rows - 1, 0) = i .TextMatrix(.rows - 1, 1) = Trim(mrc.Fields(1)) .TextMatrix(.rows - 1, 2) = Trim(mrc.Fields(2)) .TextMatrix(.rows - 1, 3) = Trim(mrc.Fields(6)) .TextMatrix(.rows - 1, 4) = Trim(mrc.Fields(7)) .TextMatrix(.rows - 1, 5) = Trim(mrc.Fields(8)) & "" .TextMatrix(.rows - 1, 6) = Trim(mrc.Fields(9)) & "" .TextMatrix(.rows - 1, 7) = Trim(mrc.Fields(11)) .TextMatrix(.rows - 1, 8) = Trim(mrc.Fields(12)) mrc.MoveNext Loop Next i MsgBox "筛选条件信息显示完毕!", vbOKOnly, "提示!" Else MsgBox "筛选条件中未找到任何信息!", vbOKOnly, "提示" End If End With mrc.Close Linemod_Exit: Exit Sub Linemod_Error: With MSHFlexGrid1 .rows = 1 .TextMatrix(0, 0) = "编号" .TextMatrix(0, 1) = "卡号" .TextMatrix(0, 2) = "姓名" .TextMatrix(0, 3) = "上机日期" .TextMatrix(0, 4) = "上机时间" .TextMatrix(0, 5) = "下机日期" .TextMatrix(0, 6) = "下机时间" .TextMatrix(0, 7) = "消费金额" .TextMatrix(0, 8) = "余额" End With MsgString = "查询错误:" & Err.Description Resume Linemod_Exit End Sub
② 操作员工记录
Public Function FiledName(a As String) As String Select Case a Case "教师编号" FiledName = "UserID" Case "级别" FiledName = "level" Case "注册日期" FiledName = "LoginDate" Case "注册时间" FiledName = "LoginTime" Case "注销日期" FiledName = "LogoutDate" Case "注销时间" FiledName = "LogoutTime" Case "机器名" FiledName = "computer" Case "状态" FiledName = "status" Case "与" FiledName = " And " Case "或" FiledName = " Or " End Select End Function
'查询按钮' Private Sub cmdInquiry_Click() Dim txtSQL, UserSQL, MsgText As String Dim dd(4) As Boolean Dim mrc, mrcUser As ADODB.Recordset On Error GoTo worklogmod_Error txtSQL = "select * from worklog_Info where " If Trim(comboField1.Text <> "") Or Trim(comboOpSign1.Text <> "") Or Trim(InquiryContent1.Text <> "") Then If Trim(comboField1.Text = "") Or Trim(comboOpSign1.Text = "") Or Trim(InquiryContent1.Text = "") Then MsgBox "第一条查询条件不可空缺!", 0, "系统提示" Exit Sub Else dd(0) = True txtSQL = txtSQL & FiledName(comboField1.Text) & Trim(comboOpSign1.Text) & "'" & Trim(InquiryContent1.Text) & "'" End If End If If Trim(comboField2.Text <> "") Or Trim(comboOpSign2.Text <> "") Or Trim(InquiryContent2.Text <> "") Then If Trim(comboField2.Text = "") Or Trim(comboOpSign2.Text = "") Or Trim(InquiryContent2.Text = "") Then MsgBox "请把第二条查询条件填写完整!", 0, "系统提示" Exit Sub Else dd(1) = True If Not dd(0) Then txtSQL = txtSQL & FiledName(comboField2.Text) & Trim(comboOpSign2.Text) & "'" & Trim(InquiryContent2.Text) & "'" Else If comboCombineRelation1.Text = "" Then MsgBox "请选择第一条组合关系!", 0, "系统提示" Exit Sub Else txtSQL = txtSQL & " " & FiledName(comboCombineRelation1.Text) & " " & FiledName(comboField2.Text) & " " & Trim(comboOpSign2.Text) & " " & "'" & Trim(InquiryContent2.Text) & "'" End If End If End If End If If Trim(comboField3.Text <> "") Or Trim(comboOpSign3.Text <> "") Or Trim(InquiryContent3.Text <> "") Then If Trim(comboField3.Text = "") Or Trim(comboOpSign3.Text = "") Or Trim(InquiryContent3.Text = "") Then MsgBox "请把第三条查询条件填写完整!", 0, "系统提示" Exit Sub Else dd(2) = True If Not dd(1) Then txtSQL = txtSQL & FiledName(comboField3.Text) & Trim(comboOpSign3.Text) & "'" & Trim(InquiryContent3.Text) & "'" Else If comboCombineRelation2.Text = "" Then MsgBox "请选择第二条组合关系!", 0, "系统提示" Exit Sub Else txtSQL = txtSQL & " " & FiledName(comboCombineRelation2.Text) & " " & FiledName(comboField2.Text) & Trim(comboOpSign2.Text) & " " & "'" & Trim(InquiryContent2.Text) & "'" If dd(0) And dd(1) Then txtSQL = txtSQL & " " & FiledName(comboCombineRelation1.Text) & " " & FiledName(comboField1.Text) & " " & Trim(comboOpSign1.Text) & " " & "'" & Trim(InquiryContent1.Text) & "'" End If End If End If End If End If If dd(0) = True And dd(1) = False And dd(2) = True Then dd(3) = True MsgBox "不可跨行查询!", 0, "系统提示" Exit Sub End If If Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then MsgBox "请设置查询方式!", vbOKOnly + vbExclamation, "警告" Exit Sub Exit Sub End If Set mrc = ExecuteSQL(txtSQL, MsgText) With MSHFlexGrid1 .rows = 1 .TextMatrix(0, 0) = "编号" .TextMatrix(0, 1) = "教师编号" .TextMatrix(0, 2) = "级别" .TextMatrix(0, 3) = "注册日期" .TextMatrix(0, 4) = "注册时间" .TextMatrix(0, 5) = "注销日期" .TextMatrix(0, 6) = "注销时间" .TextMatrix(0, 7) = "机器名" .TextMatrix(0, 8) = "状态" If Not (mrc.BOF Or mrc.EOF) Then For i = 0 To n Do While Not mrc.EOF i = i + 1 .rows = .rows + 1 .CellAlignment = 4 .TextMatrix(.rows - 1, 0) = i .TextMatrix(.rows - 1, 1) = Trim(mrc.Fields(1)) .TextMatrix(.rows - 1, 2) = Trim(mrc.Fields(2)) .TextMatrix(.rows - 1, 3) = Trim(mrc.Fields(3)) .TextMatrix(.rows - 1, 4) = Trim(mrc.Fields(4)) .TextMatrix(.rows - 1, 5) = Trim(mrc.Fields(5)) & "" .TextMatrix(.rows - 1, 6) = Trim(mrc.Fields(6)) & "" .TextMatrix(.rows - 1, 7) = Trim(mrc.Fields(7)) .TextMatrix(.rows - 1, 8) = Trim(mrc.Fields(8)) mrc.MoveNext Loop Next i MsgBox "筛选条件信息显示完毕!", vbOKOnly, "提示!" Else MsgBox "筛选条件中未找到任何信息!", vbOKOnly, "提示" End If End With mrc.Close worklogmod_Exit: Exit Sub worklogmod_Error: With MSHFlexGrid1 .rows = 1 .TextMatrix(0, 0) = "编号" .TextMatrix(0, 1) = "教师编号" .TextMatrix(0, 2) = "级别" .TextMatrix(0, 3) = "注册日期" .TextMatrix(0, 4) = "注册时间" .TextMatrix(0, 5) = "注销日期" .TextMatrix(0, 6) = "注销时间" .TextMatrix(0, 7) = "机器名" .TextMatrix(0, 8) = "状态" End With MsgString = "查询错误:" & Err.Description Resume worklogmod_Exit End Sub=
③ 查看学生基本信息
Public Function FiledName(a As String) As String Select Case a Case "学号" FiledName = "studentNo" Case "卡号" FiledName = "cardno" Case "姓名" FiledName = "studentName" Case "性别" FiledName = "sex" Case "系别" FiledName = "department" Case "年级" FiledName = "grade" Case "班级" FiledName = "class" Case "余额" FiledName = "cash" Case "备注" FiledName = "explain" Case "注册日期" FiledName = "date" Case "注册时间" FiledName = "time" Case "用户类型" FiledName = "type" Case "与" FiledName = " And " Case "或" FiledName = " Or " End Select End Function
'查询按钮' Private Sub cmdInquiry_Click() Dim txtSQL, MsgText As String Dim dd(4) As Boolean Dim mrc As ADODB.Recordset On Error GoTo studentmod_Error txtSQL = "select * from student_Info where " If Trim(comboField1.Text <> "") Or Trim(comboOpSign1.Text <> "") Or Trim(InquiryContent1.Text <> "") Then If Trim(comboField1.Text = "") Or Trim(comboOpSign1.Text = "") Or Trim(InquiryContent1.Text = "") Then MsgBox "第一条查询条件不可空缺!", 0, "系统提示" Exit Sub Else dd(0) = True txtSQL = txtSQL & FiledName(comboField1.Text) & Trim(comboOpSign1.Text) & "'" & Trim(InquiryContent1.Text) & "'" End If End If If Trim(comboField2.Text <> "") Or Trim(comboOpSign2.Text <> "") Or Trim(InquiryContent2.Text <> "") Then If Trim(comboField2.Text = "") Or Trim(comboOpSign2.Text = "") Or Trim(InquiryContent2.Text = "") Then MsgBox "请把第二条查询条件填写完整!", 0, "系统提示" Exit Sub Else dd(1) = True If Not dd(0) Then txtSQL = txtSQL & FiledName(comboField2.Text) & Trim(comboOpSign2.Text) & "'" & Trim(InquiryContent2.Text) & "'" Else If comboCombineRelation1.Text = "" Then MsgBox "请选择第一条组合关系!", 0, "系统提示" Exit Sub Else txtSQL = txtSQL & " " & FiledName(comboCombineRelation1.Text) & " " & FiledName(comboField2.Text) & " " & Trim(comboOpSign2.Text) & " " & "'" & Trim(InquiryContent2.Text) & "'" End If End If End If End If If Trim(comboField3.Text <> "") Or Trim(comboOpSign3.Text <> "") Or Trim(InquiryContent3.Text <> "") Then If Trim(comboField3.Text = "") Or Trim(comboOpSign3.Text = "") Or Trim(InquiryContent3.Text = "") Then MsgBox "请把第三条查询条件填写完整!", 0, "系统提示" Exit Sub Else dd(2) = True If Not dd(1) Then txtSQL = txtSQL & FiledName(comboField3.Text) & Trim(comboOpSign3.Text) & "'" & Trim(InquiryContent3.Text) & "'" Else If comboCombineRelation2.Text = "" Then MsgBox "请选择第二条组合关系!", 0, "系统提示" Exit Sub Else txtSQL = txtSQL & " " & FiledName(comboCombineRelation2.Text) & " " & FiledName(comboField2.Text) & Trim(comboOpSign2.Text) & " " & "'" & Trim(InquiryContent2.Text) & "'" If dd(0) And dd(1) Then txtSQL = txtSQL & " " & FiledName(comboCombineRelation1.Text) & " " & FiledName(comboField1.Text) & " " & Trim(comboOpSign1.Text) & " " & "'" & Trim(InquiryContent1.Text) & "'" End If End If End If End If End If If dd(0) = True And dd(1) = False And dd(2) = True Then dd(3) = True MsgBox "不可跨行查询!", 0, "系统提示" Exit Sub End If If Not (dd(0) Or dd(1) Or dd(2) Or dd(3)) Then MsgBox "请设置查询方式!", vbOKOnly + vbExclamation, "警告" Exit Sub End If Set mrc = ExecuteSQL(txtSQL, MsgText) With MSHFlexGrid1 .rows = 1 .TextMatrix(0, 0) = "编号" .TextMatrix(0, 1) = "卡号" .TextMatrix(0, 2) = "学号" .TextMatrix(0, 3) = "姓名" .TextMatrix(0, 4) = "性别" .TextMatrix(0, 5) = "系别" .TextMatrix(0, 6) = "年级" .TextMatrix(0, 7) = "班级" .TextMatrix(0, 8) = "余额" .TextMatrix(0, 9) = "备注" .TextMatrix(0, 10) = "状态" .TextMatrix(0, 11) = "注册日期" .TextMatrix(0, 12) = "注册时间" .TextMatrix(0, 13) = "用户类型" If Not (mrc.BOF Or mrc.EOF) Then For i = 0 To n Do While Not mrc.EOF i = i + 1 .rows = .rows + 1 .CellAlignment = 4 .TextMatrix(.rows - 1, 0) = i .TextMatrix(.rows - 1, 1) = Trim(mrc.Fields(0)) .TextMatrix(.rows - 1, 2) = Trim(mrc.Fields(1)) .TextMatrix(.rows - 1, 3) = Trim(mrc.Fields(2)) .TextMatrix(.rows - 1, 4) = Trim(mrc.Fields(3)) .TextMatrix(.rows - 1, 5) = Trim(mrc.Fields(4)) .TextMatrix(.rows - 1, 6) = Trim(mrc.Fields(5)) .TextMatrix(.rows - 1, 7) = Trim(mrc.Fields(6)) .TextMatrix(.rows - 1, 8) = Trim(mrc.Fields(7)) .TextMatrix(.rows - 1, 9) = Trim(mrc.Fields(8)) & "" .TextMatrix(.rows - 1, 10) = Trim(mrc.Fields(10)) .TextMatrix(.rows - 1, 11) = Trim(mrc.Fields(11)) .TextMatrix(.rows - 1, 12) = Trim(mrc.Fields(12)) .TextMatrix(.rows - 1, 13) = Trim(mrc.Fields(13)) mrc.MoveNext Loop Next i MsgBox "筛选条件信息显示完毕!", vbOKOnly, "提示!" Else MsgBox "筛选条件中未找到任何信息!", vbOKOnly, "提示" End If End With mrc.Close studentmod_Exit: Exit Sub studentmod_Error: With MSHFlexGrid1 .rows = 1 .TextMatrix(0, 0) = "编号" .TextMatrix(0, 1) = "卡号" .TextMatrix(0, 2) = "学号" .TextMatrix(0, 3) = "姓名" .TextMatrix(0, 4) = "性别" .TextMatrix(0, 5) = "系别" .TextMatrix(0, 6) = "年级" .TextMatrix(0, 7) = "班级" .TextMatrix(0, 8) = "余额" .TextMatrix(0, 9) = "备注" .TextMatrix(0, 10) = "状态" .TextMatrix(0, 11) = "注册日期" .TextMatrix(0, 12) = "注册时间" .TextMatrix(0, 13) = "用户类型" End With MsgString = "查询错误:" & Err.Description Resume studentmod_Exit End Sub