Added code to handle collection was modified error when copying items

Added code to make F5 and Shift-F5 keystrokes in the editor work identical to the right mouse button context menu of the tree view with regards to copy and paste of items
Added code to assure only items of similar type (eg: procedure, section, high level step, etc) can be copied and pasted at similar locations within a procedure or working draft
This commit is contained in:
Rich 2014-08-28 02:41:23 +00:00
parent 1baf690bc6
commit f9de5305f2
3 changed files with 125 additions and 41 deletions

View File

@ -465,6 +465,11 @@ namespace VEPROMS.CSLA.Library
}
private bool HandleSqlExceptionOnCopy(Exception ex)
{
if (ex.Message.Contains("Collection was modified;"))
{
_MyLog.WarnFormat(ex.Message);
return true;
}
if (ex.Message.Contains("This step has been deleted"))
{
System.Windows.Forms.MessageBox.Show("The step being pasted has been deleted!", "Cannot Paste Deleted Step"

View File

@ -2033,8 +2033,19 @@ namespace Volian.Controls.Library
if (e.Shift)
{
e.Handled = true;
if (!OnCheckClipboard(this, new EventArgs())) return; // check if 'clipboard' contains a step.
ItemInfo myCopyStep = (this.Parent.Parent.Parent as StepTabPanel).MyDisplayTabControl.MyCopyStep;
if (myCopyStep != null)
{
if (this.MyItemInfo.IsSection && myCopyStep.IsSection)
OnSetMenu(this, new StepRTBMenuEventArgs("StepPaste"));
if (this.MyItemInfo.IsStep && myCopyStep.IsStep)
{
if ((this.MyItemInfo.IsHigh && myCopyStep.IsHigh) || (!this.MyItemInfo.IsHigh && !myCopyStep.IsHigh))
OnSetMenu(this, new StepRTBMenuEventArgs("StepPaste"));
}
}
//if (!OnCheckClipboard(this, new EventArgs())) return; // check if 'clipboard' contains a step.
//OnSetMenu(this, new StepRTBMenuEventArgs("StepPaste"));
}
else if (!e.Control && !e.Alt)
{

View File

@ -941,42 +941,110 @@ namespace Volian.Controls.Library
private void SetPasteButtonEnabled()
{
// if there is no 'copied' step, or if a procedure is copied, just turn all buttons off, this can only
// be done from the tree.
#region new code
StepTabPanel tmp = Parent as StepTabPanel;
if (tmp.MyDisplayTabControl.MyCopyStep == null || tmp.MyDisplayTabControl.MyCopyStep.IsProcedurePart)
//turn all on
btnPasteBefore.Enabled = btnCMPasteBefore.Enabled = true;
btnPasteAfter.Enabled = btnCMPasteAfter.Enabled = true;
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = true;
//copy item is null, turn all off and return
if (tmp.MyDisplayTabControl.MyCopyStep == null)
{
btnPasteReplace.Enabled = btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnStepPaste.Enabled = false;
btnPasteBefore.Enabled = btnCMPasteBefore.Enabled = false;
btnPasteAfter.Enabled = btnCMPasteAfter.Enabled = false;
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
// If a section is copied, it can be pasted as a section (before/after/replace). If can also
// be pasted as a subsection if the format allows it.
if (tmp.MyDisplayTabControl.MyCopyStep.IsSectionPart)
//copy item is procedure, turn all off and return must be done from tree
if(tmp.MyDisplayTabControl.MyCopyStep.IsProcedure)
{
btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = MyItemInfo.IsSectionPart;
// when doing 'substep' part of paste, need to check if format allows subsection.
}
else if (tmp.MyDisplayTabControl.MyCopyStep.IsCautionPart || tmp.MyDisplayTabControl.MyCopyStep.IsNotePart)
// Part type of copied step must be same as Part type of destination, with exceptions of caution/note and step/rno
// can be pasted into each other.
// Part types are procedure - 1, section = 2, step = 6, caution = 3, note = 4, RNO (IsRNO), = 5 table/figure = 7.
btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = (MyItemInfo.IsCautionPart || MyItemInfo.IsNotePart);
else if (tmp.MyDisplayTabControl.MyCopyStep.IsRNOPart || tmp.MyDisplayTabControl.MyCopyStep.IsStepPart)
btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = (MyItemInfo.IsRNOPart || MyItemInfo.IsStepPart);
else if (tmp.MyDisplayTabControl.MyCopyStep.IsTable && MyItemInfo.IsTable)
{
btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnCMPasteBefore.Enabled = btnCMPasteAfter.Enabled = false;
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = true;
}
else if (tmp.MyDisplayTabControl.MyCopyStep.IsTable && !MyItemInfo.IsTable)
{
btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnCMPasteBefore.Enabled = btnCMPasteAfter.Enabled = false;
btnPasteBefore.Enabled = btnCMPasteBefore.Enabled = false;
btnPasteAfter.Enabled = btnCMPasteAfter.Enabled = false;
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
// Can't replace step with same step
if (tmp.MyDisplayTabControl.MyCopyStep.ItemID == MyItemInfo.ItemID) btnPasteReplace.Enabled = false;
//copy item is section
if (tmp.MyDisplayTabControl.MyCopyStep.IsSection && !MyItemInfo.IsSection)
{
btnPasteBefore.Enabled = btnCMPasteBefore.Enabled = false;
btnPasteAfter.Enabled = btnCMPasteAfter.Enabled = false;
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
if (tmp.MyDisplayTabControl.MyCopyStep.IsSection && MyItemInfo.IsSection && tmp.MyDisplayTabControl.MyCopyStep.ItemID == MyItemInfo.ItemID)
{
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
//copy item is high level step
if (tmp.MyDisplayTabControl.MyCopyStep.IsHigh && !MyItemInfo.IsHigh)
{
btnPasteBefore.Enabled = btnCMPasteBefore.Enabled = false;
btnPasteAfter.Enabled = btnCMPasteAfter.Enabled = false;
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
if (tmp.MyDisplayTabControl.MyCopyStep.IsHigh && MyItemInfo.IsHigh && tmp.MyDisplayTabControl.MyCopyStep.ItemID == MyItemInfo.ItemID)
{
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
//copy item is step that is not high is not a table and is not a figure
if (tmp.MyDisplayTabControl.MyCopyStep.IsSubStep && !MyItemInfo.IsSubStep)
{
btnPasteBefore.Enabled = btnCMPasteBefore.Enabled = false;
btnPasteAfter.Enabled = btnCMPasteAfter.Enabled = false;
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
if (tmp.MyDisplayTabControl.MyCopyStep.IsStep && MyItemInfo.IsStep && tmp.MyDisplayTabControl.MyCopyStep.ItemID == MyItemInfo.ItemID)
{
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
//otherwise everything is ok except for same item prevent replace
if (tmp.MyDisplayTabControl.MyCopyStep.ItemID == MyItemInfo.ItemID)
{
btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
return;
}
#endregion
#region original code
//// if there is no 'copied' step, or if a procedure is copied, just turn all buttons off, this can only
//// be done from the tree.
//StepTabPanel tmp = Parent as StepTabPanel;
//if (tmp.MyDisplayTabControl.MyCopyStep == null || tmp.MyDisplayTabControl.MyCopyStep.IsProcedurePart)
//{
// btnPasteReplace.Enabled = btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnStepPaste.Enabled = false;
// return;
//}
//// If a section is copied, it can be pasted as a section (before/after/replace). If can also
//// be pasted as a subsection if the format allows it.
//if (tmp.MyDisplayTabControl.MyCopyStep.IsSectionPart)
//{
// btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = MyItemInfo.IsSectionPart;
// // when doing 'substep' part of paste, need to check if format allows subsection.
//}
//else if (tmp.MyDisplayTabControl.MyCopyStep.IsCautionPart || tmp.MyDisplayTabControl.MyCopyStep.IsNotePart)
// // Part type of copied step must be same as Part type of destination, with exceptions of caution/note and step/rno
// // can be pasted into each other.
// // Part types are procedure - 1, section = 2, step = 6, caution = 3, note = 4, RNO (IsRNO), = 5 table/figure = 7.
// btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = (MyItemInfo.IsCautionPart || MyItemInfo.IsNotePart);
//else if (tmp.MyDisplayTabControl.MyCopyStep.IsRNOPart || tmp.MyDisplayTabControl.MyCopyStep.IsStepPart)
// btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnPasteReplace.Enabled = (MyItemInfo.IsRNOPart || MyItemInfo.IsStepPart);
//else if (tmp.MyDisplayTabControl.MyCopyStep.IsTable && MyItemInfo.IsTable)
//{
// btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnCMPasteBefore.Enabled = btnCMPasteAfter.Enabled = false;
// btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = true;
//}
//else if (tmp.MyDisplayTabControl.MyCopyStep.IsTable && !MyItemInfo.IsTable)
//{
// btnPasteBefore.Enabled = btnPasteAfter.Enabled = btnCMPasteBefore.Enabled = btnCMPasteAfter.Enabled = false;
// btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false;
//}
//// Can't replace step with same step
//if (tmp.MyDisplayTabControl.MyCopyStep.ItemID == MyItemInfo.ItemID) btnPasteReplace.Enabled = false;
#endregion
}
private void SetChangeIdRibbon()
{