From 289db67a2b58c4acc27dc022ac1b5ec8be72a38d Mon Sep 17 00:00:00 2001 From: Kathy Date: Mon, 9 May 2016 11:29:00 +0000 Subject: [PATCH] Enhanced: Code to refresh contents for item list that is unlinked; gets list of items that have text differences between enhanced/source and refresh text Enhanced: Insert new procs & section for enhanced docs; Link 2 existing items, enhanced <->source --- .../VEPROMS.CSLA.Library/Extension/ItemExt.cs | 222 ++++++++++++++++++ .../Extension/ItemInsertExt.cs | 220 +++++++++++++++-- 2 files changed, 424 insertions(+), 18 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index 612f1926..da9abd64 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -2217,6 +2217,31 @@ namespace VEPROMS.CSLA.Library // return ToString(); //} #endregion + #region UnlinkEnhanced + public void DoUnlinkEnhanced(ItemInfo enhii) + { + try + { + using (ContentInfoList cil = ContentInfoList.DoEnhancedUnlink(enhii.ItemID)) + { + foreach (ContentInfo ci in cil) + { + using (Content c = ci.Get()) + { + // first refresh configs because the ContentInfo.Refresh causes events to occur that refresh screen + // and if configs aren't done first, the screen refresh, if based on config data, will not be correct. + foreach (ItemInfo ii in ci.ContentItems) ii.RefreshConfig(); + ContentInfo.Refresh(c); + } + } + } + } + catch (Exception ex) + { + throw new DbCslaException("Error on ProcedureInfo:DoUnlinkEnhanced", ex); + } + } + #endregion UnlinkEnhanced #region Search internal string _SearchDVPath; public string SearchDVPath @@ -5125,6 +5150,138 @@ namespace VEPROMS.CSLA.Library this.Add(itemInfo); IsReadOnly = true; } + #region EnhancedSupport + #region EnhancedGetTextDifferences + public static ItemInfoList GetListEnhancedTextDifferences(ItemInfo procItem) + { + try + { + ItemInfoList tmp = DataPortal.Fetch(new ItemListEnhancedTextDifferencesCriteria(procItem.ItemID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfoList.GetListEnhancedTextDifferences", ex); + } + } + [Serializable()] + private class ItemListEnhancedTextDifferencesCriteria + { + private int _ProcID; + public int ProcID + { + get { return _ProcID; } + set { _ProcID = value; } + } + public ItemListEnhancedTextDifferencesCriteria(int procid) + { + _ProcID = procid; + } + } + private void DataPortal_Fetch(ItemListEnhancedTextDifferencesCriteria criteria) + { + this.RaiseListChangedEvents = false; + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_ListItemsToRefresh"; + cm.Parameters.AddWithValue("@ProcID", criteria.ProcID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) + { + ItemInfo itemInfo = new ItemInfo(dr); + IsReadOnly = false; + this.Add(itemInfo); + IsReadOnly = true; + } + } + } + } + } + catch (Exception ex) + { + Database.LogException("ItemInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion // EnhancedGetTextDifferences + #region EnhancedGetMissingEnh + public static ItemInfoList GetListEnhancedForMissing(ItemInfo srcItem, int enhType) + { + try + { + ItemInfoList tmp = DataPortal.Fetch(new ItemListEnhancedMissingCriteria(srcItem.ItemID, enhType)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ItemInfoList.GetListEnhancedForMissing", ex); + } + } + [Serializable()] + private class ItemListEnhancedMissingCriteria + { + private int _ItemID; + public int ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + private int _EnhType; + public int EnhType + { + get { return _EnhType; } + set { _EnhType = value; } + } + public ItemListEnhancedMissingCriteria(int itemid, int enhtype) + { + _ItemID = itemid; + _EnhType = enhtype; + } + } + private void DataPortal_Fetch(ItemListEnhancedMissingCriteria criteria) + { + this.RaiseListChangedEvents = false; + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_ListUnlinkedItems"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + cm.Parameters.AddWithValue("@EnhType", criteria.EnhType); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) + { + ItemInfo itemInfo = new ItemInfo(dr); + IsReadOnly = false; + this.Add(itemInfo); + IsReadOnly = true; + } + } + } + } + } + catch (Exception ex) + { + Database.LogException("ItemInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex); + } + this.RaiseListChangedEvents = true; + } + #endregion // EnhancedGetMissingEnh + #endregion // EnhancedSupport #region Text Search public static ItemInfoList GetListFromTextSearch(string docVersionList, string stepTypeList, string searchString, int caseSensitive, ItemSearchIncludeLinks includeLinks, bool includeRtfFormatting, bool includeSpecialCharacters, string unitPrefix) { @@ -5912,6 +6069,7 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on ProcedureInfo:ClearChangeBarOverrides", ex); } } + //jcb add 20120501 item and children by unit public static ProcedureInfo GetItemAndChildrenByUnit(int? itemID, int? parentID, int? unitID) { @@ -6061,7 +6219,71 @@ namespace VEPROMS.CSLA.Library MyLookup = lookup; } //jcb end add 20120501 item and children by unit + #region EnhancedProcedureRefreshTextDifferences + public ItemInfoList FindEnhancedProcedureTextDifferences() + { + // for this enhanced procedure, get a list of differences of text between it and its source document. + // Return list is list of items in ENHANCED procedure that need their text refreshed. + // first check if enhanced: + EnhancedDocuments eds = GetMyEnhancedDocuments(); + if (eds == null || eds.Count == 0) return null; + if (eds[0].Type != 0) return null; + + // now get its enhtype from the source: + int enhtype = -1; + ItemInfo sourceProc = ItemInfo.Get(eds[0].ItemID); + EnhancedDocuments sourceProcEds = sourceProc.GetMyEnhancedDocuments(); + foreach (EnhancedDocument spe in sourceProcEds) + { + if (spe.ItemID == ItemID) enhtype = spe.Type; + } + if (enhtype == -1) return null; // something went wrong (it should never get to here) + + // get list of differences from sql. This list does not resolve links and may have other rtf commands. + // also this list is source items, not enhanced. + ItemInfoList iil = ItemInfoList.GetListEnhancedTextDifferences(this); + if (iil == null || iil.Count == 0) return null; // no differences were found. + + // from sql list, get display text of source items & compare to this procedure's items. This + // will determine true 'text' differences. Then return this list. + ItemInfoList retiil = null; // new ItemInfoList(null); + foreach (ItemInfo ii in iil) + { + EnhancedDocuments seds = ii.GetMyEnhancedDocuments(); + if (seds != null && seds.Count != 0) + { + ItemInfo srcItem = ItemInfo.Get(seds[0].ItemID); + if (srcItem.DisplayText != ii.DisplayText) + { + if (retiil == null) retiil = new ItemInfoList(ii); + else retiil.AddItem(ii); + } + } + } + return retiil; + } + public void EnhancedProcedureRefreshTextDifferences(ItemInfoList iil) + { + // the input list is a list of enhanced items within a procedure where + // the text is different between the source and this enhanced item. Refresh + // the text in the enhanced item based on the displaytext of the source item. + foreach (ItemInfo ii in iil) + { + EnhancedDocuments seds = ii.GetMyEnhancedDocuments(); + if (seds != null && seds.Count != 0) + { + ItemInfo srcItem = ItemInfo.Get(seds[0].ItemID); + using (Item enhItem = Item.Get(ii.ItemID)) + { + enhItem.MyContent.Text = srcItem.DisplayText; + enhItem.Save(); + } + } + } + return; + } + #endregion // EnhancedProcedureRefreshTextDifferences #region ProcedureConfig [NonSerialized] private ProcedureConfig _ProcedureConfig; diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index c8270800..5ab84189 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -852,6 +852,60 @@ namespace VEPROMS.CSLA.Library SaveConfig(sc.ToString()); return newEnhancedItemInfo; } + + // this method handles inserting new procedures & sections for enhanced documents. + // It also handles the case of inserting a step within an EMPTY section. In this case, the template steps + public ItemInfo InsertEnhancedItems(string text, string number, EAddpingPart addType, int? type, int eDocType, int newSourceID) + { + ItemInfo tmp = null; + if (this.IsProcedure && addType == EAddpingPart.Child) // Created a section off a procedure + { + string scng = null; + ProcedureConfig pc = new ProcedureConfig(""); + pc.AddEnhancedDocument(0, newSourceID); + scng = pc.ToString(); + tmp = InsertChild(E_FromType.Section, 10000, "New Section", null); + tmp.SaveConfig(scng); + } + else if (this.IsSection && addType == EAddpingPart.Child) // Created a HLS off a section, note that the template gets added for the HLS + { + string scng = null; + StepConfig sc = new StepConfig(""); + sc.AddEnhancedDocument(0, newSourceID); + scng = sc.ToString(); + tmp = InsertChild(E_FromType.Step, 20002, "New Step", null); + tmp.SaveConfig(scng); + } + else // the following code is used for inserting before/after. + { + string scng = null; + if (IsSection) + { + SectionConfig sc = new SectionConfig(); + sc.AddEnhancedDocument(0, newSourceID); + scng = sc.ToString(); + } + else + { + ProcedureConfig sc = new ProcedureConfig(""); + sc.AddEnhancedDocument(0, newSourceID); + scng = sc.ToString(); + } + tmp = NewItemInfoFetch(ItemID, addType, number, text, type, null, null, scng, DateTime.Now, Volian.Base.Library.VlnSettings.UserID); + } + if (tmp == null) return null; + // if next exists, it is updated in SQL so we have to manually force the iteminfo updates + // Refresh ItemInfo to update PreviousID field + if (tmp.NextItem != null) using (Item item = tmp.NextItem.Get()) ItemInfo.Refresh(item); + RefreshNextItems(); + if (addType == EAddpingPart.Child) + OnNewChild(new ItemInfoInsertEventArgs(tmp, EAddpingPart.Child)); + else if (addType == EAddpingPart.After) + OnNewSiblingAfter(new ItemInfoInsertEventArgs(tmp, EAddpingPart.After)); + else if (addType == EAddpingPart.Before) + OnNewSiblingBefore(new ItemInfoInsertEventArgs(tmp, EAddpingPart.Before)); + return tmp; + } public ItemInfo InsertEnhancedSteps(string text, string number, EAddpingPart addType, int? type, int eDocType, int newSourceID) { ItemInfo tmp = null; @@ -1452,11 +1506,11 @@ namespace VEPROMS.CSLA.Library } RefreshConfig(); } - public ItemInfo DoAddMissingEnhancedSteps(int enhtype) + public ItemInfo DoAddMissingEnhancedItems(int enhtype) { - // from this step, need to find an insertion point in the enhanced procedure/section. Look for a step that has enhanced - // links in its config: first go through previous steps, then if none found in previous go through next, if none found - // go to parent + // from this item, need to find an insertion point in the enhanced procedure/section. Look for an item that has enhanced + // links in its config: first go through previous items, then if none found in previous go through next, if none found + // go to parent ItemInfo newEnh = null; // look through pervious first: ItemInfo iiCur = this.MyPrevious; @@ -1468,14 +1522,17 @@ namespace VEPROMS.CSLA.Library if (edSource.Type == enhtype) // found one to use: { ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); - newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); + if (exEnh.IsStep) + newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); + else + newEnh = exEnh.InsertEnhancedItems(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); } } iiCur = iiCur.MyPrevious; } // no previous have enhanced links. now go through next: - ItemInfo iiNxt = this.GetNextItem(); + ItemInfo iiNxt = this.NextItem; addtype = EAddpingPart.Before; while (iiNxt != null && newEnh == null) { @@ -1484,35 +1541,162 @@ namespace VEPROMS.CSLA.Library if (edSource.Type == enhtype) // found one to use: { ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); - newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); + if (exEnh.IsStep) + newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); + else + newEnh = exEnh.InsertEnhancedItems(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); } } iiNxt = iiNxt.GetNextItem(); } // no next either, try the parent. - ItemInfo iiPar = this.MyParent; - addtype = EAddpingPart.Child; - while (iiPar != null && !iiPar.IsProcedure && newEnh == null) + if (this.IsProcedure && newEnh == null) // procedure is a special case since it has to be added from the doc version: { - foreach (EnhancedDocument edSource in iiPar.GetMyEnhancedDocuments()) + // need to make a new procedure off working draft of enhanced set: + DocVersionConfig dvc = this.MyDocVersion.MyConfig as DocVersionConfig; + ProcedureInfo pi = ProcedureInfo.Get(this.ItemID); + ProcedureConfig sourcecfg = pi.ProcedureConfig; + if (dvc != null) { - if (edSource.Type == enhtype) // found one to use: + foreach (DVEnhancedDocument ded in dvc.MyEnhancedDocuments) { - ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); - newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); + if (ded.Type == enhtype) + { + // get the enhaced docversioninfo: + DocVersionInfo enhDVInfo = DocVersionInfo.Get(ded.VersionID); + using (Procedure newenhProcedure = Procedure.MakeProcedure(enhDVInfo, enhDVInfo.Procedures.Count != 0 ? enhDVInfo.Procedures[enhDVInfo.Procedures.Count - 1] : null, null, "New Procedure", 0)) + { + newEnh = ItemInfo.Get(newenhProcedure.ItemID); + string scng = null; + ProcedureConfig sc = new ProcedureConfig(""); + sc.AddEnhancedDocument(0, pi.ItemID); + scng = sc.ToString(); + newEnh.SaveConfig(scng); + enhDVInfo.ResetProcedures(); + break; + } + } } } - iiPar = iiPar.MyParent; } + else + { + ItemInfo iiPar = this.MyParent; + addtype = EAddpingPart.Child; + while (iiPar != null && newEnh == null) + { + foreach (EnhancedDocument edSource in iiPar.GetMyEnhancedDocuments()) + { + if (edSource.Type == enhtype) // found one to use: + { + ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); + if (exEnh.IsStep) + newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); + else + newEnh = exEnh.InsertEnhancedItems(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); + break; + } + } + iiPar = iiPar.MyParent; + } + } + // Now set the config in the source to link to the newly created enhanced item: if (newEnh != null) { - StepConfig sc = new StepConfig(MyContent.Config); - sc.AddEnhancedDocument(enhtype, newEnh.ItemID); - SaveConfig(sc.ToString()); + if (IsStep) + { + StepConfig sc = new StepConfig(MyContent.Config); + sc.AddEnhancedDocument(enhtype, newEnh.ItemID); + SaveConfig(sc.ToString()); + } + else if (IsSection) + { + SectionConfig sc = new SectionConfig(SectionInfo.Get(this.ItemID)); + sc.AddEnhancedDocument(enhtype, newEnh.ItemID); + sc.Section_LnkEnh = "Y"; + SaveConfig(sc.ToString()); + } + else if (IsProcedure) + { + ProcedureConfig sc = new ProcedureConfig(MyContent.Config); + sc.AddEnhancedDocument(enhtype, newEnh.ItemID); + SaveConfig(sc.ToString()); + } } return newEnh; } + public void DoCreateLinksEnhancedSteps(ItemInfo enhii, int enhtype) + { + // Link the 2 items, srcII & enhii: + if (IsStep) + { + using (Item ii = this.Get()) + { + StepConfig sc = this.MyConfig as StepConfig; + sc.AddEnhancedDocument(enhtype, enhii.ItemID); + sc.SaveEnhancedDocuments(); + ii.MyContent.Config = sc.ToString(); + ii.Save(); + RefreshConfig(); + } + using (Item ei = Item.Get(enhii.ItemID)) + { + StepConfig sc = enhii.MyConfig as StepConfig; + sc.AddEnhancedDocument(0, this.ItemID); + sc.SaveEnhancedDocuments(); + ei.MyContent.Text = DisplayText; + ei.MyContent.Config = sc.ToString(); + ei.Save(); + enhii.RefreshConfig(); + } + } + else if (IsSection) + { + using (Item ii = this.Get()) + { + SectionConfig sc = this.MyConfig as SectionConfig; + sc.AddEnhancedDocument(enhtype, enhii.ItemID); + sc.SaveEnhancedDocuments(); + sc.Section_LnkEnh = "Y"; + ii.MyContent.Config = sc.ToString(); + ii.Save(); + RefreshConfig(); + } + using (Item ei = Item.Get(enhii.ItemID)) + { + SectionConfig sc = enhii.MyConfig as SectionConfig; + sc.AddEnhancedDocument(0, this.ItemID); + sc.SaveEnhancedDocuments(); + ei.MyContent.Text = DisplayText; + ei.MyContent.Config = sc.ToString(); + ei.Save(); + enhii.RefreshConfig(); + } + } + else if (IsProcedure) + { + using (Item ii = this.Get()) + { + ProcedureConfig sc = this.MyConfig as ProcedureConfig; + sc.AddEnhancedDocument(enhtype, enhii.ItemID); + sc.SaveEnhancedDocuments(); + ii.MyContent.Config = sc.ToString(); + ii.Save(); + RefreshConfig(); + } + using (Item ei = Item.Get(enhii.ItemID)) + { + ProcedureConfig sc = enhii.MyConfig as ProcedureConfig; + sc.AddEnhancedDocument(0, this.ItemID); + sc.SaveEnhancedDocuments(); + ei.MyContent.Text = DisplayText; + ei.MyContent.Config = sc.ToString(); + ei.Save(); + enhii.RefreshConfig(); + } + } + } #endregion #region DataPortal private void DataPortal_Fetch(PastingPartCriteria criteria)