349 lines
11 KiB
C#
349 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Sarand.Core.Bus;
|
|
using Sarand.PatientMgr.Core.Bus;
|
|
using Sarand.Win.Forms.Utils;
|
|
using Sarand.Core.Base;
|
|
using Sarand.PatientMgr.Core.App;
|
|
using Sarand.PatientMgr.Win.Forms.Maint;
|
|
using Sarand.PatientMgr.Win.Forms.Controls;
|
|
|
|
namespace Sarand.PatientMgr.Win.Forms.Panels
|
|
{
|
|
//=======================================================================
|
|
public partial class SpmPanel_EmployeeRoles : SpmPanel_Items
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Configuration.
|
|
public enum PanelMode
|
|
{
|
|
Search,
|
|
Maintain,
|
|
}
|
|
public new class Config : SpmPanel_Items.Config
|
|
{
|
|
public PanelMode Mode { get; set; } = PanelMode.Maintain;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private Config config = new Config();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SpmPanel_EmployeeRoles() : this(new Config()) { }
|
|
public SpmPanel_EmployeeRoles(Config config) : base(config)
|
|
{
|
|
this.config = config;
|
|
InitializeComponent();
|
|
}
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
if (components != null) components.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
protected override String DefaultMessageTitle { get { return "EmployeeRole"; } }
|
|
public override int ItemTotal { get { return listViewEmployeeRole.ItemTotal; } }
|
|
public override int ItemCount { get { return listViewEmployeeRole.ItemCount; } }
|
|
public override int SelectedItemCount { get { return listViewEmployeeRole.SelectedItemCount; } }
|
|
public SysId SelectedItemId { get { return listViewEmployeeRole.SelectedItemId; } }
|
|
public List<SysId> SelectedItemIds { get { return listViewEmployeeRole.SelectedItemIds; } }
|
|
public SpmEmployeeRole SelectedEmployeeRole { get { return listViewEmployeeRole.SelectedEmployeeRole; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// Configure.
|
|
public void SetConfig(Config config)
|
|
{
|
|
base.SetConfig(config);
|
|
this.config = config;
|
|
ConfigurePanel();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Initialisation.
|
|
protected override void OnCreateControl()
|
|
{
|
|
base.OnCreateControl();
|
|
if (this.IsDesignerHosted()) return;
|
|
|
|
ConfigurePanel();
|
|
}
|
|
|
|
private void ConfigurePanel()
|
|
{
|
|
if (!Created) return;
|
|
if (this.IsDesignerHosted()) return;
|
|
|
|
// Complete form initialisation.
|
|
SetControlActivity();
|
|
PositionControls();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Initialise tabs.
|
|
private void InitTabs()
|
|
{
|
|
/*tabControl.TabPages.Clear();
|
|
tabPages.Clear();
|
|
if (!config.DisplayTabs) return;
|
|
|
|
|
|
foreach (var tabPage in tabPages)
|
|
tabControl.TabPages.Add(tabPage);
|
|
tabControl.Visible = (tabControl.TabPages.Count > 0);*/
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// P a n e l I n t e r f a c e
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
// F i l t e r
|
|
//-------------------------------------------------------------------
|
|
public SpmEmployeeRole.Params GetParams()
|
|
{
|
|
SpmEmployeeRole.Params prmEmployeeRole = new SpmEmployeeRole.Params();
|
|
|
|
// Sort columns.
|
|
prmEmployeeRole.SortColumns.AddRange(listViewEmployeeRole.GetSortColumns());
|
|
return prmEmployeeRole;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// A c t i o n s
|
|
//-------------------------------------------------------------------
|
|
public override void RefreshDataItems()
|
|
{
|
|
listViewEmployeeRole.RefreshEmployeeRoles(GetParams());
|
|
}
|
|
public override void RefreshDataItem(SysId id)
|
|
{
|
|
listViewEmployeeRole.RefreshEmployeeRole(id);
|
|
}
|
|
public override void RemoveDataItem(SysId id)
|
|
{
|
|
listViewEmployeeRole.RemoveItemById(id);
|
|
}
|
|
//-------------------------------------------------------------------
|
|
// Create item.
|
|
public override bool CanCreateItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
//if (!SecurityProfile.UserCanCreateItemType(Spm.DataItemType.EmployeeRole)) return false;
|
|
return true;
|
|
}
|
|
public override void CreateItem()
|
|
{
|
|
if (!CanCreateItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
// Create new EmployeeRole.
|
|
SpmForm_EmployeeRole.Config configEmployeeRole = new SpmForm_EmployeeRole.Config();
|
|
using (var form = new SpmForm_EmployeeRole(configEmployeeRole))
|
|
{
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
/*RefreshDataItem(form.NewItemId);
|
|
InvokeItemCreatedEvent(Spm.ItemType.EmployeeRole, form.NewItemId);*/
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// View/Update item.
|
|
public override bool CanViewItem()
|
|
{
|
|
return true;
|
|
}
|
|
public override bool CanUpdateItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
/*bool canMaintainEmployeeRoles = SecurityProfile.UserCanCreateItemType(Spm.ItemType.EmployeeRole) || SecurityProfile.UserCanUpdateItemType(Spm.ItemType.EmployeeRole);
|
|
if (!canMaintainEmployeeRoles) return false;*/
|
|
return true;
|
|
}
|
|
public override void UpdateItem(bool updateItem = true)
|
|
{
|
|
//if (!CanUpdateItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
SpmEmployeeRole employeeRole = SelectedEmployeeRole;
|
|
if (SelectedItemCount != 1) return;
|
|
if (!CanUpdateItem() && !CanViewItem()) return;
|
|
if (!CanUpdateItem()) updateItem = false;
|
|
if (employeeRole == null)
|
|
{
|
|
MessageConsole.ShowMessageWarning("Failed to retrieve selected item");
|
|
return;
|
|
}
|
|
SpmForm_EmployeeRole.Config configEmployeeRole = new SpmForm_EmployeeRole.Config();
|
|
configEmployeeRole.EmployeeRoleToUpdate = employeeRole;
|
|
configEmployeeRole.ReadOnly = (config.ReadOnly || !updateItem);
|
|
using (SpmForm_EmployeeRole formEmployeeRole = new SpmForm_EmployeeRole(configEmployeeRole))
|
|
{
|
|
// Perform the update.
|
|
if (formEmployeeRole.ShowDialog() == DialogResult.OK)
|
|
{
|
|
// EmployeeRole has been updated.
|
|
RefreshDataItem(employeeRole.Id);
|
|
listViewEmployeeRole.RefreshEmployeeRole(employeeRole.Id);
|
|
InvokeItemUpdatedEvent(Spm.DataItemType.EmployeeRole, employeeRole.Id);
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Delete item.
|
|
public override bool CanDeleteItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
//if (!SecurityProfile.UserCanRemoveItemType(Spm.ItemType.EmployeeRole)) return false;
|
|
return true;
|
|
}
|
|
public override void DeleteItem()
|
|
{
|
|
if (!CanDeleteItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
if (SelectedItemCount != 1) return;
|
|
SpmEmployeeRole employeeRole = SelectedEmployeeRole;
|
|
if (employeeRole == null)
|
|
{
|
|
MessageConsole.ShowMessageWarning("Failed to retrieve item for deletion.");
|
|
return;
|
|
}
|
|
if (!DepartmentMgr.EmployeeRoleCanBeDeleted(employeeRole))
|
|
{
|
|
MessageConsole.ShowMessageError("Unable to remove employeeRole - " + DepartmentMgr.ErrorStateMessage + ".");
|
|
return;
|
|
}
|
|
if (MessageConsole.ShowMessageConfirm("Are you sure that this employeeRole should be removed from the system?"))
|
|
{
|
|
if (DepartmentMgr.DeleteEmployeeRole(employeeRole, DbUpdateInfo))
|
|
{
|
|
int selectIdx = listViewEmployeeRole.SelectedIndex;
|
|
listViewEmployeeRole.RemoveItemById(employeeRole.Id.ToString());
|
|
if (selectIdx >= listViewEmployeeRole.ItemCount - 1) selectIdx--;
|
|
listViewEmployeeRole.SelectedIndices.Clear();
|
|
listViewEmployeeRole.SelectedIndices.Add(selectIdx);
|
|
}
|
|
else MessageConsole.ShowMessageError("Failed to remove employeeRole - " + DepartmentMgr.ErrorStateMessage + ".");
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status change - Deactivate.
|
|
protected void DeactivateItem(object sender, EventArgs e) { DeactivateItem(); }
|
|
public void DeactivateItem()
|
|
{
|
|
SpmEmployeeRole employeeRole = SelectedEmployeeRole;
|
|
if (employeeRole != null && employeeRole.Status == SaStatus.Active)
|
|
{
|
|
employeeRole.Status = SaStatus.Inactive;
|
|
if (DepartmentMgr.UpdateEmployeeRole(employeeRole, DbUpdateInfo))
|
|
{
|
|
RefreshDataItem(employeeRole.Id);
|
|
//InvokeItemUpdatedEvent(Spm.ItemType.EmployeeRole, employeeRole.Id);
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Import data.
|
|
public override bool CanImportData()
|
|
{
|
|
return false;
|
|
}
|
|
public override void ImportData()
|
|
{
|
|
if (!CanImportData()) return;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Export data.
|
|
public override bool CanExportData()
|
|
{
|
|
return false;
|
|
}
|
|
public override void ExportData()
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t e x t M e n u
|
|
//-------------------------------------------------------------------
|
|
private SpmContextMenuStrip contextMenuStrip = new SpmContextMenuStrip();
|
|
private void RefreshContextMenu()
|
|
{
|
|
contextMenuStrip.Name = "EmployeeRole";
|
|
contextMenuStrip.Items.Clear();
|
|
if (CanCreateItem())
|
|
contextMenuStrip.Items.Add("Create", null, CreateItem);
|
|
if (SysId.IsValid(listViewEmployeeRole.SelectedItemId))
|
|
{
|
|
SpmEmployeeRole employeeRole = SelectedEmployeeRole;
|
|
if (employeeRole != null)
|
|
{
|
|
if (CanUpdateItem())
|
|
{
|
|
if (contextMenuStrip.Items.Count > 0)
|
|
contextMenuStrip.Items.Add(new ToolStripSeparator());
|
|
contextMenuStrip.Items.Add("Update", null, UpdateItem);
|
|
}
|
|
}
|
|
}
|
|
if (CanExportData() || CanImportData())
|
|
{
|
|
if (contextMenuStrip.Items.Count > 0)
|
|
contextMenuStrip.Items.Add(new ToolStripSeparator());
|
|
if (CanImportData())
|
|
contextMenuStrip.Items.Add("Import", null, ImportData);
|
|
if (CanExportData())
|
|
contextMenuStrip.Items.Add("Export", null, ExportData);
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l A c t i v i t y
|
|
//-------------------------------------------------------------------
|
|
protected override void SetControlActivity()
|
|
{
|
|
// EmployeeRole list:
|
|
listViewEmployeeRole.Enabled = Enabled;
|
|
SetControlsReadOnly();
|
|
|
|
|
|
//ToDo SpmPanel_EmployeeRole > UpdateStats
|
|
}
|
|
protected override void SetControlsReadOnly()
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// P o s i t i o n C o n t r o l s
|
|
//-------------------------------------------------------------------
|
|
protected override void PositionControls()
|
|
{
|
|
if (this.IsDesignerHosted()) return;
|
|
base.PositionControls();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// F o r m E v e n t s
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|