Added code to raise an error if trying to paste a step in reference to a step that has been deleted by another user (eg: paste before, paste after or paste replace)

Added handlers for new treeview events of NodeCopy and ClipboardStatus
Added exception handlers to handle the exception of trying to use a deleted step as a reference point for a paste operation (before, after or replace)
Added code to set the MyCopyStep property to the value of the new step added in a paste replace operation
This commit is contained in:
Rich 2014-08-06 00:55:41 +00:00
parent b5ded05838
commit a17c27c0a8
5 changed files with 85 additions and 20 deletions

View File

@ -53,6 +53,11 @@ BEGIN TRY -- Try Block
ContentID INT ContentID INT
) )
if exists (select * from tblitems where itemid = @ItemID and DeleteStatus !=0)
BEGIN
RAISERROR ('###Cannot Paste Step###This current step has been deleted in another session',16,1)
RETURN
END
-- First check if the replaced item can be deleted, i.e. it doesn't have transitions -- First check if the replaced item can be deleted, i.e. it doesn't have transitions
-- pointing to it or children. -- pointing to it or children.
@ -419,6 +424,11 @@ WITH EXECUTE AS OWNER
AS AS
BEGIN TRY -- Try Block BEGIN TRY -- Try Block
BEGIN TRANSACTION BEGIN TRANSACTION
if exists (select * from tblitems where itemid = @ItemID and DeleteStatus !=0)
BEGIN
RAISERROR ('###Cannot Paste Step###This current step has been deleted in another session',16,1)
RETURN
END
-- First make a copy of the input StartItemID -- First make a copy of the input StartItemID
-- DestFormatID is the formatid for the destination parent's format -- DestFormatID is the formatid for the destination parent's format
DECLARE @DestFormatID int DECLARE @DestFormatID int
@ -526,6 +536,11 @@ WITH EXECUTE AS OWNER
AS AS
BEGIN TRY -- Try Block BEGIN TRY -- Try Block
BEGIN TRANSACTION BEGIN TRANSACTION
if exists (select * from tblitems where itemid = @ItemID and DeleteStatus !=0)
BEGIN
RAISERROR ('###Cannot Paste Step###This current step has been deleted in another session',16,1)
RETURN
END
-- First make a copy of the input CopyStartID -- First make a copy of the input CopyStartID
-- DestFormatID is the formatid for the destination parent's format -- DestFormatID is the formatid for the destination parent's format
DECLARE @DestFormatID int DECLARE @DestFormatID int

View File

