- Fixed FindTop to work when the parent has a bottom value that is negative.

- Added code to remove a StepItem and the associated DB records.
 - Changed AdjustLocation to work properly when an AER and the next step has an RNO.
 - Temporary event handler to RemoveItem when the StepRTB is double-clicked.
This commit is contained in:
Rich 2009-10-22 19:09:07 +00:00
parent 988bd786a4
commit 5e3b830a3b

View File

@ -319,12 +319,13 @@ namespace Volian.Controls.Library
}
private int FindTop(int bottom)
{
int lastBottomPrev = 0;
int lastBottomParent = 0;
int lastBottomPrev = bottom; // This is necessary if the value of bottom can be negative.
//int lastBottomPrev = 0;
//int lastBottomParent = 0;
if (_MyPreviousStepItem != null)
lastBottomPrev = _MyPreviousStepItem.BottomMostStepItem.Bottom;
else if(_MyParentStepItem != null)
lastBottomParent = MyParentStepItem.BottomMostStepItem.Bottom;
//else if(_MyParentStepItem != null)
// lastBottomParent = MyParentStepItem.BottomMostStepItem.Bottom;
int? bottomRNO = BottomOfParentRNO();
//if (MyID == 2123)
// Console.WriteLine("Oops! {0},{1}", bottomRNO, bottom);
@ -333,11 +334,11 @@ namespace Volian.Controls.Library
// Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", MyID, lastBottomPrev,lastBottomParent, bottom, bottomRNO);
//if (MyID == 2125)
// Console.WriteLine("Oops!");
if (lastBottomPrev > bottom) bottom = lastBottomPrev; // RHM 20090615 ES02 Step8
if (lastBottomPrev > bottom) bottom = (int)(lastBottomPrev); // RHM 20090615 ES02 Step8
// Moving from Step 8 to the Note preceeding step 8 caused the step 9 to be positioned in the wrong place.
//if (lastBottomParent > bottom) bottom = lastBottomParent;
if (bottomRNO == null) return bottom;
return (int) max(bottomRNO, bottom);
//if (bottomRNO == null) return bottom;
return (int) max(bottomRNO, bottom);
}
/// <summary>
/// The left edge of the Tab
@ -919,6 +920,157 @@ namespace Volian.Controls.Library
// return tmp;
//}
#endregion
#region RemoveItem
protected void ShowTops(string title)
{
int TopMostY = TopMostStepItem.Top;
int? TopMostParentY = (MyParentStepItem == null ? null : (int?)(MyParentStepItem.TopMostStepItem.Top));
int? ParentY = (MyParentStepItem == null ? null : (int?)(MyParentStepItem.Top));
//Console.Write("{0}: TopMostY={1}, TopMostParentY={2}, ParentY = {3}",title, TopMostY, TopMostParentY, ParentY);
Console.Write("{0}{1},{2},{3}", title, TopMostY, TopMostParentY.ToString() ?? "null", ParentY.ToString() ?? "null");
}
public void RemoveItem()
{
MyStepPanel.SelectedStepRTB = null; // Unselect the item to be deleted
StepItem newFocus = null;
ShowTops("\r\n");
int TopMostYBefore = TopMostStepItem.Top;
int? TopMostParentY = (MyParentStepItem == null ? null : (int?)(MyParentStepItem.TopMostStepItem.Top));
int? ParentY = (MyParentStepItem == null ? null : (int?)(MyParentStepItem.Top));
try
{
Item.DeleteItemAndChildren(MyItemInfo);
}
catch (System.Data.SqlClient.SqlException ex)
{
HandleSqlExceptionOnDelete(ex);
return;
}
// Remove StepItems
RemoveFromParentsChildList();
if (MyNextStepItem != null)
{
if (MyPreviousStepItem != null)
{
MyNextStepItem.MyPreviousStepItem = MyPreviousStepItem;
MyPreviousStepItem = null;
newFocus = MyNextStepItem;
Console.Write(",\"Next 1\",");
}
else
{
MyNextStepItem.MyParentStepItem = MyParentStepItem;
MyParentStepItem = null;
MyNextStepItem.MyPreviousStepItem = null;
newFocus = MyNextStepItem;
Console.Write(",\"Next 2\",");
}
MyNextStepItem = null;
}
else if (MyPreviousStepItem != null)
{
MyPreviousStepItem.MyNextStepItem = null;
newFocus = MyPreviousStepItem;
MyPreviousStepItem = null;
Console.Write(",\"Previous\",");
}
else
{
newFocus = MyParentStepItem;
MyParentStepItem = null;
Console.Write(",\"Parent\",");
}
newFocus.MyStepRTB.Focus();
Dispose();
newFocus.SetAllTabs();
int TopMostYAfter = newFocus.TopMostStepItem.Top;
if (TopMostYAfter > TopMostYBefore)
newFocus.TopMostStepItem.Top = TopMostYBefore;
newFocus.AdjustLocation();
newFocus.ShowTops("");
}
private void HandleSqlExceptionOnDelete(System.Data.SqlClient.SqlException ex)
{
if (ex.Message.Contains("has External Transitions and has no next step"))
{
using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitions(MyID))
{
DialogResult ans = MessageBox.Show("Transitions exist to this step and cannot be adjusted automatically." +
"\r\n\r\nDo you want to be placed on the " + (exTrans.Count > 1 ? "first " : "") + "substep with the problem Transition?" +
"\r\n\r\nSubsteps with Problem Transitions" +
Summarize(exTrans) ,
"Cannot Delete This Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (ans == DialogResult.Yes)
{
MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OpenItem(exTrans[0].MyContent.ContentItems[0]);
}
else
this.MyStepRTB.Focus();
}
}
else if (ex.Message.Contains("has External Transitions to it's children"))
{
using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitionsToChildren(MyID))
{
DialogResult ans = MessageBox.Show("Transitions exist to substeps of this step and cannot be adjusted automatically." +
"\r\n\r\nDo you want to be placed on the " + (exTrans.Count > 1 ? "first " : "") + "substep with the problem Transition?" +
"\r\n\r\nSubsteps with Problem Transitions:" +
Summarize(exTrans),
"Cannot Delete This Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (ans == DialogResult.Yes)
{
MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OpenItem(exTrans[0].MyContent.ContentItems[0]);
}
}
}
else
MessageBox.Show(ex.Message, "SQL Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
private string Summarize(TransitionInfoList exTrans)
{
StringBuilder sb = new StringBuilder("");
foreach (TransitionInfo trans in exTrans)
sb.Append("\r\n" + trans.PathFrom);
return sb.ToString();
}
private void RemoveFromParentsChildList()
{
StepItem top = this;
while (top.MyPreviousStepItem != null) top = top.MyPreviousStepItem;
StepItem parentStepItem = top.MyParentStepItem;
if (parentStepItem == null) return; // No parent, nothing to remove.
if (parentStepItem.MyAfterStepItems != null && parentStepItem.MyAfterStepItems.Contains(this))
{
parentStepItem.MyAfterStepItems.Remove(this);
if (parentStepItem.MyAfterStepItems.Count == 0)
parentStepItem.MyAfterStepItems = null;
}
else if (parentStepItem.MyBeforeStepItems != null && parentStepItem.MyBeforeStepItems.Contains(this))
{
parentStepItem.MyBeforeStepItems.Remove(this);
if(parentStepItem.MyBeforeStepItems.Count == 0)
parentStepItem.MyBeforeStepItems = null;
}
else if (parentStepItem.MyRNOStepItems != null && parentStepItem.MyRNOStepItems.Contains(this))
{
parentStepItem.MyRNOStepItems.Remove(this);
if(parentStepItem.MyRNOStepItems.Count == 0)
parentStepItem.MyRNOStepItems = null;
}
}
//private void ShowSiblings(string title)
//{
// Console.WriteLine("---{0} {1}---",title,MyID);
// StepItem top = this;
// while (top.MyPreviousStepItem != null) top = top.MyPreviousStepItem;
// do
// {
// Console.WriteLine("{0} StepItem - {1} {2}", top.MyID == MyID ? "*" : " ", top.MyID, top.MyItemInfo.MyContent.Text);
// top = top.MyNextStepItem;
// } while (top != null);
//}
#endregion
#region Add Children
/// <summary>
/// Add a child before (Notes, Cautions, etc.)
@ -1606,7 +1758,7 @@ namespace Volian.Controls.Library
/// </summary>
internal void AdjustLocation()
{
//if (RNORight) MoveRNO();
if (RNORight) MoveRNO(); // This is needed when an AER is Deleted that has an RNO.
StepItem nextStepItem = NextDownStepItem;
//if (MyID == 2138)
// Console.WriteLine("2138");
@ -1902,5 +2054,9 @@ namespace Volian.Controls.Library
return _MyItemInfo == null ? base.ToString() : string.Format("({0}) {1}", MyID, MyPath); // + "-" + MyItemInfo.MyContent.Text;
}
#endregion
private void _MyStepRTB_DoubleClick(object sender, EventArgs e)
{
RemoveItem();
}
}
}