diff --git a/PROMS/DataLoader/Formats.cs b/PROMS/DataLoader/Formats.cs index 13610f58..453558a0 100644 --- a/PROMS/DataLoader/Formats.cs +++ b/PROMS/DataLoader/Formats.cs @@ -28,57 +28,83 @@ namespace DataLoader { public string _FmtAllPath; public string _GenmacAllPath; - - private Format AddFormatToDB(Format parent, string format, bool issub, DateTime Dts, string Userid) - { - string fmtdata = null; - string genmacdata = null; - XmlDocument xd = null; + private FormatInfoList _AllFormats; + + public FormatInfoList AllFormats + { + get + { + if (_AllFormats == null) + _AllFormats = FormatInfoList.Get(); + return _AllFormats; + } + } + private Dictionary _LookupFormats; + public Dictionary LookupFormats + { + get + { + if (_LookupFormats == null) + { + _LookupFormats = new Dictionary(); + foreach (FormatInfo myFormat in AllFormats) + { + _LookupFormats.Add(myFormat.Name, myFormat.FormatID); + } + } + return _LookupFormats; + } + } + private Format AddFormatToDB(Format parent, string format, bool issub, DateTime Dts, string Userid) + { + string fmtdata = null; + string genmacdata = null; + XmlDocument xd = null; //string path = "c:\\development\\fmtall\\" + format + "all.xml"; string path = _FmtAllPath + "\\" + format + "all.xml"; - if (File.Exists(path)) - { - try - { - StreamReader srf = new StreamReader(path); - xd = new XmlDocument(); - xd.Load(srf); - //xd.Load(path); - fmtdata = xd.OuterXml; - } - catch(Exception ex) - { - frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path); - return null; - } - } - - // Do we need genmac - only if non-subformat - if (!issub) - { + if (File.Exists(path)) + { + try + { + StreamReader srf = new StreamReader(path); + xd = new XmlDocument(); + xd.Load(srf); + //xd.Load(path); + fmtdata = xd.OuterXml; + } + catch (Exception ex) + { + frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path); + return null; + } + } + + // Do we need genmac - only if non-subformat + if (!issub) + { //path = "c:\\development\\genmacall\\" + format + ".svg"; - path = _GenmacAllPath + "\\" + format + ".svg"; - if (File.Exists(path)) - { - try - { - StreamReader sr = new StreamReader(path); - XmlDocument xdg = new XmlDocument(); - xdg.Load(sr); - //xdg.Load(path); - genmacdata = xdg.OuterXml; - } - catch (Exception ex) - { - frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path); - return null; - } - } - } - // Get the name & then create the record. - if (Userid == null || Userid == "") Userid = "Migration"; - + path = _GenmacAllPath + "\\" + format + ".svg"; + if (File.Exists(path)) + { + try + { + StreamReader sr = new StreamReader(path); + XmlDocument xdg = new XmlDocument(); + xdg.Load(sr); + //xdg.Load(path); + genmacdata = xdg.OuterXml; + } + catch (Exception ex) + { + frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path); + return null; + } + } + } + // Get the name & then create the record. + if (Userid == null || Userid == "") Userid = "Migration"; + string nmattr = "Default"; // use xpath to get name. @@ -96,27 +122,24 @@ namespace DataLoader Format rec = null; try { - rec = Format.MakeFormat(parent, fname, nmattr, fmtdata, genmacdata, Dts, Userid); + if (!LookupFormats.ContainsKey(fname)) + { + rec = Format.MakeFormat(parent, fname, nmattr, fmtdata, genmacdata, Dts, Userid); + } + else + { + rec = Format.Get(LookupFormats[fname]); + rec.Data = fmtdata; + rec.GenMac = genmacdata; + rec = rec.Save(); + } } catch (Exception ex) { - FormatInfoList lst = FormatInfoList.Get(); - foreach (FormatInfo fi in lst) - { - // if this is the format we're updating, update it and break. - if (fi.Name == fname) - { - Format f = Format.Get(fi.FormatID); - f.Data = fmtdata; - f.GenMac = genmacdata; - f.Save(); - return f; - } - } - //frmMain.AddError(ex, "AddFormatToDB-make format('{0}','{1}')", parent.Name, path); + frmMain.AddError(ex, "AddFormatToDB-make format('{0}','{1}')", parent.Name, path); } - return rec; - } + return rec; + } public void LoadAllFormats() { Format basefmt = null; @@ -215,6 +238,6 @@ namespace DataLoader FormatInfo recInfo = FormatInfo.Get(rec.FormatID); return recInfo; } - + } } \ No newline at end of file diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs index e24dc5cd..11e182b8 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -44,13 +44,22 @@ namespace VEPROMS.CSLA.Library public void FixContentText(RoUsageInfo rousg, ROFSTLookup.rochild roch, ROFstInfo origROFstInfo) // string newvalue) { string newvalue = roch.value; - string lookFor = string.Format(@"", rousg.ROUsageID); - Match m = Regex.Match(Text, lookFor,RegexOptions.Singleline); - if (m != null && m.Groups.Count > 1) + string findLink = @""; + MatchCollection ms = Regex.Matches(Text, findLink); + string lookFor = string.Format(@"", rousg.ROUsageID); + foreach (Match mm in ms) { - System.Text.RegularExpressions.Group g = m.Groups[3]; - if (g.ToString() != newvalue) - Text = Text.Substring(0, g.Index) + newvalue + Text.Substring(g.Index + g.Length); + int offset = mm.Index; + Match m = Regex.Match(mm.Value, lookFor, RegexOptions.Singleline); + if (m != null && m.Groups.Count > 1) + { + System.Text.RegularExpressions.Group g = m.Groups[3]; + if (g.ToString() != newvalue) + { + Text = Text.Substring(0, offset + g.Index) + newvalue + Text.Substring(offset + g.Index + g.Length); + break; // Text has been processed + } + } } // see if there is a grid to update too. if (rousg.MyContent.MyGrid != null) @@ -58,20 +67,25 @@ namespace VEPROMS.CSLA.Library if (roch.type == (int)E_ROValueType.Table) // if change in rotable data... { List retlist = origROFstInfo.OnROTableUpdate(this, new ROFstInfoROTableUpdateEventArgs(newvalue, MyGrid.Data)); - if (Text != retlist[0])Text = retlist[0]; + if (Text != retlist[0]) Text = retlist[0]; if (MyGrid.Data != retlist[1]) MyGrid.Data = retlist[1]; } else { // if it's an ro within a table, need to process into an flex grid to save the grid data: - + string findLinkXml = @"<START\].*?\[END>"; string lookForXml = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v '?\\]+)*\\v(\\[^v \\]+)* #Link:ReferencedObject:{0} .*?\[END>", rousg.ROUsageID); - Match mg = Regex.Match(MyGrid.Data, lookForXml); - if (mg != null && mg.Groups.Count > 1) + MatchCollection msg = Regex.Matches(MyGrid.Data, findLinkXml); + foreach (Match mmg in msg) { - System.Text.RegularExpressions.Group g = mg.Groups[3]; - if (g.ToString() != newvalue) - MyGrid.Data = MyGrid.Data.Substring(0, g.Index) + newvalue + MyGrid.Data.Substring(g.Index + g.Length); + int offset = mmg.Index; + Match mg = Regex.Match(MyGrid.Data, lookForXml); + if (mg != null && mg.Groups.Count > 1) + { + System.Text.RegularExpressions.Group g = mg.Groups[3]; + if (g.ToString() != newvalue) + MyGrid.Data = MyGrid.Data.Substring(0, offset + g.Index) + newvalue + MyGrid.Data.Substring(offset + g.Index + g.Length); + } } } } diff --git a/PROMS/Volian.Controls.Library/DisplayText.cs b/PROMS/Volian.Controls.Library/DisplayText.cs index b2dc2486..da376000 100644 --- a/PROMS/Volian.Controls.Library/DisplayText.cs +++ b/PROMS/Volian.Controls.Library/DisplayText.cs @@ -257,7 +257,7 @@ namespace Volian.Controls.Library // (\\[^v' \\]+)* --> look for rtf commands but exclude \' before the \v // \\v(\\[^v \\]+)* --> look for rtf commands after the \v // if it turns out that if ro's have any embedded unicode characters this needs expanded, such as /u8209? (hard hyphen) - string lookFor = string.Format(@""); + string lookFor = string.Format(@""); MatchCollection matches = Regex.Matches(text, lookFor); for (int i = matches.Count - 1; i >= 0; i--) {