narsil/Tanshu.Accounts.PointOfSale/User Management/UserForm.cs

82 lines
2.3 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities.Auth;
2010-03-02 17:56:21 +00:00
namespace Tanshu.Accounts.PointOfSale
{
public partial class UserForm : Form
{
User _user;
public UserForm(int? userID)
2010-03-02 17:56:21 +00:00
{
InitializeComponent();
if (userID.HasValue)
using (var bi = new UserBI())
_user = bi.Get(x => x.UserID == userID.Value);
2010-03-02 17:56:21 +00:00
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
2010-03-02 17:56:21 +00:00
{
using (var bi = new UserBI())
bi.Delete(x => x.UserID == _user.UserID);
2010-03-02 17:56:21 +00:00
btnCancel_Click(sender, e);
}
private void NewUser_Load(object sender, EventArgs e)
{
if (_user == null)
return;
txtUsername.Text = _user.Name;
txtPassword.Text = _user.Password;
chkLocked.Checked = _user.LockedOut;
2010-03-02 17:56:21 +00:00
}
private bool Save()
{
if (_user == null)
_user = new User();
_user.Name = txtUsername.Text.Trim();
if (_user.Password != txtPassword.Text.Trim())
_user.Password = Common.Md5.Hash(txtPassword.Text.Trim(), "v2");
_user.LockedOut = (chkLocked.Checked == true ? true : false);
if (_user.UserID == 0)
using (var bi = new UserBI())
bi.Insert(_user);
2010-03-02 17:56:21 +00:00
else
using (var bi = new UserBI())
bi.Update(_user);
2010-03-02 17:56:21 +00:00
return true;
}
private void btnSave_Click(object sender, EventArgs e)
{
if (!ValidateValues())
{
MessageBox.Show("Missing Information: Please check the form.");
txtUsername.Focus();
}
else
{
Save();
btnCancel_Click(sender, e);
}
}
private bool ValidateValues()
{
if (txtUsername.Text.Trim() == "")
return false;
if (txtPassword.Text.Trim() == "")
return false;
return true;
}
}
}