diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index 64aa293b..b34a2ddd 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -9,6 +9,27 @@ using Csla.Data; namespace VEPROMS.CSLA.Library { + public delegate void ItemInfoInsertEvent(object sender, ItemInfoInsertEventArgs args); + public class ItemInfoInsertEventArgs + { + private ItemInfo _ItemInserted; + public ItemInfo ItemInserted + { + get { return _ItemInserted; } + set { _ItemInserted = value; } + } + private ItemInfo.EAddpingPart _AddingPart; + public ItemInfo.EAddpingPart AddingPart + { + get { return _AddingPart; } + set { _AddingPart = value; } + } + public ItemInfoInsertEventArgs(ItemInfo itemInserted,ItemInfo.EAddpingPart addingPart) + { + _ItemInserted = itemInserted; + _AddingPart = addingPart; + } + } public partial class ItemInfo { #region Old Insert @@ -163,6 +184,57 @@ namespace VEPROMS.CSLA.Library { if (Deleted != null) Deleted(sender); } + public event ItemInfoInsertEvent NewSiblingAfter; + internal void OnNewSiblingAfter(object sender, ItemInfoInsertEventArgs args) + { + if (NewSiblingAfter != null) NewSiblingAfter(sender,args); + } + internal void OnNewSiblingAfter(ItemInfoInsertEventArgs args) + { + string key = ItemID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) + { + ItemInfo[] items = _CacheByPrimaryKey[key].ToArray(); + foreach (ItemInfo item in items) + { + item.OnNewSiblingAfter(item,args); + } + } + } + public event ItemInfoInsertEvent NewSiblingBefore; + internal void OnNewSiblingBefore(object sender, ItemInfoInsertEventArgs args) + { + if (NewSiblingBefore != null) NewSiblingBefore(sender,args); + } + internal void OnNewSiblingBefore(ItemInfoInsertEventArgs args) + { + string key = ItemID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) + { + ItemInfo[] items = _CacheByPrimaryKey[key].ToArray(); + foreach (ItemInfo item in items) + { + item.OnNewSiblingBefore(item,args); + } + } + } + public event ItemInfoInsertEvent NewChild; + internal void OnNewChild(object sender, ItemInfoInsertEventArgs args) + { + if (NewChild != null) NewChild(sender, args); + } + internal void OnNewChild(ItemInfoInsertEventArgs args) + { + string key = ItemID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) + { + ItemInfo[] items = _CacheByPrimaryKey[key].ToArray(); + foreach (ItemInfo item in items) + { + item.OnNewChild(item, args); + } + } + } #endregion #region Insert Before public ItemInfo InsertSiblingBefore(string text) @@ -177,6 +249,8 @@ namespace VEPROMS.CSLA.Library using (Item item = Get()) ItemInfo.Refresh(item); // Update all of the content records that have transitions that point to the Siblings or Sibling Children of the new item tmp.UpdateTransitionText(); + OnNewSiblingBefore(new ItemInfoInsertEventArgs(tmp, EAddpingPart.Before)); + ((ItemInfo)ActiveParent).MyContent.RefreshContentParts(); return tmp; } #endregion @@ -199,6 +273,7 @@ namespace VEPROMS.CSLA.Library RefreshNextItems(); // Update all of the content records that have transitions that point to the Siblings or Sibling Children of the new item tmp.UpdateTransitionText(); + OnNewSiblingAfter(new ItemInfoInsertEventArgs(tmp, EAddpingPart.After)); return tmp; } private ItemInfo NewItemInfoFetch(int itemID, EAddpingPart addType, string number, string text, int? type, int? fromType, int? formatID, string config, DateTime dts, string userID) @@ -263,6 +338,8 @@ namespace VEPROMS.CSLA.Library if (tmp.NextItem != null) using (Item item = tmp.NextItem.Get()) ItemInfo.Refresh(item); // Update all of the content records that have transitions that point to the Siblings or Sibling Children of the new item tmp.UpdateTransitionText(); + MyContent.RefreshContentParts(); + OnNewChild(new ItemInfoInsertEventArgs(tmp, EAddpingPart.Child)); return tmp; } #endregion @@ -422,7 +499,7 @@ namespace VEPROMS.CSLA.Library return null; } } - private static void ResetOrdinal(int itemID) + private static void ResetOrdinal(int itemID) { ConvertListToDictionary(); string key = itemID.ToString(); @@ -432,7 +509,7 @@ namespace VEPROMS.CSLA.Library key = null; foreach (ItemInfo item in items) { - //Console.WriteLine("item = {0}, ordinal = {1}",item,item.Ordinal); + //Console.WriteLine("ResetOrdinal item = {0}, ordinal = {1}", item, item.Ordinal); item._Ordinal = null; item._TagsSetup = false; item.MyContent.ShowChange(); @@ -555,8 +632,11 @@ namespace VEPROMS.CSLA.Library if (nextItem != null) // Adjust PreviousID for NextItem { ItemInfo.RefreshPrevious(nextItem.ItemID, item.PreviousID); - nextItem.ResetOrdinal(); + // The order of the next two methods was required to fix a null reference + // when getting myparent. This bug was found when deleting a node from the + // tree when the stepitem was not open (i.e. in the step editor window). nextItem.RefreshItemParts(); + nextItem.ResetOrdinal(); nextItem.UpdateTransitionText(); } else if (prevItem != null) @@ -565,6 +645,7 @@ namespace VEPROMS.CSLA.Library } catch (Exception ex) { + Console.WriteLine("ItemInsertExt: Stacktrace = {0}", ex.StackTrace); System.Data.SqlClient.SqlException exSQL = SqlException(ex); if (exSQL != null && exSQL.Message.Contains("###Cannot Delete Item###")) //return false;