2011-02-09 12:03:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Tanshu.Accounts.Helpers;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class AssignUserGroups : Form
|
|
|
|
|
{
|
|
|
|
|
public AssignUserGroups()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AssignRoles_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
FillUsers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillUsers()
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
cmbUser.DisplayMember = "Name";
|
|
|
|
|
cmbUser.ValueMember = "UserID";
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var bi = new UserBI())
|
2014-10-16 11:11:55 +00:00
|
|
|
|
cmbUser.DataSource = bi.List();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cmbUsers_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (cmbUser.SelectedValue == null)
|
|
|
|
|
GetGroups(null);
|
|
|
|
|
else
|
|
|
|
|
GetGroups((Guid)cmbUser.SelectedValue);
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void GetGroups(Guid? userID)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using (var bi = new UserBI())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
var groups = bi.GroupList();
|
|
|
|
|
clbGroups.DataSource = groups;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (userID.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var user = bi.Get(x => x.UserID == userID.Value);
|
|
|
|
|
for (int i = 0; i < clbGroups.Items.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = (Group)clbGroups.Items[i];
|
|
|
|
|
if (item.UserGroups.Any(x => x.User == user))
|
|
|
|
|
{
|
|
|
|
|
clbGroups.SetItemChecked(i, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (cmbUser.SelectedValue != null)
|
|
|
|
|
Save((Guid)cmbUser.SelectedValue);
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void Save(Guid userID)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using (var bi = new UserBI())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
var user = bi.Get(x => x.UserID == userID);
|
|
|
|
|
bi.Update(user, clbGroups.CheckedItems.OfType<Group>());
|
|
|
|
|
bi.SaveChanges();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
2014-10-16 11:11:55 +00:00
|
|
|
|
MessageBox.Show("Update / Save Successful");
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
this.Close();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void clbGroups_Format(object sender, ListControlConvertEventArgs e)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
e.Value = ((Group)e.ListItem).Name;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|