C2022-001 logic to handle the new parent/child format of the RO.FST

This commit is contained in:
John Jenko 2022-01-21 14:33:49 +00:00
parent c66c01332e
commit 8a2b19521d

View File

@ -312,47 +312,78 @@ namespace VEPROMS.CSLA.Library
return val;
}
// C2021-026 Get the child RO value if it exists, otherwise to the default (parent) RO value
// C2022-001 new logic to handle new format of Parent/Child RO.FST
// The RO.FST will not have a specific child value if that child value is the same as the default value
public string GetParentChildROValue(rochild roc)
{
string roval = roc.value;
// B2021-093 Don't look for child RO values if "roval" is null
if (roval == null) return null;
// get the child (slave) information and set the rtnchld.value to the corresponding RO Value
//string childName = MyDocVersionInfo.DocVersionConfig.Unit_Name;
MatchCollection mm = Regex.Matches(roval, "(<APL [^<?]+) /APL>");
if (mm.Count > 1)
Console.WriteLine("Matches {0}", mm.Count);
StringBuilder sb = new StringBuilder();
int lastIndex = 0;
// Get selected child Idx
int selChldIdx = MyDocVersionInfo.DocVersionConfig.SelectedSlave;
string childName = MyDocVersionInfo.DocVersionConfig.Unit_Name;
string aplString = roval;
string ChldValue = "";
// C2021-065 see if we need to get the RO information for the "Other" Child applicability value
if (OtherChild != null && OtherChild != "")
{
selChldIdx = Convert.ToInt32(OtherChild); // the OTHER unit number
childName = MyDocVersionInfo.DocVersionConfig.Other_Unit_Name;
}
// if the RO Value contains Parent/Child values, parse out default value and the child (slave or unit specific) value
while (roval != null && roval.Contains("<APL DefaultVal="))
foreach (Match m in mm)
{
int startCVIdx = roval.IndexOf("<APL DefaultVal=");
int EndCVidx = roval.IndexOf(" /APL>", startCVIdx);
aplString = roval.Substring(startCVIdx, EndCVidx + 6 - startCVIdx);
int endDefIdx = aplString.IndexOf(",UnitIdx=",startCVIdx); // look for more than just a comma incase value contains a comma
string defValue = aplString.Substring(16,endDefIdx-16); // save the default RO value
int idx = aplString.IndexOf("UnitIdx=" + selChldIdx.ToString()); // look for a specific child (slave/unit) value
if (selChldIdx > 0 && idx > -1 && idx < aplString.Length)
{
idx = aplString.IndexOf("Value=", idx) + 6;
int idxEndVal = aplString.IndexOf(",UnitIdx=", idx); // look for more than just a comma incase value contains a comma
if (idxEndVal == -1)// if last child value is up to " /APL>"
idxEndVal = aplString.IndexOf(" /APL>", idx); // B2021-141 get end of Parent/Child RO Values for this RO reference
if (idxEndVal > idx)
ChldValue = aplString.Substring(idx, idxEndVal - idx); // selected Child RO value
else
ChldValue = defValue; // incomplete "<APL ..." structure use default value
}
sb.Append(roval.Substring(lastIndex, m.Index - lastIndex));
Console.WriteLine("Index={0},Length={1},value={2}",m.Index,m.Length,m.Value);
string aplString = m.Value;
string chldValStr = string.Format("UnitIdx={0} Value=", selChldIdx);
int offsetIdx = aplString.IndexOf(chldValStr);//m.Value.IndexOf(chldValStr);
int nextIDX = -1;
if (offsetIdx == -1)
offsetIdx = aplString.IndexOf("DefaultVal=") + 11;
else
ChldValue = defValue; // could not find a value for the selected child so use the default value
roval = roval.Replace(aplString, ChldValue); // replace the entire Parent/Child value string ("<APL ... /APL>") with the specifc value
offsetIdx += chldValStr.Length;
nextIDX = aplString.IndexOf(",UnitIdx", offsetIdx);
if (nextIDX == -1) nextIDX = aplString.IndexOf(" /APL>");
sb.Append(aplString.Substring(offsetIdx, nextIDX - offsetIdx));
lastIndex += m.Index + m.Length;
}
return roval;
return sb.ToString();
//int startCVIdx = roval.IndexOf("<APL DefaultVal=");
//// Get default value from DefaultVal= to UnitIdx= or /APL>;
//int EndCVidx = roval.IndexOf(" /APL>", startCVIdx);
//int endDefIdx = roval.IndexOf(",UnitIdx=", startCVIdx); // look for more than just a comma incase value contains a comma
//string defValue = roval.Substring(16, (endDefIdx > 0 ? endDefIdx : EndCVidx) - 16); // save the default RO value
//// Get
//// Get selected child Idx
//int selChldIdx = MyDocVersionInfo.DocVersionConfig.SelectedSlave;
//// Get selected value
////return either default value or child value as appropriate
//return defValue;
// get the child (slave) information and set the rtnchld.value to the corresponding RO Value
//string aplString = roval;
////string ChldValue = "";
//// if the RO Value contains Parent/Child values, parse out default value and the child (slave or unit specific) value
////while (roval != null && roval.Contains("<APL DefaultVal="))
////{
// aplString = roval.Substring(startCVIdx, EndCVidx + 6 - startCVIdx);
// int idx = aplString.IndexOf("UnitIdx=" + selChldIdx.ToString()); // look for a specific child (slave/unit) value
// if (selChldIdx > 0 && idx > -1 && idx < aplString.Length)
// {
// idx = aplString.IndexOf("Value=", idx) + 6;
// int idxEndVal = aplString.IndexOf(",UnitIdx=", idx); // look for more than just a comma incase value contains a comma
// if (idxEndVal == -1)// if last child value is up to " /APL>"
// idxEndVal = aplString.IndexOf(" /APL>", idx); // B2021-141 get end of Parent/Child RO Values for this RO reference
// if (idxEndVal > idx)
// ChldValue = aplString.Substring(idx, idxEndVal - idx); // selected Child RO value
// else
// ChldValue = defValue; // incomplete "<APL ..." structure use default value
// }
// else
// ChldValue = defValue; // could not find a value for the selected child so use the default value
// roval = roval.Replace(aplString, ChldValue); // replace the entire Parent/Child value string ("<APL ... /APL>") with the specifc value
////}
//return roval;
}
// this only gets rochild values. Later we may want another
// dictionary to get groups.