From 236f2b9fe9d31e73a94c3a25c99c873afdbec322 Mon Sep 17 00:00:00 2001 From: Kathy Date: Fri, 13 Nov 2009 13:30:19 +0000 Subject: [PATCH] --- .../Extension/ContentExt.cs | 8 ++ .../VEPROMS.CSLA.Library/Extension/ItemExt.cs | 5 +- .../Extension/ItemInsertExt.cs | 101 ++++++++++++++++-- 3 files changed, 106 insertions(+), 8 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs index c9eddf34..f618683f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -42,6 +42,10 @@ namespace VEPROMS.CSLA.Library } public partial class ContentInfo { + public PartInfoList LocalContentParts + { + get { return _ContentParts; } + } public void AddPart(SafeDataReader dr, ItemInfo itemInfo) { if (_ContentParts == null) @@ -53,6 +57,10 @@ namespace VEPROMS.CSLA.Library { return string.Format("{0} {1}", Number, Text); } + public void ShowChange() + { + OnChange(); + } //public XmlNode ToXml(XmlNode xn) //{ // XmlNode nd = xn.OwnerDocument.CreateElement("Content"); diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index 3cd970ff..f806a4cf 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -889,7 +889,8 @@ namespace VEPROMS.CSLA.Library ContentInfo cont = MyContent; //string number = cont.Number; string number = DisplayNumber; - if (cont.Type >= 20000) number = Ordinal.ToString() + "."; + //if (cont.Type >= 20000) number = Ordinal.ToString() + "."; + if (cont.Type >= 20000) number = MyTab.CleanText; return string.Format("{0} {1}", number, DisplayText).Trim(); //return string.Format("{0} {1}", number, cont.Text).Trim(); //return string.Format("{0} {1}", cont.Number, cont.Text); @@ -1503,7 +1504,7 @@ namespace VEPROMS.CSLA.Library protected bool _TagsSetup = false; public virtual void SetupTags() { - _MyTab = new Tab(_ActiveFormat.PlantFormat.FormatData.Font); + _MyTab = new Tab(ActiveFormat.PlantFormat.FormatData.Font); _MyHeader = null; _MyFooter = null; _MyTab.CleanText = DisplayNumber; diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs index 980c12fc..64aa293b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemInsertExt.cs @@ -118,6 +118,52 @@ namespace VEPROMS.CSLA.Library // return newItemInfo; //} #endregion + #region Events + public event ItemInfoEvent BeforeDelete; + public void OnBeforeDelete() + { + OnBeforeDelete(ItemID); + + if (MyContent.ContentPartCount > 0) + { + foreach (PartInfo pi in MyContent.ContentParts) + { + foreach (ItemInfo ii in pi.MyItems) + { + ii.OnBeforeDelete(); + } + } + } + //if (ItemPartCount > 0) + //{ + // foreach (PartInfo pi in ItemParts) + // { + // foreach (ItemInfo ii in pi.MyItems) + // { + // ii.OnBeforeDelete(); + // } + // } + //} + } + + private void OnBeforeDelete(int ItemID) + { + if (_CacheByPrimaryKey.ContainsKey(ItemID.ToString())) + { + List itmlst = _CacheByPrimaryKey[ItemID.ToString()]; + foreach (ItemInfo itm in itmlst) + if (itm.BeforeDelete != null) + { + itm.BeforeDelete(itm); + } + } + } + public event ItemInfoEvent Deleted; + internal void OnDeleted(object sender) + { + if (Deleted != null) Deleted(sender); + } + #endregion #region Insert Before public ItemInfo InsertSiblingBefore(string text) { @@ -389,6 +435,7 @@ namespace VEPROMS.CSLA.Library //Console.WriteLine("item = {0}, ordinal = {1}",item,item.Ordinal); item._Ordinal = null; item._TagsSetup = false; + item.MyContent.ShowChange(); if (key == null && item.NextItem != null) key = item.NextItem.ItemID.ToString(); } @@ -409,22 +456,63 @@ namespace VEPROMS.CSLA.Library ItemInfo parent = items[0].ActiveParent as ItemInfo; if (parent != null) ItemInfo.ResetParts(parent.ItemID); + //Console.WriteLine("\r\n\r\n'Deleting Item {0}'\r\n{0}'Type ','ParentID','ParentUnique','ItemID','Unique'",itemID); foreach (ItemInfo item in items) - item.DeleteItemInfoAndChildren(); + { + item.OnDeleted(item); + item.DeleteItemInfoAndChildren(" "); + } + //Console.WriteLine("\r\n'Item Deleted'"); + } } - private void DeleteItemInfoAndChildren() + private void DeleteItemInfoAndChildren(string depth) { - if (_ItemParts != null) + if (MyContent.LocalContentParts != null) { - foreach (PartInfo part in _ItemParts) + foreach (PartInfo part in MyContent.LocalContentParts) { if (part._MyItems != null) { - foreach (ItemInfo item in part._MyItems) + int whereami = 1; + try { - item.DeleteItemInfoAndChildren(); + List items = new List(); + foreach (ItemInfo item in part._MyItems) + { + items.Add(item); + } + foreach (ItemInfo item in items) + { + string key = item.ItemID.ToString(); + if (_CacheByPrimaryKey.ContainsKey(key)) + { + ItemInfo[] itemz = _CacheByPrimaryKey[key].ToArray(); + foreach (ItemInfo itm in itemz) + { + //Console.WriteLine("'{0}cache ',{1},{2},{3},{4}", depth + depth, this.ItemID, this._MyItemInfoUnique, itm.ItemID, itm._MyItemInfoUnique); + //whereami = 2; + itm.OnDeleted(itm); + //whereami = 4; + itm.DeleteItemInfoAndChildren(depth + " "); + //whereami = 3; + } + } + else + { + //Console.WriteLine("'{0}noncache',{1},{2},{3},{4}", depth + depth, this.ItemID, this._MyItemInfoUnique, item.ItemID, item._MyItemInfoUnique); + //whereami = 5; + item.OnDeleted(item); + //whereami = 7; + item.DeleteItemInfoAndChildren(depth + " "); + //whereami = 6; + } + } + } + catch (Exception ex) + { + Console.WriteLine("where = {0}, type = {1}, msg = {2}", whereami, ex.GetType().Name, ex.Message); } } } @@ -462,6 +550,7 @@ namespace VEPROMS.CSLA.Library { ItemInfo nextItem = item.NextItem; ItemInfo prevItem = item.MyPrevious; + item.OnBeforeDelete(); DataPortal.Delete(new DeleteCriteria(item.ItemID,Environment.UserName)); if (nextItem != null) // Adjust PreviousID for NextItem {