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
This commit is contained in:
Kathy Ruffing 2016-05-09 11:29:00 +00:00
parent 37ffe8dd7b
commit 289db67a2b
2 changed files with 424 additions and 18 deletions

View File

@ -2217,6 +2217,31 @@ namespace VEPROMS.CSLA.Library
// return ToString(); // return ToString();
//} //}
#endregion #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 #region Search
internal string _SearchDVPath; internal string _SearchDVPath;
public string SearchDVPath public string SearchDVPath
@ -5125,6 +5150,138 @@ namespace VEPROMS.CSLA.Library
this.Add(itemInfo); this.Add(itemInfo);
IsReadOnly = true; IsReadOnly = true;
} }
#region EnhancedSupport
#region EnhancedGetTextDifferences
public static ItemInfoList GetListEnhancedTextDifferences(ItemInfo procItem)
{
try
{
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(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<ItemInfoList>(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 #region Text Search
public static ItemInfoList GetListFromTextSearch(string docVersionList, string stepTypeList, string searchString, int caseSensitive, ItemSearchIncludeLinks includeLinks, bool includeRtfFormatting, bool includeSpecialCharacters, string unitPrefix) 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); throw new DbCslaException("Error on ProcedureInfo:ClearChangeBarOverrides", ex);
} }
} }
//jcb add 20120501 item and children by unit //jcb add 20120501 item and children by unit
public static ProcedureInfo GetItemAndChildrenByUnit(int? itemID, int? parentID, int? unitID) public static ProcedureInfo GetItemAndChildrenByUnit(int? itemID, int? parentID, int? unitID)
{ {
@ -6061,7 +6219,71 @@ namespace VEPROMS.CSLA.Library
MyLookup = lookup; MyLookup = lookup;
} }
//jcb end add 20120501 item and children by unit //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 #region ProcedureConfig
[NonSerialized] [NonSerialized]
private ProcedureConfig _ProcedureConfig; private ProcedureConfig _ProcedureConfig;

View File

@ -852,6 +852,60 @@ namespace VEPROMS.CSLA.Library
SaveConfig(sc.ToString()); SaveConfig(sc.ToString());
return newEnhancedItemInfo; 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("<Config/>");
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("<Config/>");
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("<Config/>");
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) public ItemInfo InsertEnhancedSteps(string text, string number, EAddpingPart addType, int? type, int eDocType, int newSourceID)
{ {
ItemInfo tmp = null; ItemInfo tmp = null;
@ -1452,10 +1506,10 @@ namespace VEPROMS.CSLA.Library
} }
RefreshConfig(); 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 // 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 steps, then if none found in previous go through next, if none found // links in its config: first go through previous items, then if none found in previous go through next, if none found
// go to parent // go to parent
ItemInfo newEnh = null; ItemInfo newEnh = null;
// look through pervious first: // look through pervious first:
@ -1468,14 +1522,17 @@ namespace VEPROMS.CSLA.Library
if (edSource.Type == enhtype) // found one to use: if (edSource.Type == enhtype) // found one to use:
{ {
ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); ItemInfo exEnh = ItemInfo.Get(edSource.ItemID);
if (exEnh.IsStep)
newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); 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; iiCur = iiCur.MyPrevious;
} }
// no previous have enhanced links. now go through next: // no previous have enhanced links. now go through next:
ItemInfo iiNxt = this.GetNextItem(); ItemInfo iiNxt = this.NextItem;
addtype = EAddpingPart.Before; addtype = EAddpingPart.Before;
while (iiNxt != null && newEnh == null) while (iiNxt != null && newEnh == null)
{ {
@ -1484,35 +1541,162 @@ namespace VEPROMS.CSLA.Library
if (edSource.Type == enhtype) // found one to use: if (edSource.Type == enhtype) // found one to use:
{ {
ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); ItemInfo exEnh = ItemInfo.Get(edSource.ItemID);
if (exEnh.IsStep)
newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); 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(); iiNxt = iiNxt.GetNextItem();
} }
// no next either, try the parent. // no next either, try the parent.
if (this.IsProcedure && newEnh == null) // procedure is a special case since it has to be added from the doc version:
{
// 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)
{
foreach (DVEnhancedDocument ded in dvc.MyEnhancedDocuments)
{
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("<Config/>");
sc.AddEnhancedDocument(0, pi.ItemID);
scng = sc.ToString();
newEnh.SaveConfig(scng);
enhDVInfo.ResetProcedures();
break;
}
}
}
}
}
else
{
ItemInfo iiPar = this.MyParent; ItemInfo iiPar = this.MyParent;
addtype = EAddpingPart.Child; addtype = EAddpingPart.Child;
while (iiPar != null && !iiPar.IsProcedure && newEnh == null) while (iiPar != null && newEnh == null)
{ {
foreach (EnhancedDocument edSource in iiPar.GetMyEnhancedDocuments()) foreach (EnhancedDocument edSource in iiPar.GetMyEnhancedDocuments())
{ {
if (edSource.Type == enhtype) // found one to use: if (edSource.Type == enhtype) // found one to use:
{ {
ItemInfo exEnh = ItemInfo.Get(edSource.ItemID); ItemInfo exEnh = ItemInfo.Get(edSource.ItemID);
if (exEnh.IsStep)
newEnh = exEnh.InsertEnhancedSteps(MyContent.Text, null, addtype, MyContent.Type, edSource.Type, this.ItemID); 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; iiPar = iiPar.MyParent;
} }
}
// Now set the config in the source to link to the newly created enhanced item:
if (newEnh != null) if (newEnh != null)
{
if (IsStep)
{ {
StepConfig sc = new StepConfig(MyContent.Config); StepConfig sc = new StepConfig(MyContent.Config);
sc.AddEnhancedDocument(enhtype, newEnh.ItemID); sc.AddEnhancedDocument(enhtype, newEnh.ItemID);
SaveConfig(sc.ToString()); 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; 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 #endregion
#region DataPortal #region DataPortal
private void DataPortal_Fetch(PastingPartCriteria criteria) private void DataPortal_Fetch(PastingPartCriteria criteria)