📄 login.vb
字号:
CType(Me.AxNiceCheck1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.AxNiceButton1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.AxNiceButton2, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Public ADOcmd As SqlDataAdapter
Public ds As DataSet = New DataSet
Public mytable As Data.DataTable
Public row As DataRow
Public sql As String
Public rownumber As Integer
Public cmd As SqlCommandBuilder
Public conn As String
Public Declare Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal nVirtKey As Integer) As Integer
Private Shared m_Form As New login
Public Shared ReadOnly Property NewForm() As login
Get
If m_Form Is Nothing OrElse m_Form.IsDisposed Then
m_Form = New login
End If
Return m_Form
End Get
End Property
Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxNiceButton1.Style = NiceFormControl.MnuStyle.流线造型2
AxNiceButton2.Style = NiceFormControl.MnuStyle.流线造型2
flash.NewForm.ShowDialog(Me) '加载欢迎闪屏
txtServer.Text = GetSetting("lin077", "宿舍管理系统", "SQLserver", "(local)") '取出注册表值
Dim conn As String
Dim SqlDb, SqlUid, SqlPwd As String
SqlDb = GetSetting("lin077", "宿舍管理系统", "SQLdb", "house") '取注册表
SqlUid = GetSetting("lin077", "宿舍管理系统", "SQLuid", "sa") '取注册表
SqlPwd = GetSetting("lin077", "宿舍管理系统", "SQLpwd", "") '取注册表
conn = "server=" & Trim(txtServer.Text) & ";database=" & SqlDb & ";uid=" & SqlUid & ";pwd=" & SqlPwd
AxNiceCheck1.Tag = txtServer.Text '存储临时以备用
If AxNiceCheck1.Tag = "(local)" Then '如果不是默认值取改变CHECK状态
AxNiceCheck1.Value = 0
txtServer.Enabled = False
Else
AxNiceCheck1.Value = 1
txtServer.Enabled = True
End If
Dim tablename As String
tablename = "用户表"
sql = "select * FROM 用户表"
Try
'ExecuteSQL(sql, tablename)
Dim ap As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Dim ds1 As DataSet = New DataSet
ap.Fill(ds1, tablename)
Me.cmdName.DataSource = ds1.Tables.Item(0)
cmdName.DisplayMember = "用户名"
'取注册表用户名
cmdName.Text = GetSetting("lin077", "宿舍管理系统", "GoName", ds1.Tables(0).Rows(0).Item("用户名")) '取注册表
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub txtPwd_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPwd.KeyDown
If (GetKeyState(&H14) And 1 = 1) Then
Label4.Visible = True
Else
Label4.Visible = False
End If
If e.KeyCode = Keys.CapsLock Then
If (GetKeyState(&H14)) = 65409 Then
Label4.Visible = True
Else
Label4.Visible = False
End If
End If
End Sub
Private Sub AxNiceButton2_ClickEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxNiceButton2.ClickEvent
Application.Exit()
End Sub
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
FormSQLreg.NewForm.ShowDialog(Me)
End Sub
Private Sub AxNiceCheck1_ClickEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxNiceCheck1.ClickEvent
If AxNiceCheck1.Value = NiceFormControl.State.Checked Then
txtServer.Text = "(local)" '当不选时默认为本地
txtServer.Enabled = False
End If
If AxNiceCheck1.Value = NiceFormControl.State.Unchecked Then
txtServer.Text = AxNiceCheck1.Tag
txtServer.Enabled = True
End If
cmdName.Focus()
End Sub
Private Sub txtPwd_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPwd.LostFocus
Label4.Visible = False
End Sub
Private Sub txtPwd_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPwd.GotFocus
If (GetKeyState(&H14) And 1 = 1) Then
Label4.Visible = True
Else
Label4.Visible = False
End If
End Sub
Private Sub FormLoad_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
If Me.Tag = "End" Then
End
End If
End Sub
Private Sub AxNiceButton1_ClickEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxNiceButton1.ClickEvent
If Me.cmdName.Text = "" Then
If AxNiceButton1.Tag > 1 Then '三次登陆失败后关闭程序
MsgBox("用户名不能为空!", MsgBoxStyle.Exclamation, "用户登陆")
txtPwd.Clear()
cmdName.SelectAll()
txtPwd.Focus()
AxNiceButton1.Tag = AxNiceButton1.Tag - 1
Return
End If
End If
If Me.txtPwd.Text = "" Then
If AxNiceButton1.Tag > 1 Then '三次登陆失败后关闭程序
MsgBox("密码不能为空!", MsgBoxStyle.Exclamation, "用户登陆")
txtPwd.Clear()
cmdName.SelectAll()
txtPwd.Focus()
AxNiceButton1.Tag = AxNiceButton1.Tag - 1
Return
End If
End If
Dim tablename As String
tablename = "用户表"
sql = "select * FROM 用户表 where 用户名 = '" & cmdName.Text & "' and 密码='" & Me.txtPwd.Text & "'"
Try
ExecuteSQL(sql, tablename)
Catch
If AxNiceButton1.Tag > 1 Then '三次登陆失败后关闭程序
MsgBox("用户名或密码错误,请重新登陆!", MsgBoxStyle.Exclamation, "用户登陆")
txtPwd.Clear()
cmdName.SelectAll()
txtPwd.Focus()
AxNiceButton1.Tag = AxNiceButton1.Tag - 1
Else
MsgBox("对不起,你已三次登陆失败,你无权使用本系统!", MsgBoxStyle.Critical, "非法登陆")
Application.Exit()
End If
End Try
End Sub
Public Function ExecuteSQL(ByVal SQL As String, ByVal table As String)
SaveSetting("lin077", "宿舍管理系统", "SQLserver", txtServer.Text) '保存到注册表
SaveSetting("lin077", "宿舍管理系统", "GoName", cmdName.Text) '保存to注册表
Dim conn As String
Dim SqlDb, SqlUid, SqlPwd As String
SqlDb = GetSetting("lin077", "宿舍管理系统", "SQLdb", "house") '取注册表
SqlUid = GetSetting("lin077", "宿舍管理系统", "SQLuid", "sa") '取注册表
SqlPwd = GetSetting("lin077", "宿舍管理系统", "SQLpwd", "") '取注册表
conn = "server=" & Trim(txtServer.Text) & ";database=" & SqlDb & ";uid=" & SqlUid & ";pwd=" & SqlPwd
ADOcmd = New SqlDataAdapter(SQL, conn)
ADOcmd.Fill(ds, table)
mytable = ds.Tables.Item(0)
rownumber = 0
row = mytable.Rows.Item(rownumber)
If mytable.Rows.Count = 1 Then
Dim m As New main
m.stb.Tag = conn
m.StatusBarPanel2.Text = cmdName.Text
m.StatusBarPanel3.Text = row.Item(2).ToString
m.StatusBarPanel5.Text = Me.txtServer.Text
m.stb.Text = Me.txtPwd.Text
Dim x As New xgmm
mm = Me.txtPwd.Text
m.Show()
Me.Hide()
End If
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -