narsil/Tanshu.Accounts.PointOfSale/User Management/UserForm.cs
tanshu 69617949bd Important! : Need to update to new schema using SQL Scripts
Important! : This version will not work.  It is pre-alpha and saved in case of catastrophic failure
Refactor: Remove dependency on Fluent Nhibernate.
Refactor: All Primary keys are now Guids.
Refactor: Class Mappings changed from AutoMap to Explicit Mappings.
Breakage: All Cascading is now disabled and entities must be explicitly saved/updated/deleted
Breakage: Auto Commiting is now off and "SaveChanges()" needs to be called on all BIs.
Refactor: Changed the pattern where all relevant db code for an operation is basically in the same function.
Chore: Removed Advance and Payments options.
2014-10-12 15:11:45 +05:30

91 lines
2.5 KiB
C#

using System;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.PointOfSale
{
public partial class UserForm : Form
{
User _user;
public UserForm(Guid? userID)
{
InitializeComponent();
if (userID.HasValue)
using (var bi = new UserBI())
_user = bi.Get(x => x.UserID == userID.Value);
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
{
using (var bi = new UserBI())
{
bi.Delete(x => x.UserID == _user.UserID);
bi.SaveChanges();
}
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;
}
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 == Guid.Empty)
using (var bi = new UserBI())
{
bi.Insert(_user);
bi.SaveChanges();
}
else
using (var bi = new UserBI())
{
bi.Update(_user);
bi.SaveChanges();
}
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;
}
}
}