Added code to ResetProcedures in Working Draft after they are moved.

Added logic to use SQL Stored Procedure to move
Procedures, Sections or Steps
This commit is contained in:
Rich 2013-03-12 15:00:17 +00:00
parent 23ad3d8d7b
commit 5588328899
2 changed files with 226 additions and 26 deletions

View File

@ -369,6 +369,13 @@ namespace VEPROMS.CSLA.Library
{
_Procedures = null;
}
public static void ResetProcedures(int versionID)
{
string key = versionID.ToString();
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (DocVersionInfo dvi in _CacheByPrimaryKey[key])
dvi.ResetProcedures();
}
#region IVEReadOnlyItem
public System.Collections.IList GetChildren()
{

View File

@ -129,7 +129,7 @@ namespace VEPROMS.CSLA.Library
children = (IList<ItemInfo>)parentInfoDV.GetChildren();
int numChild = children.Count;
if (this.MyPrevious == null) wasfirstchild = true;
if (this.PreviousID == null) wasfirstchild = true;//Use PreviousID rather than MyPrevious so the item is not cached
Item origNextItem = null;
// First, remove from this item from its list. To do this, get the current item's next point and redirect it's myprevious
@ -166,12 +166,15 @@ namespace VEPROMS.CSLA.Library
Save();
}
}
// RHM Moving Change
//else
//{
// MyPrevious = null;
// Save();
//}
else// RHM 2/20/2013 Moving Change
{
MyPrevious = null;
// Console.WriteLine(">Setting MyPrevious Null {0}", ItemID);
Save();
// Console.WriteLine("'Moved','e{0}','u{1}','{2}',{3}", ItemID, _MyItemUnique, StringIt(_LastChanged), index);
ItemInfo.RefreshParent(this, parentInfo);
//Console.WriteLine("<Setting MyPrevious Null {0}", ItemID);
}
// newPreviousInfo == null if moving into first child, and wasfirstchild == true if moving out of first child.
// This will require adjusting the DocVersion to point to the correct first child if a procedure is moved.
if (newPreviousInfo == null || wasfirstchild)
@ -216,11 +219,29 @@ namespace VEPROMS.CSLA.Library
if (origNextItem != null) origNextItem.Dispose();
if (parentInfo != null)
parentInfo.MyContent.RefreshContentParts();
if (parentInfoDV != null)
parentInfoDV.ResetProcedures();
}
//ShowItemAndSections("After MoveItem", pInfo as ItemInfo);
if (parentInfoDV != null)
DocVersionInfo.ResetProcedures(parentInfoDV.VersionID);
if (parentInfo != null)
ItemInfo.ResetParts(parentInfo.ItemID);
//ShowItemAndSections("After Refresh", pInfo as ItemInfo);
}
//private static string StringIt(byte[] _LastChanged)
//{
// StringBuilder sb = new StringBuilder();
// for (int i = 0; i < _LastChanged.Length; i++)
// sb.Append(string.Format("{0:X2}",_LastChanged[i]));
// return sb.ToString();
//}
//private void ShowItemAndSections(string title, ItemInfo pinfo)
//{
//
// pinfo.ShowThis(title + "-Parent");
// int i=0;
// foreach (ItemInfo child in pinfo.Sections)
// child.ShowThis(title + string.Format("-Child {0}", ++i));
//}
protected static int MakeNewItem(IVEDrillDownReadOnly parentInfoDD, ItemInfo previousInfo, string number, string title, int type, E_FromType partType)
{
int newitemid = 0;
@ -303,6 +324,68 @@ namespace VEPROMS.CSLA.Library
#region ItemInfo
public partial class ItemInfo:IVEDrillDownReadOnly
{
public void MoveItem(IVEDrillDownReadOnly pInfo, int index)
{
using (ItemInfoList movedItems = ItemInfoList.GetMoveItem(ItemID, index))
{
foreach (ItemInfo itm in movedItems)
ItemInfo.Refresh(itm);
}
DocVersionInfo parentInfoDV = pInfo as DocVersionInfo;
if (parentInfoDV != null)
DocVersionInfo.ResetProcedures(parentInfoDV.VersionID);
ItemInfo parentInfo = pInfo as ItemInfo;
if (parentInfo != null)
ItemInfo.ResetParts(parentInfo.ItemID);
}
public static void Refresh(ItemInfo tmp)
{
string key = tmp.ItemID.ToString();
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
protected virtual void RefreshFields(ItemInfo tmp)
{
if (_PreviousID != tmp.PreviousID)
{
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for old value
_PreviousID = tmp.PreviousID; // Update the value
}
_MyPrevious = null; // Reset list so that the next line gets a new list
if (MyPrevious != null) MyPrevious.RefreshNextItems(); // Update List for new value
//if (_ContentID != tmp.ContentID)
//{
if (MyContent != null) MyContent.RefreshContentItems(); // Update List for old value
_ContentID = tmp.ContentID; // Update the value
//}
_MyContent = null; // Reset list so that the next line gets a new list
if (MyContent != null) MyContent.RefreshContentItems(); // Update List for new value
_DTS = tmp.DTS;
_UserID = tmp.UserID;
_ItemInfoExtension.Refresh(this);
OnChange();// raise an event
}
private bool _Moving = false;
public bool Moving
{
get { return _Moving; }
set { _Moving = value; }
}
public static void RefreshParent(Item tmp,ItemInfo pInfo)
{
string key = tmp.ItemID.ToString();
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (ItemInfo tmpInfo in _CacheByPrimaryKey[key])
{
tmpInfo._ActiveParent=pInfo;
tmpInfo.RefreshItemParts();
}
}
private bool _NewTransToUnNumberedItem = false;
public bool NewTransToUnNumberedItem
{
@ -1530,9 +1613,36 @@ namespace VEPROMS.CSLA.Library
retval = Regex.Replace(retval, @"\\'[0-9A-Fa-f][0-9A-Fa-f]", new MatchEvaluator(ReplaceSpecialHexCharacter));
return retval;
}
//public void ShowThis(string title)
//{
// Console.WriteLine("'{0}',,,,'i{1}','u{2}',{3},'{4}','{5}','{6}','{7}'", title, ItemID, MyItemInfoUnique, PreviousID, this, _MyPrevious, _MyParent, _ActiveParent);
//}
public VE_Font GetItemFont()
{
/*
FormatInfo fmt = ActiveFormat;
if (fmt == null)
{
ShowThis();
if (MyPrevious != null)
{
MyPrevious.ShowThis();
if (MyPrevious.ActiveFormat == null)
{
_ActiveParent = MyPrevious.MyParent;
MyPrevious._ActiveParent = _ActiveParent;
fmt = _ActiveParent.ActiveFormat;
MyPrevious._ActiveFormat = fmt;
Console.WriteLine("OOPS!");
}
else if (MyParent != null)
{
_ActiveParent = MyParent;
fmt = _ActiveParent.ActiveFormat;
}
}
}
*/
return GetItemFont(ActiveFormat);
}
@ -2027,7 +2137,7 @@ namespace VEPROMS.CSLA.Library
}
}
}
return _ActiveParent==this ? null : _ActiveParent;
return _ActiveParent == this ? null : _ActiveParent;
}
internal set
//set
@ -2075,8 +2185,8 @@ namespace VEPROMS.CSLA.Library
int subtyp = typ % 10000;
if (subtyp >= ActiveFormat.PlantFormat.DocStyles.DocStyleList.Count) return ActiveFormat.PlantFormat.DocStyles.DocStyleList[0];
_MyDocStyle = ActiveFormat.PlantFormat.DocStyles.DocStyleList[subtyp];
}
return _MyDocStyle;
}
return _MyDocStyle;
}
set
{
@ -3023,6 +3133,19 @@ namespace VEPROMS.CSLA.Library
{
AddItem(itemInfo);
}
public static ItemInfoList GetMoveItem(int? itemID, int index)
{
try
{
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new MoveItemCriteria(itemID, index));
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
}
}
public static ItemInfoList GetList(int? itemID,int type)
{
try
@ -3092,6 +3215,27 @@ namespace VEPROMS.CSLA.Library
}
}
[Serializable()]
private class MoveItemCriteria
{
public MoveItemCriteria(int? itemID, int index)
{
_ItemID = itemID;
_Index = index;
}
private int? _ItemID;
public int? ItemID
{
get { return _ItemID; }
set { _ItemID = value; }
}
private int _Index;
public int Index
{
get { return _Index; }
set { _Index = value; }
}
}
[Serializable()]
private class ItemListCriteria
{
public ItemListCriteria(int? itemID,int type)
@ -3134,6 +3278,52 @@ namespace VEPROMS.CSLA.Library
set { _Type = value; }
}
}
private void DataPortal_Fetch(MoveItemCriteria criteria)
{
this.RaiseListChangedEvents = false;
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "MoveItem";
cm.Parameters.AddWithValue("@ItemID", criteria.ItemID);
cm.Parameters.AddWithValue("@Index", criteria.Index);
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
ItemInfo itemInfo = new ItemInfo(dr);
//switch ((E_FromType)criteria.Type)
//{
// case E_FromType.Procedure:
// itemInfo = new ProcedureInfo(dr);
// break;
// case E_FromType.Section:
// itemInfo = new SectionInfo(dr);
// break;
// default:
// itemInfo = new StepInfo(dr);
// break;
//}
IsReadOnly = false;
this.Add(itemInfo);
IsReadOnly = true;
}
}
}
}
}
catch (Exception ex)
{
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
}
private void DataPortal_Fetch(ItemListCriteria criteria)
{
this.RaiseListChangedEvents = false;
@ -3942,10 +4132,11 @@ namespace VEPROMS.CSLA.Library
}
public void MoveProcedure(IVEDrillDownReadOnly pInfo, int index)
{
using (Item ii = Item.Get(this.ItemID))
{
ii.MoveItem(pInfo, index);
}
MoveItem(pInfo, index);
//using (Item ii = Item.Get(this.ItemID))
//{
// ii.MoveItem(pInfo, index);
//}
}
public new Procedure Get()
{
@ -4377,10 +4568,11 @@ namespace VEPROMS.CSLA.Library
}
public void MoveSection(IVEDrillDownReadOnly pInfo, int index)
{
using (Item ii = Item.Get(this.ItemID))
{
ii.MoveItem(pInfo, index);
}
MoveItem(pInfo, index);
//using (Item ii = Item.Get(this.ItemID))
//{
// ii.MoveItem(pInfo, index);
//}
}
public new Section Get()
{
@ -4519,10 +4711,11 @@ namespace VEPROMS.CSLA.Library
}
public void MoveStep(IVEDrillDownReadOnly pInfo, int index)
{
using (Item ii = Item.Get(this.ItemID))
{
ii.MoveItem(pInfo, index);
}
MoveItem(pInfo, index);
//using (Item ii = Item.Get(this.ItemID))
//{
// ii.MoveItem(pInfo, index);
//}
}
public new Step Get()
{