narsil/Tanshu.Accounts.PointOfSale/User Management/UserForm.cs
tanshu 69560cfb07 Chore: Removed Waiter as it was not ever used.
Refactor: Changed the user list form to a normal form.
Feature: Service Charge disabled setting removes it from the Product Form.
2016-01-18 16:13:43 +05:30

91 lines
2.6 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 UserForm_Load(object sender, EventArgs e)
{
if (_user == null)
return;
txtUsername.Text = _user.Name;
txtPassword.Text = _user.Password;
txtRetype.Text = _user.Password;
chkLocked.Checked = _user.LockedOut;
}
private void Save()
{
using (var bi = new UserBI())
{
if (_user == null)
_user = new User();
else
_user = bi.Get(x => x.UserID == _user.UserID);
_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)
bi.Insert(_user);
else
bi.Update(_user);
bi.SaveChanges();
}
}
private void btnSave_Click(object sender, EventArgs e)
{
if (txtUsername.Text.Trim() == "")
{
MessageBox.Show("Username cannot be blank.");
txtUsername.Focus();
}
else if (txtPassword.Text.Trim() != txtRetype.Text.Trim())
{
MessageBox.Show("Passwords do not match.");
txtPassword.Focus();
}
else if (string.IsNullOrEmpty(txtPassword.Text.Trim()))
{
MessageBox.Show("Password cannot be empty.");
txtPassword.Focus();
}
else
{
Save();
btnCancel_Click(sender, e);
}
}
}
}