From b9352fc0f53644bb57e77592dc481ae9350870f1 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 5 Mar 2020 15:05:36 +0000 Subject: [PATCH] =?UTF-8?q?C2020-003=20Added=20logic=20to=20sort=20the=20c?= =?UTF-8?q?heckoff=20list=20using=20both=20the=20Index=20and=20(if=20avail?= =?UTF-8?q?able)=20the=20OrderBy=20elements.=20C2020-003=20=E2=80=93=20Add?= =?UTF-8?q?ed=20the=20OderBy=20element=20to=20the=20Checkoff=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frmSectionProperties.cs | 54 +++++++++++++++++-- .../Format/PlantFormat.cs | 8 +++ PROMS/Volian.Controls.Library/DisplayTags.cs | 48 +++++++++++++++-- 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/PROMS/VEPROMS User Interface/frmSectionProperties.cs b/PROMS/VEPROMS User Interface/frmSectionProperties.cs index 3cc16e6b..7e550cda 100644 --- a/PROMS/VEPROMS User Interface/frmSectionProperties.cs +++ b/PROMS/VEPROMS User Interface/frmSectionProperties.cs @@ -102,7 +102,6 @@ namespace VEPROMS rbStepSect.Enabled = (numStepSects > 0 && (isNewSection || ii.IsStepSection)); // there are step section types and current section is a step section or creating new section rbWordSect.Enabled = (numWordSects > 0 && (isNewSection || !ii.IsStepSection)); // there are word section types and current section is a word section or creating new section } - private void btnSectPropOK_Click(object sender, EventArgs e) { sectionConfigBindingSource.EndEdit(); @@ -122,9 +121,10 @@ namespace VEPROMS CheckOffList chkoffList = pf.FormatData.ProcData.CheckOffData.CheckOffList; CheckOffHeaderList chkoffHeaderList = pf.FormatData.ProcData.CheckOffData.CheckOffHeaderList; int maxindx = pf.FormatData.ProcData.CheckOffUCF ? pf.FormatData.ProcData.CheckOffData.CheckOffList.MaxIndex : pf.FormatData.ProcData.CheckOffData.CheckOffList.MaxIndexNoInherit; + // C2020-003 use the _CheckOffIndex dictionary to get and save the index of the selected checkoff from the sorted checkoff list if (ppGpbxSignoffCheckoff.Enabled && (chkoffList != null && maxindx > 1) - && (ppCmbxCheckoffType.SelectedIndex != _SectionConfig.Section_CheckoffListSelection - (_hasSectionCheckoffDefault? 1:0))) - _SectionConfig.Section_CheckoffListSelection = ppCmbxCheckoffType.SelectedIndex + (_hasSectionCheckoffDefault? 1:0); + && (_CheckOffIndex[ppCmbxCheckoffType.SelectedIndex] != _SectionConfig.Section_CheckoffListSelection)) + _SectionConfig.Section_CheckoffListSelection = _CheckOffIndex[ppCmbxCheckoffType.SelectedIndex]; if (ppCmbxCheckoffHeading.Enabled && chkoffHeaderList != null && chkoffHeaderList.MaxIndexNoInherit > 1) _SectionConfig.Section_CheckoffHeaderSelection = ppCmbxCheckoffHeading.SelectedIndex; @@ -732,7 +732,43 @@ namespace VEPROMS if (_isStepSection) SetupCheckoffsDropdowns(); } + // C2020-003 This is used to sort the checkoff list from the format file + // if the checkoff has an OrderBy element, then use it for the sorting, otherwise use th checkoff Index element + private static int CompareCheckoffUsingOrderBy(CheckOff ckf1, CheckOff ckf2) + { + if (ckf1.OrderBy == null) + { + if (ckf2.OrderBy == null) // neither ckf1 nor ckf2 uses OrderBy index + { + if (ckf1.Index > ckf2.Index) return 1; //ckf1 goes before ckf2 + if (ckf1.Index < ckf2.Index) return -1; // ckf1 goes after ckf2 + return 0; //ckf1 and ckf2 have the same index value + } + else // ckf1 does not have OrderBy index but ckf2 has OrderBy index + { + if (ckf1.Index > ckf2.OrderBy) return 1; //ckf1 goes before ckf2 + if (ckf1.Index < ckf2.OrderBy) return -1; // ckf1 goes after ckf2 + return 0; //ckf1 and ckf2 have the same index value + } + } + else //ckf1 has orderBy + { + if (ckf2.OrderBy == null) // ckf1 has OrderBy index but ckf2 does not + { + if (ckf1.OrderBy > ckf2.Index) return 1; //ckf1 goes before ckf2 + if (ckf1.OrderBy < ckf2.Index) return -1; // ckf1 goes after ckf2 + return 0; //ckf1 and ckf2 have the same index value + } + else // both ckf1 and ckf2 has OrderBy index + { + if (ckf1.OrderBy > ckf2.OrderBy) return 1; //ckf1 goes before ckf2 + if (ckf2.OrderBy > ckf1.OrderBy) return -1; // ckf1 goes after ckf2 + return 0; //ckf1 and ckf2 have the same index value + } + } + } private List SectionPropertyCheckOffList = null; + private Dictionary _CheckOffIndex = new Dictionary(); // C2020-003 translate the sorted index number to the actual checkoff index private void SetupCheckoffsDropdowns() { if (!_isStepSection) return; // not needed for accessory pages (word attachments) @@ -740,6 +776,7 @@ namespace VEPROMS _Initializing = true; PlantFormat pf = _SectionConfig.MyFormat!=null?_SectionConfig.MyFormat.PlantFormat:_SectionConfig.MyDefaultFormat.PlantFormat; CheckOffList chkoffList = pf.FormatData.ProcData.CheckOffData.CheckOffList; + if (chkoffList != null) chkoffList.Sort(CompareCheckoffUsingOrderBy); // C2020-003 sort the checkoff list via the Index and/or OrderBy elements CheckOffHeaderList chkoffHeaderList = pf.FormatData.ProcData.CheckOffData.CheckOffHeaderList; int maxindx = pf.FormatData.ProcData.CheckOffUCF ? pf.FormatData.ProcData.CheckOffData.CheckOffList.MaxIndex : pf.FormatData.ProcData.CheckOffData.CheckOffList.MaxIndexNoInherit; // B2019-013: was crashing on indexer of checkofflist. If there were UCF checkoffs but none in original format, the indexer @@ -764,14 +801,23 @@ namespace VEPROMS SectionPropertyCheckOffList = new List(); // Don't put up the first item in the chkoffList, it is '{Section Default}'. //for (int i = 1; i < chkoffList.Count; i++) + int idxcnt = 0; + int translatedCfgIdx = 0; + _CheckOffIndex.Clear(); foreach (CheckOff co in chkoffList) { if (!co.MenuItem.ToUpper().Equals("{SECTION DEFAULT}")) + { SectionPropertyCheckOffList.Add(co); + _CheckOffIndex.Add(idxcnt, (int)co.Index); // C2020-003 dictionary of sorted indexes to format checkoff Index element + if (_SectionConfig.Section_CheckoffListSelection == co.Index) + translatedCfgIdx = idxcnt; // C2020-003 translate the previous checkoff select to the sorted checkoff list position + idxcnt++; + } } ppGpbxSignoffCheckoff.Enabled = true; ppCmbxCheckoffType.DataSource = SectionPropertyCheckOffList; - ppCmbxCheckoffType.SelectedIndex = _SectionConfig.Section_CheckoffListSelection - (_hasSectionCheckoffDefault ? 1 : 0); + ppCmbxCheckoffType.SelectedIndex = translatedCfgIdx; // C2020-003 save the actual checkoff index } else { diff --git a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs index 74869269..3913e11d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs @@ -1940,6 +1940,14 @@ namespace VEPROMS.CSLA.Library return LazyLoad(ref _Index, "@Index"); } } + private LazyLoad _OrderBy; // C2020-003 used to sort list of checkoffs in the combo box + public float? OrderBy + { + get + { + return LazyLoad(ref _OrderBy, "@OrderBy"); + } + } private LazyLoad _UIMark; public int? UIMark { diff --git a/PROMS/Volian.Controls.Library/DisplayTags.cs b/PROMS/Volian.Controls.Library/DisplayTags.cs index 4dced40c..ed28b11a 100644 --- a/PROMS/Volian.Controls.Library/DisplayTags.cs +++ b/PROMS/Volian.Controls.Library/DisplayTags.cs @@ -188,7 +188,43 @@ namespace Volian.Controls.Library get { return _MyUserInfo; } set { _MyUserInfo = value; } } + // C2020-003 This is used to sort the checkoff list from the format file + // if the checkoff has an OrderBy element, then use it for the sorting, otherwise use th checkoff Index element + private static int CompareCheckoffUsingOrderBy(CheckOff ckf1, CheckOff ckf2) + { + if (ckf1.OrderBy == null) + { + if (ckf2.OrderBy == null) // neither ckf1 nor ckf2 uses OrderBy index + { + if (ckf1.Index > ckf2.Index) return 1; //ckf1 goes before ckf2 + if (ckf1.Index < ckf2.Index) return -1; // ckf1 goes after ckf2 + return 0; //ckf1 and ckf2 have the same index value + } + else // ckf1 does not have OrderBy index but ckf2 has OrderBy index + { + if (ckf1.Index > ckf2.OrderBy) return 1; //ckf1 goes before ckf2 + if (ckf1.Index < ckf2.OrderBy) return -1; // ckf1 goes after ckf2 + return 0; //ckf1 and ckf2 have the same index value + } + } + else //ckf1 has orderBy + { + if (ckf2.OrderBy == null) // ckf1 has OrderBy index but ckf2 does not + { + if (ckf1.OrderBy > ckf2.Index) return 1; //ckf1 goes before ckf2 + if (ckf1.OrderBy < ckf2.Index) return -1; // ckf1 goes after ckf2 + return 0; //ckf1 and ckf2 have the same index value + } + else // both ckf1 and ckf2 has OrderBy index + { + if (ckf1.OrderBy > ckf2.OrderBy) return 1; //ckf1 goes before ckf2 + if (ckf2.OrderBy > ckf1.OrderBy) return -1; // ckf1 goes after ckf2 + return 0; //ckf1 and ckf2 have the same index value + } + } + } + private Dictionary _CheckOffIndex = new Dictionary(); // C2020-003 translate the sorted index number to the actual checkoff index private void TagsFillIn() { _Initalizing = true; @@ -277,10 +313,16 @@ namespace Volian.Controls.Library int maxindx = fmtdata.ProcData.CheckOffUCF ? fmtdata.ProcData.CheckOffData.CheckOffList.MaxIndex : fmtdata.ProcData.CheckOffData.CheckOffList.MaxIndexNoInherit; if (_checkoffsAllowed && !(fmtdata.ProcData.CheckOffData.CheckOffList == null) && !(maxindx == 0)) { + CheckOffList chkoffList = fmtdata.ProcData.CheckOffData.CheckOffList; + if (chkoffList != null) chkoffList.Sort(CompareCheckoffUsingOrderBy); // C2020-003 sort the checkoff list via the Index and/or OrderBy elements cmbCheckoff.Items.Clear(); - foreach (CheckOff co in fmtdata.ProcData.CheckOffData.CheckOffList) + _CheckOffIndex.Clear(); // C2020-003 clear the checkoff index dictionary + int sortedIndx = 0; + foreach (CheckOff co in chkoffList) { cmbCheckoff.Items.Add(co.MenuItem); + _CheckOffIndex.Add(sortedIndx, (int)co.Index); // C2020-003 add the real index number for each sorted index + sortedIndx++; } // bug fix B2015-186 // the config had a really big number for the checkoff index. @@ -654,9 +696,9 @@ namespace Volian.Controls.Library if (_Initalizing) return; MyEditItem.SaveContents(); // set selected index in the step's config. - int indx = cmbCheckoff.SelectedIndex; + int indx = _CheckOffIndex[cmbCheckoff.SelectedIndex]; // C2020-003 get the non-sorted index from the sorted index // get index, if greater than 100, store that - otherwise store index down list. - // if this format does not have ucf signoffs, indx is just the selected index from the combo mobx. + // if this format does not have ucf signoffs, indx is just the selected index from the combo box. if (CurItemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffUCF) { // get index, if greater than 100, store that - otherwise store index down list.