348 lines
11 KiB
C#
348 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_Departments : 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_Departments() : this(new Config()) { }
|
|
public SpmPanel_Departments(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 "Department"; } }
|
|
public override int ItemTotal { get { return listViewDepartment.ItemTotal; } }
|
|
public override int ItemCount { get { return listViewDepartment.ItemCount; } }
|
|
public override int SelectedItemCount { get { return listViewDepartment.SelectedItemCount; } }
|
|
public SysId SelectedItemId { get { return listViewDepartment.SelectedItemId; } }
|
|
public List<SysId> SelectedItemIds { get { return listViewDepartment.SelectedItemIds; } }
|
|
public SpmDepartment SelectedDepartment { get { return listViewDepartment.SelectedDepartment; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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 SpmDepartment.Params GetParams()
|
|
{
|
|
SpmDepartment.Params prmDepartment = new SpmDepartment.Params();
|
|
|
|
// Sort columns.
|
|
prmDepartment.SortColumns.AddRange(listViewDepartment.GetSortColumns());
|
|
return prmDepartment;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// A c t i o n s
|
|
//-------------------------------------------------------------------
|
|
public override void RefreshDataItems()
|
|
{
|
|
listViewDepartment.RefreshDepartments(GetParams());
|
|
}
|
|
public override void RefreshDataItem(SysId id)
|
|
{
|
|
listViewDepartment.RefreshDepartment(id);
|
|
}
|
|
public override void RemoveDataItem(SysId id)
|
|
{
|
|
listViewDepartment.RemoveItemById(id);
|
|
}
|
|
//-------------------------------------------------------------------
|
|
// Create item.
|
|
public override bool CanCreateItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
//if (!SecurityProfile.UserCanCreateItemType(Spm.DataItemType.Department)) return false;
|
|
return true;
|
|
}
|
|
public override void CreateItem()
|
|
{
|
|
if (!CanCreateItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
// Create new Department.
|
|
SpmForm_Department.Config configDepartment = new SpmForm_Department.Config();
|
|
using (var form = new SpmForm_Department(configDepartment))
|
|
{
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
/*RefreshDataItem(form.NewItemId);
|
|
InvokeItemCreatedEvent(Spm.ItemType.Department, form.NewItemId);*/
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// View/Update item.
|
|
public override bool CanViewItem()
|
|
{
|
|
return true;
|
|
}
|
|
public override bool CanUpdateItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
/*bool canMaintainDepartments = SecurityProfile.UserCanCreateItemType(Spm.ItemType.Department) || SecurityProfile.UserCanUpdateItemType(Spm.ItemType.Department);
|
|
if (!canMaintainDepartments) return false;*/
|
|
return true;
|
|
}
|
|
public override void UpdateItem(bool updateItem = true)
|
|
{
|
|
if (config.Mode == PanelMode.Search) return;
|
|
SpmDepartment department = SelectedDepartment;
|
|
if (SelectedItemCount != 1) return;
|
|
if (!CanUpdateItem() && !CanViewItem()) return;
|
|
if (!CanUpdateItem()) updateItem = false;
|
|
if (department == null)
|
|
{
|
|
MessageConsole.ShowMessageWarning("Failed to retrieve selected item");
|
|
return;
|
|
}
|
|
SpmForm_Department.Config configDepartment = new SpmForm_Department.Config();
|
|
configDepartment.DepartmentToUpdate = department;
|
|
configDepartment.ReadOnly = (config.ReadOnly || !updateItem);
|
|
using (SpmForm_Department formDepartment = new SpmForm_Department(configDepartment))
|
|
{
|
|
// Perform the update.
|
|
if (formDepartment.ShowDialog() == DialogResult.OK)
|
|
{
|
|
// Department has been updated.
|
|
RefreshDataItem(department.Id);
|
|
listViewDepartment.RefreshDepartment(department.Id);
|
|
InvokeItemUpdatedEvent(Spm.DataItemType.Department, department.Id);
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Delete item.
|
|
public override bool CanDeleteItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
//if (!SecurityProfile.UserCanRemoveItemType(Spm.ItemType.Department)) return false;
|
|
return true;
|
|
}
|
|
public override void DeleteItem()
|
|
{
|
|
if (!CanDeleteItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
if (SelectedItemCount != 1) return;
|
|
SpmDepartment department = SelectedDepartment;
|
|
if (department == null)
|
|
{
|
|
MessageConsole.ShowMessageWarning("Failed to retrieve item for deletion.");
|
|
return;
|
|
}
|
|
if (!DepartmentMgr.DepartmentCanBeDeleted(department))
|
|
{
|
|
MessageConsole.ShowMessageError("Unable to remove department - " + DepartmentMgr.ErrorStateMessage + ".");
|
|
return;
|
|
}
|
|
if (MessageConsole.ShowMessageConfirm("Are you sure that this department should be removed from the system?"))
|
|
{
|
|
if (DepartmentMgr.DeleteDepartment(department, DbUpdateInfo))
|
|
{
|
|
int selectIdx = listViewDepartment.SelectedIndex;
|
|
listViewDepartment.RemoveItemById(department.Id.ToString());
|
|
if (selectIdx >= listViewDepartment.ItemCount - 1) selectIdx--;
|
|
listViewDepartment.SelectedIndices.Clear();
|
|
listViewDepartment.SelectedIndices.Add(selectIdx);
|
|
}
|
|
else MessageConsole.ShowMessageError("Failed to remove department - " + DepartmentMgr.ErrorStateMessage + ".");
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status change - Deactivate.
|
|
protected void DeactivateItem(object sender, EventArgs e) { DeactivateItem(); }
|
|
public void DeactivateItem()
|
|
{
|
|
SpmDepartment department = SelectedDepartment;
|
|
if (department != null && department.Status == SaStatus.Active)
|
|
{
|
|
department.Status = SaStatus.Inactive;
|
|
if (DepartmentMgr.UpdateDepartment(department, DbUpdateInfo))
|
|
{
|
|
RefreshDataItem(department.Id);
|
|
//InvokeItemUpdatedEvent(Spm.ItemType.Department, department.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 = "Department";
|
|
contextMenuStrip.Items.Clear();
|
|
if (CanCreateItem())
|
|
contextMenuStrip.Items.Add("Create", null, CreateItem);
|
|
if (SysId.IsValid(listViewDepartment.SelectedItemId))
|
|
{
|
|
SpmDepartment department = SelectedDepartment;
|
|
if (department != 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()
|
|
{
|
|
// Department list:
|
|
listViewDepartment.Enabled = Enabled;
|
|
SetControlsReadOnly();
|
|
|
|
|
|
//ToDo SpmPanel_Department > 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
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|