diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs
index 3acf07b3..fe5121c2 100644
--- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs
+++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs
@@ -310,6 +310,19 @@ namespace VEPROMS.CSLA.Library
// return ii._ItemID == _ItemID;
// return false;
//}
+ internal static void SetParentSectionAndDocVersion(ItemInfo itemInfo, IVEDrillDownReadOnly itemParent, SectionInfo sectionInfo, ProcedureInfo procInfo, DocVersionInfo docVersionInfo)
+ {
+ if (itemInfo == null) return;
+ itemInfo.LoadAllAtOnce = true;
+ itemInfo.ActiveParent = itemParent;
+ itemInfo.ActiveSection = sectionInfo;
+ itemInfo.MyProcedure = procInfo;
+ itemInfo.MyDocVersion = docVersionInfo;
+ if (itemInfo.MyContent.ContentPartCount > 0)
+ foreach (PartInfo pi in itemInfo.MyContent.ContentParts)
+ foreach (ItemInfo ii in pi.MyItems)
+ SetParentSectionAndDocVersion(ii, itemInfo, (itemInfo as SectionInfo) ?? sectionInfo, procInfo, docVersionInfo);
+ }
private int _PrintBias = 0;
public int PrintBias
{
@@ -730,7 +743,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
}
}
- private void AddPart(SafeDataReader dr, ItemInfo itemInfo)
+ internal void AddPart(SafeDataReader dr, ItemInfo itemInfo)
{
// Either a new PartInfo or an existing PartInfo
if (dr.IsDBNull(dr.GetOrdinal("PreviousID")))
@@ -971,7 +984,9 @@ namespace VEPROMS.CSLA.Library
// check config value on my section, if null/default use Pmode of active format
if (ActiveSection != null)
{
- SectionInfo si = SectionInfo.Get(ActiveSection.ItemID); //ActiveSection as SectionInfo;
+ SectionInfo si = ActiveSection as SectionInfo;
+ if(si == null)
+ si = SectionInfo.Get(ActiveSection.ItemID); //ActiveSection as SectionInfo;
if (si != null)
{
// there is no longer a "default" ENUM item - SectionConfig will return format default if needed
@@ -1185,8 +1200,8 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Ordinal CslaType and Tostring
- [NonSerialized]
- private int? _Ordinal;
+ //[NonSerialized]
+ internal int? _Ordinal;
public int Ordinal
{
get
@@ -1569,14 +1584,19 @@ namespace VEPROMS.CSLA.Library
}
}
}
+ internal ItemInfo _MyParent;
public ItemInfo MyParent
{
get
{
+ if (_MyParent == null)
+ {
//if (ItemDocVersionCount > 0) return ItemDocVersions[0]; Need to create one interface to support Folders, DocVersions and Items
ContentInfo parentContent = ParentContent;
if (parentContent == null || parentContent.ContentItemCount == 0) return null;
- return parentContent.ContentItems[0];
+ _MyParent = parentContent.ContentItems[0];
+ }
+ return _MyParent;
}
}
#endregion
@@ -1587,6 +1607,12 @@ namespace VEPROMS.CSLA.Library
itemInfoList = Lookup(fromType);
return itemInfoList;
}
+ private bool _LoadAllAtOnce;
+ public bool LoadAllAtOnce
+ {
+ get { return _LoadAllAtOnce; }
+ set { _LoadAllAtOnce = value; }
+ }
internal ItemInfoList Lookup(int fromType)
{
ItemInfoList itemInfoList = null;
@@ -1594,6 +1620,9 @@ namespace VEPROMS.CSLA.Library
foreach (PartInfo partInfo in MyContent.ContentParts)
if (partInfo.FromType == fromType)
{
+ if(LoadAllAtOnce)
+ itemInfoList = partInfo._MyItems;// = ItemInfoList.GetList(partInfo.ItemID, partInfo.FromType);
+ else
itemInfoList = partInfo._MyItems = ItemInfoList.GetList(partInfo.ItemID, partInfo.FromType);
return itemInfoList;
}
@@ -1798,17 +1827,27 @@ namespace VEPROMS.CSLA.Library
return true;
}
}
+ private ProcedureInfo _MyProcedure;
public ProcedureInfo MyProcedure
{
get
{
- // Walk up active parents until the parent is not an item
- ItemInfo tmp = this;
- while (tmp.ActiveParent != null && !tmp.ActiveParent.IsDocVersion)
- tmp = (ItemInfo)tmp.ActiveParent;
- if (tmp is ProcedureInfo)
- return tmp as ProcedureInfo;
- return ProcedureInfo.Get(tmp.ItemID);
+ if (_MyProcedure == null)
+ {
+ // Walk up active parents until the parent is not an item
+ ItemInfo tmp = this;
+ while (tmp.ActiveParent != null && !tmp.ActiveParent.IsDocVersion)
+ tmp = (ItemInfo)tmp.ActiveParent;
+ if (tmp is ProcedureInfo)
+ _MyProcedure = tmp as ProcedureInfo;
+ else
+ _MyProcedure = ProcedureInfo.Get(tmp.ItemID);
+ }
+ return _MyProcedure;
+ }
+ set
+ {
+ _MyProcedure = value;
}
}
private ItemInfo _MyHLS = null;
@@ -1847,8 +1886,9 @@ namespace VEPROMS.CSLA.Library
}
return _MyDocVersion;
}
+ set { _MyDocVersion = value; }
}
- private IVEDrillDownReadOnly _ActiveParent = null;
+ internal IVEDrillDownReadOnly _ActiveParent = null;
public IVEDrillDownReadOnly MyActiveParent { get { return _ActiveParent; } }
public IVEDrillDownReadOnly ActiveParent
{
@@ -1895,7 +1935,7 @@ namespace VEPROMS.CSLA.Library
_ActiveParent = value;
}
}
- private ItemInfo _ActiveSection = null;
+ internal ItemInfo _ActiveSection = null;
///
/// MyActiveSection is used to determine if _ActiveSection is null or not.
///
@@ -3666,7 +3706,7 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Item");
try
{
- ProcedureInfo tmp = GetCachedByPrimaryKey(itemID) as ProcedureInfo;
+ ProcedureInfo tmp = GetCachedByPrimaryKey(itemID);
if (tmp == null)
{
tmp = DataPortal.Fetch(new PKCriteria(itemID));
@@ -3680,6 +3720,16 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on Item.Get", ex);
}
}
+ protected new static ProcedureInfo GetCachedByPrimaryKey(int itemID)
+ {
+ ConvertListToDictionary();
+ string key = itemID.ToString();
+ if (_CacheByPrimaryKey.ContainsKey(key))
+ foreach (ItemInfo ii in _CacheByPrimaryKey[key])
+ if (ii is ProcedureInfo)
+ return ii as ProcedureInfo;
+ return null;
+ }
public void MoveProcedure(IVEDrillDownReadOnly pInfo, int index)
{
using (Item ii = Item.Get(this.ItemID))
@@ -3706,6 +3756,99 @@ namespace VEPROMS.CSLA.Library
{
get { return ActiveParent as DocVersionInfo; }
}
+ public static ProcedureInfo GetItemAndChildren(int? itemID)
+ {
+ try
+ {
+ ProcedureInfo tmp = DataPortal.Fetch(new ItemAndChildrenCriteria(itemID));
+ //AddToCache(tmp);
+ if (tmp.ErrorMessage == "No Record Found") tmp = null;
+ if (tmp != null)
+ SetParentSectionAndDocVersion(tmp, tmp.MyDocVersion, null, tmp, tmp.MyDocVersion);
+ return tmp;
+ }
+ catch (Exception ex)
+ {
+ throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
+ }
+ }
+ [Serializable()]
+ private class ItemAndChildrenCriteria
+ {
+ public ItemAndChildrenCriteria(int? itemID)
+ {
+ _ItemID = itemID;
+ }
+ private int? _ItemID;
+ public int? ItemID
+ {
+ get { return _ItemID; }
+ set { _ItemID = value; }
+ }
+ }
+ // Data Portal to Get Item and Children
+ private void DataPortal_Fetch(ItemAndChildrenCriteria criteria)
+ {
+ //ItemInfo tmp = null;
+ Dictionary lookup = new Dictionary(); ;
+ try
+ {
+ using (SqlConnection cn = Database.VEPROMS_SqlConnection)
+ {
+ using (SqlCommand cm = cn.CreateCommand())
+ {
+ cm.CommandType = CommandType.StoredProcedure;
+ cm.CommandText = "vesp_ListItemAndChildren";
+ cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
+ cm.Parameters.AddWithValue("@ParentID", 0);
+ cm.CommandTimeout = Database.DefaultTimeout;
+ using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
+ {
+ while (dr.Read())
+ {
+ if (dr.GetInt32("Level") == 0)
+ {
+ //tmp = itemInfo;
+ ReadData(dr);
+ AddContent(dr);
+ lookup[this.ItemID] = this;
+ }
+ else
+ {
+ ItemInfo itemInfo = null;
+ int itemType = dr.GetInt32("Type") / 10000;
+ switch (itemType)
+ {
+ case 0:
+ itemInfo = new ProcedureInfo(dr);
+ break;
+ case 1:
+ itemInfo = new SectionInfo(dr);
+ break;
+ case 2:
+ itemInfo = new StepInfo(dr);
+ break;
+ }
+ // Load Children
+ itemInfo.AddContent(dr);
+ ItemInfo parent = lookup[dr.GetInt32("ParentID")];
+ itemInfo._ActiveParent = parent;
+ itemInfo._ActiveSection = (itemInfo.IsSection ? itemInfo : parent._ActiveSection);
+ parent.AddPart(dr, itemInfo);
+ lookup.Add(itemInfo.ItemID, itemInfo);
+ }
+ }
+ //Console.WriteLine("I'm here {0}",this.MyContent.ContentPartCount);
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
+ throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
+ }
+ }
}
#endregion
#region Procedure
@@ -3854,7 +3997,7 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Item");
try
{
- SectionInfo tmp = GetCachedByPrimaryKey(itemID) as SectionInfo;
+ SectionInfo tmp = GetCachedByPrimaryKey(itemID);
if (tmp == null)
{
tmp = DataPortal.Fetch(new PKCriteria(itemID));
@@ -3868,6 +4011,16 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on Item.Get", ex);
}
}
+ protected new static SectionInfo GetCachedByPrimaryKey(int itemID)
+ {
+ ConvertListToDictionary();
+ string key = itemID.ToString();
+ if (_CacheByPrimaryKey.ContainsKey(key))
+ foreach (ItemInfo ii in _CacheByPrimaryKey[key])
+ if (ii is SectionInfo)
+ return ii as SectionInfo;
+ return null;
+ }
public void MoveSection(IVEDrillDownReadOnly pInfo, int index)
{
using (Item ii = Item.Get(this.ItemID))
@@ -3986,7 +4139,7 @@ namespace VEPROMS.CSLA.Library
// throw new System.Security.SecurityException("User not authorized to view a Item");
try
{
- StepInfo tmp = GetCachedByPrimaryKey(itemID) as StepInfo;
+ StepInfo tmp = GetCachedByPrimaryKey(itemID);
if (tmp == null)
{
tmp = DataPortal.Fetch(new PKCriteria(itemID));
@@ -4000,6 +4153,16 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on Item.Get", ex);
}
}
+ protected new static StepInfo GetCachedByPrimaryKey(int itemID)
+ {
+ ConvertListToDictionary();
+ string key = itemID.ToString();
+ if (_CacheByPrimaryKey.ContainsKey(key))
+ foreach (ItemInfo ii in _CacheByPrimaryKey[key])
+ if (ii is StepInfo)
+ return ii as StepInfo;
+ return null;
+ }
public void MoveStep(IVEDrillDownReadOnly pInfo, int index)
{
using (Item ii = Item.Get(this.ItemID))