349 lines
12 KiB
C#
349 lines
12 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_FacilityTemplates : 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_FacilityTemplates() : this(new Config()) { }
|
|
public SpmPanel_FacilityTemplates(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 "FacilityTemplate"; } }
|
|
public override int ItemTotal { get { return listViewFacilityTemplate.ItemTotal; } }
|
|
public override int ItemCount { get { return listViewFacilityTemplate.ItemCount; } }
|
|
public override int SelectedItemCount { get { return listViewFacilityTemplate.SelectedItemCount; } }
|
|
public SysId SelectedItemId { get { return listViewFacilityTemplate.SelectedItemId; } }
|
|
public List<SysId> SelectedItemIds { get { return listViewFacilityTemplate.SelectedItemIds; } }
|
|
public SpmFacilityTemplate SelectedFacilityTemplate { get { return listViewFacilityTemplate.SelectedFacilityTemplate; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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 SpmFacilityTemplate.Params GetParams()
|
|
{
|
|
SpmFacilityTemplate.Params prmFacilityTemplate = new SpmFacilityTemplate.Params();
|
|
|
|
// Sort columns.
|
|
prmFacilityTemplate.SortColumns.AddRange(listViewFacilityTemplate.GetSortColumns());
|
|
return prmFacilityTemplate;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// A c t i o n s
|
|
//-------------------------------------------------------------------
|
|
public override void RefreshDataItems()
|
|
{
|
|
listViewFacilityTemplate.RefreshFacilityTemplates(GetParams());
|
|
}
|
|
public override void RefreshDataItem(SysId id)
|
|
{
|
|
listViewFacilityTemplate.RefreshFacilityTemplate(id);
|
|
}
|
|
public override void RemoveDataItem(SysId id)
|
|
{
|
|
listViewFacilityTemplate.RemoveItemById(id);
|
|
}
|
|
//-------------------------------------------------------------------
|
|
// Create item.
|
|
public override bool CanCreateItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
//if (!SecurityProfile.UserCanCreateItemType(Spm.DataItemType.FacilityTemplate)) return false;
|
|
return true;
|
|
}
|
|
public override void CreateItem()
|
|
{
|
|
if (!CanCreateItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
// Create new FacilityTemplate.
|
|
SpmForm_FacilityTemplate.Config configFacilityTemplate = new SpmForm_FacilityTemplate.Config();
|
|
using (var form = new SpmForm_FacilityTemplate(configFacilityTemplate))
|
|
{
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
/*RefreshDataItem(form.NewItemId);
|
|
InvokeItemCreatedEvent(Spm.ItemType.FacilityTemplate, form.NewItemId);*/
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// View/Update item.
|
|
public override bool CanViewItem()
|
|
{
|
|
return true;
|
|
}
|
|
public override bool CanUpdateItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
/*bool canMaintainFacilityTemplates = SecurityProfile.UserCanCreateItemType(Spm.ItemType.FacilityTemplate) || SecurityProfile.UserCanUpdateItemType(Spm.ItemType.FacilityTemplate);
|
|
if (!canMaintainFacilityTemplates) return false;*/
|
|
return true;
|
|
}
|
|
public override void UpdateItem(bool updateItem = true)
|
|
{
|
|
//if (!CanUpdateItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
SpmFacilityTemplate facilityTemplate = SelectedFacilityTemplate;
|
|
if (SelectedItemCount != 1) return;
|
|
if (!CanUpdateItem() && !CanViewItem()) return;
|
|
if (!CanUpdateItem()) updateItem = false;
|
|
if (facilityTemplate == null)
|
|
{
|
|
MessageConsole.ShowMessageWarning("Failed to retrieve selected item");
|
|
return;
|
|
}
|
|
SpmForm_FacilityTemplate.Config configFacilityTemplate = new SpmForm_FacilityTemplate.Config();
|
|
configFacilityTemplate.FacilityTemplateToUpdate = facilityTemplate;
|
|
configFacilityTemplate.ReadOnly = (config.ReadOnly || !updateItem);
|
|
using (SpmForm_FacilityTemplate formFacilityTemplate = new SpmForm_FacilityTemplate(configFacilityTemplate))
|
|
{
|
|
// Perform the update.
|
|
if (formFacilityTemplate.ShowDialog() == DialogResult.OK)
|
|
{
|
|
// FacilityTemplate has been updated.
|
|
RefreshDataItem(facilityTemplate.Id);
|
|
listViewFacilityTemplate.RefreshFacilityTemplate(facilityTemplate.Id);
|
|
InvokeItemUpdatedEvent(Spm.DataItemType.FacilityTemplate, facilityTemplate.Id);
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Delete item.
|
|
public override bool CanDeleteItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
//if (!SecurityProfile.UserCanRemoveItemType(Spm.ItemType.FacilityTemplate)) return false;
|
|
return true;
|
|
}
|
|
public override void DeleteItem()
|
|
{
|
|
if (!CanDeleteItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
if (SelectedItemCount != 1) return;
|
|
SpmFacilityTemplate facilityTemplate = SelectedFacilityTemplate;
|
|
if (facilityTemplate == null)
|
|
{
|
|
MessageConsole.ShowMessageWarning("Failed to retrieve item for deletion.");
|
|
return;
|
|
}
|
|
if (!DepartmentMgr.FacilityTemplateCanBeDeleted(facilityTemplate))
|
|
{
|
|
MessageConsole.ShowMessageError("Unable to remove facilityTemplate - " + DepartmentMgr.ErrorStateMessage + ".");
|
|
return;
|
|
}
|
|
if (MessageConsole.ShowMessageConfirm("Are you sure that this facilityTemplate should be removed from the system?"))
|
|
{
|
|
if (DepartmentMgr.DeleteFacilityTemplate(facilityTemplate, DbUpdateInfo))
|
|
{
|
|
int selectIdx = listViewFacilityTemplate.SelectedIndex;
|
|
listViewFacilityTemplate.RemoveItemById(facilityTemplate.Id.ToString());
|
|
if (selectIdx >= listViewFacilityTemplate.ItemCount - 1) selectIdx--;
|
|
listViewFacilityTemplate.SelectedIndices.Clear();
|
|
listViewFacilityTemplate.SelectedIndices.Add(selectIdx);
|
|
}
|
|
else MessageConsole.ShowMessageError("Failed to remove facilityTemplate - " + DepartmentMgr.ErrorStateMessage + ".");
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status change - Deactivate.
|
|
protected void DeactivateItem(object sender, EventArgs e) { DeactivateItem(); }
|
|
public void DeactivateItem()
|
|
{
|
|
SpmFacilityTemplate facilityTemplate = SelectedFacilityTemplate;
|
|
if (facilityTemplate != null && facilityTemplate.Status == SaStatus.Active)
|
|
{
|
|
facilityTemplate.Status = SaStatus.Inactive;
|
|
if (DepartmentMgr.UpdateFacilityTemplate(facilityTemplate, DbUpdateInfo))
|
|
{
|
|
RefreshDataItem(facilityTemplate.Id);
|
|
//InvokeItemUpdatedEvent(Spm.ItemType.FacilityTemplate, facilityTemplate.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 = "FacilityTemplate";
|
|
contextMenuStrip.Items.Clear();
|
|
if (CanCreateItem())
|
|
contextMenuStrip.Items.Add("Create", null, CreateItem);
|
|
if (SysId.IsValid(listViewFacilityTemplate.SelectedItemId))
|
|
{
|
|
SpmFacilityTemplate facilityTemplate = SelectedFacilityTemplate;
|
|
if (facilityTemplate != 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()
|
|
{
|
|
// FacilityTemplate list:
|
|
listViewFacilityTemplate.Enabled = Enabled;
|
|
SetControlsReadOnly();
|
|
|
|
|
|
//ToDo SpmPanel_FacilityTemplate > 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
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|