Files
PatientMgr-CSharp/SaPatMgrWinForms/Win/Forms/TabPages/SpmTabPage_Department.cs
T

241 lines
7.6 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.PatientMgr.Win.Forms.Base;
using Sarand.PatientMgr.Core.Bus;
using Sarand.Core.Base;
using Sarand.PatientMgr.Win.Forms.Panels;
using Sarand.Win.Forms.UpdateLog;
using Sarand.Win.Forms.Controls;
using Sarand.PatientMgr.Win.Forms.Maint;
using Sarand.PatientMgr.Core.App;
using Sarand.Core.Bus;
using Sarand.Win.Forms.Utils;
namespace Sarand.PatientMgr.Win.Forms.TabPages
{
//=======================================================================
public partial class SpmTabPage_Department : SpmTabPage
{
//-------------------------------------------------------------------
// Configuration.
public enum PanelType
{
Unknown = 0,
// Department properties.
Notes,
// Department list.
Theatres,
Clinics,
Wards,
// Common.
Config,
Updates,
}
public new class Config : SpmTabPage.Config
{
/// <summary>Department form hosting the tab control.</summary>
public SpmForm_Department DepartmentForm { get; set; } = null;
/// <summary>Panels to display on this tab page.</summary>
public List<PanelType> PanelTypes { get; } = new List<PanelType>();
/// <summary>Number of panels on this tab page.</summary>
public override int PanelCount { get { return PanelTypes.Count; } }
}
//-------------------------------------------------------------------
// Data members.
private Config config = new Config();
private SpmPanel_Facilities panelTheatres = null;
private SpmPanel_Facilities panelWards = null;
private SpmPanel_Facilities panelClinics = null;
private SaPanel_UpdateLog panelUpdates = null;
//-------------------------------------------------------------------
// Construction.
public SpmTabPage_Department (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.
/// <summary>Panels to display on this tab page.</summary>
public List<PanelType> PanelTypes { get { return config.PanelTypes; } }
//-------------------------------------------------------------------
// Initialisation.
protected override void OnCreateControl()
{
base.OnCreateControl();
if (this.IsDesignerHosted()) return;
// Configure page.
// Initial panels.
List<SacsPanel> panels = new List<SacsPanel>();
foreach (var panelType in config.PanelTypes)
{
SacsPanel panel = null;
switch (panelType)
{
case PanelType.Theatres:
{
SpmPanel_Facilities.Config configPanel = new SpmPanel_Facilities.Config();
configPanel.Mode = SpmPanel_Facilities.PanelMode.Maintain;
configPanel.FacilityType = Spm.FacilityType.Theatre;
panelTheatres = new SpmPanel_Facilities(configPanel);
panel = panelTheatres;
panel.SizeChanged += Panel_Resize;
break;
}
case PanelType.Clinics:
{
SpmPanel_Facilities.Config configPanel = new SpmPanel_Facilities.Config();
configPanel.Mode = SpmPanel_Facilities.PanelMode.Maintain;
configPanel.FacilityType = Spm.FacilityType.Clinic;
panelClinics = new SpmPanel_Facilities(configPanel);
panel = panelClinics;
panel.SizeChanged += Panel_Resize;
break;
}
case PanelType.Wards:
{
SpmPanel_Facilities.Config configPanel = new SpmPanel_Facilities.Config();
configPanel.Mode = SpmPanel_Facilities.PanelMode.Maintain;
configPanel.FacilityType = Spm.FacilityType.Ward;
panelWards = new SpmPanel_Facilities(configPanel);
panel = panelWards;
panel.SizeChanged += Panel_Resize;
break;
}
case PanelType.Updates:
{
SaPanel_UpdateLog.Config configPanel = new SaPanel_UpdateLog.Config();
configPanel.UpdateLogConsole = UpdateLogConsole;
panelUpdates = new SaPanel_UpdateLog();
panelUpdates.SetConfig(configPanel);
panel = panelUpdates;
panel.SizeChanged += Panel_Resize;
break;
}
}
if (panel != null)
panels.Add(panel);
else Logger.Warn(GetType().Name + ".OnCreateControl Panel type not supported: " + panelType.ToString());
}
AddPanelsToPage(panels);
// Complete panel initialisation.
SetControlsReadOnly();
SetControlActivity();
}
//-------------------------------------------------------------------
// P a g e I n t e r f a c e
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// P o p u l a t i o n
//-------------------------------------------------------------------
public void PopulateToControls(SpmDepartment.Data data)
{
if (panelTheatres != null)
panelTheatres.DepartmentId = data.Id;
if (panelClinics != null)
panelClinics.DepartmentId = data.Id;
if (panelWards != null)
panelWards.DepartmentId = data.Id;
if (panelUpdates != null)
panelUpdates.ItemId = new ItemId((short)Spm.DataItemType.Department, data.Id);
}
public bool IsDataValid(SpmDepartment.Data data)
{
return true;
}
public void PopulateFromControls(SpmDepartment.Data data)
{
}
public bool UpdateAssociatedData(SpmDepartment.Data data)
{
return true;
}
//-------------------------------------------------------------------
// C o n t r o l A c t i v i t y
//-------------------------------------------------------------------
protected void SetControlActivity()
{
if (panelUpdates != null)
panelUpdates.Enabled = Enabled;
}
public bool IsFieldReadOnly(SpmDbDfn.ColumnIdx col)
{
return false;
}
protected void SetControlsReadOnly()
{
return;
}
//-------------------------------------------------------------------
// P a n e l E v e n t s
//-------------------------------------------------------------------
private void panel_ItemCreated(object sender, SpmPanel_Items.ItemModifiedEventArgs e)
{
InvokeItemCreatedEvent((short)e.ItemType, e.ItemId);
}
private void panel_ItemUpdated(object sender, SpmPanel_Items.ItemModifiedEventArgs e)
{
InvokeItemUpdatedEvent((short)e.ItemType, e.ItemId);
}
private void panel_ItemDeleted(object sender, SpmPanel_Items.ItemModifiedEventArgs e)
{
InvokeItemDeletedEvent((short)e.ItemType, e.ItemId);
}
//-------------------------------------------------------------------
// P a n e l S i z e a n d P o s i t i o n
//-------------------------------------------------------------------
protected override void PositionControls()
{
base.PositionControls();
Rectangle clientRect = ClientRectangle;
}
//-------------------------------------------------------------------
}
//=======================================================================
public static class SpmTabPage_DepartmentList
{
public static void PopulateToControls (this List<SpmTabPage_Department> tabPages, SpmDepartment.Data data)
{
foreach (SpmTabPage_Department tabPage in tabPages)
tabPage.PopulateToControls(data);
}
public static void PopulateFromControls (this List<SpmTabPage_Department> tabPages, SpmDepartment.Data data)
{
foreach (SpmTabPage_Department tabPage in tabPages)
tabPage.PopulateFromControls(data);
}
}
//=======================================================================
}