Inserting New Items, FixTransition Text
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text.RegularExpressions;
|
||||
using Csla;
|
||||
using Csla.Data;
|
||||
|
||||
@@ -125,6 +126,11 @@ namespace VEPROMS.CSLA.Library
|
||||
public ItemInfo InsertSiblingBefore(string text, string number)
|
||||
{
|
||||
ItemInfo tmp = DataPortal.Fetch<ItemInfo>(new AddingPartCriteria(ItemID, EAddpingPart.Before, number, text, null, null, null, null, DateTime.Now, Environment.UserName));
|
||||
// this item is updated in SQL so we have to manually force the iteminfo updates
|
||||
// Refresh ItemInfo to update Previous
|
||||
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();
|
||||
return tmp;
|
||||
}
|
||||
#endregion
|
||||
@@ -140,8 +146,31 @@ namespace VEPROMS.CSLA.Library
|
||||
public ItemInfo InsertSiblingAfter(string text, string number, int? type)
|
||||
{
|
||||
ItemInfo tmp = DataPortal.Fetch<ItemInfo>(new AddingPartCriteria(ItemID, EAddpingPart.After, number, text, type, null, null, null, DateTime.Now, Environment.UserName));
|
||||
// if next exists, it is updated in SQL so we have to manually force the iteminfo updates
|
||||
// Refresh ItemInfo to update PreviousID field
|
||||
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();
|
||||
return tmp;
|
||||
}
|
||||
public void UpdateTransitionText()
|
||||
{
|
||||
// Update Ordinals from here down
|
||||
ResetOrdinal();
|
||||
// This returns a list of all of the transitions that may have been affected
|
||||
using(TransitionInfoList trans = TransitionInfoList.GetAffected(this.ItemID))
|
||||
{
|
||||
foreach (TransitionInfo tran in trans)
|
||||
{
|
||||
using (Content content = tran.MyContent.Get())
|
||||
{
|
||||
content.FixTransitionText(tran);
|
||||
if (content.IsDirty)
|
||||
content.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Insert Child
|
||||
public ItemInfo InsertChild(E_FromType fromType, int type, string text)
|
||||
@@ -151,6 +180,11 @@ namespace VEPROMS.CSLA.Library
|
||||
public ItemInfo InsertChild(E_FromType fromType, int type, string text, string number)
|
||||
{
|
||||
ItemInfo tmp = DataPortal.Fetch<ItemInfo>(new AddingPartCriteria(ItemID, EAddpingPart.Child, number, text, type, (int?) fromType, null, null, DateTime.Now, Environment.UserName));
|
||||
// if next exists, it is updated in SQL so we have to manually force the iteminfo updates
|
||||
// Refresh ItemInfo to update PreviousID field
|
||||
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();
|
||||
return tmp;
|
||||
}
|
||||
#endregion
|
||||
@@ -312,27 +346,23 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
private static void ResetOrdinal(int itemID)
|
||||
{
|
||||
bool first = true;
|
||||
ConvertListToDictionary();
|
||||
string key = itemID.ToString();
|
||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
||||
while (key != null && _CacheByPrimaryKey.ContainsKey(key))
|
||||
{
|
||||
foreach (ItemInfo itm in _CacheByPrimaryKey[key])
|
||||
ItemInfo[] items = _CacheByPrimaryKey[key].ToArray();
|
||||
key = null;
|
||||
foreach (ItemInfo item in items)
|
||||
{
|
||||
itm._Ordinal = null;
|
||||
//Console.WriteLine("Ordinal {0},{1}",key,itm.MyPrevious == null ? 0 : itm.MyPrevious._Ordinal);
|
||||
if (first && itm.NextItem != null)
|
||||
{
|
||||
ResetOrdinal(itm.NextItem.ItemID);
|
||||
first = false;
|
||||
}
|
||||
//Console.WriteLine("item = {0}, ordinal = {1}",item,item.Ordinal);
|
||||
item._Ordinal = null;
|
||||
if (key == null && item.NextItem != null)
|
||||
key = item.NextItem.ItemID.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ResetOrdinal()
|
||||
{
|
||||
//_Ordinal = null;
|
||||
//Console.WriteLine("Ordinal {0},{1}",ItemID,MyPrevious == null ? 0 : MyPrevious.Ordinal);
|
||||
ResetOrdinal(ItemID);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user