LoginForm - Add UI check status auto login

This commit is contained in:
DucDangAnh 2020-07-16 16:23:43 +07:00
parent 01098b4597
commit 2c6e326008
2 changed files with 28 additions and 43 deletions

View File

@ -37,8 +37,8 @@
this.txtServerAddress = new System.Windows.Forms.TextBox(); this.txtServerAddress = new System.Windows.Forms.TextBox();
this.lblServerAddress = new System.Windows.Forms.Label(); this.lblServerAddress = new System.Windows.Forms.Label();
this.btnLogin = new System.Windows.Forms.Button(); this.btnLogin = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.lblLoginStatus = new System.Windows.Forms.Label(); this.lblLoginStatus = new System.Windows.Forms.Label();
this.chkAutoLogin = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxImageLogo)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxImageLogo)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -70,7 +70,7 @@
// //
// txtPassword // txtPassword
// //
this.txtPassword.Location = new System.Drawing.Point(294, 52); this.txtPassword.Location = new System.Drawing.Point(294, 45);
this.txtPassword.Name = "txtPassword"; this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*'; this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(227, 20); this.txtPassword.Size = new System.Drawing.Size(227, 20);
@ -80,7 +80,7 @@
// lblPassword // lblPassword
// //
this.lblPassword.AutoSize = true; this.lblPassword.AutoSize = true;
this.lblPassword.Location = new System.Drawing.Point(214, 55); this.lblPassword.Location = new System.Drawing.Point(214, 48);
this.lblPassword.Name = "lblPassword"; this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(52, 13); this.lblPassword.Size = new System.Drawing.Size(52, 13);
this.lblPassword.TabIndex = 2; this.lblPassword.TabIndex = 2;
@ -88,7 +88,7 @@
// //
// txtServerAddress // txtServerAddress
// //
this.txtServerAddress.Location = new System.Drawing.Point(294, 90); this.txtServerAddress.Location = new System.Drawing.Point(294, 77);
this.txtServerAddress.Name = "txtServerAddress"; this.txtServerAddress.Name = "txtServerAddress";
this.txtServerAddress.Size = new System.Drawing.Size(227, 20); this.txtServerAddress.Size = new System.Drawing.Size(227, 20);
this.txtServerAddress.TabIndex = 1; this.txtServerAddress.TabIndex = 1;
@ -97,7 +97,7 @@
// lblServerAddress // lblServerAddress
// //
this.lblServerAddress.AutoSize = true; this.lblServerAddress.AutoSize = true;
this.lblServerAddress.Location = new System.Drawing.Point(214, 93); this.lblServerAddress.Location = new System.Drawing.Point(214, 80);
this.lblServerAddress.Name = "lblServerAddress"; this.lblServerAddress.Name = "lblServerAddress";
this.lblServerAddress.Size = new System.Drawing.Size(48, 13); this.lblServerAddress.Size = new System.Drawing.Size(48, 13);
this.lblServerAddress.TabIndex = 2; this.lblServerAddress.TabIndex = 2;
@ -105,42 +105,44 @@
// //
// btnLogin // btnLogin
// //
this.btnLogin.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnLogin.Location = new System.Drawing.Point(294, 162); this.btnLogin.Location = new System.Drawing.Point(294, 162);
this.btnLogin.Name = "btnLogin"; this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(101, 37); this.btnLogin.Size = new System.Drawing.Size(227, 37);
this.btnLogin.TabIndex = 3; this.btnLogin.TabIndex = 3;
this.btnLogin.Text = "Đăng nhập"; this.btnLogin.Text = "Đăng nhập";
this.btnLogin.UseVisualStyleBackColor = true; this.btnLogin.UseVisualStyleBackColor = true;
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click); this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
// //
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(421, 162);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(101, 37);
this.btnExit.TabIndex = 3;
this.btnExit.Text = "Thoát";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// lblLoginStatus // lblLoginStatus
// //
this.lblLoginStatus.AutoSize = true; this.lblLoginStatus.AutoSize = true;
this.lblLoginStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblLoginStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblLoginStatus.ForeColor = System.Drawing.SystemColors.ControlLight; this.lblLoginStatus.ForeColor = System.Drawing.SystemColors.ControlLight;
this.lblLoginStatus.Location = new System.Drawing.Point(294, 117); this.lblLoginStatus.Location = new System.Drawing.Point(291, 100);
this.lblLoginStatus.Name = "lblLoginStatus"; this.lblLoginStatus.Name = "lblLoginStatus";
this.lblLoginStatus.Size = new System.Drawing.Size(90, 18); this.lblLoginStatus.Size = new System.Drawing.Size(90, 18);
this.lblLoginStatus.TabIndex = 4; this.lblLoginStatus.TabIndex = 4;
this.lblLoginStatus.Text = "Login Status"; this.lblLoginStatus.Text = "Login Status";
// //
// chkAutoLogin
//
this.chkAutoLogin.AutoSize = true;
this.chkAutoLogin.Location = new System.Drawing.Point(295, 142);
this.chkAutoLogin.Name = "chkAutoLogin";
this.chkAutoLogin.Size = new System.Drawing.Size(122, 17);
this.chkAutoLogin.TabIndex = 5;
this.chkAutoLogin.Text = "Tự động đăng nhập";
this.chkAutoLogin.UseVisualStyleBackColor = true;
this.chkAutoLogin.CheckedChanged += new System.EventHandler(this.chkAutoLogin_CheckedChanged);
//
// LoginForm // LoginForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(534, 211); this.ClientSize = new System.Drawing.Size(534, 211);
this.Controls.Add(this.chkAutoLogin);
this.Controls.Add(this.lblLoginStatus); this.Controls.Add(this.lblLoginStatus);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnLogin); this.Controls.Add(this.btnLogin);
this.Controls.Add(this.lblServerAddress); this.Controls.Add(this.lblServerAddress);
this.Controls.Add(this.lblPassword); this.Controls.Add(this.lblPassword);
@ -173,7 +175,7 @@
private System.Windows.Forms.TextBox txtServerAddress; private System.Windows.Forms.TextBox txtServerAddress;
private System.Windows.Forms.Label lblServerAddress; private System.Windows.Forms.Label lblServerAddress;
private System.Windows.Forms.Button btnLogin; private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Label lblLoginStatus; private System.Windows.Forms.Label lblLoginStatus;
private System.Windows.Forms.CheckBox chkAutoLogin;
} }
} }

View File

@ -111,30 +111,6 @@ namespace AIParkingApplication
Login(); Login();
} }
private void btnExit_Click(object sender, EventArgs e)
{
if (DialogResult.OK == MessageBox.Show("AIParking - Bạn muốn thoát ứng dụng?", "Cảnh báo!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
{
applicationLogger.Log(LogLevel.Info, "Login - Thoát ứng dụng");
Application.Exit();
}
}
private void DoAutoLogin()
{
try
{
}
catch (Exception ex)
{
Util.AddOrUpdateAppSettings("AUTO_LOGIN", string.Empty);
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadAccessControlDeviceIPConfiguration\t{ex.Message}");
applicationLogger.Log(LogLevel.Error, "Không thể đọc cấu hình tài khoản mặc định: DEFAULT_USERNAME, DEFAULT_PASSWORD");
}
}
private void ReadAppConfigurationFromFile() private void ReadAppConfigurationFromFile()
{ {
try try
@ -145,6 +121,7 @@ namespace AIParkingApplication
Thread.Sleep(500); Thread.Sleep(500);
if (isAutoLogin) if (isAutoLogin)
{ {
chkAutoLogin.Checked = true;
lblLoginStatus.UpdateLabel("Đang đăng nhập", Color.Green, Color.White); lblLoginStatus.UpdateLabel("Đang đăng nhập", Color.Green, Color.White);
Login(); Login();
} }
@ -156,6 +133,7 @@ namespace AIParkingApplication
Util.AddOrUpdateAppSettings("DEFAULT_USERNAME", string.Empty); Util.AddOrUpdateAppSettings("DEFAULT_USERNAME", string.Empty);
Util.AddOrUpdateAppSettings("DEFAULT_PASSWORD", string.Empty); Util.AddOrUpdateAppSettings("DEFAULT_PASSWORD", string.Empty);
Util.AddOrUpdateAppSettings("AUTO_LOGIN", "false"); Util.AddOrUpdateAppSettings("AUTO_LOGIN", "false");
chkAutoLogin.Checked = false;
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadAccessControlDeviceIPConfiguration\t{ex.Message}"); Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadAccessControlDeviceIPConfiguration\t{ex.Message}");
applicationLogger.Log(LogLevel.Error, "Không thể đọc cấu hình tài khoản mặc định: DEFAULT_USERNAME, DEFAULT_PASSWORD"); applicationLogger.Log(LogLevel.Error, "Không thể đọc cấu hình tài khoản mặc định: DEFAULT_USERNAME, DEFAULT_PASSWORD");
} }
@ -165,5 +143,10 @@ namespace AIParkingApplication
{ {
ReadAppConfigurationFromFile(); ReadAppConfigurationFromFile();
} }
private void chkAutoLogin_CheckedChanged(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings("AUTO_LOGIN", (sender as CheckBox).Checked.ToString().ToLower());
}
} }
} }