260 lines
8.2 KiB
C#
260 lines
8.2 KiB
C#
using Sarand.Core.Bus;
|
|
using Sarand.PatientMgr.Core.App;
|
|
using Sarand.PatientMgr.Core.Bus;
|
|
using Sarand.PatientMgr.Win.Forms.Base;
|
|
using Sarand.Win.Forms.Controls;
|
|
using Sarand.Win.Forms.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Sarand.PatientMgr.Win.Forms.Maint
|
|
{
|
|
//=======================================================================
|
|
public partial class SpmForm_Department : SpmForm_Item
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Configuration.
|
|
public new class Config : SpmForm_Item.Config
|
|
{
|
|
/// <summary>Institution - mandatory for department creation.</summary>
|
|
public SysId InstitutionId { get; set; }
|
|
/// <summary>Department to update.</summary>
|
|
public SpmDepartment DepartmentToUpdate { internal get; set; } = null;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private Config config = new Config();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SpmForm_Department () : this(new Config()) { }
|
|
public SpmForm_Department (Config config) : base(config)
|
|
{
|
|
this.config = config;
|
|
if (SpmGlobals.System != null)
|
|
{
|
|
}
|
|
InitializeComponent();
|
|
}
|
|
protected override void Dispose (bool disposing)
|
|
{
|
|
if (disposing && (components != null))
|
|
{
|
|
components.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
[Browsable(false)]
|
|
protected override String DefaultMessageTitle { get { return "Department"; } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// S h o w D i a l o g
|
|
//-------------------------------------------------------------------
|
|
public new DialogResult ShowDialog ()
|
|
{
|
|
if (!ValidateConfiguration()) return DialogResult;
|
|
if (config.DepartmentToUpdate == null)
|
|
{
|
|
// Creating new affiliate.
|
|
AddMode = true;
|
|
}
|
|
else
|
|
{
|
|
// Updating existing affiliate.
|
|
config.InstitutionId = config.DepartmentToUpdate.InstitutionId;
|
|
}
|
|
return base.ShowDialog();
|
|
}
|
|
// Validate configuration to ensure that form can be opened correctly.
|
|
private bool ValidateConfiguration ()
|
|
{
|
|
DialogResult = DialogResult.None;
|
|
if (config.DepartmentToUpdate == null)
|
|
{
|
|
// Creating new department.
|
|
if (!SysId.IsValid(config.InstitutionId))
|
|
return MessageConsole.ShowMessageWarning("Institution must be specified.");
|
|
if (!InstitutionMgr.InstitutionExistsById(config.InstitutionId))
|
|
return MessageConsole.ShowMessageWarning("Invalid Institution specified.");
|
|
}
|
|
else
|
|
{
|
|
if (SysId.IsValid(config.InstitutionId) && !config.InstitutionId.Equals(config.DepartmentToUpdate.InstitutionId))
|
|
return MessageConsole.ShowMessageWarning("Inconsistent Institution specified.");
|
|
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// I n i t i a l i s a t i o n
|
|
//-------------------------------------------------------------------
|
|
protected override void OnCreateControl ()
|
|
{
|
|
base.OnCreateControl();
|
|
if (this.IsDesignerHosted()) return;
|
|
AcceptButton = buttonOk;
|
|
CancelButton = buttonCancel;
|
|
|
|
if (ReadOnly)
|
|
{
|
|
buttonOk.Visible = false;
|
|
buttonCancel.Text = "Close";
|
|
}
|
|
else
|
|
{
|
|
buttonOk.Visible = true;
|
|
buttonCancel.Text = "Cancel";
|
|
}
|
|
|
|
// Institution.
|
|
SpmInstitution institution = InstitutionMgr.GetInstitutionById(config.InstitutionId);
|
|
textBoxInstitution.Text = institution?.Name ?? "Unknown";
|
|
|
|
// Applicable dates.
|
|
dateTimePickerApplicableFrom.Type = DateTimePickerType.Date;
|
|
dateTimePickerApplicableFrom.ShowCheckBox = true;
|
|
dateTimePickerApplicableFrom.Checked = false;
|
|
dateTimePickerApplicableTo.Type = DateTimePickerType.Date;
|
|
dateTimePickerApplicableTo.ShowCheckBox = true;
|
|
dateTimePickerApplicableTo.Checked = false;
|
|
|
|
// Configure controls.
|
|
//InitTabs();
|
|
|
|
// Initial display.
|
|
if (AddMode)
|
|
{
|
|
Text = "Create Department";
|
|
panelUpdateStamp.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
Text = "Update Department";
|
|
PopulateToControls(config.DepartmentToUpdate.GetData());
|
|
panelUpdateStamp.ItemData = config.DepartmentToUpdate.GetData();
|
|
}
|
|
|
|
// Complete dialog initialisation.
|
|
PositionControls();
|
|
AcceptChanges();
|
|
SetControlActivity();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
protected override void OnShown (EventArgs e)
|
|
{
|
|
base.OnShown(e);
|
|
// Initial focus.
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// P o p u l a t i o n
|
|
//-------------------------------------------------------------------
|
|
// PopulateToControls.
|
|
private void PopulateToControls (SpmDepartment.Data data)
|
|
{
|
|
// Populate item properties to controls.
|
|
textBoxName.Text = data.Name;
|
|
dateTimePickerApplicableFrom.Value = data.ApplicableFrom;
|
|
dateTimePickerApplicableTo.Value = data.ApplicableTo;
|
|
checkBoxTheatres.Checked = data.HasFacilityType(Spm.FacilityType.Theatre);
|
|
checkBoxAllowAnyTheatres.Checked = data.AllowAnyFacility(Spm.FacilityType.Theatre);
|
|
checkBoxClinics.Checked = data.HasFacilityType(Spm.FacilityType.Clinic);
|
|
checkBoxAllowAnyClinics.Checked = data.AllowAnyFacility(Spm.FacilityType.Clinic);
|
|
checkBoxWards.Checked = data.HasFacilityType(Spm.FacilityType.Ward);
|
|
checkBoxAllowAnyWards.Checked = data.AllowAnyFacility(Spm.FacilityType.Ward);
|
|
|
|
AcceptChanges();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate properties.
|
|
public bool IsDataValid (SpmDepartment.Data data)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// PopulateFromControls.
|
|
private void PopulateFromControls (SpmDepartment.Data data)
|
|
{
|
|
if (!SysId.IsValid(data.InstitutionId))
|
|
data.InstitutionId = config.InstitutionId;
|
|
if (textBoxName.Visible && !textBoxName.ReadOnly)
|
|
data.Name = textBoxName.Text;
|
|
if (dateTimePickerApplicableFrom.Visible && !dateTimePickerApplicableFrom.ReadOnly)
|
|
data.ApplicableFrom = dateTimePickerApplicableFrom.Value;
|
|
if (dateTimePickerApplicableTo.Visible && !dateTimePickerApplicableTo.ReadOnly)
|
|
data.ApplicableTo = dateTimePickerApplicableTo.Value;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// UpdatedAssociated Data.
|
|
public bool UpdateAssociatedData ()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C l o s e F o r m
|
|
//-------------------------------------------------------------------
|
|
private void buttonOk_Click (object sender, EventArgs e)
|
|
{
|
|
}
|
|
private void buttonCancel_Click (object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l A c t i v i t y
|
|
//-------------------------------------------------------------------
|
|
protected override void SetControlActivity ()
|
|
{
|
|
SetControlsReadOnly();
|
|
|
|
textBoxName.Enabled = Enabled;
|
|
}
|
|
public bool IsFieldReadOnly (SpmDbDfn.ColumnIdx col)
|
|
{
|
|
if (ReadOnly) return true;
|
|
|
|
return false;
|
|
}
|
|
protected override void SetControlsReadOnly ()
|
|
{
|
|
textBoxName.ReadOnly = IsFieldReadOnly(SpmDbDfn.ColumnIdx.SwmDepartment_Name);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// P o s i t i o n C o n t r o l s
|
|
//-------------------------------------------------------------------
|
|
protected override void PositionControls ()
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// F o r m E v e n t s
|
|
//-------------------------------------------------------------------
|
|
private void textBoxName_TextChanged (object sender, EventArgs e)
|
|
{
|
|
Changed = true;
|
|
SetControlActivity();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|