362 lines
11 KiB
C#
362 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_Facilities : SpmPanel_Items
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Configuration.
|
|
public enum PanelMode
|
|
{
|
|
Search,
|
|
Maintain,
|
|
}
|
|
public new class Config : SpmPanel_Items.Config
|
|
{
|
|
public PanelMode Mode { get; set; } = PanelMode.Maintain;
|
|
public Spm.FacilityType FacilityType { get; set; } = Spm.FacilityType.Unknown;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private Config config = new Config();
|
|
private SysId departmentId = null;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SpmPanel_Facilities() : this(new Config()) { }
|
|
public SpmPanel_Facilities(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 "Facility"; } }
|
|
[Browsable(false), ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public SysId DepartmentId
|
|
{
|
|
get { return departmentId; }
|
|
set
|
|
{
|
|
if (SysId.ToInt(departmentId) == SysId.ToInt(value)) return;
|
|
departmentId = value;
|
|
RefreshDataItems();
|
|
}
|
|
}
|
|
public override int ItemTotal { get { return listViewFacility.ItemTotal; } }
|
|
public override int ItemCount { get { return listViewFacility.ItemCount; } }
|
|
public override int SelectedItemCount { get { return listViewFacility.SelectedItemCount; } }
|
|
public SysId SelectedItemId { get { return listViewFacility.SelectedItemId; } }
|
|
public List<SysId> SelectedItemIds { get { return listViewFacility.SelectedItemIds; } }
|
|
public SpmFacility SelectedFacility { get { return listViewFacility.SelectedFacility; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// 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 SpmFacility.Params GetParams()
|
|
{
|
|
SpmFacility.Params prmFacility = new SpmFacility.Params();
|
|
|
|
// Sort columns.
|
|
prmFacility.SortColumns.AddRange(listViewFacility.GetSortColumns());
|
|
return prmFacility;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// A c t i o n s
|
|
//-------------------------------------------------------------------
|
|
public override void RefreshDataItems()
|
|
{
|
|
listViewFacility.RefreshFacilitys(GetParams());
|
|
}
|
|
public override void RefreshDataItem(SysId id)
|
|
{
|
|
listViewFacility.RefreshFacility(id);
|
|
}
|
|
public override void RemoveDataItem(SysId id)
|
|
{
|
|
listViewFacility.RemoveItemById(id);
|
|
}
|
|
//-------------------------------------------------------------------
|
|
// Create item.
|
|
public override bool CanCreateItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
//if (!SecurityProfile.UserCanCreateItemType(Spm.DataItemType.Facility)) return false;
|
|
return true;
|
|
}
|
|
public override void CreateItem()
|
|
{
|
|
if (!CanCreateItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
// Create new Facility.
|
|
SpmForm_Facility.Config configFacility = new SpmForm_Facility.Config();
|
|
using (var form = new SpmForm_Facility(configFacility))
|
|
{
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
/*RefreshDataItem(form.NewItemId);
|
|
InvokeItemCreatedEvent(Spm.ItemType.Facility, form.NewItemId);*/
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// View/Update item.
|
|
public override bool CanViewItem()
|
|
{
|
|
return true;
|
|
}
|
|
public override bool CanUpdateItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
/*bool canMaintainFacilitys = SecurityProfile.UserCanCreateItemType(Spm.ItemType.Facility) || SecurityProfile.UserCanUpdateItemType(Spm.ItemType.Facility);
|
|
if (!canMaintainFacilitys) return false;*/
|
|
return true;
|
|
}
|
|
public override void UpdateItem(bool updateItem = true)
|
|
{
|
|
//if (!CanUpdateItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
SpmFacility facility = SelectedFacility;
|
|
if (SelectedItemCount != 1) return;
|
|
if (!CanUpdateItem() && !CanViewItem()) return;
|
|
if (!CanUpdateItem()) updateItem = false;
|
|
if (facility == null)
|
|
{
|
|
MessageConsole.ShowMessageWarning("Failed to retrieve selected item");
|
|
return;
|
|
}
|
|
SpmForm_Facility.Config configFacility = new SpmForm_Facility.Config();
|
|
configFacility.FacilityToUpdate = facility;
|
|
configFacility.ReadOnly = (config.ReadOnly || !updateItem);
|
|
using (SpmForm_Facility formFacility = new SpmForm_Facility(configFacility))
|
|
{
|
|
// Perform the update.
|
|
if (formFacility.ShowDialog() == DialogResult.OK)
|
|
{
|
|
// Facility has been updated.
|
|
RefreshDataItem(facility.Id);
|
|
listViewFacility.RefreshFacility(facility.Id);
|
|
InvokeItemUpdatedEvent(Spm.DataItemType.Facility, facility.Id);
|
|
}
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Delete item.
|
|
public override bool CanDeleteItem()
|
|
{
|
|
if (ReadOnly) return false;
|
|
//if (!SecurityProfile.UserCanRemoveItemType(Spm.ItemType.Facility)) return false;
|
|
return true;
|
|
}
|
|
public override void DeleteItem()
|
|
{
|
|
if (!CanDeleteItem()) return;
|
|
if (config.Mode == PanelMode.Search) return;
|
|
if (SelectedItemCount != 1) return;
|
|
SpmFacility facility = SelectedFacility;
|
|
if (facility == null)
|
|
{
|
|
MessageConsole.ShowMessageWarning("Failed to retrieve item for deletion.");
|
|
return;
|
|
}
|
|
if (!DepartmentMgr.FacilityCanBeDeleted(facility))
|
|
{
|
|
MessageConsole.ShowMessageError("Unable to remove facility - " + DepartmentMgr.ErrorStateMessage + ".");
|
|
return;
|
|
}
|
|
if (MessageConsole.ShowMessageConfirm("Are you sure that this facility should be removed from the system?"))
|
|
{
|
|
if (DepartmentMgr.DeleteFacility(facility, DbUpdateInfo))
|
|
{
|
|
int selectIdx = listViewFacility.SelectedIndex;
|
|
listViewFacility.RemoveItemById(facility.Id.ToString());
|
|
if (selectIdx >= listViewFacility.ItemCount - 1) selectIdx--;
|
|
listViewFacility.SelectedIndices.Clear();
|
|
listViewFacility.SelectedIndices.Add(selectIdx);
|
|
}
|
|
else MessageConsole.ShowMessageError("Failed to remove facility - " + DepartmentMgr.ErrorStateMessage + ".");
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Status change - Deactivate.
|
|
protected void DeactivateItem(object sender, EventArgs e) { DeactivateItem(); }
|
|
public void DeactivateItem()
|
|
{
|
|
SpmFacility facility = SelectedFacility;
|
|
if (facility != null && facility.Status == SaStatus.Active)
|
|
{
|
|
facility.Status = SaStatus.Inactive;
|
|
if (DepartmentMgr.UpdateFacility(facility, DbUpdateInfo))
|
|
{
|
|
RefreshDataItem(facility.Id);
|
|
//InvokeItemUpdatedEvent(Spm.ItemType.Facility, facility.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 = "Facility";
|
|
contextMenuStrip.Items.Clear();
|
|
if (CanCreateItem())
|
|
contextMenuStrip.Items.Add("Create", null, CreateItem);
|
|
if (SysId.IsValid(listViewFacility.SelectedItemId))
|
|
{
|
|
SpmFacility facility = SelectedFacility;
|
|
if (facility != 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()
|
|
{
|
|
// Facility list:
|
|
listViewFacility.Enabled = Enabled;
|
|
SetControlsReadOnly();
|
|
|
|
|
|
//ToDo SpmPanel_Facility > 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
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|