From cb52bad3e9bfa48c789d21253500234bde5e2dd3 Mon Sep 17 00:00:00 2001 From: Rich Date: Wed, 18 Feb 2015 02:36:42 +0000 Subject: [PATCH] Improved conversion ot Referenced Objects and Transitions to text Added code to implement deleting pdfs Fixed problems with searching by Textm Annotations, Referenced Objects and Transitions --- .../Extension/ContentExt.cs | 51 +++++++++++---- .../VEPROMS.CSLA.Library/Extension/ItemExt.cs | 63 ++++++++++--------- .../VEPROMS.CSLA.Library/Extension/PdfExt.cs | 47 ++++++++++++++ .../Volian.Controls.Library/DisplaySearch.cs | 52 ++++++++++++++- 4 files changed, 167 insertions(+), 46 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs index a52baa65..c1596ba2 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -32,13 +32,25 @@ namespace VEPROMS.CSLA.Library // if (g.ToString() != transText) // Text = Text.Substring(0, g.Index) + transText + Text.Substring(g.Index + g.Length); //} - string newvalue = tran.ResolvePathTo(); + string newvalue = tran != null ? tran.ResolvePathTo() : string.Empty; if (forceConvertToText) newvalue = "?"; string findLink = @""; MatchCollection ms = Regex.Matches(Text, findLink); //string lookFor = string.Format(@"", rousg.ROUsageID); - string lookFor = string.Format(@"^", tran.TranType, tran.TransitionID); + string lookFor; + if (tran == null) + { + int loc1 = Text.IndexOf("#Link:Transition:", 0) + ("#Link:Transition:").Length; + int loc2 = Text.IndexOf(" ", loc1); + string trantype = Text.Substring(loc1, loc2 - loc1); + loc1 = loc2 + 1; + loc2 = Text.IndexOf(" ", loc1); + string tranid = Text.Substring(loc1, loc2 - loc1); + lookFor = string.Format(@"^", trantype, tranid); + } + else + lookFor = string.Format(@"^", tran.TranType, tran.TransitionID); foreach (Match mm in ms) { Match m = Regex.Match(mm.Value, lookFor, RegexOptions.Singleline); @@ -57,8 +69,9 @@ namespace VEPROMS.CSLA.Library { string rv = ConvertTransitionToText(tran, newvalue); //Text = Text.Substring(0, myIndex - 14) + gg + Text.Substring(myIndex + myLength); - Annotation.MakeAnnotation(this.ContentItems[0].MyItem, ItemInfo.VolianCommentType, "", string.Format("Transition ({0}) converted to text", ItemInfo.ConvertToDisplayText(gg)), null); - Transition.Delete(tran.TransitionID); + Annotation.MakeAnnotation(this.ContentItems[0].MyItem, AnnotationType.GetByName("Verification Required"), "", string.Format("Transition ({0}) converted to text", ItemInfo.ConvertToDisplayText(gg)), null); + if(tran != null) + Transition.Delete(tran.TransitionID); break; } else if ((gg.Contains("\\u8209?") ? gg.Replace("\\u8209?", "-") : gg) != (newvalue.Contains("\\u8209?") ? newvalue.Replace("\\u8209?", "-") : newvalue)) @@ -69,7 +82,7 @@ namespace VEPROMS.CSLA.Library } } // see if there is a grid to update too. - if (tran.MyContent.MyGrid != null) + if (tran != null && tran.MyContent.MyGrid != null) { //string lookForXml = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* ([^#]*?)(\\[^v'? \\]+)*\\v(\\[^v \\]+)* #Link:Transition[^:]*?:{0} {1}( [0-9]*){{1,2}}\[END>", tran.TranType, tran.TransitionID); //Match mg = Regex.Match(MyGrid.Data, lookForXml); @@ -128,7 +141,19 @@ namespace VEPROMS.CSLA.Library MatchCollection ms = Regex.Matches(Text, findLink); //string lookFor = string.Format(@"", rousg.ROUsageID); //string lookFor = string.Format(@"^$", rousg.ROUsageID); - string lookFor = string.Format(@"^", tran.TranType, tran.TransitionID); + string lookFor; + if (tran == null) + { + int loc1 = Text.IndexOf("#Link:Transition:", 0) + ("#Link:Transition:").Length; + int loc2 = Text.IndexOf(" ", loc1); + string trantype = Text.Substring(loc1, loc2 - loc1); + loc1 = loc2 + 1; + loc2 = Text.IndexOf(" ", loc1); + string tranid = Text.Substring(loc1, loc2 - loc1); + lookFor = string.Format(@"^", trantype, tranid); + } + else + lookFor = string.Format(@"^", tran.TranType, tran.TransitionID); int lastIndex = 0; string newText = Text; foreach (Match mm in ms) @@ -403,7 +428,7 @@ namespace VEPROMS.CSLA.Library if (value == "?") { retval = this.ConvertROToText(rousg, value, rotype, origROFstInfo); - Annotation.MakeAnnotation(this.ContentItems[0].MyItem, ItemInfo.VolianCommentType, "", string.Format("RO value ({0}) converted to text", ItemInfo.ConvertToDisplayText(retval)), null); + Annotation.MakeAnnotation(this.ContentItems[0].MyItem, AnnotationType.GetByName("Verification Required"), "", string.Format("RO value ({0}) converted to text", ItemInfo.ConvertToDisplayText(retval)), null); RoUsage.Delete(rousg.ROUsageID); return retval; } @@ -545,9 +570,9 @@ namespace VEPROMS.CSLA.Library } public void FixTransitionText(TransitionInfo tran, TransitionLookup tranLookup, ItemInfo ii) { - FixTransitionText(tran, tranLookup, ii, false); + FixTransitionText(tran, tranLookup, ii, ""); } - public void FixTransitionText(TransitionInfo tran, TransitionLookup tranLookup, ItemInfo ii, bool forceConvertToText) + public void FixTransitionText(TransitionInfo tran, TransitionLookup tranLookup, ItemInfo ii, string forceConvertToText) { //string transText = tran.ResolvePathTo(); //string lookFor = string.Format(@"", tran.TranType, tran.TransitionID); @@ -565,7 +590,7 @@ namespace VEPROMS.CSLA.Library newvalue = tran.ResolvePathTo(); else newvalue = tran.ResolvePathTo(tranLookup); - if (forceConvertToText) + if (forceConvertToText != string.Empty) newvalue = "?"; string findLink = @""; MatchCollection ms = Regex.Matches(Text, findLink); @@ -592,7 +617,7 @@ namespace VEPROMS.CSLA.Library if (newvalue == "?") { gg = ItemInfo.ConvertToDisplayText(gg); - newvalue = "Invalid Transition"; + newvalue = forceConvertToText; OnStaticContentInfoChange(ii, new StaticContentInfoEventArgs(gg, newvalue, "TX")); break; } @@ -666,9 +691,9 @@ namespace VEPROMS.CSLA.Library } public void FixTransitionText(TransitionInfo tran, ItemInfo ii) { - FixTransitionText(tran, ii, false); + FixTransitionText(tran, ii, ""); } - public void FixTransitionText(TransitionInfo tran, ItemInfo ii, bool forceConvertToText) + public void FixTransitionText(TransitionInfo tran, ItemInfo ii, string forceConvertToText) { FixTransitionText(tran, null, ii, forceConvertToText); //string transText = tran.ResolvePathTo(tranLookup); diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index 47d46012..c7462ecd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -585,26 +585,26 @@ namespace VEPROMS.CSLA.Library { bool forceConvertToText = false; TranCheckCount++; - if (TransitionsToNonEditable != null) - { - if (IsTransitionToNonEditable(traninfo)) - { - forceConvertToText = true; - TranFixCount++; - itemInfo.MyContent.FixTransitionText(traninfo, itemInfo, true); - Content content = Content.Get(itemInfo.MyContent.ContentID); - content.FixTransitionText(traninfo, true); - content.Save(); - } - } - else + //if (TransitionsToNonEditable != null) + //{ + // if (IsTransitionToNonEditable(traninfo)) + // { + // forceConvertToText = true; + // TranFixCount++; + // itemInfo.MyContent.FixTransitionText(traninfo, itemInfo, "Reason for Change: Transition to Non-Editable Step"); + // Content content = Content.Get(itemInfo.MyContent.ContentID); + // content.FixTransitionText(traninfo, true); + // content.Save(); + // } + //} + if (!forceConvertToText) { SectionConfig sc = traninfo.MyItemToID.ActiveSection.MyConfig as SectionConfig; forceConvertToText = (sc.SubSection_Edit == "N"); if (forceConvertToText) { TranFixCount++; - itemInfo.MyContent.FixTransitionText(traninfo, itemInfo, true); + itemInfo.MyContent.FixTransitionText(traninfo, itemInfo, "Reason for Change: Transition to Non-Editable Step"); Content content = Content.Get(itemInfo.MyContent.ContentID); content.FixTransitionText(traninfo, true); content.Save(); @@ -617,7 +617,7 @@ namespace VEPROMS.CSLA.Library { forceConvertToText = true; TranFixCount++; - itemInfo.MyContent.FixTransitionText(traninfo, itemInfo, true); + itemInfo.MyContent.FixTransitionText(traninfo, itemInfo, "Reason for Change: Transition to External Procedure using Internal Format"); Content content = Content.Get(itemInfo.MyContent.ContentID); content.FixTransitionText(traninfo, true); content.Save(); @@ -627,12 +627,15 @@ namespace VEPROMS.CSLA.Library { if (itemInfo.MyDocVersion.VersionID != traninfo.MyItemToID.MyDocVersion.VersionID) //different doc version { - forceConvertToText = true; - TranFixCount++; - itemInfo.MyContent.FixTransitionText(traninfo, itemInfo, true); - Content content = Content.Get(itemInfo.MyContent.ContentID); - content.FixTransitionText(traninfo, true); - content.Save(); + if (!itemInfo.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList[traninfo.TranType].TransMenu.Contains("Proc")) //internal format + { + forceConvertToText = true; + TranFixCount++; + itemInfo.MyContent.FixTransitionText(traninfo, itemInfo, "Reason for Change: Transition to Outside Procedure using Internal Format"); + Content content = Content.Get(itemInfo.MyContent.ContentID); + content.FixTransitionText(traninfo, true); + content.Save(); + } } } if (!forceConvertToText) @@ -710,7 +713,7 @@ namespace VEPROMS.CSLA.Library if (roval == "?") { oldText = content.ConvertROToText(rousage, roval, roch.type, rofstinfo); - Annotation.MakeAnnotation(content.ContentItems[0].MyItem, VolianCommentType, "", string.Format("RO value ({0}) converted to text", ItemInfo.ConvertToDisplayText(oldText)), null); + Annotation.MakeAnnotation(content.ContentItems[0].MyItem, AnnotationType.GetByName("Verification Required"), "", string.Format("RO value ({0}) converted to text", ItemInfo.ConvertToDisplayText(oldText)), null); } else content.FixContentText(rousage, roval, roch.type, rofstinfo); @@ -748,7 +751,7 @@ namespace VEPROMS.CSLA.Library if (roval == "?") { oldText = content.ConvertROToText(rousage, roval, roch.type, rofstinfo); - Annotation.MakeAnnotation(content.ContentItems[0].MyItem, VolianCommentType, "", string.Format("RO value ({0}) converted to text", ItemInfo.ConvertToDisplayText(oldText)), null); + Annotation.MakeAnnotation(content.ContentItems[0].MyItem, AnnotationType.GetByName("Verification Required"), "", string.Format("RO value ({0}) converted to text", ItemInfo.ConvertToDisplayText(oldText)), null); } else content.FixContentText(rousage, roval, roch.type, rofstinfo); @@ -5559,14 +5562,14 @@ namespace VEPROMS.CSLA.Library { return (Procedure)(_Editable = Procedure.Get(ItemID)); } - public static void RefreshTransitions(ProcedureInfo tmp) - { - RefreshTransitions(tmp, null, null); - } - public static void RefreshTransitions(ProcedureInfo tmp, TransitionInfoList transitionToDisconnected, TransitionInfoList transitionsToNonEditable) + //public static void RefreshTransitions(ProcedureInfo tmp) + //{ + // RefreshTransitions(tmp, null, null); + //} + public static void RefreshTransitions(ProcedureInfo tmp)//, TransitionInfoList transitionToDisconnected, TransitionInfoList transitionsToNonEditable) { - TransitionsToDisconnected = transitionToDisconnected; - TransitionsToNonEditable = transitionsToNonEditable; + //TransitionsToDisconnected = transitionToDisconnected; + //TransitionsToNonEditable = transitionsToNonEditable; TransitionLookup tranLookup = new TransitionLookup(0, tmp.ItemID, tmp.MyLookup); tranLookup.ApplicabilityUnit = tmp.MyDocVersion.DocVersionConfig.SelectedSlave; tranLookup.NewLookupNeeded += new TransitionLookupEvent(GetNewLookup); diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/PdfExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/PdfExt.cs index c4eb1d5a..1bb29271 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/PdfExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/PdfExt.cs @@ -92,4 +92,51 @@ namespace VEPROMS.CSLA.Library public partial class PdfInfoList { } + public class ExecuteStoredProcedure : CommandBase + { + private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + #region Factory Methods + private string _StoredProcedure; + public string StoredProcedure + { + get { return _StoredProcedure; } + set { _StoredProcedure = value; } + } + private int _AffectedRows; + public int AffectedRows + { + get { return _AffectedRows; } + set { _AffectedRows = value; } + } + public static int Execute(string storedProcedure) + { + ExecuteStoredProcedure cmd = new ExecuteStoredProcedure(); + cmd.StoredProcedure = storedProcedure; + DataPortal.Execute(cmd); + return cmd.AffectedRows; + } + #endregion + #region Server-Side code + protected override void DataPortal_Execute() + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn)) + { + cmd.CommandType = CommandType.StoredProcedure; + cmd.CommandTimeout = 0; + AffectedRows = cmd.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedure Error", ex); + throw new ApplicationException("Failure on ExecuteStoredProcedure", ex); + } + } + #endregion + } } diff --git a/PROMS/Volian.Controls.Library/DisplaySearch.cs b/PROMS/Volian.Controls.Library/DisplaySearch.cs index 65c20d32..e899b59c 100644 --- a/PROMS/Volian.Controls.Library/DisplaySearch.cs +++ b/PROMS/Volian.Controls.Library/DisplaySearch.cs @@ -150,6 +150,21 @@ namespace Volian.Controls.Library { if (e.NewTab == tabTranSearch) { + //enable-disable doc version nodes based on version type if selected + if (cbxTranVersion.SelectedIndex > -1) + { + if (dicExpandedDocVersionNodes.Count > 0) + { + foreach (DevComponents.AdvTree.Node n in dicExpandedDocVersionNodes.Keys) + { + DocVersionInfo dvi = (DocVersionInfo)n.Tag; + if(cbxTranVersion.Tag.ToString().Contains(dvi.VersionID.ToString())) + n.Enabled = true; + else + n.Enabled = false; + } + } + } //setup transition format versions this.Cursor = Cursors.WaitCursor; if (myFormatVersionList == null) @@ -170,6 +185,19 @@ namespace Volian.Controls.Library } this.Cursor = Cursors.Default; } + else + { + foreach (DevComponents.AdvTree.Node n in dicExpandedDocVersionNodes.Keys) + n.Enabled = true; + if (dicSelectedDocVersionNodes.Count > 0) + { + foreach (DevComponents.AdvTree.Node n in dicSelectedDocVersionNodes.Keys) + { + n.Enabled = true; + } + dicSelectedDocVersionNodes.Clear(); + } + } } void cbxTranFormat_SelectedIndexChanged(object sender, EventArgs e) @@ -254,6 +282,18 @@ namespace Volian.Controls.Library } cbxTranVersion.Tag = versionList; cbxTranFormatFillIn(versionList); + if (dicExpandedDocVersionNodes.Count > 0) + { + foreach (DevComponents.AdvTree.Node n in dicExpandedDocVersionNodes.Keys) + { + DocVersionInfo dvi = (DocVersionInfo)n.Tag; + if (cbxTranVersion.Tag.ToString().Contains(dvi.VersionID.ToString())) + n.Enabled = true; + else + n.Enabled = false; + } + } + List uncheckNodes = new List(); foreach (DevComponents.AdvTree.Node n in dicSelectedDocVersionNodes.Keys) { @@ -456,6 +496,7 @@ namespace Volian.Controls.Library // vlnStackTrace.ShowStackLocal(e.Node.Text,1,10); //} private Dictionary dicSelectedDocVersionNodes = new Dictionary(); + private Dictionary dicExpandedDocVersionNodes = new Dictionary(); void advTreeProcSets_BeforeExpand(object sender, DevComponents.AdvTree.AdvTreeNodeCancelEventArgs e) { DevComponents.AdvTree.Node par = e.Node; @@ -498,10 +539,15 @@ namespace Volian.Controls.Library newnode.CheckBoxStyle = eCheckBoxStyle.CheckBox; newnode.CheckBoxThreeState = false; newnode.CheckBoxVisible = true; - if (!dicSelectedDocVersionNodes.ContainsKey(newnode)) dicSelectedDocVersionNodes.Add(newnode, false); - - newnode.Enabled = cbxTranVersion.Tag != null ? cbxTranVersion.Tag.ToString().Contains(dv.VersionID.ToString()) : false; + if (tabSearchTypes.SelectedTab == tabTranSearch) + { + if (!dicSelectedDocVersionNodes.ContainsKey(newnode)) dicSelectedDocVersionNodes.Add(newnode, false); + newnode.Enabled = cbxTranVersion.Tag != null ? cbxTranVersion.Tag.ToString().Contains(dv.VersionID.ToString()) : false; + } + else + newnode.Enabled = true; par.Nodes.Add(newnode); + dicExpandedDocVersionNodes.Add(newnode, newnode.Enabled); //} } }