narsil/Tanshu.Accounts.PointOfSale/User Management/AssignRoleGroups.cs
tanshu da929ad036 Breaking Change: Changed Kot/Voucher Table Name to Guid Foreign key
Breaking Change: Renamed Discontinued to IsActive and added NA field to products.
Cleanup: Removed not used attributes
Change: RoleConstants changed to simple string
Feature: Table Create/Edit/Reorder and Modifier Create/Edit Form
Feature: Bills now show the Tax name from the database and not a hack
2014-10-16 16:41:55 +05:30

87 lines
2.4 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;
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;
}
}
}