📄 frmlogin.vb
字号:
Imports System
Imports System.Data
Imports System.DBNull
Imports System.Drawing
Imports System.Data.SqlClient
Namespace HZC.DinningService
Public Class frmLogin
Inherits System.Windows.Forms.Form
Private _User As String = String.Empty
Private _Password As String = String.Empty
Private _LogonInfo As String = String.Empty
Private _StartPath As String = Application.StartupPath & "\ApplicationInitials.ini"
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
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 lbTitle As System.Windows.Forms.Label
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents btnLogin As System.Windows.Forms.Button
Friend WithEvents txtPassword As System.Windows.Forms.TextBox
Friend WithEvents txtUserName As System.Windows.Forms.TextBox
Friend WithEvents lbPassword As System.Windows.Forms.Label
Friend WithEvents lbUserName As System.Windows.Forms.Label
Friend WithEvents LoginErrorProvider As System.Windows.Forms.ErrorProvider
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmLogin))
Me.lbTitle = New System.Windows.Forms.Label
Me.btnCancel = New System.Windows.Forms.Button
Me.btnLogin = New System.Windows.Forms.Button
Me.txtPassword = New System.Windows.Forms.TextBox
Me.txtUserName = New System.Windows.Forms.TextBox
Me.lbPassword = New System.Windows.Forms.Label
Me.lbUserName = New System.Windows.Forms.Label
Me.LoginErrorProvider = New System.Windows.Forms.ErrorProvider
Me.SuspendLayout()
'
'lbTitle
'
Me.lbTitle.Font = New System.Drawing.Font("华文行楷", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.lbTitle.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
Me.lbTitle.Location = New System.Drawing.Point(24, 24)
Me.lbTitle.Name = "lbTitle"
Me.lbTitle.Size = New System.Drawing.Size(392, 56)
Me.lbTitle.TabIndex = 0
Me.lbTitle.Text = "单机版餐饮服务"
Me.lbTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnCancel.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.btnCancel.ForeColor = System.Drawing.Color.Navy
Me.btnCancel.Location = New System.Drawing.Point(232, 224)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(72, 24)
Me.btnCancel.TabIndex = 13
Me.btnCancel.Text = "取消"
'
'btnLogin
'
Me.btnLogin.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btnLogin.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.btnLogin.ForeColor = System.Drawing.Color.Navy
Me.btnLogin.Location = New System.Drawing.Point(144, 224)
Me.btnLogin.Name = "btnLogin"
Me.btnLogin.Size = New System.Drawing.Size(72, 24)
Me.btnLogin.TabIndex = 12
Me.btnLogin.Text = "登录"
'
'txtPassword
'
Me.txtPassword.BackColor = System.Drawing.SystemColors.Info
Me.txtPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.txtPassword.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
Me.LoginErrorProvider.SetIconPadding(Me.txtPassword, 4)
Me.txtPassword.Location = New System.Drawing.Point(192, 176)
Me.txtPassword.MaxLength = 15
Me.txtPassword.Name = "txtPassword"
Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassword.Size = New System.Drawing.Size(112, 21)
Me.txtPassword.TabIndex = 11
Me.txtPassword.Text = "123456789"
'
'txtUserName
'
Me.txtUserName.AutoSize = False
Me.txtUserName.BackColor = System.Drawing.SystemColors.Info
Me.txtUserName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.txtUserName.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
Me.LoginErrorProvider.SetIconPadding(Me.txtUserName, 4)
Me.txtUserName.Location = New System.Drawing.Point(192, 128)
Me.txtUserName.MaxLength = 15
Me.txtUserName.Name = "txtUserName"
Me.txtUserName.Size = New System.Drawing.Size(112, 21)
Me.txtUserName.TabIndex = 10
Me.txtUserName.Text = "Administrator"
'
'lbPassword
'
Me.lbPassword.ForeColor = System.Drawing.Color.Navy
Me.lbPassword.Location = New System.Drawing.Point(112, 176)
Me.lbPassword.Name = "lbPassword"
Me.lbPassword.Size = New System.Drawing.Size(80, 24)
Me.lbPassword.TabIndex = 9
Me.lbPassword.Text = "登录密码:"
Me.lbPassword.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'lbUserName
'
Me.lbUserName.ForeColor = System.Drawing.Color.Navy
Me.lbUserName.Location = New System.Drawing.Point(112, 128)
Me.lbUserName.Name = "lbUserName"
Me.lbUserName.Size = New System.Drawing.Size(80, 24)
Me.lbUserName.TabIndex = 8
Me.lbUserName.Text = "登录账号:"
Me.lbUserName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'LoginErrorProvider
'
Me.LoginErrorProvider.BlinkRate = 100
Me.LoginErrorProvider.ContainerControl = Me
'
'frmLogin
'
Me.AcceptButton = Me.btnLogin
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(434, 288)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnLogin)
Me.Controls.Add(Me.txtPassword)
Me.Controls.Add(Me.txtUserName)
Me.Controls.Add(Me.lbPassword)
Me.Controls.Add(Me.lbUserName)
Me.Controls.Add(Me.lbTitle)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "frmLogin"
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "登录单机版餐饮服务系统"
Me.ResumeLayout(False)
End Sub
#End Region
Public ReadOnly Property GetLogonInfo() As String
Get
Return _LogonInfo
End Get
End Property
Private Sub btnCancel_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles btnCancel.Click
If MsgBox("您真的不登录餐饮服务管理系统吗?", _
MsgBoxStyle.YesNo + MsgBoxStyle.Question, "退出登录系统") _
= MsgBoxResult.Yes Then
Application.Exit()
Else
Exit Sub
End If
End Sub
Private Sub frmLogin_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
If MsgBox("您真的不登录餐饮服务管理系统吗?", _
MsgBoxStyle.YesNo + MsgBoxStyle.Question, "退出登录系统") _
= MsgBoxResult.Yes Then
e.Cancel = False
Else
e.Cancel = True
End If
End Sub
Private Sub txtUserName_Validated( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles txtUserName.Validated
If IsUserNameValid() Then
LoginErrorProvider.SetError(txtUserName, String.Empty)
Else
LoginErrorProvider.SetError(txtUserName, "登录帐号不能为空")
End If
End Sub
Private Sub txtPassword_Validated( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles txtPassword.Validated
If IsPasswordValid() Then
LoginErrorProvider.SetError(txtPassword, String.Empty)
Else
LoginErrorProvider.SetError(txtPassword, "登录密码不能为空")
End If
End Sub
Private Function IsUserNameValid() As Boolean
Return (txtUserName.TextLength > 0)
End Function
Private Function IsPasswordValid() As Boolean
Return (txtPassword.TextLength > 0)
End Function
Private Sub btnLogin_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnLogin.Click
_User = txtUserName.Text.Trim
_Password = txtPassword.Text.Trim
If (_User = String.Empty) Or (_Password = String.Empty) Then
Throw New ArgumentNullException
End If
_LogonInfo = Logon.Authenticate(_User, _Password)
If Me.GetLogonInfo = String.Empty Then
Exit Sub
End If
Dim frmMainWindows As New frmMain
frmMainWindows.LogonInfo = Me.GetLogonInfo
frmMainWindows.Show()
Me.Finalize()
End Sub
Private Sub frmLogin_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Load
AccessToDatabase.InitializeSqlServer(_StartPath)
If AccessToDatabase.ConnectToDataBase() = False Then
MsgBox("连接数据库失败,请检查数据库的连接参数。", _
MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "连接数据库失败")
Application.Exit()
End If
End Sub
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -