SourceCode/PROMS/Volian.Controls.Library/DisplayFoldoutMaint.cs
John b29176f636 B2019-043 Added checks for being in design mode during initialization of variables
B2019-043 Added checks for being in design mode during initialization of variables.  Also needed to remove the parameter from the constructor
2019-03-22 15:19:19 +00:00

153 lines
4.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using VEPROMS.CSLA.Library;
namespace Volian.Controls.Library
{
public partial class DisplayFoldoutMaint : UserControl
{
private ItemInfo _MyItemInfo;
public ItemInfo MyItemInfo
{
get { return _MyItemInfo; }
set
{
if (DesignMode) return; // B2019-043 need to check if we are just saving changes to the user interface
_MyItemInfo = value;
_MainStepSection = null;
FillInControls();
}
}
private SectionInfo _MainStepSection;
public SectionInfo MainStepSection
{
get
{
if (!DesignMode && _MainStepSection == null) // B2019-043 need to check if we are just saving changes to the user interface
{
foreach (SectionInfo si in MyItemInfo.MyProcedure.Sections)
{
SectionConfig sc = (SectionConfig)si.MyConfig;
if (sc.Section_OriginalSteps == "Y") _MainStepSection = si;
}
}
return _MainStepSection;
}
}
//private ItemInfo _firstStep;
//private ItemInfo _lastStep;
private bool _Initializing;
public DisplayFoldoutMaint()
{
InitializeComponent();
FillInControls();
}
private void FillInControls()
{
// for this iteminfo, get the procedure and then the list of sections. For any section, starting with
// Foldout, add it to list:
if (MyItemInfo != null)
{
if (MyItemInfo.MyProcedure.Sections == null || MyItemInfo.MyProcedure.Sections.Count == 0) return;
_Initializing = true;
ProcedureInfo pi = MyItemInfo.MyProcedure;
listBoxFoldouts.Items.Clear();
lstCBSteps.Items.Clear();
foreach (SectionInfo si in pi.Sections)
if (si.DisplayText.ToUpper().StartsWith("FOLDOUT")) listBoxFoldouts.Items.Add(si);
if (listBoxFoldouts.Items.Count > 0) listBoxFoldouts.SelectedIndex = 0;
else
{
listBoxFoldouts.Items.Add("No Foldouts Exist");
return;
}
// find default step section & use its steps to fill in tree.
FillInSteps();
_Initializing = false;
}
}
private void FillInSteps()
{
ItemInfo foldOutselected = listBoxFoldouts.SelectedItem as ItemInfo;
ItemInfo startitm = MainStepSection.Steps != null && MainStepSection.Steps.Count > 0 ? MainStepSection.Steps[0] : null;
while (startitm != null)
{
StepConfig sc = startitm.MyConfig as StepConfig;
if (sc != null)
{
if (sc.Step_FloatingFoldout == foldOutselected.ItemID)
{
lstCBSteps.Items.Add(startitm, CheckState.Checked);
}
else
lstCBSteps.Items.Add(startitm, CheckState.Unchecked);
}
else
lstCBSteps.Items.Add(startitm, CheckState.Unchecked);
startitm = startitm.GetNext();
}
}
private void listBoxFoldouts_SelectedIndexChanged(object sender, EventArgs e)
{
ItemInfo foldOutselected = listBoxFoldouts.SelectedItem as ItemInfo;
int itemInList = 0;
for (int i = 0; i < lstCBSteps.Items.Count; i++)
{
ItemInfo startitm = lstCBSteps.Items[i] as ItemInfo;
StepConfig sc = startitm.MyConfig as StepConfig;
if (sc != null)
lstCBSteps.SetItemChecked(itemInList, sc.Step_FloatingFoldout == foldOutselected.ItemID);
else
lstCBSteps.SetItemChecked(itemInList, false);
itemInList++;
}
}
private void btnSave_Click(object sender, EventArgs e)
{
SectionInfo foldOutselected = listBoxFoldouts.SelectedItem as SectionInfo;
int itemInList = 0;
for (int i = 0; i < lstCBSteps.Items.Count; i++)
{
bool savit = false;
ItemInfo startitm = lstCBSteps.Items[i] as ItemInfo;
StepConfig sc = startitm.MyConfig as StepConfig;
if (lstCBSteps.GetItemChecked(itemInList)) // associate with foldout (if not already)
{
if (sc == null || sc != null && sc.Step_FloatingFoldout != foldOutselected.ItemID)
{
sc.Step_FloatingFoldout = foldOutselected.ItemID;
savit = true;
}
}
else // remove association if exists
{
if (sc != null && sc.Step_FloatingFoldout == foldOutselected.ItemID)
{
sc.Step_FloatingFoldout = 0;
savit = true;
}
}
itemInList++;
if (savit)
{
using (Item itm = startitm.Get())
{
itm.MyContent.Config = sc.ToString();
itm.MyContent.DTS = DateTime.Now;
itm.MyContent.UserID = Volian.Base.Library.VlnSettings.UserID;
itm.Save();
}
}
}
}
}
}