From c10da9820489e58ac1f2a16ff65469995b67dc07 Mon Sep 17 00:00:00 2001 From: Rich Date: Wed, 14 Mar 2018 15:23:23 +0000 Subject: [PATCH] B2018-046 - Fix code so that duplicate ROs will not cause problems when they are converted to text during import. --- .../VEPROMS User Interface/dlgExportImport.cs | 68 +++++++++++-------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index 20a71c33..676c0f5d 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -3270,41 +3270,49 @@ namespace VEPROMS string lookFor = string.Format(@"^$", rousageid); int lastIndex = 0; string newText = content.Text; - foreach (Match mm in ms) + // B2018-046 This loop repeats code to convert duplicate ROs in text to text + int originalCount = 0; + while (ms.Count > 0 && (originalCount == 0 || ms.Count < originalCount)) { - int offset = mm.Index; - Match m = Regex.Match(mm.Value, lookFor, RegexOptions.Singleline); - if (m != null && m.Groups.Count > 1) + originalCount = ms.Count; + foreach (Match mm in ms) { - string prefix = GetMyPrefix(content.Text, mm.Index, lastIndex); - string suffix = GetMySuffix(content.Text, mm.Index + mm.Length); - int myIndex = m.Groups[4].Index + mm.Index; - int myLength = m.Groups[4].Length; - if (m.Groups[3].Value != " ") + int offset = mm.Index; + Match m = Regex.Match(mm.Value, lookFor, RegexOptions.Singleline); + if (m != null && m.Groups.Count > 1) { - myIndex = m.Groups[3].Index + mm.Index; - myLength += m.Groups[3].Length; + string prefix = GetMyPrefix(content.Text, mm.Index, lastIndex); + string suffix = GetMySuffix(content.Text, mm.Index + mm.Length); + int myIndex = m.Groups[4].Index + mm.Index; + int myLength = m.Groups[4].Length; + if (m.Groups[3].Value != " ") + { + myIndex = m.Groups[3].Index + mm.Index; + myLength += m.Groups[3].Length; + } + string gg = newText.Substring(myIndex, myLength); + gg = gg.Replace("{", @"\{").Replace("}", @"\}"); + string part1 = newText.Substring(0, mm.Index); + string part2 = gg; + string part3 = newText.Substring(mm.Index + mm.Length); + //modify part1 based on prefix + if (prefix == @"\v ") + part1 = part1.Substring(0, part1.Length - 3); + else + part1 = part1.Substring(0, part1.Length - 3) + " "; + //modify part3 based on suffix + if (suffix == @"\v0 ") + part3 = part3.Substring(4); + else + part3 = suffix.Replace(@"\v0", "") + part3.Substring(suffix.Length); + content.Text = part1 + part2 + part3; + ROToTextAnnotation(content, part2); // B2016-225 (follow through) add annotation when RO is converted to text + _DidProcessROs = true; // B2017-076 flag that ROs where processed + break; // B2018-046 If it finds a match try again } - string gg = newText.Substring(myIndex, myLength); - gg = gg.Replace("{", @"\{").Replace("}", @"\}"); - string part1 = newText.Substring(0, mm.Index); - string part2 = gg; - string part3 = newText.Substring(mm.Index + mm.Length); - //modify part1 based on prefix - if (prefix == @"\v ") - part1 = part1.Substring(0, part1.Length - 3); - else - part1 = part1.Substring(0, part1.Length - 3) + " "; - //modify part3 based on suffix - if (suffix == @"\v0 ") - part3 = part3.Substring(4); - else - part3 = suffix.Replace(@"\v0", "") + part3.Substring(suffix.Length); - content.Text = part1 + part2 + part3; - ROToTextAnnotation(content, part2); // B2016-225 (follow through) add annotation when RO is converted to text - _DidProcessROs = true; // B2017-076 flag that ROs where processed + lastIndex = mm.Index + mm.Length; } - lastIndex = mm.Index + mm.Length; + ms = Regex.Matches(content.Text, findLink); // B2018-046 Look for match again } } content.Save();