📄 loginform.vb
字号:
'---------------------------------------------------------------------
' This file is part of the Microsoft .NET Framework SDK Code Samples.
'
' Copyright (C) Microsoft Corporation. All rights reserved.
'
' This source code is intended only as a supplement to Microsoft
' Development Tools and/or on-line documentation. See these other
' materials for detailed information regarding Microsoft code samples.
'
' THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'---------------------------------------------------------------------
Imports Microsoft.Win32
Public Class LoginForm
Inherits System.Windows.Forms.Form
Public Sub New(ByVal dl As DataLayer)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
m_DataLayer = dl
End Sub
Private m_DataLayer As DataLayer
Private m_ResourceManager As New Resources.ResourceManager("TeamVision.Localize", System.Reflection.Assembly.GetExecutingAssembly())
Private Sub LoginForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblVersion.Text = "Version " & Application.ProductVersion
Dim userName As String = String.Empty
Dim password As String = String.Empty
Dim rememberLogin As Boolean = False
'Access configuration parameters defined in the Project > Properties > Settings
Try
userName = My.Settings.userName
password = DataProtection.UnprotectData(My.Settings.password)
rememberLogin = My.Settings.rememberLogin
Catch ex As Exception
'if something fails log the error and allow the app to continue
LogError.Write(ex.Message & vbCrLf & ex.StackTrace)
End Try
If rememberLogin = True Then
txtUserName.Text = userName
txtPassword.Text = password
End If
cbRemember.Checked = rememberLogin
txtUserName.Focus()
End Sub
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Me.DialogResult = System.Windows.Forms.DialogResult.None
If txtUserName.Text.Trim() <> String.Empty AndAlso txtPassword.Text.Trim() <> String.Empty Then
MyBase.Cursor = Cursors.WaitCursor
Dim dlResult As DataLayerResult = m_DataLayer.Login(txtUserName.Text, txtPassword.Text)
MyBase.Cursor = Cursors.Arrow
If dlResult = DataLayerResult.Success Then
'successful login, save the login info to the registry if desired
Try
If cbRemember.Checked Then
My.Settings.userName = txtUserName.Text
My.Settings.password = DataProtection.ProtectData(txtPassword.Text, "TeamVisionPassword")
My.Settings.rememberLogin = True
Else
My.Settings.rememberLogin = False
My.Settings.userName = ""
My.Settings.password = DataProtection.ProtectData("", "TeamVisionPassword")
End If
Catch ex As Exception
'if something fails log the error and allow the app to continue
LogError.Write(ex.Message & vbCrLf & ex.StackTrace)
End Try
My.Settings.Save()
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
Else
txtUserName.Focus()
If dlResult = DataLayerResult.ServiceFailure Then
MessageBox.Show(m_ResourceManager.GetString("MessageBoxShow_An_error_has_occurred") & vbCrLf & vbCrLf & m_ResourceManager.GetString("Please_contact_your_network_administrator"))
ElseIf dlResult = DataLayerResult.ConnectionFailure Then
MessageBox.Show(m_ResourceManager.GetString("MessageBoxShow_The_remote_server_is_unreachable") & vbCrLf & vbCrLf & m_ResourceManager.GetString("Please_check_your_connection_and_try_again"))
ElseIf dlResult = DataLayerResult.AuthenticationFailure Then
MessageBox.Show(m_ResourceManager.GetString("The_username_or_password_is_incorrect") & vbCrLf & vbCrLf & m_ResourceManager.GetString("Please_re_type_your_information"))
Else
MessageBox.Show(m_ResourceManager.GetString("An_unknown_error_has_occurred") & vbCrLf & vbCrLf & m_ResourceManager.GetString("Please_review_the_event_log_for_more_information"))
End If
End If
Else
MessageBox.Show(m_ResourceManager.GetString("Please_re_type_your_information") & vbCrLf & vbCrLf & m_ResourceManager.GetString("Please_re_type_your_information"))
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -