70 lines
2.3 KiB
C#
70 lines
2.3 KiB
C#
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AIParkingApplication
|
|
{
|
|
public partial class LoginForm : Form
|
|
{
|
|
private ApiController apiController;
|
|
|
|
public LoginForm()
|
|
{
|
|
InitializeComponent();
|
|
pictureBoxImageLogo.Image = new Bitmap(@".\Images\ApplicationLogo.ico");
|
|
txtUsername.Focus();
|
|
lblLoginStatus.Text = string.Empty;
|
|
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;
|
|
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
|
|
{
|
|
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)
|
|
{
|
|
new AIParkingApplicationForm(apiController, loginResult.LoginData).Show();
|
|
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)
|
|
{
|
|
Login();
|
|
}
|
|
|
|
private void btnExit_Click(object sender, System.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))
|
|
{
|
|
Application.Exit();
|
|
}
|
|
}
|
|
}
|
|
}
|