This commit is contained in:
Kathy Ruffing 2009-11-13 16:14:46 +00:00
parent 10898f5d90
commit c17133d47e

View File

@ -16,7 +16,9 @@ namespace Volian.Controls.Library
{
#region DelegatesAndEventArgs
public delegate void vlnTreeViewEvent(object sender, vlnTreeEventArgs args);
public delegate void vlnTreeViewItemInfoEvent(object sender, vlnTreeItemInfoEventArgs args);
public delegate bool vlnTreeViewBoolEvent(object sender, vlnTreeEventArgs args);
public delegate bool vlnTreeViewItemInfoDeleteEvent(object sender, vlnTreeItemInfoEventArgs args);
public delegate TreeNode vlnTreeViewTreeNodeEvent(object sender, vlnTreeEventArgs args);
public delegate DialogResult vlnTreeViewPropertyEvent(object sender, vlnTreePropertyEventArgs args);
public delegate void vlnTreeViewSectionInfoEvent(object sender, vlnTreeSectionInfoEventArgs args);
@ -69,6 +71,24 @@ namespace Volian.Controls.Library
}
#endregion
}
public partial class vlnTreeItemInfoEventArgs
{
#region Business Methods
private ItemInfo _MyItemInfo;
public ItemInfo MyItemInfo
{
get { return _MyItemInfo; }
set { _MyItemInfo = value; }
}
#endregion
#region Factory Methods
private vlnTreeItemInfoEventArgs() { ;}
public vlnTreeItemInfoEventArgs(ItemInfo myItemInfo)
{
_MyItemInfo = myItemInfo;
}
#endregion
}
public partial class vlnTreePropertyEventArgs : EventArgs
{
private string _Title;
@ -145,6 +165,12 @@ namespace Volian.Controls.Library
ItemInfo _LastItemInfo = null;
#endregion
#region Events
public event vlnTreeViewItemInfoDeleteEvent DeleteItemInfo;
private bool OnDeleteItemInfo(object sender, vlnTreeItemInfoEventArgs args)
{
if (DeleteItemInfo != null) return DeleteItemInfo(sender, args);
return false;
}
public event vlnTreeViewEvent NodeMove;
private void OnNodeMove(object sender, vlnTreeEventArgs args)
{
@ -176,6 +202,11 @@ namespace Volian.Controls.Library
{
if (SectionShouldClose != null) SectionShouldClose(sender, args);
}
public event vlnTreeViewItemInfoEvent OpenItem;
private void OnOpenItem(object sender, vlnTreeItemInfoEventArgs args)
{
if (OpenItem != null) OpenItem(sender, args);
}
#endregion
#region Constructors
public vlnTreeView()
@ -327,11 +358,16 @@ namespace Volian.Controls.Library
}
#endregion
#region Menu_Delete
// Add delete to the menu unless at the very 'top' node.
if (tn.Parent!=null) cm.MenuItems.Add("Delete", new EventHandler(mi_Click));
// Add delete to the menu unless at the very 'top' node or on a grouping (partinfo)
// node (RNOs, Steps, Cautions, Notes)
PartInfo pi = tn.VEObject as PartInfo;
if (pi == null && tn.Parent!=null) cm.MenuItems.Add("Delete", new EventHandler(mi_Click));
#endregion
#region Menu_Properties
cm.MenuItems.Add("Properties...", new EventHandler(mi_Click));
// Add delete to the menu unless at the very 'top' node or on a grouping (partinfo)
// node (RNOs, Steps, Cautions, Notes)
PartInfo pia = tn.VEObject as PartInfo;
if (pia == null) cm.MenuItems.Add("Properties...", new EventHandler(mi_Click));
#endregion
cm.Show(this, new Point(e.X, e.Y));
}
@ -341,7 +377,6 @@ namespace Volian.Controls.Library
void mi_Click(object sender, EventArgs e)
{
MenuItem mi = (MenuItem)sender;
SelectedNode.Expand();
switch (mi.Text)
{
case "Open":
@ -353,13 +388,16 @@ namespace Volian.Controls.Library
case "Insert Folder After":
tv_NodeNew(MenuSelections.FolderAfter);
break;
case "New Folder":
case "New Folder":
SelectedNode.Expand();
tv_NodeNew(MenuSelections.Folder);
break;
case "Create Working Draft":
SelectedNode.Expand();
tv_NodeNew(MenuSelections.DocVersion);
break;
case "New Procedure":
SelectedNode.Expand();
tv_NodeNew(MenuSelections.Procedure);
break;
case "Insert Procedure Before":
@ -370,6 +408,7 @@ namespace Volian.Controls.Library
break;
case "New Section":
case "New Subsection":
SelectedNode.Expand();
tv_NodeNew(MenuSelections.Section);
break;
case "Insert Section Before":
@ -385,6 +424,7 @@ namespace Volian.Controls.Library
tv_NodeNew(MenuSelections.StepAfter);
break;
case "New Step":
SelectedNode.Expand();
tv_NodeNew(MenuSelections.Step);
break;
case "Copy"://Copy the selected node
@ -405,7 +445,7 @@ namespace Volian.Controls.Library
case "Paste Step After":
tv_NodePaste(mi.Text);
break;
case "Delete"://Delete the selected node
case "Delete":
if (tv_NodeDelete())
{
TreeNode myParent = SelectedNode.Parent;
@ -577,7 +617,7 @@ namespace Volian.Controls.Library
VETreeNode tn = SelectedNode as VETreeNode;
if (tn != null)
{
if (tn.VEObject.GetType() == typeof(FolderInfo) || tn.VEObject.GetType() == typeof(DocVersionInfo))
if (tn.VEObject.GetType() == typeof(FolderInfo) || tn.VEObject.GetType() == typeof(DocVersionInfo) || tn.VEObject.GetType() == typeof(PartInfo))
{
if (tn.Nodes.Count > 0)
{
@ -819,7 +859,6 @@ namespace Volian.Controls.Library
#region DeleteAllLevels
private bool tv_NodeDelete()
{
OnNodeSelect(this, new vlnTreeEventArgs(SelectedNode));
SetLastValues((VETreeNode)SelectedNode);
DialogResult result = MessageBox.Show("Are you sure you want to delete " + SelectedNode.Text, "Verify Delete",
@ -840,25 +879,80 @@ namespace Volian.Controls.Library
}
else if (_LastProcedureInfo != null)
{
Procedure.Delete(_LastProcedureInfo.ItemID);
// always return false because an event gets fired to delete tree nodes.
if (!DeleteItemInfoAndChildren(_LastProcedureInfo)) return false;
_LastProcedureInfo = null;
return true;
return false;
}
else if (_LastSectionInfo != null)
{
Section.Delete(_LastSectionInfo.ItemID);
OnSectionShouldClose(this, new vlnTreeSectionInfoEventArgs(_LastSectionInfo));
// always return false because an event gets fired to delete tree nodes.
if (!DeleteItemInfoAndChildren(_LastSectionInfo)) return false;
_LastSectionInfo = null;
return true;
return false;
}
else if (_LastStepInfo != null)
{
Step.Delete(_LastStepInfo.ItemID);
// always return false because an event gets fired to delete tree nodes.
if (!DeleteItemInfoAndChildren(_LastStepInfo)) return false;
_LastStepInfo = null;
return true;
return false;
}
}
return false;
}
private bool DeleteItemInfoAndChildren(ItemInfo ii)
{
try
{
// if the procedure is open & you're deleting procedure, you want to close open
// window.
if (!OnDeleteItemInfo(this, new vlnTreeItemInfoEventArgs(ii)))
Item.DeleteItemAndChildren(ii);
return true;
}
catch (System.Data.SqlClient.SqlException ex)
{
HandleSqlExceptionOnDelete(ex, ii);
return false;
}
}
private void HandleSqlExceptionOnDelete(System.Data.SqlClient.SqlException ex, ItemInfo ii)
{
if (ex.Message.Contains("has External Transitions and has no next step"))
{
using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitions(ii.ItemID))
{
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" +
exTrans.Summarize(),
"Cannot Delete This Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (ans == DialogResult.Yes)
{
OnOpenItem(this, new vlnTreeItemInfoEventArgs(exTrans[0].MyContent.ContentItems[0]));
}
}
}
else if (ex.Message.Contains("has External Transitions to it's children"))
{
using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitionsToChildren(ii.ItemID))
{
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:" +
exTrans.Summarize(),
"Cannot Delete This Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (ans == DialogResult.Yes)
{
OnOpenItem(this, new vlnTreeItemInfoEventArgs(exTrans[0].MyContent.ContentItems[0]));
}
}
}
else
MessageBox.Show(ex.Message, "SQL Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
#endregion
#region SetLastValuesAndSaveIfChangedStuff
private void SetLastValues(VETreeNode node)