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

64 lines
2.0 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Windows.Forms;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
using Tanshu.Common.KeyboardControl;
2010-03-02 17:56:21 +00:00
namespace Tanshu.Accounts.PointOfSale
{
public partial class LoginForm : Form
{
private User user;
private IKeyboardControl keyboardControl;
public LoginForm(IKeyboardControl keyboardControl)
2010-03-02 17:56:21 +00:00
{
InitializeComponent();
user = null;
this.keyboardControl = keyboardControl;
var control = keyboardControl as UserControl;
if (control != null)
{
control.Location = new System.Drawing.Point(6, 87);
var border = (this.Width - this.ClientSize.Width) / 2;
var titlebarHeight = this.Height - this.ClientSize.Height - (2 * border);
this.Controls.Add(control);
this.Width = 6 + control.Width + 6 + (border * 2);
this.Height = titlebarHeight + 87 + control.Height + 6 + (border * 2);
}
2010-03-02 17:56:21 +00:00
}
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)
{
user = UserBI.ValidateUser(txtUserName.Text.Trim(), Tanshu.Common.Md5.Hash(txtPassword.Text, "v2"));
if (user != null)
2010-03-02 17:56:21 +00:00
this.Close();
else
MessageBox.Show("Username or password is not valid");
}
public bool UserName(out string userName)
{
userName = this.user == null ? "" : this.user.Name;
return this.user != null;
2010-03-02 17:56:21 +00:00
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}