narsil/Tanshu.Accounts.PointOfSale/Authentication/LoginForm.cs

62 lines
1.7 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class LoginForm : Form
{
private User _user;
private IKeyboardControl _keyboardControl;
public LoginForm(IKeyboardControl keyboardControl)
{
InitializeComponent();
_user = null;
this._keyboardControl = keyboardControl;
var control = keyboardControl as UserControl;
if (control != null)
{
control.Location = new Point(6, 87);
this.Controls.Add(control);
this.Size = this.SizeFromClientSize(new Size(6 + control.Width + 6, 87 + control.Height + 6));
}
}
private void txtUserName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
txtPassword.Focus();
}
private void txtPassword_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
btnLogin_Click(sender, e);
}
private void btnLogin_Click(object sender, EventArgs e)
{
using (var bi = new UserBI())
_user = bi.ValidateUser(txtUserName.Text.Trim(), txtPassword.Text);
if (_user != null)
this.Close();
else
MessageBox.Show("Username or password is not valid");
}
public User User()
{
return _user;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}