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 { _MyItemInfo = value; _MainStepSection = null; FillInControls(); } } private SectionInfo _MainStepSection; public SectionInfo MainStepSection { get { if (_MainStepSection == null) { 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.NextItem != null && startitm.NextItems.Count > 0 ? startitm.NextItems[0] : null); } } 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(); } } } } } }