2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
using System.Linq;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
using System.Windows.Forms;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
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;
|
2014-10-12 09:41:45 +00:00
|
|
|
|
public UserForm(Guid? userID)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
if (userID.HasValue)
|
2018-08-24 10:41:33 +00:00
|
|
|
|
_user = UserBI.Get(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
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
UserBI.Delete(_user.UserID);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
btnCancel_Click(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 10:43:43 +00:00
|
|
|
|
private void UserForm_Load(object sender, EventArgs e)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
var roles = RoleBI.List();
|
|
|
|
|
clbRoles.DataSource = roles;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (_user == null)
|
|
|
|
|
return;
|
|
|
|
|
txtUsername.Text = _user.Name;
|
|
|
|
|
txtPassword.Text = _user.Password;
|
2016-01-18 10:43:43 +00:00
|
|
|
|
txtRetype.Text = _user.Password;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
chkLocked.Checked = _user.LockedOut;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < clbRoles.Items.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = (Role)clbRoles.Items[i];
|
|
|
|
|
clbRoles.SetItemChecked(i, _user.Roles.Any(x => x.RoleID == item.RoleID));
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 10:43:43 +00:00
|
|
|
|
private void Save()
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
if (_user == null)
|
|
|
|
|
_user = new User();
|
|
|
|
|
else
|
|
|
|
|
_user = UserBI.Get(_user.UserID);
|
2016-01-18 10:43:43 +00:00
|
|
|
|
|
2018-08-24 10:41:33 +00:00
|
|
|
|
_user.Name = txtUsername.Text.Trim();
|
|
|
|
|
if (_user.Password != txtPassword.Text.Trim())
|
|
|
|
|
_user.Password = txtPassword.Text.Trim();
|
|
|
|
|
_user.LockedOut = (chkLocked.Checked == true ? true : false);
|
|
|
|
|
_user.Roles = clbRoles.CheckedItems.OfType<Role>().ToList();
|
2016-01-18 10:43:43 +00:00
|
|
|
|
|
2018-08-24 10:41:33 +00:00
|
|
|
|
if (_user.UserID == Guid.Empty)
|
|
|
|
|
UserBI.Insert(_user);
|
|
|
|
|
else
|
|
|
|
|
UserBI.Update(_user);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-08-24 10:41:33 +00:00
|
|
|
|
if (string.IsNullOrEmpty(txtUsername.Text.Trim()))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2016-01-18 10:43:43 +00:00
|
|
|
|
MessageBox.Show("Username cannot be blank.");
|
2010-03-02 17:56:21 +00:00
|
|
|
|
txtUsername.Focus();
|
|
|
|
|
}
|
2016-01-18 10:43:43 +00:00
|
|
|
|
else if (txtPassword.Text.Trim() != txtRetype.Text.Trim())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Passwords do not match.");
|
|
|
|
|
txtPassword.Focus();
|
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
else if (_user == null && string.IsNullOrEmpty(txtPassword.Text.Trim()))
|
2016-01-18 10:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Password cannot be empty.");
|
|
|
|
|
txtPassword.Focus();
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Save();
|
2018-08-24 10:41:33 +00:00
|
|
|
|
this.Close();
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-24 10:41:33 +00:00
|
|
|
|
|
|
|
|
|
private void clbRoles_Format(object sender, ListControlConvertEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.Value = ((Role)e.ListItem).Name;
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|