2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
User _user;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public UserForm(int? userID)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
if (userID.HasValue)
|
2011-06-23 12:47:48 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +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)
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
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
|
2011-06-23 12:47:48 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|