C2020-003 Added logic to sort the checkoff list using both the Index and (if available) the OrderBy elements.

C2020-003 – Added the OderBy element to the Checkoff item
This commit is contained in:
2020-03-05 15:05:36 +00:00
parent 83ec578e88
commit b9352fc0f5
3 changed files with 103 additions and 7 deletions

View File

@@ -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<int, int> _CheckOffIndex = new Dictionary<int, int>(); // 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.