211 lines
5.6 KiB
C#
211 lines
5.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
|
|
namespace WinApp
|
|
{
|
|
public partial class frmRoles : Form
|
|
{
|
|
Role _role;
|
|
private PermLookup _pl=new PermLookup();
|
|
public frmRoles()
|
|
{
|
|
InitializeComponent();
|
|
roleInfoListBindingSource.DataSource = RoleInfoList.Get();
|
|
permADLookupBindingSource.DataSource = _pl.PermADLookup;
|
|
SetupDetail();
|
|
SetupButtons();
|
|
}
|
|
private DialogResult SaveAsNeeded()
|
|
{
|
|
if (_role != null && _role.IsSavable)
|
|
{
|
|
DialogResult dr = MessageBox.Show("Do you want to save changes", "Save Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (dr == DialogResult.Yes) Save();
|
|
if (dr == DialogResult.No) Cancel();
|
|
// TODO: Need a Cancel
|
|
return dr;
|
|
}
|
|
return DialogResult.Yes;
|
|
}
|
|
private void SetupDetail()
|
|
{
|
|
if (lbRoles.SelectedValue != null)
|
|
{
|
|
int rid = (int)lbRoles.SelectedValue;
|
|
if (_role == null || _role.RID != rid)
|
|
{
|
|
if (SaveAsNeeded() != DialogResult.Cancel)
|
|
{
|
|
_role = Role.Get(rid);
|
|
roleBindingSource.DataSource = _role;
|
|
roleAssignmentsBindingSource.DataSource = _role.RoleAssignments;
|
|
rolePermissionsBindingSource.DataSource = _role.RolePermissions;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void lbRole_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
SetupDetail();
|
|
}
|
|
private void SetupButtons()
|
|
{
|
|
if (_role != null)
|
|
{
|
|
btnSave.Enabled = _role.IsSavable;
|
|
btnCancel.Enabled = _role.IsDirty;
|
|
btnNew.Enabled = _role.IsValid;
|
|
}
|
|
else
|
|
{
|
|
btnSave.Enabled = false;
|
|
btnCancel.Enabled = false;
|
|
btnNew.Enabled = true;
|
|
}
|
|
}
|
|
private void CurrentItemChanged(object sender, EventArgs e)
|
|
{
|
|
SetupButtons();
|
|
}
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
Cancel();
|
|
}
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
Save();
|
|
}
|
|
private void btnNew_Click(object sender, EventArgs e)
|
|
{
|
|
New();
|
|
}
|
|
private void Cancel()
|
|
{
|
|
_role.CancelEdit();
|
|
_role.BeginEdit();
|
|
}
|
|
private void Save()
|
|
{
|
|
roleBindingSource.RaiseListChangedEvents = false;
|
|
roleAssignmentsBindingSource.RaiseListChangedEvents = false;
|
|
rolePermissionsBindingSource.RaiseListChangedEvents = false;
|
|
roleBindingSource.EndEdit();
|
|
roleAssignmentsBindingSource.EndEdit();
|
|
rolePermissionsBindingSource.EndEdit();
|
|
try
|
|
{
|
|
Role temp = _role.Clone();
|
|
_role = temp.Save();
|
|
_role.BeginEdit();
|
|
roleBindingSource.DataSource = null;
|
|
roleAssignmentsBindingSource.DataSource = null;
|
|
rolePermissionsBindingSource.DataSource = null;
|
|
int rid = _role.RID;
|
|
roleInfoListBindingSource.DataSource = RoleInfoList.Get();
|
|
if (lbRoles.SelectedIndex == -1)
|
|
lbRoles.SelectedValue = rid;
|
|
roleBindingSource.DataSource = _role;
|
|
roleAssignmentsBindingSource.DataSource = _role.RoleAssignments;
|
|
rolePermissionsBindingSource.DataSource = _role.RolePermissions;
|
|
}
|
|
catch (Csla.DataPortalException ex)
|
|
{
|
|
MessageBox.Show(ex.BusinessException.ToString(),
|
|
"Error saving", MessageBoxButtons.OK,
|
|
MessageBoxIcon.Exclamation);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.ToString(), "Error saving",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
}
|
|
finally
|
|
{
|
|
roleBindingSource.RaiseListChangedEvents = true;
|
|
roleAssignmentsBindingSource.RaiseListChangedEvents = true;
|
|
rolePermissionsBindingSource.RaiseListChangedEvents = true;
|
|
roleBindingSource.ResetBindings(false);
|
|
roleAssignmentsBindingSource.ResetBindings(false);
|
|
rolePermissionsBindingSource.ResetBindings(false);
|
|
}
|
|
SetupButtons();
|
|
}
|
|
public void New()
|
|
{
|
|
if (SaveAsNeeded() != DialogResult.Cancel)
|
|
{
|
|
_role = Role.New();
|
|
roleBindingSource.DataSource = _role;
|
|
roleAssignmentsBindingSource.DataSource = _role.RoleAssignments;
|
|
rolePermissionsBindingSource.DataSource = _role.RolePermissions;
|
|
}
|
|
}
|
|
|
|
private void BeforeFormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
e.Cancel = (SaveAsNeeded() == DialogResult.Cancel);
|
|
}
|
|
|
|
private void btnNewPermission_Click(object sender, EventArgs e)
|
|
{
|
|
_role.RolePermissions.Add(RolePermission.New());
|
|
}
|
|
|
|
private void frmRoles_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
//private void btnNewGA_Click(object sender, EventArgs e)
|
|
//{
|
|
// using (frmUserSelect f = new frmUserSelect())
|
|
// {
|
|
// f.ShowDialog();
|
|
// if (f.DialogResult == DialogResult.OK)
|
|
// {
|
|
// _group.GroupMemberships.Add(f.UID);
|
|
// SetupButtons();
|
|
// }
|
|
// }
|
|
//}
|
|
//private void btnRemoveGA_Click(object sender, EventArgs e)
|
|
//{
|
|
// if (this.groupMembershipsDataGridView.SelectedRows.Count > 0)
|
|
// {
|
|
// int uid = int.Parse(
|
|
// this.groupMembershipsDataGridView.SelectedRows[0].Cells[0].Value.ToString());
|
|
// _group.GroupMemberships.Remove(uid);
|
|
// }
|
|
//}
|
|
|
|
//private void btnRemoveAssign_Click(object sender, EventArgs e)
|
|
//{
|
|
// if (this.groupPermissionsDataGridView.SelectedRows.Count > 0)
|
|
// {
|
|
// int folderid = int.Parse(
|
|
// this.groupMembershipsDataGridView.SelectedRows[1].Cells[0].Value.ToString());
|
|
// int rid = int.Parse(
|
|
// this.groupMembershipsDataGridView.SelectedRows[2].Cells[0].Value.ToString());
|
|
// _group.GroupAssignments.Remove(folderid, rid);
|
|
// }
|
|
|
|
//}
|
|
|
|
//private void btnNewAssign_Click(object sender, EventArgs e)
|
|
//{
|
|
// using (frmAssignmentSelect f = new frmAssignmentSelect(_group))
|
|
// {
|
|
// f.ShowDialog();
|
|
// if (f.DialogResult == DialogResult.OK)
|
|
// {
|
|
// //TODO: Do I need to refresh Assignments?
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
} |