This commit is contained in:
@@ -268,6 +268,70 @@ namespace VEPROMS.CSLA.Library
|
||||
return tmp;
|
||||
}
|
||||
#endregion
|
||||
#region PasteSiblingBefore
|
||||
public ItemInfo PasteSiblingBefore(int copyStartID)
|
||||
{
|
||||
// To determine 'type' of pasted item, if it's a step (type >=20000), use the originating
|
||||
// item, i.e. item inserting after. If it's a section or procedure, use the copied item's type.
|
||||
ItemInfo cpItem = ItemInfo.Get(copyStartID);
|
||||
int? type = MyContent.Type >= 20000 ? MyContent.Type : cpItem.MyContent.Type;
|
||||
ItemInfo tmp = CopyPasteItemInfoFetch(copyStartID, this.ItemID, type, type, EAddpingPart.Before);
|
||||
using (Item item = Get()) ItemInfo.Refresh(item);
|
||||
tmp.UpdateTransitionText();
|
||||
tmp.UpdatePastedStepTransitionText();
|
||||
OnNewSiblingBefore(new ItemInfoInsertEventArgs(tmp, EAddpingPart.Before));
|
||||
return tmp;
|
||||
}
|
||||
public ItemInfo PasteSiblingAfter(int copyStartID)
|
||||
{
|
||||
// To determine 'type' of pasted item, if it's a step (type >=20000), use the originating
|
||||
// item, i.e. item inserting after. If it's a section or procedure, use the copied item's type.
|
||||
ItemInfo cpItem = ItemInfo.Get(copyStartID);
|
||||
int? type = MyContent.Type >= 20000 ? MyContent.Type : cpItem.MyContent.Type;
|
||||
ItemInfo tmp = CopyPasteItemInfoFetch(copyStartID, this.ItemID, type, type, EAddpingPart.After);
|
||||
using (Item item = Get()) ItemInfo.Refresh(item);
|
||||
if (tmp.NextItem != null) using (Item item = tmp.NextItem.Get()) ItemInfo.Refresh(item);
|
||||
RefreshNextItems();
|
||||
// if inserting after a caution or note, refreshes tabs. This will adjust bullets
|
||||
// of any previous cautions or notes.
|
||||
if (tmp.IsCaution || tmp.IsNote) ResetOrdinal();
|
||||
tmp.UpdateTransitionText();
|
||||
tmp.UpdatePastedStepTransitionText();
|
||||
OnNewSiblingAfter(new ItemInfoInsertEventArgs(tmp, EAddpingPart.After));
|
||||
return tmp;
|
||||
}
|
||||
private ItemInfo CopyPasteItemInfoFetch(int copyStartID, int itemID, int? type, int? fromType, EAddpingPart addType)
|
||||
{
|
||||
ItemInfo tmp=null;
|
||||
if (addType == EAddpingPart.Child) // has to add in child relationship - uses 'fromtype'
|
||||
{
|
||||
// adding children. Type is based on 'fromType'
|
||||
switch ((E_FromType)fromType)
|
||||
{
|
||||
case E_FromType.Procedure:
|
||||
tmp = DataPortal.Fetch<ProcedureInfo>(new PastingPartCriteria(copyStartID, itemID, addType, type, fromType, DateTime.Now, Environment.UserName));
|
||||
break;
|
||||
case E_FromType.Section:
|
||||
tmp = DataPortal.Fetch<SectionInfo>(new PastingPartCriteria(copyStartID, itemID, addType, type, fromType, DateTime.Now, Environment.UserName));
|
||||
break;
|
||||
default:
|
||||
tmp = DataPortal.Fetch<StepInfo>(new PastingPartCriteria(copyStartID, itemID, addType, type, fromType, DateTime.Now, Environment.UserName));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetType() == typeof(ProcedureInfo))
|
||||
tmp = DataPortal.Fetch<ProcedureInfo>(new PastingPartCriteria(copyStartID, itemID, addType, type, fromType, DateTime.Now, Environment.UserName));
|
||||
else if (GetType() == typeof(SectionInfo))
|
||||
tmp = DataPortal.Fetch<SectionInfo>(new PastingPartCriteria(copyStartID, itemID, addType, type, fromType, DateTime.Now, Environment.UserName));
|
||||
else
|
||||
tmp = DataPortal.Fetch<StepInfo>(new PastingPartCriteria(copyStartID, itemID, addType, type, fromType, DateTime.Now, Environment.UserName));
|
||||
}
|
||||
return tmp;
|
||||
|
||||
}
|
||||
#endregion
|
||||
#region Insert After
|
||||
public ItemInfo InsertSiblingAfter(string text)
|
||||
{
|
||||
@@ -293,6 +357,7 @@ namespace VEPROMS.CSLA.Library
|
||||
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)
|
||||
{
|
||||
ItemInfo tmp;
|
||||
@@ -344,6 +409,25 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
public void UpdatePastedStepTransitionText()
|
||||
{
|
||||
// Get a list of all of the transitions included in this step & its children.
|
||||
// Their transition text may have been affected, i.e. depending on the format, etc
|
||||
using (TransitionInfoList trans = TransitionInfoList.GetPastedAffected(this.ItemID))
|
||||
{
|
||||
foreach (TransitionInfo tran in trans)
|
||||
{
|
||||
using (Content content = tran.MyContent.Get())
|
||||
{
|
||||
content.FixTransitionText(tran);
|
||||
if (content.IsDirty)
|
||||
content.Save();
|
||||
else // Update ContentInfo objects to reflect the change in the transition
|
||||
ContentInfo.Refresh(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Insert Child
|
||||
public ItemInfo InsertChild(E_FromType fromType, int type, string text)
|
||||
@@ -364,6 +448,64 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region DataPortal
|
||||
private void DataPortal_Fetch(PastingPartCriteria criteria)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode());
|
||||
try
|
||||
{
|
||||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||||
{
|
||||
ApplicationContext.LocalContext["cn"] = cn;
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.Parameters.AddWithValue("@StartItemID", criteria.StartItemID);
|
||||
cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); //ABC After Before Child
|
||||
cm.Parameters.AddWithValue("@Type", criteria.Type); //ABC
|
||||
cm.Parameters.AddWithValue("@DTS", criteria.DTS); //ABC
|
||||
cm.Parameters.AddWithValue("@UserID", criteria.UserID); //ABC
|
||||
SqlParameter param_ContentID = new SqlParameter("@NewItemID", SqlDbType.Int);
|
||||
param_ContentID.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_ContentID);
|
||||
switch (criteria.AddType)
|
||||
{
|
||||
case EAddpingPart.Child:
|
||||
//cm.CommandText = "addItemChild";
|
||||
//cm.Parameters.AddWithValue("@FromType", criteria.FromType); //--C
|
||||
break;
|
||||
case EAddpingPart.Before:
|
||||
cm.CommandText = "PasteItemSiblingBefore";
|
||||
break;
|
||||
case EAddpingPart.After:
|
||||
cm.CommandText = "PasteItemSiblingAfter";
|
||||
break;
|
||||
case EAddpingPart.Replace:
|
||||
cm.CommandText = "PasteItemReplace";
|
||||
break;
|
||||
}
|
||||
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
|
||||
{
|
||||
//newItemID = (int)cm.Parameters["@newContentID"].Value;
|
||||
if (!dr.Read())
|
||||
{
|
||||
_ErrorMessage = "No Record Found";
|
||||
return;
|
||||
}
|
||||
ReadData(dr);
|
||||
}
|
||||
}
|
||||
// removing of item only needed for local data portal
|
||||
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
|
||||
ApplicationContext.LocalContext.Remove("cn");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex);
|
||||
}
|
||||
}
|
||||
private void DataPortal_Fetch(AddingPartCriteria criteria)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ItemInfo.DataPortal_Fetch", GetHashCode());
|
||||
@@ -423,6 +565,74 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region PastingPartCriteria
|
||||
[Serializable()]
|
||||
public class PastingPartCriteria
|
||||
{
|
||||
#region Properties
|
||||
private int _StartItemID;
|
||||
public int StartItemID
|
||||
{
|
||||
get { return _StartItemID; }
|
||||
set { _StartItemID = value; }
|
||||
}
|
||||
//private int _CopyEndID;
|
||||
//public int CopyEndID
|
||||
//{
|
||||
// get { return _CopyEndID; }
|
||||
// set { _CopyEndID = value; }
|
||||
//}
|
||||
private int _ItemID; // paste relative to this itemid
|
||||
public int ItemID
|
||||
{
|
||||
get { return _ItemID; }
|
||||
set { _ItemID = value; }
|
||||
}
|
||||
private EAddpingPart _AddType;
|
||||
public EAddpingPart AddType
|
||||
{
|
||||
get { return _AddType; }
|
||||
set { _AddType = value; }
|
||||
}
|
||||
private int? _FromType = null;
|
||||
public int? FromType
|
||||
{
|
||||
get { return _FromType; }
|
||||
set { _FromType = value; }
|
||||
}
|
||||
private int? _Type = null;
|
||||
public int? Type
|
||||
{
|
||||
get { return _Type; }
|
||||
set { _Type = value; }
|
||||
}
|
||||
private DateTime _DTS;
|
||||
public DateTime DTS
|
||||
{
|
||||
get { return _DTS; }
|
||||
set { _DTS = value; }
|
||||
}
|
||||
private string _UserID;
|
||||
public string UserID
|
||||
{
|
||||
get { return _UserID; }
|
||||
set { _UserID = value; }
|
||||
}
|
||||
#endregion
|
||||
#region Constructor
|
||||
public PastingPartCriteria(int startItemid, int itemID, EAddpingPart addType, int? type, int? fromType, DateTime dts, string userID)
|
||||
{
|
||||
_StartItemID = startItemid;
|
||||
_ItemID = itemID;
|
||||
_AddType = addType;
|
||||
_Type = type;
|
||||
_FromType = fromType;
|
||||
_DTS = dts;
|
||||
_UserID = userID;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
[Serializable()]
|
||||
protected class AddingPartCriteria
|
||||
{
|
||||
@@ -508,7 +718,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
Child=0,
|
||||
Before=1,
|
||||
After=2
|
||||
After=2,
|
||||
Replace=3
|
||||
}
|
||||
public ItemInfo NextItem
|
||||
{
|
||||
@@ -731,5 +942,55 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region PasteReplace
|
||||
public static ItemInfo PasteReplace(ItemInfo itemInfo, int copyStartID)
|
||||
{
|
||||
if (!CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Item");
|
||||
ItemInfo newItemInfo = CopyPasteReplaceItemInfoFetch(copyStartID, itemInfo); //itemInfo.ItemID, itemInfo.MyContent.Type, itemInfo.MyContent.Type);
|
||||
// Delete business objects, including remove from tree
|
||||
ItemInfo.DeleteItemInfoAndChildren(itemInfo.ItemID); // Dispose ItemInfo and Children
|
||||
using (Item item = Get(newItemInfo.ItemID)) ItemInfo.Refresh(item);
|
||||
if (newItemInfo.NextItem != null) using (Item item = newItemInfo.NextItem.Get()) ItemInfo.Refresh(item);
|
||||
newItemInfo.RefreshNextItems();
|
||||
// if inserting after a caution or note, refreshes tabs. This will adjust bullets
|
||||
// of any previous cautions or notes.
|
||||
if (newItemInfo.IsCaution || newItemInfo.IsNote) newItemInfo.ResetOrdinal();
|
||||
newItemInfo.UpdateTransitionText();
|
||||
newItemInfo.UpdatePastedStepTransitionText();
|
||||
// Add to tree
|
||||
if (newItemInfo.NextItemCount > 0)
|
||||
{
|
||||
using (ItemInfo itm = ItemInfo.Get(newItemInfo.NextItem.ItemID))
|
||||
{
|
||||
itm.OnNewSiblingBefore(new ItemInfoInsertEventArgs(newItemInfo, ItemInfo.EAddpingPart.Before));
|
||||
}
|
||||
}
|
||||
else if (newItemInfo.PreviousID != null)
|
||||
{
|
||||
using (ItemInfo itm2 = ItemInfo.Get((int)newItemInfo.PreviousID))
|
||||
{
|
||||
itm2.OnNewSiblingAfter(new ItemInfoInsertEventArgs(newItemInfo, ItemInfo.EAddpingPart.After));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newItemInfo.MyParent.OnNewChild(new ItemInfoInsertEventArgs(newItemInfo, ItemInfo.EAddpingPart.Child));
|
||||
}
|
||||
return newItemInfo;
|
||||
}
|
||||
private static ItemInfo CopyPasteReplaceItemInfoFetch(int copyStartID, ItemInfo itemInfo) // int itemID, int? type, int? fromType)
|
||||
{
|
||||
ItemInfo tmp = null;
|
||||
if (itemInfo.GetType() == typeof(ProcedureInfo))
|
||||
tmp = DataPortal.Fetch<ProcedureInfo>(new ItemInfo.PastingPartCriteria(copyStartID, itemInfo.ItemID, ItemInfo.EAddpingPart.Replace, itemInfo.MyContent.Type, itemInfo.MyContent.Type, DateTime.Now, Environment.UserName));
|
||||
else if (itemInfo.GetType() == typeof(SectionInfo))
|
||||
tmp = DataPortal.Fetch<SectionInfo>(new ItemInfo.PastingPartCriteria(copyStartID, itemInfo.ItemID, ItemInfo.EAddpingPart.Replace, itemInfo.MyContent.Type, itemInfo.MyContent.Type, DateTime.Now, Environment.UserName));
|
||||
else
|
||||
tmp = DataPortal.Fetch<StepInfo>(new ItemInfo.PastingPartCriteria(copyStartID, itemInfo.ItemID, ItemInfo.EAddpingPart.Replace, itemInfo.MyContent.Type, itemInfo.MyContent.Type, DateTime.Now, Environment.UserName));
|
||||
|
||||
return tmp;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user