using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using Sarand.Core.UpdateLog; using Sarand.Core.CodeTypes; using Sarand.Win.Forms.Controls; using Sarand.PatientMgr.Core.App; using Sarand.PatientMgr.Win.Forms.App; using Sarand.Core.Base; using Sarand.Core.Interfaces; using Sarand.Core.Dbas.Base; using Sarand.PatientMgr.Win.Forms.Panels; using Sarand.Win.Forms.Utils; using Sarand.PatientMgr.Core.Bus; using Sarand.PatientMgr.Core.Mgr; using Sarand.Core.Security; using Sarand.Core.ItemDocs; using Sarand.Core.ItemOptions; namespace Sarand.PatientMgr.Win.Forms.Base { //======================================================================= public partial class SpmTabPage : SacsTabPage { //------------------------------------------------------------------- // Configuration. public new class Config : SacsTabPage.Config { /// Wrap single panel on tab page in group box. Default - no group box for single panel. public virtual bool WrapSinglePanelInGroupBox { get; protected set; } = false; /// Wrap multiple panels on tab page in group boxes. Default - multiple panels are wrapped in group boxes. public virtual bool WrapMultiplePanelsInGroupBoxes { get; protected set; } = true; /// Pass Internals via Config to share cached data. public SpmInternals Internals { get; set; } = null; } //------------------------------------------------------------------- // Data members. private Config config = new Config(); private SpmInternals internals = null; //------------------------------------------------------------------- // Construction. private SpmTabPage() : this(new Config()) { } protected SpmTabPage(Config config) : base(config) { this.config = config; InitializeComponent(); } protected override void Dispose(bool disposing) { if (disposing && (components != null)) { if (components != null) components.Dispose(); if (internals != null) internals.Dispose(); } base.Dispose(disposing); } //------------------------------------------------------------------- // Properties. [Browsable(false), ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool PanelsAddedToPage { get; private set; } = false; protected bool WrapPanelsInGroupBoxes { get { return (config.PanelCount == 1 && config.WrapSinglePanelInGroupBox) || (config.PanelCount > 1 && config.WrapMultiplePanelsInGroupBoxes); } } // Session. protected SpmSessionProfile_Win SessionProfile { get; } = SpmGlobals_Win.SessionProfile; protected SpmUserContext UserContext { get { return SessionProfile.UserContext; } } protected SpmSessionContext SessionContext { get { return SessionProfile.SessionContext; } } protected SpmInternals Internals { get { if (config.Internals != null) return config.Internals; if (internals == null) internals = new SpmInternals(UserContext); return internals; } } // Security. public SpmSecurityProfile SecurityProfile { get { return Internals.SecurityProfile; } } // Managers. public SpmInstitutionMgr InstitutionMgr { get { return Internals.InstitutionMgr; } } public SpmDepartmentMgr DepartmentMgr { get { return Internals.DepartmentMgr; } } public SpmAdmissionMgr AdmissionMgr { get { return Internals.AdmissionMgr; } } // Consoles. public SaSecurityConsole SecurityConsole { get { return Internals.SecurityConsole; } } public SaCodeTypeConsole CodeTypeConsole { get { return Internals.CodeTypeConsole; } } public SaUpdateLogConsole UpdateLogConsole { get { return Internals.UpdateLogConsole; } } public SaItemOptionConsole ItemOptionConsole { get { return Internals.ItemOptionConsole; } } //------------------------------------------------------------------- // I n i t i a l i s a t i o n //------------------------------------------------------------------- protected override void OnCreateControl() { base.OnCreateControl(); if (!this.IsDesignerHosted()) return; } //------------------------------------------------------------------- // P a n e l s //------------------------------------------------------------------- protected void AddPanelsToPage(List panels) { if (Controls.Count > 0) throw new NotSupportedException(GetType().Name + ".AddPanelsToPage TabPage already contains controls"); // Adjust width from default (maybe as little as 200) to parent's width to ensure panels with minimum width are sized correctly. int initialWidth = Parent.Width - (Parent.Padding.Left + Parent.Padding.Right) - (Margin.Left + Margin.Right); if (Width < initialWidth) Width = initialWidth; int panelTop = Parent.Padding.Top; int tabIndex = 0; foreach (SacsPanel panel in panels) { if (WrapPanelsInGroupBoxes) { // Group box. SpmGroupBox groupBox = new SpmGroupBox(); groupBox.Text = panel.Text; groupBox.TabIndex = ++tabIndex; PositionPanel(groupBox, panelTop); Controls.Add(groupBox); // Explicitly set the panel's font to avoid group box's font cascading. panel.Font = this.Font; // Add panel to group box's controls and resize. panel.Top = groupBox.DisplayRectangle.Top + panel.Margin.Top; panel.Left = groupBox.DisplayRectangle.Left + panel.Margin.Left; panel.Width = groupBox.DisplayRectangle.Width - panel.Left - panel.Margin.Right; if (config.PanelCount == 1) { panel.Height = groupBox.DisplayRectangle.Bottom - panel.Top - panel.Margin.Bottom; panel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; } else panel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; groupBox.Controls.Add(panel); groupBox.SetHeightToControls(); panelTop += groupBox.Height + groupBox.Margin.Bottom; //Logger.Trace(GetType().Name + ".AddPanelsToPage GroupBox: " + groupBox.GetType().Name + " . Width: " + groupBox.Width); //Logger.Trace(GetType().Name + ".AddPanelsToPage Panel: " + panel.GetType().Name + " . Width: " + panel.Width); } else { // Position panel. panel.TabIndex = ++tabIndex; PositionPanel(panel, panelTop); panelTop += panel.Height + panel.Margin.Bottom; panelTop += panel.Height + panel.Margin.Bottom; Controls.Add(panel); } } PanelsAddedToPage = true; } //------------------------------------------------------------------- // P a n e l S i z e a n d P o s i t i o n //------------------------------------------------------------------- protected override void PositionControls() { //String fn = GetType().Name + ".PositionControls"; base.PositionControls(); Rectangle clientRect = ClientRectangle; PositionPanels(); } protected void PositionPanel(Control panel, int panelTop) { panel.Top = panelTop + panel.Margin.Top; panel.Left = (Parent.Padding.Left + panel.Margin.Left); panel.Width = ClientSize.Width - panel.Left - (Parent.Padding.Right + panel.Margin.Right); // Single panel fills page. if (config.PanelCount == 1) panel.Dock = DockStyle.Fill; else panel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; } protected void PositionPanels() { if (!PanelsAddedToPage) return; //Logger.Trace(GetType().Name + ".PositionPanels"); int panelTop = Parent.Padding.Top; // Refresh each panel's position. foreach (Control panel in Controls) { PositionPanel(panel, panelTop); panelTop += panel.Height + panel.Margin.Bottom; } } //------------------------------------------------------------------- // P a n e l E v e n t s //------------------------------------------------------------------- protected void Panel_Resize(object sender, EventArgs e) { if (!PanelsAddedToPage) return; //Logger.Trace(GetType().Name + ".Panel_Resize Sender: " + sender.ToString()); PositionControls(); } protected virtual void panel_ItemCreated(object sender, SpmPanel_Items.ItemModifiedEventArgs e) { InvokeItemCreatedEvent((short)e.ItemType, e.ItemId); } protected virtual void panel_ItemUpdated(object sender, SpmPanel_Items.ItemModifiedEventArgs e) { InvokeItemUpdatedEvent((short)e.ItemType, e.ItemId); } protected virtual void panel_ItemDeleted(object sender, SpmPanel_Items.ItemModifiedEventArgs e) { InvokeItemDeletedEvent((short)e.ItemType, e.ItemId); } //------------------------------------------------------------------- } //======================================================================= }