2011-02-09 12:03:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using System.Linq;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class AssignGroupRoles : Form
|
|
|
|
|
{
|
|
|
|
|
public AssignGroupRoles()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AssignGroupRoles_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
FillGroups();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void FillGroups()
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
|
|
|
|
cmbGroup.DisplayMember = "Name";
|
|
|
|
|
cmbGroup.ValueMember = "GroupID";
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using (var bi = new GroupBI())
|
|
|
|
|
cmbGroup.DataSource = bi.List();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void cmbGroup_SelectedIndexChanged(object sender, EventArgs e)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (cmbGroup.SelectedValue == null)
|
|
|
|
|
GetRoles(null);
|
|
|
|
|
else
|
|
|
|
|
GetRoles((Guid)cmbGroup.SelectedValue);
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void GetRoles(Guid? groupID)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using (var bi = new GroupBI())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
var roles = bi.RoleList();
|
|
|
|
|
clbRoles.DataSource = roles;
|
2014-11-10 07:24:48 +00:00
|
|
|
|
for (int i = 0; i < clbRoles.Items.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
clbRoles.SetItemChecked(i, false);
|
|
|
|
|
}
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (groupID.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var group = bi.Get(x => x.GroupID == groupID.Value);
|
|
|
|
|
for (int i = 0; i < clbRoles.Items.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = (Role)clbRoles.Items[i];
|
|
|
|
|
if (item.Groups.Any(x => x.Group == group))
|
|
|
|
|
{
|
|
|
|
|
clbRoles.SetItemChecked(i, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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 btnOk_Click(object sender, EventArgs e)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
if (cmbGroup.SelectedValue != null)
|
|
|
|
|
Save((Guid)cmbGroup.SelectedValue);
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
2014-10-16 11:11:55 +00:00
|
|
|
|
private void Save(Guid groupID)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
using (var bi = new GroupBI())
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
var group = bi.Get(x => x.GroupID == groupID);
|
|
|
|
|
bi.Update(group, clbRoles.CheckedItems.OfType<Role>());
|
|
|
|
|
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 clbRoles_Format(object sender, ListControlConvertEventArgs e)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2014-10-16 11:11:55 +00:00
|
|
|
|
e.Value = ((Role)e.ListItem).Name;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|