LoginForm - Catch exception to handle login status. (API needs to fixed same return data type: todo DongPD)
This commit is contained in:
parent
53f457b020
commit
5f7ac10f22
|
@ -42,7 +42,8 @@ namespace AIParkingApplication
|
||||||
Console.WriteLine($"Login Exception:\t{DateTime.Now.GetTimeFormatted()} \t {ex.Message}");
|
Console.WriteLine($"Login Exception:\t{DateTime.Now.GetTimeFormatted()} \t {ex.Message}");
|
||||||
return new LoginDataModel
|
return new LoginDataModel
|
||||||
{
|
{
|
||||||
IsLoginSuccess = false
|
IsLoginSuccess = false,
|
||||||
|
Exception = ex
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +110,7 @@ namespace AIParkingApplication
|
||||||
CardID = cardID,
|
CardID = cardID,
|
||||||
TextPlate = plateString,
|
TextPlate = plateString,
|
||||||
CameraID = cameraID,
|
CameraID = cameraID,
|
||||||
ModePlate = plateType == PlateType.Square ? "1":"0",
|
ModePlate = plateType == PlateType.Square ? "1" : "0",
|
||||||
Timestamp = timestamp,
|
Timestamp = timestamp,
|
||||||
PlateImage = plateImageBase64,
|
PlateImage = plateImageBase64,
|
||||||
PlateResultImage = plateImageResultBase64,
|
PlateResultImage = plateImageResultBase64,
|
||||||
|
@ -259,6 +260,8 @@ namespace AIParkingApplication
|
||||||
|
|
||||||
[JsonProperty("data")]
|
[JsonProperty("data")]
|
||||||
public Config LoginData { get; set; }
|
public Config LoginData { get; set; }
|
||||||
|
|
||||||
|
public Exception Exception { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Config
|
public class Config
|
||||||
|
|
|
@ -55,15 +55,26 @@ namespace AIParkingApplication
|
||||||
}
|
}
|
||||||
|
|
||||||
var loginResult = await apiController.Login(new LoginModel { Username = username, Password = password });
|
var loginResult = await apiController.Login(new LoginModel { Username = username, Password = password });
|
||||||
|
if (loginResult.Exception != null)
|
||||||
|
{
|
||||||
|
var execeptioMessage = loginResult.Exception.Message;
|
||||||
|
if (execeptioMessage.Contains("Error converting value"))
|
||||||
|
{
|
||||||
|
lblLoginStatus.UpdateLabel("Tên tài khoản hoặc mật khẩu không đúng!", Color.Red);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (execeptioMessage.Contains("An error occurred while sending the request"))
|
||||||
|
{
|
||||||
|
lblLoginStatus.UpdateLabel("Không có kết nối tới server!\r\nKiểm tra lại kết nối tới server!", Color.Red, Color.White);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (loginResult.IsLoginSuccess)
|
if (loginResult.IsLoginSuccess)
|
||||||
{
|
{
|
||||||
new AIParkingApplicationForm(apiController, loginResult.LoginData).Show();
|
new AIParkingApplicationForm(apiController, loginResult.LoginData).Show();
|
||||||
Hide();
|
Hide();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
lblLoginStatus.Text = "Tên tài khoản hoặc mật khẩu không đúng!";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnLogin_Click(object sender, System.EventArgs e)
|
private void btnLogin_Click(object sender, System.EventArgs e)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user