Public fMainForm As frmMain
Public UserName As String
Sub Main()
Dim fLogin As New frmLogin
fLogin.Show vbModal
If Not fLogin.OK Then
'Login Failed so exit app
End
End If
Unload fLogin
Set fMainForm = New frmMain
fMainForm.Show
End Sub
.........................................................................................................
Public Function ConnectString() _
As String
'returns a DB ConnectString
ConnectString = "FileDSN=studentinfo.dsn;UID=sa;PWD="
End Function
.......................................... SQL语句执行程序 ..............................................
Public Function ExecuteSQL(ByVal SQL _
As String, MsgString As String) _
As ADODB.Recordset
'executes SQL and returns Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", _
UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & _
" query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, _
adOpenKeyset, _
adLockOptimistic
'rst.MoveLast 'get RecordCount
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & _
" 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
MsgString = "查询错误: " & _
Err.Description
Resume ExecuteSQL_Exit
End Function
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public OK As Boolean
'记录确定次数
Dim miCount As Integer
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
miCount = 0
End Sub
Private Sub cmdCancel_Click()
OK = False
Me.Hide
End Sub
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim MsgText As String
'T
oDo: create test for correct password
'check for correct password
UserName = ""
If Trim(txtUserName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
txtSQL = "select * from user_Info where user_ID = '" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
OK = True
mrc.Close
Me.Hide
UserName = Trim(txtUserName.Text)
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtPassword.SetFocus
txtPassword.Text = ""
End If
End If
End If
miCount = miCount + 1
If miCount = 3 Then
Me.Hide
End If
Exit Sub
End Sub
............................... frmMain 系统主窗口代码 .........................................
Private Sub addcinfoMenu_Click()
frmAddclassinfo.Show
End Sub
Private Sub addcourseMenu_Click()
frmAddcourseinfo.Show
End Sub
Private Sub addresultMenu_Click()
frmAddresult.Show
End Sub
Private Sub addsinfoMenu_Click()
frmAddsinfo.Show
End Sub
Private Sub adduserMenu_Click()
frmAdduser.Show
sbStatusBar.Panels(1).Text = "添加用户"
End Sub
Private Sub exitMenu_Click()
End
End Sub
Private Sub exitsinfoMenu_Click()
Unload frminquireinfo
End Sub
Private Sub gradecourseMenu_Click()
frmSetcourseinfo.Show
End Sub
Private Sub inquireresultMenu_Click()
frmInquireresult.Show
End Sub
Private Sub inquiresinfoMenu_Click()
frmInquiresinfo.Show
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
If Me.WindowState <> vbMinimized Then
SaveSetting App.Title, "Settings", "MainLeft", Me.Left
SaveSetting App.Title, "Settings", "MainTop", Me.Top
SaveSetting App.Title, "Settings", "MainWidth", Me.Width
SaveSetting App.Title, "Settings", "MainHeight", Me.Height
End If
End Sub
Private Sub modifycinfoMenu_Click()
frmModifyclassinfo.Show
End Sub
Private Sub modifycourseMenu_Click()
frmModifycourseinfo.Show
End Sub
Private Sub modifypwdMenu_Click()
frmModifyuserinfo.Show
End Sub
Private Sub modifyresultMenu_Click()
frmModifyresult.Show
End Sub
Private Sub modifysinfo_Menu_Click()
frmModifysinfo.Show
End Sub
..........................................................................................................
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim MsgText As String
If Trim(Text1(0).Text) = "" Then
MsgBox "请输入用户名称!", vbOKOnly + vbExclamation, "警告"
Exit Sub
Text1(0).SetFocus
Else
txtSQL = "select * from user_Info "
Set mrc = ExecuteSQL(txtSQL, MsgText)
While (mrc.EOF = False)
If Trim(m
rc.Fields(0)) = Trim(Text1(0)) Then
MsgBox "用户已经存在,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
Text1(0).SetFocus
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Exit Sub
Else
mrc.MoveNext
End If
Wend
End If
If Trim(Text1(1).Text) <> Trim(Text1(2).Text) Then
MsgBox "两次输入密码不一样,请确认!", vbOKOnly + vbExclamation, "警告"
Text1(1).SetFocus
Text1(1).Text = ""
Text1(2).Text = ""
Exit Sub
Else
If Text1(1).Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbExclamation, "警告"
Text1(1).SetFocus
Text1(1).Text = ""
Text1(2).Text = ""
Else
mrc.AddNew
mrc.Fields(0) = Trim(Text1(0).Text)
mrc.Fields(1) = Trim(Text1(1).Text)
mrc.Update
mrc.Close
Me.Hide
MsgBox "添加用户成功!", vbOKOnly + vbExclamation, "添加用户"
End If
End If
End Sub
............................... frmAddsinfo 添加学籍信息窗口代码 .................................
Private Sub Command1_Click()
Dim mrc As ADODB.Recordset
Dim txtSQL As String
Dim MsgText As String
If Not Testtxt(txtSID.Text) Then
MsgBox "请输入学号!", vbOKOnly + vbExclamation, "警告"
txtSID.SetFocus
Exit Sub
End If
If Not Testtxt(txtName.Text) Then
MsgBox "请输入姓名!", vbOKOnly + vbExclamation, "警告"
txtName.SetFocus
Exit Sub
End If
If Not Testtxt(comboSex.Text) Then
MsgBox "请选择性别?quot;, vbOKOnly + vbExclamation, "警告"
comboSex.SetFocus
Exit Sub
End If
If Not Testtxt(txtBorndate.Text) Then
MsgBox "请输入出生日期!", vbOKOnly + vbExclamation, "警告"
txtBorndate.SetFocus
Exit Sub
End If
If Not Testtxt(comboClassNo.Text) Then
MsgBox "请选择班号!", vbOKOnly + vbExclamation, "警告"
comboClassNo.SetFocus
Exit Sub
End If
If Not Testtxt(txtTel.Text) Then
MsgBox "请输入联系电话!", vbOKOnly + vbExclamation, "警告"
txtTel.SetFocus
Exit Sub
End If
If Not Testtxt(txtRudate.Text) Then
MsgBox "请输入入校日期!", vbOKOnly + vbExclamation, "警告"
txtRudate.SetFocus
Exit Sub
End If
If Not Testtxt(txtAddress.Text) Then
MsgBox "请输入家庭住址!", vbOKOnly + vbExclamation, "警告"
txtAddress.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(txtSID.Text)) Then
MsgBox "请输入数字!", vbOKOnly + vbExclamation, "警告"
Exit Sub
txtSID.SetFocus
End If
txtSQL = "select * from student_Info where student_ID = '" & Trim(txtSID.Text) & "'"
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF = False Then
MsgBox "学号重复,请重新输入!", vbOKOnly + vbExclamation, "警告"
mrc.Close
txtSID.SetFocus
Else
mrc.Close
If Not IsDate(txtBorndate.Text) Then
MsgBox "出生时间应输入日期格式(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
txtBorndate.SetFocus
Else
txtBorndate = Format(txtBorndate, "yyyy-mm-dd")
If Not IsDate(txtRudate.Text) Then
MsgBox "入校时间应输入日期格式(yyyy-mm-dd)!", vbOKOnly + vbExclamation, "警告"
txtRudate.SetFocus
Else
txtRudate = Format(txtRudate, "yyyy-mm-dd")
txtSQL = "select * from student_Info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
mrc.AddNew
mrc.Fields(0) = Trim(txtSID.Text)
mrc.Fields(1) = Trim(txtName.Text)
mrc.Fields(2) = Trim(comboSex.Text)
mrc.Fields(3) = Trim(txtBorndate.Text)
mrc.Fields(4) = Trim(comboClassNo.T