1、Imports System.DataImports System.Data.OleDbPublic Class Login Inherits System.Windows.Forms.FormDim ServerLog As New AddServer Dim StrServer As String = ServerLog.TSever.Text Private Conn As New OleDbConnection(Integrated Security=SSPI;Packet Size=4096;Data Source= & StrServer & ;Tag with column co
2、llation when possible=False;Initial Catalog=ys;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=SQLOLEDB.1;Workstation ID= & StrServer & ;Use Encryption for Data=False) Private DC As New OleDbConnection Private DA As New OleDbDataAdapter Private DS As New DataSet
3、Dim Adminform As New Administrator Dim stuform As New student Dim Teaform As New Teacher Private Function Query(ByVal QueryString As String) As Boolean DS.Clear() Try DA = New OleDbDataAdapter(QueryString, Conn) DA.Fill(DS, TMInfo) Catch MessageBox.Show(Err.Description, 警告, _ MessageBoxButtons.OK, M
4、essageBoxIcon.Warning) Exit Function End Try Dim dt As New DataTable dt = DS.Tables.Item(0) If account.Text = Or passwords.Text = Then MessageBox.Show( 账号或密码不能为空, 提醒信息, MessageBoxButtons.OK, MessageBoxIcon.Information) Return False ElseIf dt.Rows.Count = 0 Then 错误 MessageBox.Show( _ 您输入账号不存在, _ 警告,
5、MessageBoxButtons.OK, MessageBoxIcon.Error) Return False End If Dim row As Data.DataRow 定义一个表格行对象。 row = dt.Rows.Item(0) 将表格第一行即密码读出 passwords.Text = row.Item(password) If passwords.Text row.Item(password) Then 用户密码不正确 MessageBox.Show( _ 对不起,您密码有误。, _ 警告, MessageBoxButtons.OK, MessageBoxIcon.Error)
6、Return False End If Return True End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim QueryString As String QueryString = select * from TeaMagInfo where id= & account.Text & If account.Text = Administrator And passwords.Text = pa
7、ss Then Dim Addserv As New AddServer Addserv.ShowDialog() Else If (Query(QueryString) = True) Then Try DA = New OleDbDataAdapter(QueryString, Conn) DA.Fill(DS, TMInfo) Catch MessageBox.Show(Err.Description, 警告, _ MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End Try Dim dt As New DataTable
8、dt = DS.Tables.Item(0) Dim row As Data.DataRow 定义一个表格行对象。 row = dt.Rows.Item(0) If RadioAdmin.Checked Then If row.Item(ocu) 管理员.ToString Then MessageBox.Show(你选择用户类型不正确, 提醒信息, MessageBoxButtons.OK, MessageBoxIcon.Information) Else Adminform.Show() Me.Visible = False End If End If If RadioTeacher.Che
9、cked Then If row.Item(ocu) 老师.ToString Then MessageBox.Show(你选择用户类型不正确, 提醒信息, MessageBoxButtons.OK, MessageBoxIcon.Information) Else Me.Visible = False Me.DialogResult = DialogResult.OK Teaform.Show() Me.Visible = False End If End If End If End If If Radiostu.Checked Then DS.Clear() If account.Text
10、= Or passwords.Text = Then MessageBox.Show( 账号或密码不能为空, 提醒信息, MessageBoxButtons.OK, MessageBoxIcon.Information) Else Dim stu As Boolean = False Dim QuerString As String QuerString = select * from stuBaseInfo where stuID= & account.Text & and password= & passwords.Text & Try DA = New OleDbDataAdapter(
11、QuerString, Conn) DA.Fill(DS, lk) Dim dtab As DataTable dtab = DS.Tables.Item(lk) If dtab.Rows.Count 0 Then stu = True Else MessageBox.Show(不存在此账号信息或原始密码错, 提醒信息, MessageBoxButtons.OK, MessageBoxIcon.Information) End If Catch ex As Exception MessageBox.Show(Err.Description, 警告, MessageBoxButtons.OKCa
12、ncel, MessageBoxIcon.Warning) End Try If stu Then stuform.Show() Me.Visible = False End If End If End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal
13、e As System.EventArgs) Handles MyBase.Load Me.AcceptButton = Button1 Me.CancelButton = Button2 End Sub Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Radiostu.CheckedChanged End Sub Private Sub RadioTeacher_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioTeacher.CheckedChanged End SubEnd Class