narsil/Tanshu.Accounts.PointOfSale/User Management/AssignGroupRoles.cs
tanshu 5e64209b76 Feature: Added a Tax Management form and a beer consumption report.
Chore: Fixed some Form_Load function names as they were copied from old forms and were not neat.
Feature: Management BI Improved and should be pretty much solid by now.
2016-07-04 11:51:39 +05:30

90 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
namespace Tanshu.Accounts.PointOfSale
{
public partial class AssignGroupRoles : Form
{
public AssignGroupRoles()
{
InitializeComponent();
}
private void AssignGroupRoles_Load(object sender, EventArgs e)
{
FillGroups();
}
private void FillGroups()
{
cmbGroup.DisplayMember = "Name";
cmbGroup.ValueMember = "GroupID";
using (var bi = new GroupBI())
cmbGroup.DataSource = bi.List();
}
private void cmbGroup_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbGroup.SelectedValue == null)
GetRoles(null);
else
GetRoles((Guid)cmbGroup.SelectedValue);
}
private void GetRoles(Guid? groupID)
{
using (var bi = new GroupBI())
{
var roles = bi.RoleList();
clbRoles.DataSource = roles;
for (int i = 0; i < clbRoles.Items.Count; i++)
{
clbRoles.SetItemChecked(i, false);
}
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);
}
}
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnOk_Click(object sender, EventArgs e)
{
if (cmbGroup.SelectedValue != null)
Save((Guid)cmbGroup.SelectedValue);
}
private void Save(Guid groupID)
{
using (var bi = new GroupBI())
{
var group = bi.Get(x => x.GroupID == groupID);
bi.Update(group, clbRoles.CheckedItems.OfType<Role>());
bi.SaveChanges();
}
MessageBox.Show("Update / Save Successful");
}
private void clbRoles_Format(object sender, ListControlConvertEventArgs e)
{
e.Value = ((Role)e.ListItem).Name;
}
}
}