diff --git a/AIParkingApplication/LoginForm.Designer.cs b/AIParkingApplication/LoginForm.Designer.cs index 791d40f..632cad4 100644 --- a/AIParkingApplication/LoginForm.Designer.cs +++ b/AIParkingApplication/LoginForm.Designer.cs @@ -34,8 +34,8 @@ this.lblUsername = new System.Windows.Forms.Label(); this.txtPassword = new System.Windows.Forms.TextBox(); this.lblPassword = new System.Windows.Forms.Label(); - this.lblServerAddress = new System.Windows.Forms.TextBox(); - this.lblServerIP = new System.Windows.Forms.Label(); + 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(); @@ -87,22 +87,22 @@ this.lblPassword.TabIndex = 2; this.lblPassword.Text = "Mật khẩu"; // + // txtServerAddress + // + this.txtServerAddress.Location = new System.Drawing.Point(294, 90); + this.txtServerAddress.Name = "txtServerAddress"; + this.txtServerAddress.Size = new System.Drawing.Size(227, 20); + this.txtServerAddress.TabIndex = 1; + this.txtServerAddress.Text = "http://localhost:80/"; + // // lblServerAddress // - this.lblServerAddress.Location = new System.Drawing.Point(294, 90); + this.lblServerAddress.AutoSize = true; + this.lblServerAddress.Location = new System.Drawing.Point(214, 93); this.lblServerAddress.Name = "lblServerAddress"; - this.lblServerAddress.Size = new System.Drawing.Size(227, 20); - this.lblServerAddress.TabIndex = 1; - this.lblServerAddress.Text = "localhost"; - // - // lblServerIP - // - this.lblServerIP.AutoSize = true; - this.lblServerIP.Location = new System.Drawing.Point(214, 93); - this.lblServerIP.Name = "lblServerIP"; - this.lblServerIP.Size = new System.Drawing.Size(48, 13); - this.lblServerIP.TabIndex = 2; - this.lblServerIP.Text = "Máy chủ"; + this.lblServerAddress.Size = new System.Drawing.Size(48, 13); + this.lblServerAddress.TabIndex = 2; + this.lblServerAddress.Text = "Máy chủ"; // // btnLogin // @@ -141,10 +141,10 @@ this.Controls.Add(this.lblLoginStatus); this.Controls.Add(this.btnExit); this.Controls.Add(this.btnLogin); - this.Controls.Add(this.lblServerIP); + this.Controls.Add(this.lblServerAddress); this.Controls.Add(this.lblPassword); this.Controls.Add(this.lblUsername); - this.Controls.Add(this.lblServerAddress); + this.Controls.Add(this.txtServerAddress); this.Controls.Add(this.txtPassword); this.Controls.Add(this.txtUsername); this.Controls.Add(this.pictureBoxImageLogo); @@ -168,8 +168,8 @@ private System.Windows.Forms.Label lblUsername; private System.Windows.Forms.TextBox txtPassword; private System.Windows.Forms.Label lblPassword; - private System.Windows.Forms.TextBox lblServerAddress; - private System.Windows.Forms.Label lblServerIP; + 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; diff --git a/AIParkingApplication/LoginForm.cs b/AIParkingApplication/LoginForm.cs index e789aa8..fc4ef11 100644 --- a/AIParkingApplication/LoginForm.cs +++ b/AIParkingApplication/LoginForm.cs @@ -13,13 +13,25 @@ namespace AIParkingApplication InitializeComponent(); pictureBoxImageLogo.Image = new Bitmap(@".\Images\ApplicationLogo.ico"); lblLoginStatus.Text = string.Empty; - - apiController = new ApiController(serverBaseAddress); this.AcceptButton = btnLogin; } private async void Login() { + if (string.IsNullOrEmpty(txtServerAddress.Text)) + { + lblLoginStatus.Text = "Địa chỉ server không được để trống!"; + return; + } + + if (!Util.IsUrlValid(txtServerAddress.Text)) + { + lblLoginStatus.Text = "Địa chỉ server không đúng định dạng: \r\n http://localhost:80 hoặc http://192.168.1.2:80"; + return; + } + + apiController = new ApiController(txtServerAddress.Text); + lblLoginStatus.Text = string.Empty; string username = txtUsername.Text; string password = txtPassword.Text; @@ -28,6 +40,7 @@ namespace AIParkingApplication lblLoginStatus.Text = "Tên tài khoản hoặc mật khẩu không được để trống!"; return; } + var loginResult = await apiController.Login(new LoginModel { Username = username, Password = password }); if (loginResult.IsLoginSuccess) { diff --git a/AIParkingApplication/Util.cs b/AIParkingApplication/Util.cs index 1b350ae..0827ae7 100644 --- a/AIParkingApplication/Util.cs +++ b/AIParkingApplication/Util.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.IO; using System.Net.Http; using System.Net.NetworkInformation; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; @@ -168,6 +169,14 @@ namespace AIParkingApplication //process.Close(); } } + + public static bool IsUrlValid(string url) + { + + string pattern = @"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$"; + Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); + return reg.IsMatch(url); + } } public class PlateRequestEngineModel