@ -245,6 +245,8 @@ namespace VEPROMS
tv.InsertItemInfo += new vlnTreeViewItemInfoInsertEvent(tv_InsertItemInfo); tv.InsertItemInfo += new vlnTreeViewItemInfoInsertEvent(tv_InsertItemInfo);
tv.NodeInsert += new vlnTreeViewEvent(tv_NodeInsert); tv.NodeInsert += new vlnTreeViewEvent(tv_NodeInsert);
tv.PasteItemInfo += new vlnTreeViewItemInfoPasteEvent(tv_PasteItemInfo); tv.PasteItemInfo += new vlnTreeViewItemInfoPasteEvent(tv_PasteItemInfo);
tv.NodeCopy += new vlnTreeViewEvent(tv_NodeCopy);
tv.ClipboardStatus += new vlnTreeViewClipboardStatusEvent(tv_ClipboardStatus);
tc.ItemPaste += new StepPanelItemPastedEvent(tc_ItemPasted); tc.ItemPaste += new StepPanelItemPastedEvent(tc_ItemPasted);
displayHistory.HistorySelectionChanged += new DisplayHistoryEvent(displayHistory_HistorySelectionChanged); displayHistory.HistorySelectionChanged += new DisplayHistoryEvent(displayHistory_HistorySelectionChanged);
_CommentTitleBckColor = epAnnotations.TitleStyle.BackColor1.Color; _CommentTitleBckColor = epAnnotations.TitleStyle.BackColor1.Color;
@ -280,7 +282,16 @@ namespace VEPROMS
displayApplicability.ApplicabilityViewModeChanged += new DisplayApplicability.DisplayApplicabilityEvent(displayApplicability_ApplicabilityViewModeChanged); displayApplicability.ApplicabilityViewModeChanged += new DisplayApplicability.DisplayApplicabilityEvent(displayApplicability_ApplicabilityViewModeChanged);
tv.ExportImportProcedureSets += new vlnTreeViewEvent(tv_ExportImportProcedureSets); tv.ExportImportProcedureSets += new vlnTreeViewEvent(tv_ExportImportProcedureSets);
} }
ItemInfo tv_ClipboardStatus(object sender, vlnTreeEventArgs args)
{
return tc.MyCopyStep;
}
void tv_NodeCopy(object sender, vlnTreeEventArgs args)
{
VETreeNode tn = args.Node as VETreeNode;
ItemInfo ii = tn.VEObject as ItemInfo;
tc.MyCopyStep = ii;
}
void tv_ExportImportProcedureSets(object sender, vlnTreeEventArgs args) void tv_ExportImportProcedureSets(object sender, vlnTreeEventArgs args)
{ {
FolderInfo fi = null; FolderInfo fi = null;

View File

@ -471,6 +471,12 @@ namespace VEPROMS.CSLA.Library
, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand); , System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
return true; return true;
} }
if(ex.Message.Contains("This current step has been deleted in another session"))
{
System.Windows.Forms.MessageBox.Show("The highlighted step has been deleted by another user!", "Cannot Paste Step"
, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
return true;
}
return false; return false;
} }
private ItemInfo CopyPasteItemInfoFetch(int copyStartID, int itemID, int? type, int? fromType, EAddpingPart addType) private ItemInfo CopyPasteItemInfoFetch(int copyStartID, int itemID, int? type, int? fromType, EAddpingPart addType)
@ -717,7 +723,10 @@ namespace VEPROMS.CSLA.Library
} }
catch (Exception ex) catch (Exception ex)
{ {
if (!ex.Message.Contains("This step has been deleted") && !ex.Message.Contains("This current step has been deleted in another session"))
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex); if (_MyLog.IsErrorEnabled) _MyLog.Error("ItemInfo.DataPortal_Fetch", ex);
}
_ErrorMessage = ex.Message; _ErrorMessage = ex.Message;
throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex); throw new DbCslaException("ItemInfo.DataPortal_Fetch", ex);
} }
@ -1237,15 +1246,36 @@ namespace VEPROMS.CSLA.Library
} }
catch (Exception ex) catch (Exception ex)
{ {
if (!HandleSqlExceptionOnCopy(ex))
{
if (ex.Message.Contains("has External Transitions and has no next step") if (ex.Message.Contains("has External Transitions and has no next step")
|| ex.Message.Contains("has External Transitions to it's children") || ex.Message.Contains("has External Transitions to it's children")
|| ex.Message.Contains("This step has been deleted") || ex.Message.Contains("This step has been deleted")
) )
throw ex; throw ex;
System.Windows.Forms.MessageBox.Show("Details were written to the Error Log.", "Paste Replace Failed", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); System.Windows.Forms.MessageBox.Show("Details were written to the Error Log.", "Paste Replace Failed", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
return itemInfo;
}
else
return itemInfo; return itemInfo;
} }
} }
#endregion #endregion
private static bool HandleSqlExceptionOnCopy(Exception ex)
{
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"
, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
return true;
}
if (ex.Message.Contains("This current step has been deleted in another session"))
{
System.Windows.Forms.MessageBox.Show("The highlighted step has been deleted by another user!", "Cannot Paste Step"
, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
return true;
}
return false;
}
} }
} }

View File

@ -449,8 +449,12 @@ namespace Volian.Controls.Library
edtitm.PasteSiblingAfter(copyStartID); edtitm.PasteSiblingAfter(copyStartID);
break; break;
case ItemInfo.EAddpingPart.Replace: case ItemInfo.EAddpingPart.Replace:
edtitm.PasteReplace(copyStartID); EditItem ei = edtitm.PasteReplace(copyStartID);
if (ei.MyItemInfo.ItemID != edtitm.MyItemInfo.ItemID)
{
edtitm.Dispose(); edtitm.Dispose();
MyCopyStep = ei.MyItemInfo;
}
break; break;
default: default:
return false; ; return false; ;

View File

@ -1246,7 +1246,7 @@ namespace Volian.Controls.Library
//catch (System.Data.SqlClient.SqlException ex) //catch (System.Data.SqlClient.SqlException ex)
catch (Exception ex) catch (Exception ex)
{ {
if(!HandleSqlExceptionOnCopy(ex)) if (HandleSqlExceptionOnCopy(ex)) return this;
HandleSqlExceptionOnDelete(ex); HandleSqlExceptionOnDelete(ex);
return this; return this;
} }
@ -1307,6 +1307,11 @@ namespace Volian.Controls.Library
MessageBox.Show("The step being pasted has been deleted", "Cannot Paste Step", MessageBoxButtons.OK, MessageBoxIcon.Hand); MessageBox.Show("The step being pasted has been deleted", "Cannot Paste Step", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return true; return true;
} }
if(ex.Message.Contains("This current step has been deleted in another session"))
{
MessageBox.Show("The highlighted step has been deleted by another user.", "Cannot Paste Step", MessageBoxButtons.OK, MessageBoxIcon.Hand);
return true;
}
return false; return false;
} }
public void IdentifyChildren(bool highlight) public void IdentifyChildren(bool highlight)