73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using Tanshu.Accounts.Entities;
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
{
|
|
public partial class RolesForm : Form
|
|
{
|
|
public RolesForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void RolesForm_Load(object sender, EventArgs e)
|
|
{
|
|
FillRoles();
|
|
}
|
|
|
|
private void FillRoles()
|
|
{
|
|
cmbRole.DisplayMember = "Name";
|
|
cmbRole.ValueMember = "RoleID";
|
|
cmbRole.DataSource = RoleBI.List();
|
|
}
|
|
|
|
private void cmbGroup_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (cmbRole.SelectedValue == null)
|
|
GetPermissions(null);
|
|
else
|
|
GetPermissions((Role)cmbRole.SelectedItem);
|
|
}
|
|
|
|
private void GetPermissions(Role role)
|
|
{
|
|
var permissions = RoleBI.Permissions();
|
|
clbPermissions.DataSource = permissions;
|
|
if (role != null)
|
|
{
|
|
for (int i = 0; i < clbPermissions.Items.Count; i++)
|
|
{
|
|
var item = (Permission)clbPermissions.Items[i];
|
|
clbPermissions.SetItemChecked(i, role.Permissions.Any(x => x.PermissionID == item.PermissionID));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
{
|
|
if (cmbRole.SelectedValue != null)
|
|
Save((Role)cmbRole.SelectedItem);
|
|
}
|
|
private void Save(Role role)
|
|
{
|
|
role.Permissions = clbPermissions.CheckedItems.OfType<Permission>().ToList();
|
|
RoleBI.Update(role);
|
|
MessageBox.Show("Update / Save Successful");
|
|
}
|
|
|
|
private void clbRoles_Format(object sender, ListControlConvertEventArgs e)
|
|
{
|
|
e.Value = ((Permission)e.ListItem).Name;
|
|
}
|
|
}
|
|
}
|