From 258b1d2d1fbe4949c8499bc6c7e0a5d1b59146f2 Mon Sep 17 00:00:00 2001 From: John Jenko Date: Fri, 23 Jan 2026 15:55:36 -0500 Subject: [PATCH] B2026-003 Imported memory handling in the FlexGrid (table) code for when we are replacing many RO values in table cells --- PROMS/Volian.Controls.Library/GridItem.cs | 25 +++++++++++--------- PROMS/Volian.Controls.Library/VlnFlexGrid.cs | 25 +++++++++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/PROMS/Volian.Controls.Library/GridItem.cs b/PROMS/Volian.Controls.Library/GridItem.cs index 1a2292cc..4b794d91 100644 --- a/PROMS/Volian.Controls.Library/GridItem.cs +++ b/PROMS/Volian.Controls.Library/GridItem.cs @@ -537,6 +537,10 @@ namespace Volian.Controls.Library // if it is a modify and there will be no usages if it is new (the usage gets created on the save) if (!MyFlexGrid.IsRoTable) { + // B2026-003 we where using a string.format on this inside the while loop - allocating memory each time + // so I move it outside the while loop and did a simple assigment of text + string lookForLinks = @""; + while (r < h) { CellRange cr = MyFlexGrid.GetMergedRange(r, c); @@ -546,8 +550,7 @@ namespace Volian.Controls.Library { // see if there are any links and save these so that any deleted ROs or transitions in the // steprtb can have associated usages/transitions records removed from the database. - string lookFor = string.Format(@""); - MatchCollection matches = Regex.Matches((string)MyFlexGrid[r, c], lookFor); + MatchCollection matches = Regex.Matches((string)MyFlexGrid[r, c], lookForLinks); for (int i = matches.Count - 1; i >= 0; i--) { Match m = matches[i]; @@ -569,15 +572,15 @@ namespace Volian.Controls.Library { int tid = int.Parse(myMatch.Groups[2].Value); RtfTransList.Add(tid); - int myIndex = m.Groups[4].Index; - int myLength = m.Groups[4].Length; - if (m.Groups[3].Value != " ") - { - myIndex = m.Groups[3].Index; - myLength += m.Groups[3].Length; - } - string gg = ((string)MyFlexGrid[r, c]).Substring(myIndex, myLength); - if (gg.ToUpper().Contains("(PAGE ~)")) RtfTransPageNumList.Add(tid); // B2020-089, check for upper case Page ~ in case step was upper cased + int myIndex = m.Groups[4].Index; + int myLength = m.Groups[4].Length; + if (m.Groups[3].Value != " ") + { + myIndex = m.Groups[3].Index; + myLength += m.Groups[3].Length; + } + string gg = ((string)MyFlexGrid[r, c]).Substring(myIndex, myLength); + if (gg.ToUpper().Contains("(PAGE ~)")) RtfTransPageNumList.Add(tid); // B2020-089, check for upper case Page ~ in case step was upper cased } } } diff --git a/PROMS/Volian.Controls.Library/VlnFlexGrid.cs b/PROMS/Volian.Controls.Library/VlnFlexGrid.cs index 046af0aa..ee6162dc 100644 --- a/PROMS/Volian.Controls.Library/VlnFlexGrid.cs +++ b/PROMS/Volian.Controls.Library/VlnFlexGrid.cs @@ -272,21 +272,24 @@ namespace Volian.Controls.Library for (int i = 0; i < rows * cols; i++) datum.Add("|"); XmlNodeList nl = xd.SelectNodes("C1FlexGrid/Cells/Cell/Data"); - string data = string.Empty; + // B2026-003 use StringBuilder a "using" statement around the RichTextBox for better mememory management + StringBuilder data = new StringBuilder(); foreach (XmlNode xn in nl) { - RichTextBox rtb = new RichTextBox(); - rtb.Rtf = xn.InnerText; - XmlAttribute xa = xn.ParentNode.Attributes.GetNamedItem("index") as XmlAttribute; - string[] rc = xa.InnerText.Split(','); - int r = int.Parse(rc[0]); - int c = int.Parse(rc[1]); - int index = r * cols + c; - datum[index] = "|" + (rtb.Text == "" ? "" : rtb.Text); + using (RichTextBox rtb = new RichTextBox()) + { + rtb.Rtf = xn.InnerText; + XmlAttribute xa = xn.ParentNode.Attributes.GetNamedItem("index") as XmlAttribute; + string[] rc = xa.InnerText.Split(','); + int r = int.Parse(rc[0]); + int c = int.Parse(rc[1]); + int index = r * cols + c; + datum[index] = "|" + (rtb.Text == "" ? "" : rtb.Text); + } } foreach (string s in datum) - data += s; - return data; + data.Append(s); + return data.ToString(); } private string GetCellFormatString(XmlDocument xd) {