📄 login.vb
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间
Imports System
Imports System.IO
Public Class win_login
Inherits System.Windows.Forms.Form
Public Shared loginid As Integer
'loginid用户的自动编号ID,datapath数据库原整路径
Dim sqlstr As String 'SQL语句标记
Dim objDS As DataSet '数据在内存中的缓存
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents rbadmin As System.Windows.Forms.RadioButton
Friend WithEvents rbstudent As System.Windows.Forms.RadioButton
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btcancel As System.Windows.Forms.Button
Friend WithEvents btsubmit As System.Windows.Forms.Button
Friend WithEvents tbpassword As System.Windows.Forms.TextBox
Friend WithEvents tbname As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(win_login))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.rbadmin = New System.Windows.Forms.RadioButton
Me.rbstudent = New System.Windows.Forms.RadioButton
Me.tbpassword = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.btcancel = New System.Windows.Forms.Button
Me.btsubmit = New System.Windows.Forms.Button
Me.tbname = New System.Windows.Forms.TextBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.rbadmin)
Me.GroupBox1.Controls.Add(Me.rbstudent)
Me.GroupBox1.Controls.Add(Me.tbpassword)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.btcancel)
Me.GroupBox1.Controls.Add(Me.btsubmit)
Me.GroupBox1.Controls.Add(Me.tbname)
Me.GroupBox1.ForeColor = System.Drawing.SystemColors.ControlDark
Me.GroupBox1.Location = New System.Drawing.Point(8, 6)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(232, 146)
Me.GroupBox1.TabIndex = 1
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "学生登陆"
'
'rbadmin
'
Me.rbadmin.ForeColor = System.Drawing.SystemColors.ControlText
Me.rbadmin.Location = New System.Drawing.Point(120, 80)
Me.rbadmin.Name = "rbadmin"
Me.rbadmin.Size = New System.Drawing.Size(64, 24)
Me.rbadmin.TabIndex = 4
Me.rbadmin.Text = "管理员"
'
'rbstudent
'
Me.rbstudent.Checked = True
Me.rbstudent.ForeColor = System.Drawing.SystemColors.ControlText
Me.rbstudent.Location = New System.Drawing.Point(64, 80)
Me.rbstudent.Name = "rbstudent"
Me.rbstudent.Size = New System.Drawing.Size(64, 24)
Me.rbstudent.TabIndex = 3
Me.rbstudent.TabStop = True
Me.rbstudent.Text = "学生"
'
'tbpassword
'
Me.tbpassword.ForeColor = System.Drawing.SystemColors.ControlText
Me.tbpassword.Location = New System.Drawing.Point(100, 48)
Me.tbpassword.MaxLength = 10
Me.tbpassword.Name = "tbpassword"
Me.tbpassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.tbpassword.Size = New System.Drawing.Size(88, 21)
Me.tbpassword.TabIndex = 2
Me.tbpassword.Text = ""
'
'Label2
'
Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label2.Location = New System.Drawing.Point(44, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 24)
Me.Label2.TabIndex = 6
Me.Label2.Text = "密码:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label1
'
Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label1.Location = New System.Drawing.Point(44, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 24)
Me.Label1.TabIndex = 5
Me.Label1.Text = "学号:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'btcancel
'
Me.btcancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btcancel.ForeColor = System.Drawing.SystemColors.ControlText
Me.btcancel.Location = New System.Drawing.Point(128, 112)
Me.btcancel.Name = "btcancel"
Me.btcancel.Size = New System.Drawing.Size(64, 24)
Me.btcancel.TabIndex = 6
Me.btcancel.Text = "取消"
'
'btsubmit
'
Me.btsubmit.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btsubmit.ForeColor = System.Drawing.SystemColors.ControlText
Me.btsubmit.Location = New System.Drawing.Point(48, 112)
Me.btsubmit.Name = "btsubmit"
Me.btsubmit.Size = New System.Drawing.Size(64, 24)
Me.btsubmit.TabIndex = 5
Me.btsubmit.Text = "确定"
'
'tbname
'
Me.tbname.ForeColor = System.Drawing.SystemColors.ControlText
Me.tbname.Location = New System.Drawing.Point(100, 16)
Me.tbname.MaxLength = 12
Me.tbname.Name = "tbname"
Me.tbname.Size = New System.Drawing.Size(88, 21)
Me.tbname.TabIndex = 1
Me.tbname.Text = ""
'
'win_login
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.btcancel
Me.ClientSize = New System.Drawing.Size(248, 157)
Me.ControlBox = False
Me.Controls.Add(Me.GroupBox1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MaximumSize = New System.Drawing.Size(256, 184)
Me.MinimumSize = New System.Drawing.Size(256, 184)
Me.Name = "win_login"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "图书馆管理系统登陆"
Me.TopMost = True
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btsubmit.Click
If tbname.Text = "" Then '登陆名为空!
MessageBox.Show("登陆号不能有空!", "登陆错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
tbname.Focus()
Exit Sub
ElseIf tbpassword.Text = "" Then '密码为空
MessageBox.Show("登陆密码不能有空!", "登陆错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
tbpassword.Focus()
Exit Sub
End If
If rbstudent.Checked Then ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''学生登陆
sqlstr = "SELECT id,lpassword FROM studentinfo WHERE learnid='" & filter(Trim(tbname.Text).ToString) & "'"
Try
objDS = GetData(sqlstr)
If objDS.Tables(0).Rows.Count > 0 Then
If objDS.Tables(0).Rows(0)("lpassword").ToString = tbpassword.Text Then '比较输入密码和数据库的密码
Dim main As New win_main
loginid = objDS.Tables(0).Rows(0)("id")
sqlstr = "update studentinfo set logins=logins+1,lastlogin=now() where id=" & filter(Trim(loginid).ToString) & ""
objDS = GetData(sqlstr)
main.Show()
Me.Finalize()
Else
MsgBox("登陆错误,登陆密码错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End If
Else
MsgBox("登陆错误,登陆号错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End If
Catch
MsgBox("读取数据库错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End Try
Else ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''管理员登陆
sqlstr = "SELECT id,lpassword FROM admininfo WHERE adminname='" & filter(Trim(tbname.Text).ToString) & " '"
Try
objDS = GetData(sqlstr)
If objDS.Tables(0).Rows.Count > 0 Then
If objDS.Tables(0).Rows(0)("lpassword").ToString = tbpassword.Text Then '比较输入密码和数据库的密码
Dim adminmain As New win_adminmain
loginid = objDS.Tables(0).Rows(0)("id")
sqlstr = "update admininfo set logins=logins+1,lastlogin=now() where id=" & filter(Trim(loginid).ToString) & ""
objDS = GetData(sqlstr)
adminmain.Show()
Me.Finalize()
Else
MsgBox("登陆错误,登陆密码错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End If
Else
MsgBox("登陆错误,登陆号错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End If
Catch
MsgBox("读取数据库错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End Try
End If
End Sub
Private Sub btcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btcancel.Click
Me.Dispose()
End Sub
'分学生和管理员两个窗口打开
Private Sub rbstudent_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbstudent.CheckedChanged
Label1.Text = "学号:"
GroupBox1.Text = "学生登陆"
End Sub
Private Sub rbadmin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbadmin.CheckedChanged
Label1.Text = "帐号:"
GroupBox1.Text = "管理员登陆"
End Sub
Private Sub win_login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '判断是否找到数据库。
If Not File.Exists(getpath()) Then
MessageBox.Show("发生严重错误!没找到数据库!" & ControlChars.CrLf & "请将数据库与执行文件放于同一文件夹中。", "致命错误!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Application.Exit()
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -