From 2c6e3260080ca513723dabd2902284442b59a878 Mon Sep 17 00:00:00 2001 From: DucDangAnh Date: Thu, 16 Jul 2020 16:23:43 +0700 Subject: [PATCH] LoginForm - Add UI check status auto login --- AIParkingApplication/LoginForm.Designer.cs | 40 ++++++++++++---------- AIParkingApplication/LoginForm.cs | 31 ++++------------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/AIParkingApplication/LoginForm.Designer.cs b/AIParkingApplication/LoginForm.Designer.cs index 7ade62a..ad6a167 100644 --- a/AIParkingApplication/LoginForm.Designer.cs +++ b/AIParkingApplication/LoginForm.Designer.cs @@ -37,8 +37,8 @@ this.txtServerAddress = new System.Windows.Forms.TextBox(); this.lblServerAddress = new System.Windows.Forms.Label(); this.btnLogin = new System.Windows.Forms.Button(); - this.btnExit = new System.Windows.Forms.Button(); this.lblLoginStatus = new System.Windows.Forms.Label(); + this.chkAutoLogin = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxImageLogo)).BeginInit(); this.SuspendLayout(); // @@ -70,7 +70,7 @@ // // 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.PasswordChar = '*'; this.txtPassword.Size = new System.Drawing.Size(227, 20); @@ -80,7 +80,7 @@ // lblPassword // 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.Size = new System.Drawing.Size(52, 13); this.lblPassword.TabIndex = 2; @@ -88,7 +88,7 @@ // // 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.Size = new System.Drawing.Size(227, 20); this.txtServerAddress.TabIndex = 1; @@ -97,7 +97,7 @@ // lblServerAddress // 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.Size = new System.Drawing.Size(48, 13); this.lblServerAddress.TabIndex = 2; @@ -105,42 +105,44 @@ // // 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.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.Text = "Đăng nhập"; this.btnLogin.UseVisualStyleBackColor = true; 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 // 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.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.Size = new System.Drawing.Size(90, 18); this.lblLoginStatus.TabIndex = 4; 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(534, 211); + this.Controls.Add(this.chkAutoLogin); this.Controls.Add(this.lblLoginStatus); - this.Controls.Add(this.btnExit); this.Controls.Add(this.btnLogin); this.Controls.Add(this.lblServerAddress); this.Controls.Add(this.lblPassword); @@ -173,7 +175,7 @@ private System.Windows.Forms.TextBox txtServerAddress; private System.Windows.Forms.Label lblServerAddress; private System.Windows.Forms.Button btnLogin; - private System.Windows.Forms.Button btnExit; private System.Windows.Forms.Label lblLoginStatus; + private System.Windows.Forms.CheckBox chkAutoLogin; } } \ No newline at end of file diff --git a/AIParkingApplication/LoginForm.cs b/AIParkingApplication/LoginForm.cs index 33fa3cc..dad0ed6 100644 --- a/AIParkingApplication/LoginForm.cs +++ b/AIParkingApplication/LoginForm.cs @@ -111,30 +111,6 @@ namespace AIParkingApplication 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() { try @@ -145,6 +121,7 @@ namespace AIParkingApplication Thread.Sleep(500); if (isAutoLogin) { + chkAutoLogin.Checked = true; lblLoginStatus.UpdateLabel("Đang đăng nhập", Color.Green, Color.White); Login(); } @@ -156,6 +133,7 @@ namespace AIParkingApplication Util.AddOrUpdateAppSettings("DEFAULT_USERNAME", string.Empty); Util.AddOrUpdateAppSettings("DEFAULT_PASSWORD", string.Empty); Util.AddOrUpdateAppSettings("AUTO_LOGIN", "false"); + chkAutoLogin.Checked = false; 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"); } @@ -165,5 +143,10 @@ namespace AIParkingApplication { ReadAppConfigurationFromFile(); } + + private void chkAutoLogin_CheckedChanged(object sender, EventArgs e) + { + Util.AddOrUpdateAppSettings("AUTO_LOGIN", (sender as CheckBox).Checked.ToString().ToLower()); + } } }