This commit is contained in:
2009-11-13 13:30:19 +00:00
parent 57fc6fa1a7
commit 236f2b9fe9
3 changed files with 106 additions and 8 deletions

View File

@@ -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<ItemInfo> 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<ItemInfo> items = new List<ItemInfo>();
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
{