📄 loginform.frm
字号:
VERSION 5.00
Begin VB.Form LoginForm
BorderStyle = 3 'Fixed Dialog
Caption = "登录"
ClientHeight = 2640
ClientLeft = 2835
ClientTop = 3480
ClientWidth = 4230
Icon = "LoginForm.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1559.799
ScaleMode = 0 'User
ScaleWidth = 3971.741
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame2
Height = 1215
Left = 0
TabIndex = 5
Top = 720
Width = 4215
Begin VB.TextBox txtPassword
Height = 345
IMEMode = 3 'DISABLE
Left = 1215
PasswordChar = "*"
TabIndex = 7
Top = 750
Width = 2325
End
Begin VB.TextBox txtUserName
Height = 345
Left = 1215
MaxLength = 50
TabIndex = 6
Top = 320
Width = 2325
End
Begin VB.Label lblLabels
Caption = "密码(&P):"
Height = 270
Index = 1
Left = 240
TabIndex = 9
Top = 825
Width = 1080
End
Begin VB.Label lblLabels
Caption = "昵称(&U):"
Height = 270
Index = 0
Left = 255
TabIndex = 8
Top = 400
Width = 1080
End
End
Begin VB.Frame Frame1
Height = 735
Left = 0
TabIndex = 2
Top = 0
Width = 4215
Begin VB.TextBox ServerText
Height = 300
Left = 1200
TabIndex = 3
Top = 240
Width = 2265
End
Begin VB.Label TsLabel
Alignment = 1 'Right Justify
AutoSize = -1 'True
Caption = "数据服务器:"
Height = 180
Index = 7
Left = 120
TabIndex = 4
Top = 300
Width = 990
End
End
Begin VB.CommandButton cmdOK
Caption = "确定"
Default = -1 'True
Height = 390
Left = 1230
TabIndex = 0
Top = 2100
Width = 1140
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取消"
Height = 390
Left = 2835
TabIndex = 1
Top = 2100
Width = 1140
End
End
Attribute VB_Name = "LoginForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private m_mainDAO As MainDAO
Private m_recordset As ADODB.Recordset
Private Sub cmdCancel_Click()
'设置全局变量为 false
'不提示失败的登录
MainForm.g_application.m_loginSucceeded = False
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim Reg As CRegistry
Dim strTemp As String
Set Reg = New CRegistry
Reg.RootKey = "HKEY_LOCAL_MACHINE"
' 检查服务器名
If Trim(ServerText.text) = "" Then
MsgBox "服务器密码不能为空!", , "登录"
End If
'检查正确的密码
If txtPassword <> "" Then
'将代码放在这里传递
Dim ret As Boolean
Dim sex As String
ret = MainForm.g_application.m_databaseCon.Connection(Trim(ServerText.text), "jackyc", "123")
If ret Then
ret = m_mainDAO.Login(m_recordset, Trim(txtUserName.text), Trim(txtPassword.text))
'sex = Trim(m_recordset.Fields("Sex"))
If ret = False Then
MainForm.g_msgText = "用户名或密码错误,请重试!"
HMsgBox MainForm.g_msgText, hxxdOKOnly, hxxdInfomation
GoTo Over
End If
MainForm.g_application.m_userName = Trim(m_recordset.Fields("Name"))
MainForm.g_application.m_userId = Trim(m_recordset.Fields("EmployeeID"))
MainForm.g_application.m_userPassword = Trim(txtPassword.text)
MainForm.g_application.m_dimission = Trim(m_recordset.Fields("Birthday") & " ")
If Not Trim(MainForm.g_application.m_dimission) = "" Then
MainForm.g_msgText = "此用户已离职,请重试!"
HMsgBox MainForm.g_msgText, hxxdOKOnly, hxxdInfomation
GoTo Over
End If
' 把用户登陆成功的信息存放入注册表中
Reg.BaseKey = "software"
Reg.RegistryKey = "SunDoo"
Reg.BaseKey = "software\SunDoo"
Reg.RegistryKey = "LoginMsg"
Reg.SetValue "ServerIp", Trim(ServerText.text)
Reg.SetValue "UserName", Trim(txtUserName.text)
Else
MsgBox "数据库联接不上,请重试!", , "登录"
ShowControls 0
GoTo Over
End If
MainForm.g_application.m_loginSucceeded = True
Unload Me
Else
MsgBox "无效的密码,请重试!", , "登录"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
Over:
End Sub
Private Sub Form_Activate()
If Trim(txtPassword.text) = "" Then
txtPassword.SetFocus
End If
If Trim(txtUserName.text) = "" Then
txtUserName.SetFocus
End If
If Trim(ServerText.text) = "" Then
ServerText.SetFocus
End If
End Sub
Private Sub Form_Load()
Dim Reg As CRegistry
Dim strTemp As String
Set Reg = New CRegistry
Reg.RootKey = "HKEY_LOCAL_MACHINE"
Set m_mainDAO = New MainDAO
Set m_recordset = New ADODB.Recordset
Me.caption = MainForm.g_application.m_softwareCo
MainForm.g_application.m_loginSucceeded = False
' 读出注册表中的信息
Reg.BaseKey = "software\SunDoo"
ServerText.text = Reg.GetValue("LoginMsg", "ServerIp")
txtUserName.text = Reg.GetValue("LoginMsg", "UserName")
If Trim(ServerText.text) <> "" Then
ShowControls 1
Else
ShowControls 0
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MainForm.g_application.m_loginSucceeded Then
Else
End
End If
End Sub
'**************************************
'* 功 能 描 述 :根据参数显示控件情况
'* 输 入 参 数 :operate - 0 显示所有的控件
'* 1 不显示服务器的地址
'* 输 出 能 数 :无
'**************************************
Private Function ShowControls(operate As Integer)
If operate = 0 Then
Me.Height = 3015
Me.Width = 4365
Frame1.Visible = True
Frame2.Top = 425
Frame2.Height = 717
lblLabels(1).Top = 820
txtPassword.Top = 750
cmdOK.Top = 1240
cmdCancel.Top = 1240
ElseIf operate = 1 Then
Me.Height = 3015 - 100
Me.Width = 4365
Frame1.Visible = False
Frame2.Top = 0
Frame2.Height = 717 + 330
lblLabels(1).Top = 820 + 300
txtPassword.Top = 750 + 300
cmdOK.Top = 1169
cmdCancel.Top = 1169
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -