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:
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();
//}
#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<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
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;