📄 login.vb
字号:
Imports System.Data
Imports System.Data.SqlClient
Public Class frmLogin
Inherits System.Windows.Forms.Form
#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 bnadminCancel As System.Windows.Forms.Button
Friend WithEvents bnadminLogin As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents tbPwd As System.Windows.Forms.TextBox
Friend WithEvents tbLoginname As System.Windows.Forms.TextBox
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents bnusercancel As System.Windows.Forms.Button
Friend WithEvents bnuserlogin As System.Windows.Forms.Button
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents tbuserpwd As System.Windows.Forms.TextBox
Friend WithEvents tbcardid As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmLogin))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.bnadminCancel = New System.Windows.Forms.Button
Me.bnadminLogin = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.tbPwd = New System.Windows.Forms.TextBox
Me.tbLoginname = New System.Windows.Forms.TextBox
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.bnusercancel = New System.Windows.Forms.Button
Me.bnuserlogin = New System.Windows.Forms.Button
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.tbuserpwd = New System.Windows.Forms.TextBox
Me.tbcardid = New System.Windows.Forms.TextBox
Me.Label5 = New System.Windows.Forms.Label
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.bnadminCancel)
Me.GroupBox1.Controls.Add(Me.bnadminLogin)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.tbPwd)
Me.GroupBox1.Controls.Add(Me.tbLoginname)
Me.GroupBox1.Location = New System.Drawing.Point(47, 88)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(240, 152)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "管理员登录"
'
'bnadminCancel
'
Me.bnadminCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.bnadminCancel.Location = New System.Drawing.Point(144, 96)
Me.bnadminCancel.Name = "bnadminCancel"
Me.bnadminCancel.TabIndex = 11
Me.bnadminCancel.Text = "取消"
'
'bnadminLogin
'
Me.bnadminLogin.DialogResult = System.Windows.Forms.DialogResult.OK
Me.bnadminLogin.Location = New System.Drawing.Point(16, 96)
Me.bnadminLogin.Name = "bnadminLogin"
Me.bnadminLogin.TabIndex = 10
Me.bnadminLogin.Text = "登录"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(19, 72)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(48, 16)
Me.Label2.TabIndex = 9
Me.Label2.Text = "密码:"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(11, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 16)
Me.Label1.TabIndex = 8
Me.Label1.Text = "登陆名:"
'
'tbPwd
'
Me.tbPwd.Location = New System.Drawing.Point(83, 64)
Me.tbPwd.Name = "tbPwd"
Me.tbPwd.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.tbPwd.Size = New System.Drawing.Size(144, 21)
Me.tbPwd.TabIndex = 7
Me.tbPwd.Text = ""
'
'tbLoginname
'
Me.tbLoginname.Location = New System.Drawing.Point(83, 40)
Me.tbLoginname.Name = "tbLoginname"
Me.tbLoginname.Size = New System.Drawing.Size(144, 21)
Me.tbLoginname.TabIndex = 6
Me.tbLoginname.Text = ""
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.bnusercancel)
Me.GroupBox2.Controls.Add(Me.bnuserlogin)
Me.GroupBox2.Controls.Add(Me.Label3)
Me.GroupBox2.Controls.Add(Me.Label4)
Me.GroupBox2.Controls.Add(Me.tbuserpwd)
Me.GroupBox2.Controls.Add(Me.tbcardid)
Me.GroupBox2.Location = New System.Drawing.Point(295, 88)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(264, 152)
Me.GroupBox2.TabIndex = 1
Me.GroupBox2.TabStop = False
Me.GroupBox2.Text = "借阅用户登录"
'
'bnusercancel
'
Me.bnusercancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.bnusercancel.Location = New System.Drawing.Point(171, 93)
Me.bnusercancel.Name = "bnusercancel"
Me.bnusercancel.TabIndex = 11
Me.bnusercancel.Text = "取消"
'
'bnuserlogin
'
Me.bnuserlogin.DialogResult = System.Windows.Forms.DialogResult.OK
Me.bnuserlogin.Location = New System.Drawing.Point(67, 93)
Me.bnuserlogin.Name = "bnuserlogin"
Me.bnuserlogin.TabIndex = 10
Me.bnuserlogin.Text = "登录"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(35, 69)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(48, 16)
Me.Label3.TabIndex = 9
Me.Label3.Text = "密码:"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(27, 37)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(69, 16)
Me.Label4.TabIndex = 8
Me.Label4.Text = "借阅证号:"
'
'tbuserpwd
'
Me.tbuserpwd.Location = New System.Drawing.Point(99, 61)
Me.tbuserpwd.Name = "tbuserpwd"
Me.tbuserpwd.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.tbuserpwd.Size = New System.Drawing.Size(144, 21)
Me.tbuserpwd.TabIndex = 7
Me.tbuserpwd.Text = ""
'
'tbcardid
'
Me.tbcardid.Location = New System.Drawing.Point(99, 37)
Me.tbcardid.Name = "tbcardid"
Me.tbcardid.Size = New System.Drawing.Size(144, 21)
Me.tbcardid.TabIndex = 6
Me.tbcardid.Text = ""
'
'Label5
'
Me.Label5.ForeColor = System.Drawing.Color.Red
Me.Label5.Location = New System.Drawing.Point(112, 48)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(352, 16)
Me.Label5.TabIndex = 2
Me.Label5.Text = "按你的方式正确登录系统----本系统欢迎管理员或借阅用户登录"
Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'frmLogin
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(618, 256)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "frmLogin"
Me.Text = "登录"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Public iControl As Integer
Public loginname As String
Private Sub bnadminLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnadminLogin.Click
Dim strLoginname As String = tbLoginname.Text.Trim()
Dim strPwd As String = tbPwd.Text.Trim()
Dim strSource As String = "workstation id=郭洪博;packet size=4096;integrated security=SSPI;initial catalog=books;persist security info=False"
Dim strSelect As String = "select password,control from admin where username = '" + strLoginname + "'"
'server=CHANGHAIFENG;uid=sa;pwd=;database=books
Dim conn As SqlConnection = New SqlConnection(strSource)
Try
conn.Open()
Dim cmd As SqlCommand = New SqlCommand(strSelect, conn)
Dim reader As SqlDataReader = cmd.ExecuteReader()
If Not reader.HasRows Then
MessageBox.Show("登陆名错误!")
conn.Close()
Exit Sub
End If
reader.Read()
Dim strDBPwd As String = reader.Item("password").ToString().Trim()
iControl = Convert.ToInt32(reader.Item("control").ToString().Trim())
loginname = strLoginname
If strPwd = strDBPwd Then
conn.Close()
Dim frmMain As New frmadmin
Me.Hide()
frmMain.loginname = loginname
frmMain.ictrl = iControl
frmMain.Show()
Else
MessageBox.Show("口令错误!")
conn.Close()
Exit Sub
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
Exit Sub
End Try
End Sub
Private Sub bnuserlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnuserlogin.Click
Dim strcardid As String = tbcardid.Text.Trim()
Dim strPwd As String = tbuserpwd.Text.Trim()
Dim strSource As String = "workstation id=郭洪博;packet size=4096;integrated security=SSPI;initial catalog=books;persist security info=False"
Dim strSelect As String = "select password from bookcard where cardid = '" + strcardid + "'"
Dim conn As SqlConnection = New SqlConnection(strSource)
Try
conn.Open()
Dim cmd As SqlCommand = New SqlCommand(strSelect, conn)
Dim reader As SqlDataReader = cmd.ExecuteReader()
If Not reader.HasRows Then
MessageBox.Show("登陆名错误!")
conn.Close()
Exit Sub
End If
reader.Read()
Dim strDBPwd As String = reader.Item("password").ToString().Trim()
loginname = strcardid
If strPwd = strDBPwd Then
conn.Close()
Dim frmMain As New frmuser
Me.Hide()
frmMain.loginname = loginname
frmMain.Show()
Else
MessageBox.Show("口令错误!")
conn.Close()
Exit Sub
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
Exit Sub
End Try
End Sub
Private Sub bnadminCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnadminCancel.Click
Me.Close()
End Sub
Private Sub bnusercancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnusercancel.Click
Me.Close()
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -