| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using HySoft.FlowEditor;
- using HySoft.IVRFlowEditor.Utility;
- using HySoft.IVRFlowEditor.IVRControl;
- using HySoft.IVRFlowEditor.Propretity;
- using System.Reflection;
- using HySoft.IVRFlowEditor.Model;
- using HySoft.IVRFlowEditor.IVRControlUtility;
- namespace IVRFlowUI
- {
- public partial class FrmMain : Form
- {
- public FrmMain()
- {
- InitializeComponent();
- CreateBaseTabPage();
- _Menu = new System.Windows.Forms.ContextMenu();
- BindRightMeun();
- BindSelectContextMenuControl();
- }
- #region 绑定菜单栏事件
- private ContextMenu _Menu;
- /// <summary>
- /// 绑定右键菜单
- /// </summary>
- private void BindRightMeun()
- {
- MenuItem menuCheckAll = new MenuItem("全选(Ctrl+A)", new EventHandler(OnMenuItemClick));
- _Menu.MenuItems.Add(menuCheckAll);
- MenuItem menuCopy = new MenuItem("复制(Ctrl+C)", new EventHandler(OnMenuItemClick));
- _Menu.MenuItems.Add(menuCopy);
- MenuItem menuPaste = new MenuItem("粘贴(Ctrl+V)", new EventHandler(OnMenuItemClick));
- _Menu.MenuItems.Add(menuPaste);
- MenuItem menuDelete = new MenuItem("删除(Delete)", new EventHandler(OnMenuItemClick));
- _Menu.MenuItems.Add(menuDelete);
- MenuItem menuAdd = new MenuItem("放大(Ctrl++)", new EventHandler(OnMenuItemClick));
- _Menu.MenuItems.Add(menuAdd);
- MenuItem menuOemplus = new MenuItem("缩小(Ctrl+-)", new EventHandler(OnMenuItemClick));
- _Menu.MenuItems.Add(menuOemplus);
- }
- #endregion
- #region 鼠标右键菜单以及快捷键处理
-
- private List<FlowNode> CopyNodes;
- private List<FlowLine> CopyLines;
- /// <summary>
- /// 右键菜单和快捷键转换成命令字符统一进行相应的处理的函数
- /// </summary>
- /// <param name="type"></param>
- private void KeyAndMenuHandle(string type)
- {
- switch (type)
- {
- case "Control C":
- CopyLines = CopyLines == null ? CopyLines = new List<FlowLine>() : CopyLines;
- CopyLines.Clear();
- CopyNodes = CopyNodes == null ? CopyNodes = new List<FlowNode>() : CopyNodes;
- CopyNodes.Clear();
- if (GlobalController._SelectCanvas.SelectedLines != null)
- foreach (FlowLine f in GlobalController._SelectCanvas.SelectedLines)
- {
- FlowLine o = new FlowLine();
- o.LineColor = f.LineColor;
- o.Name = f.Name;
- o.Note = f.Note;
-
- o.SelectedLineColor = f.SelectedLineColor;
- o.Control.LineWidth = f.Control.LineWidth;
- o.HeadNodePort = f.HeadNodePort;
- o.TailNodePort = f.TailNodePort;
- CopyLines.Add(o);
- }
- if (GlobalController._SelectCanvas.SelectedNodes != null)
- foreach (FlowNode f in GlobalController._SelectCanvas.SelectedNodes)
- {
- ConstructorInfo ci = f.GetType().GetConstructor(new List<Type>{typeof(String),}.ToArray());
- IVRControlBase o = ci.Invoke(new List<object>{ f.Name+"_1"}.ToArray()) as IVRControlBase;
- // FlowNode o = new FlowNode(f.Size);
- o.Control.Size = f.Size;
- o.Name = f.Name + "_1";
- o.CenterPoint = f.CenterPoint;
- o.Image = f.Image;
- foreach (NodePort n in f.InputPortList)
- o.AddInputPort(n);
- foreach (NodePort n in f.OutputPortList)
- o.AddOutputPort(n);
- o.SelectedImage = f.SelectedImage;
- this.CopyNodes.Add(o);
- }
- break;
- case "Control A":
- GlobalController._SelectCanvas.SetSelectedNodes(GlobalController._SelectCanvas.NodeList.ToArray());
- GlobalController._SelectCanvas.SetSelectedLines(GlobalController._SelectCanvas.LineList.ToArray());
- break;
- case "Control V":
- if (CopyNodes != null)
- {
- foreach (IVRControlBase f in CopyNodes)
- {
- f.Pos = GlobalController._SelectCanvas.NodeList.Count.ToString();
- f.Control.DoubleClick += new EventHandler(Control_DoubleClick);
- GlobalController.SetCurrentCancasIVRControlBase(f);
- GlobalController._SelectCanvas.AddANode(f);
- }
- GlobalController._SelectCanvas.SetSelectedNodes(CopyNodes.ToArray());
- }
- if (CopyLines != null)
- {
- foreach (FlowLine f in CopyLines)
- {
- GlobalController._SelectCanvas.AddALine(f, this.CopyNodes.Find(a => a.InputPortList.Contains(f.HeadNodePort)), this.CopyNodes.Find(a => a.OutputPortList.Contains(f.TailNodePort)));
- }
- GlobalController._SelectCanvas.SetSelectedLines(CopyLines.ToArray());
- }
- CopyLines.Clear();
- CopyNodes.Clear();
- break;
- case "Control S":
- SaveFileDialog svf = new SaveFileDialog();
- svf.Filter = "XML文件|*.xml";
- svf.InitialDirectory = Application.StartupPath;
- //2017-4-26
- #region 直接按原文件名进行保存
- bool pd = false;
- string fp = this.tabControl1.SelectedTab.Text;
- if (this.tabControl1.SelectedTab.Text != "空白标签")
- {
- int ffp = fp.IndexOf(".xml");
- int startindex = fp.LastIndexOf("\\");
- int leng = ffp - startindex - 1;
- string fn = fp.Substring(startindex + 1, leng);
- svf.FileName = this.tabControl1.SelectedTab.Text;//fn;
- pd = true;
- }
- else
- {
- if (svf.ShowDialog() == DialogResult.OK)
- {
- pd = true;
- }
- }
- #endregion
- if(pd==true)//if (svf.ShowDialog() == DialogResult.OK)
- {
- List<IVRFlowSerializerInfo> f = new List<IVRFlowSerializerInfo>();
- foreach(TabPage tp in this.tabControl1.SelectedTab.Controls[0].Controls)
- {
- FlowEditorCanvas ct = (FlowEditorCanvas)tp.Controls[0];
- f.Add(new IVRFlowSerializerInfo() { IVR_Name = tp.Name, IVR_Text=tp.Text, IVRFlowType = (IVRFlowType) tp.Tag, IVRControl = new List<IVRControlBase>() });
-
- for(int i=0;i<ct.NodeList.Count;i++)
- {
- if (ct.NodeList[i].ID!="0")
- f[f.Count-1].IVRControl.Add((IVRControlBase)ct.NodeList[i]);
- }
-
- }
- MessageInfo msg =GlobalController.GetSerializerHandle().SaveFileInfo(svf.FileName, f);
- MessageBox.Show(msg.Message);
- this.tabControl1.SelectedTab.Text = svf.FileName;
- }
- break;
- //2017-4-27
- case "Control SAVEAS":
- SaveFileDialog svfa = new SaveFileDialog();
- svfa.Filter = "XML文件|*.xml";
- svfa.InitialDirectory = Application.StartupPath;
-
- if (svfa.ShowDialog() == DialogResult.OK)
- {
- List<IVRFlowSerializerInfo> f = new List<IVRFlowSerializerInfo>();
- foreach (TabPage tp in this.tabControl1.SelectedTab.Controls[0].Controls)
- {
- FlowEditorCanvas ct = (FlowEditorCanvas)tp.Controls[0];
- f.Add(new IVRFlowSerializerInfo() { IVR_Name = tp.Name, IVR_Text = tp.Text, IVRFlowType = (IVRFlowType)tp.Tag, IVRControl = new List<IVRControlBase>() });
- for (int i = 0; i < ct.NodeList.Count; i++)
- {
- if (ct.NodeList[i].ID != "0")
- f[f.Count - 1].IVRControl.Add((IVRControlBase)ct.NodeList[i]);
- }
- }
- MessageInfo msg = GlobalController.GetSerializerHandle().SaveFileInfo(svfa.FileName, f);
- MessageBox.Show(msg.Message);
- this.tabControl1.SelectedTab.Text = svfa.FileName;
- }
- break;
- case "Control O":
- OpenFileDialog opf = new OpenFileDialog();
- opf.Filter = "XML文件|*.xml";
- opf.InitialDirectory = Application.StartupPath;
- if (opf.ShowDialog() == DialogResult.OK)
- {
- List<IVRFlowSerializerInfo> f = new List<IVRFlowSerializerInfo>();
- MessageInfo msg = GlobalController.GetSerializerHandle().OpenFileInfo(opf.FileName, ref f);
- if (!msg.State)
- {
- MessageBox.Show(msg.Message);
- return;
- }
- if (f == null || f.Count == 0)
- {
- MessageBox.Show("没有解析到数据内容!");
- return;
- }
- TabPage tab1 = new TabPage();
- tab1.Text = opf.FileName;//获取带路径的文件名
- //string filen = opf.SafeFileName;//不带路径的文件名(包含扩展名)
- //string fn = System.IO .Path.GetFileNameWithoutExtension(@opf.FileName);//不带路径的文件名(不含扩展名)
- tab1.Name = this.tabControl1.Controls.Count.ToString();
- GlobalController.IVRCancas.Remove(tab1.Name);//2017-4-27添加,解决关闭再打开同一个项目时报错的问题
- GlobalController.IVRCancas.Add(tab1.Name, new IVRCanvas());
- TabControl tb = new TabControl();
- tb.Dock = DockStyle.Fill;
- tb.Name = this.tabControl1.Controls.Count.ToString();
- tb.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
- tab1.Controls.Add(tb);
- this.tabControl1.Controls.Add(tab1);
-
- foreach (IVRFlowSerializerInfo ivrflow in f)
- {
- TabPage tab=new TabPage(ivrflow.IVR_Name);
- tab.Name =ivrflow.IVR_Name;
- tab.Tag = ivrflow.IVRFlowType;
- tab.Text = ivrflow.IVR_Text;
- FlowEditorCanvas canvas = new FlowEditorCanvas();
- canvas.Name = tab.Name = GlobalController.IVRCancas[tb.Name].IVRFlows.Count.ToString();
-
- GlobalController.IVRCancas[tb.Name].IVRFlows.Add(canvas.Name, new IVRFlowInfo() { FlowID = canvas.Name, FlowName = tab.Text });
- canvas.Dock = DockStyle.Fill;
- canvas.MouseUp += new MouseEventHandler(f_MouseUp);
- canvas.MouseMove += new MouseEventHandler(f_MouseMove);
- tab.Controls.Add(canvas);
-
- tb.Controls.Add(tab);
- tb.SelectedTab = tab;
- GlobalController._SelectTabControl = tb;
- GlobalController._SelectCanvas = canvas;
- foreach (IVRControlBase ivrControl in ivrflow.IVRControl)
- {
- ivrControl.Control.DoubleClick += new EventHandler(Control_DoubleClick);
- canvas.AddANode(ivrControl);
- GlobalController.SetCurrentCancasIVRControlBase(ivrControl);
- }
- GlobalController.SetFlowVar(ivrflow.IVRVar);
-
- foreach (LineInfo line in ivrflow.LineNodes)
- {
- if (canvas.NodeList.Find(a => a.ID == line.StartNodeID).GetType().GetProperty(line.AttributeName) != null)
- canvas.NodeList.Find(a => a.ID == line.StartNodeID).GetType().GetProperty(line.AttributeName).SetValue(canvas.NodeList.Find(a => a.ID == line.StartNodeID), canvas.NodeList.Find(a => a.ID == line.EndNodeID), null);
- canvas.AddALine(GetNewFlowLine(), canvas.NodeList.Find(a => a.ID == line.StartNodeID), canvas.NodeList.Find(a => a.ID == line.EndNodeID));
- }
-
- }
-
- tb.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
- this.tabControl1.SelectedTab = tab1;
-
- MessageBox.Show(msg.Message);
- }
- break;
- case "Control Oemplus":
- case "Control Add":
- foreach (FlowLine f in GlobalController._SelectCanvas.LineList)
- {
- f.Control.LineWidth += 1;
- }
- foreach (FlowNode f in GlobalController._SelectCanvas.NodeList)
- {
- f.Control.Width += 10;
- f.Control.Height += 10;
- // canvas.ResetNodeLines(f);
- }
- this.Refresh();
- break;
- case "Control Subtract":
- case "Control OemMinus":
- foreach (FlowLine f in GlobalController._SelectCanvas.LineList)
- {
- f.Control.LineWidth += -1;
- }
- foreach (FlowNode f in GlobalController._SelectCanvas.NodeList)
- {
- f.Control.Width += -10;
- f.Control.Height += -10;
- // ResetNodeLines(f);
- }
- this.Refresh();
- break;
- case "Control ControlKey": break;
- case "None Delete":
- if (MessageBox.Show("是否要删除选中的节点吗?", "消息提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- if (GlobalController._SelectCanvas.SelectedLines != null)
- foreach (FlowLine f in GlobalController._SelectCanvas.SelectedLines)
- {
- GlobalController._SelectCanvas.DelLine(f, true, true);
- }
- if (GlobalController._SelectCanvas.SelectedNodes != null)
- foreach (FlowNode f in GlobalController._SelectCanvas.SelectedNodes)
- {
- GlobalController._SelectCanvas.DelNode(f);
- GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows[GlobalController._SelectCanvas.Name].IVRFlowNode.Remove(f as IVRControlBase);
- }
- } break;
- default: MessageBox.Show("组合键无效!"); break;
- }
- }
- #region 菜单栏点击事件转换为快捷键事件
- /// <summary>
- /// 菜单栏点击事件转换为快捷键事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void OnMenuItemClick(object sender, EventArgs e)
- {
-
- switch (sender.GetType().GetProperty("Text").GetValue(sender, null).ToString())
- {
- case "全选":
- case "全选(Ctrl+A)":
- KeyAndMenuHandle("Control A"); break;
- case "复制":
- case "复制(Ctrl+C)":
- KeyAndMenuHandle("Control C"); break;
- case "粘贴":
- case "粘贴(Ctrl+V)":
- KeyAndMenuHandle("Control V"); break;
- case "删除":
- case "删除(Delete)":
- KeyAndMenuHandle("None Delete"); break;
- case "放大":
- case "放大(Ctrl++)":
- KeyAndMenuHandle("Control Oemplus"); break;
- case "缩小":
- case "缩小(Ctrl+-)":
- KeyAndMenuHandle("Control OemMinus"); break;
- }
- }
- #endregion
- #endregion
- /// <summary>
- /// 画布双击事件
- /// </summary>
- /// <param name="f"></param>
- private void flowEditorCanvas1_DoubleClick(FlowNode f)
- {
- ShowNodeProperty(f);
- }
- #region 绑定右键菜单
- /// <summary>
- /// 绑定右键菜单
- /// </summary>
- private void BindSelectContextMenuControl()
- {
- if(this.tabControl1.Controls.Count>0)
- foreach (Control c in this.tabControl1.SelectedTab.Controls)
- {
- if (c.GetType() == typeof(TabControl))
- {
- GlobalController._SelectTabControl = (c as TabControl);
- (c as TabControl).SelectedTab.Controls[0].ContextMenu = _Menu;
- GlobalController._SelectCanvas = ((c as TabControl).SelectedTab.Controls[0] as FlowEditorCanvas);
- BindTreeNodes(GlobalController._SelectTabControl.Controls);
- }
- }
- }
- #endregion
- /// <summary>
- /// 绑定流程的树形结构
- /// </summary>
- /// <param name="con"></param>
- private void BindTreeNodes(Control.ControlCollection con)
- {
- this.treeView1.Nodes.Clear();
- this.treeView1.ImageList = GlobalController.ControlImageList;
- TreeNode t;
-
- foreach (TabPage o in con)
- {
-
- switch ((IVRFlowType)o.Tag)
- {
- case IVRFlowType.auto:
- t = new TreeNode() { Text = o.Text, SelectedImageKey= "OverFlow.gif", ImageKey = "OverFlow.gif" };
- t.Tag = o;
- this.treeView1.Nodes.Add(t);
- break;
- case IVRFlowType.normal:
- t = new TreeNode() { Text = o.Text, SelectedImageKey = "RotorFlow.gif", ImageKey = "RotorFlow.gif" };
- t.Tag = o;
- this.treeView1.Nodes.Add(t);
- break;
- case IVRFlowType.sub:
- t = new TreeNode() { Text = o.Text, SelectedImageKey = "SubFlowOver.gif", ImageKey = "SubFlowOver.gif" };
- t.Tag = o;
- this.treeView1.Nodes.Add(t);
- break;
- }
- }
- }
- /// <summary>
- /// 流程选择事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
- {
- BindSelectContextMenuControl();
- }
- /// <summary>
- /// 捕捉鼠标按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FrmMain_KeyDown(object sender, KeyEventArgs e)
- {
- KeyAndMenuHandle(e.Modifiers + " " + e.KeyCode);
- }
- #region 加载时初始化的空白页和新建空白项目时调用
- /// <summary>
- /// 初始化的空白标签
- /// </summary>
- public void CreateBaseTabPage()
- {
- TabPage t = new TabPage() { Dock = DockStyle.Fill };
- t.Text = "空白标签";
- this.tabControl1.Controls.Add(t);
- this.tabControl1.SelectedTab = t;
-
- TabControl tab = new TabControl() { Dock = DockStyle.Fill };
- tab.Name = GlobalController.IVRCancas.Count.ToString();
- GlobalController.IVRCancas.Add(tab.Name, new IVRCanvas());
- tab.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
- TabPage tab1 = new TabPage();
- FlowEditorCanvas f = new FlowEditorCanvas(); GlobalController._SelectCanvas = f;
- f.Dock = DockStyle.Fill;
- f.MouseUp += new MouseEventHandler(f_MouseUp);
- f.MouseMove += new MouseEventHandler(f_MouseMove);
- tab1.Controls.Add(f);
- tab1.Tag = IVRFlowType.normal;
- tab1.Text = "普通流程";
- f.Name = GlobalController.IVRCancas[tab.Name].IVRFlows.Count.ToString();
- GlobalController.IVRCancas[tab.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID=f.Name, FlowName=tab1.Text});
- TabPage tab2 = new TabPage();
- f = new FlowEditorCanvas();
- f.Dock = DockStyle.Fill;
- f.MouseUp += new MouseEventHandler(f_MouseUp);
- f.MouseMove += new MouseEventHandler(f_MouseMove);
- tab2.Controls.Add(f);
- tab2.Text = "自动流程";
- tab2.Tag = IVRFlowType.auto;
- f.Name = GlobalController.IVRCancas[tab.Name].IVRFlows.Count.ToString();
- GlobalController.IVRCancas[tab.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID = f.Name, FlowName = tab2.Text });
- TabPage tab3 = new TabPage();
- f = new FlowEditorCanvas();
- f.Dock = DockStyle.Fill;
- f.MouseUp += new MouseEventHandler(f_MouseUp);
- f.MouseMove += new MouseEventHandler(f_MouseMove);
- f.Name = GlobalController.IVRCancas[tab.Name].IVRFlows.Count.ToString();
- tab3.Text = "子流程";
- GlobalController.IVRCancas[tab.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID = f.Name, FlowName = tab3.Text });
- tab3.Controls.Add(f);
- tab3.Tag = IVRFlowType.sub;
- t.Controls.Add(tab);
- tab.Controls.Add(tab1);
- tab.Controls.Add(tab2);
- tab.Controls.Add(tab3);
-
- BindTreeNodes(tab.Controls);
-
-
- tab.SelectedTab = tab1;
-
- GlobalController._SelectTabControl = tab;
- }
- #endregion
- #region 鼠标弹起事件,监测是否创建控件以及创建控件
- void f_MouseUp(object sender, MouseEventArgs e)
- {
- if (GlobalController.CheckCreateNode())
- {
- int id=0;
- if((sender as FlowEditorCanvas).NodeList!=null&&(sender as FlowEditorCanvas).NodeList.Count!=0)
- id = (sender as FlowEditorCanvas).NodeList.Max(a =>Int32.Parse(a.ID));
- IVRControlBase node = GlobalController.CreateNode((id+1).ToString());
- node.Pos = (id + 1).ToString();
- Point p = new Point(0, 0);
- p = (sender as FlowEditorCanvas).PointToClient(p);
- Point CurcorPoint = new Point(Cursor.Position.X + p.X, Cursor.Position.Y + p.Y);
- node.CenterPoint = CurcorPoint;
- node.Control.DoubleClick += new EventHandler(Control_DoubleClick);
- GlobalController.SetCurrentCancasIVRControlBase(node);
- (sender as FlowEditorCanvas).AddANode(node);
-
-
- }
- }
- #endregion
- #region 创建新的连接线
- /// <summary>
- /// 创建新连线
- /// </summary>
- /// <returns></returns>
- private FlowLine GetNewFlowLine()
- {
- FlowLine line1 = new FlowLine();
- line1.LineColor = Color.Blue;
- line1.SelectedLineColor = Color.Red;
- line1.LineWidth = 1;
- return line1;
- }
- #endregion
- #region 遍历所有IVR控件并根据控件类型显示不同的属性并在确定后重绘
- private void ShowNodeProperty(FlowNode obj)
- {
- var ivr = (obj as IVRControlBase);
- var ctl=ivr.CtlProperty;
-
- ivr.IVRFlows = GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Values.ToList();
- FrmProPretity frm = new FrmProPretity(ref ivr);
- frm.Text = ivr.Name;
- if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if (ivr.InputPortList != null)
-
- for (int i = ivr.InputPortList.Count; i > 0; i--)
- {
- GlobalController._SelectCanvas.DelLine(ivr.InputPortList[i-1].Line, true, true);
-
- ivr.RemoveInputPort(ivr.InputPortList[i-1]);
-
- }
- if (ivr.GetType() == typeof(IVRStartNode))
- {
- var iVRStartNode = ivr as IVRStartNode;
- if (iVRStartNode.Next != null && iVRStartNode.Next != ivr && iVRStartNode.Next.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStartNode.Next);
- }
- }
- else if (ivr.GetType() == typeof(IVRTransfeOut))//ivr.GetType() == typeof(IVROutbound)||//2017-4-27修改
- {
- var iVROutbound = ivr as IVRTransfeOut;
- if (iVROutbound.SuccessPos != null && iVROutbound.SuccessPos != ivr && iVROutbound.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVROutbound.SuccessPos);
- }
- if (iVROutbound.FailPos != null && iVROutbound.FailPos != ivr && iVROutbound.FailPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVROutbound.FailPos);
- }
- }
- //2017-4-27 添加
- else if (ivr.GetType() == typeof(IVROutbound))
- {
- var iVROutbound = ivr as IVROutbound;
- if (iVROutbound.SuccessPos != null && iVROutbound.SuccessPos != ivr && iVROutbound.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVROutbound.SuccessPos);
- }
- if (iVROutbound.FailPos != null && iVROutbound.FailPos != ivr && iVROutbound.FailPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVROutbound.FailPos);
- }
- }
- else if (ivr.GetType() == typeof(IVRDefinevar))
- {
- var iVRDefinevar = (ivr as IVRDefinevar);
- if (iVRDefinevar.Next != null && iVRDefinevar.Next != ivr && iVRDefinevar.Next.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRDefinevar.Next);
- }
- }
- else if (ivr.GetType() == typeof(IVRSubflow))
- {
- var iVRSubflow = (ivr as IVRSubflow);
- if (iVRSubflow.Next != null && iVRSubflow.Next != ivr && iVRSubflow.Next.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSubflow.Next);
- }
- }
- else if (ivr.GetType() == typeof(IVRAudioDTMF))
- {
- var iVRAudioDTMF = (ivr as IVRAudioDTMF);
- if (iVRAudioDTMF.SuccessPos != null && iVRAudioDTMF.SuccessPos != ivr && iVRAudioDTMF.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRAudioDTMF.SuccessPos);
- }
- if (iVRAudioDTMF.FailPos != null && iVRAudioDTMF.FailPos != ivr && iVRAudioDTMF.FailPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRAudioDTMF.FailPos);
- }
- if (iVRAudioDTMF.HangupPos != null && iVRAudioDTMF.HangupPos != ivr && iVRAudioDTMF.HangupPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRAudioDTMF.HangupPos);
- }
- }
- else if (ivr.GetType() == typeof(IVRSendfax) || ivr.GetType() == typeof(IVRRecvfax))
- {
- var iVRSendfax = (ivr as IVRSendfax);
- if (iVRSendfax.SuccessPos != null && iVRSendfax.SuccessPos != ivr && iVRSendfax.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSendfax.SuccessPos);
- }
- if (iVRSendfax.FailPos != null && iVRSendfax.FailPos != ivr && iVRSendfax.FailPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSendfax.FailPos);
- }
- if (iVRSendfax.HangupPos != null && iVRSendfax.HangupPos != ivr && iVRSendfax.HangupPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSendfax.HangupPos);
- }
- }
- else if (ivr.GetType() == typeof(IVRLeaveWord))
- {
- var iVRLeaveWord = (ivr as IVRLeaveWord);
- if (iVRLeaveWord.TimeoutPos != null && iVRLeaveWord.TimeoutPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.TimeoutPos);
- }
- if (iVRLeaveWord.HangupPos != null && iVRLeaveWord.HangupPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.HangupPos);
- }
- if (iVRLeaveWord.FinishPos != null && iVRLeaveWord.FinishPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.FinishPos);
- }
- }
- else if (ivr.GetType() == typeof(IVRQueue))
- {
- var iVRQueue = (ivr as IVRQueue);
- if (iVRQueue.HangupPos != null && iVRQueue.HangupPos != ivr && iVRQueue.HangupPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.HangupPos);
- }
- if (iVRQueue.SuccessPos != null && iVRQueue.SuccessPos != ivr && iVRQueue.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.SuccessPos);
- }
- if (iVRQueue.NoAgentPos != null && iVRQueue.NoAgentPos != ivr && iVRQueue.NoAgentPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.NoAgentPos);
- }
- if (iVRQueue.NoFreePos != null && iVRQueue.NoFreePos != ivr && iVRQueue.NoFreePos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.NoFreePos);
- }
- }
- else if (ivr.GetType() == typeof(IVRContinueQueue))
- {
- var iVRContinueQueue = (ivr as IVRContinueQueue);
- if (iVRContinueQueue.TimeoutPos != null && iVRContinueQueue.TimeoutPos != ivr && iVRContinueQueue.TimeoutPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.TimeoutPos);
- }
- if (iVRContinueQueue.HangupPos != null && iVRContinueQueue.HangupPos != ivr && iVRContinueQueue.HangupPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.HangupPos);
- }
- if (iVRContinueQueue.SuccessPos != null && iVRContinueQueue.SuccessPos != ivr && iVRContinueQueue.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.SuccessPos);
- }
- }
- else if (ivr.GetType() == typeof(IVRCancelQueue))
- {
- var iVRCancelQueue = (ivr as IVRCancelQueue);
- if (iVRCancelQueue.Next != null && iVRCancelQueue.Next != ivr && iVRCancelQueue.Next.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCancelQueue.Next);
- }
- }
- else if (ivr.GetType() == typeof(IVRTurnagent))
- {
- var iVRTurnagent = (ivr as IVRTurnagent);
- if (iVRTurnagent.FailPos != null && iVRTurnagent.FailPos != ivr && iVRTurnagent.FailPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTurnagent.FailPos);
- }
- if (iVRTurnagent.HangupPos != null && iVRTurnagent.HangupPos != ivr && iVRTurnagent.HangupPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTurnagent.HangupPos);
- }
- if (iVRTurnagent.SuccessPos != null && iVRTurnagent.SuccessPos != ivr && iVRTurnagent.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTurnagent.SuccessPos);
- }
- }
- else if (ivr.GetType() == typeof(IVRCompare))
- {
- var iVRCompare = (ivr as IVRCompare);
- if (iVRCompare.TruePos != null && iVRCompare.TruePos != ivr && iVRCompare.TruePos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCompare.TruePos);
- }
- if (iVRCompare.FalsePos != null && iVRCompare.FalsePos != ivr && iVRCompare.FalsePos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCompare.FalsePos);
- }
- }
- else if (ivr.GetType() == typeof(IVRCalculate))
- {
- var iVRCalculate = (ivr as IVRCalculate);
- if (iVRCalculate.Next != null && iVRCalculate.Next != ivr && iVRCalculate.Next.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCalculate.Next);
- }
- }
- else if (ivr.GetType() == typeof(IVRStringop))
- {
- var iVRStringop = (ivr as IVRStringop);
- if (iVRStringop.Next != null && iVRStringop.Next != ivr && iVRStringop.Next.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.Next);
- }
- if (iVRStringop.TruePos != null && iVRStringop.TruePos != ivr && iVRStringop.TruePos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.TruePos);
- }
- if (iVRStringop.FalsePos != null && iVRStringop.FalsePos != ivr && iVRStringop.FalsePos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.FalsePos);
- }
- }
- else if (ivr.GetType() == typeof(IVRSql))
- {
- var iVRSql = (ivr as IVRSql);
- if (iVRSql.SuccessPos != null && iVRSql.SuccessPos != ivr && iVRSql.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSql.SuccessPos);
- }
- if (iVRSql.FailPos != null && iVRSql.FailPos != ivr && iVRSql.FailPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSql.FailPos);
- }
- }
- else if (ivr.GetType() == typeof(IVRRecordSet))
- {
- var iVRRecordSet = (ivr as IVRRecordSet);
- if (iVRRecordSet.LPos != null && iVRRecordSet.LPos != ivr && iVRRecordSet.LPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.LPos);
- }
- if (iVRRecordSet.EPos != null && iVRRecordSet.EPos != ivr && iVRRecordSet.EPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.EPos);
- }
- if (iVRRecordSet.GPos != null && iVRRecordSet.GPos != ivr && iVRRecordSet.GPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.GPos);
- }
- }
- else if (ivr.GetType() == typeof(IVRTimer))
- {
- var iVRTimer = (ivr as IVRTimer);
- if (iVRTimer.Next != null && iVRTimer.Next != ivr && iVRTimer.Next.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTimer.Next);
- }
- }
- else if (ivr.GetType() == typeof(IVRBranch))
- {
- var iVRBranch = (ivr as IVRBranch);
- if (iVRBranch.DefaultPos != null && iVRBranch.DefaultPos != ivr && iVRBranch.DefaultPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRBranch.DefaultPos);
- }
- foreach (IVRBranchVar branch in iVRBranch.Branch)
- {
- if (branch.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, GlobalController._SelectCanvas.NodeList.Where(a => a.ID == branch.Pos).First());
- }
- }
- }
- else if (ivr.GetType() == typeof(IVRSocket))
- {
- var iVRSocket = (ivr as IVRSocket);
- if (iVRSocket.SuccessPos != null && iVRSocket.SuccessPos != ivr && iVRSocket.SuccessPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSocket.SuccessPos);
- }
- if (iVRSocket.FailPos != null && iVRSocket.FailPos != ivr && iVRSocket.FailPos.Pos != "0")
- {
- GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSocket.FailPos);
- }
- }
- }
-
-
- }
- #endregion
- #region 创建流程编辑器
- private void CreateIVRFlow(IVRFlowType flowType)
- {
- TabPage tab1 = new TabPage();
- tab1.Tag = flowType;
- // if( GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].)
- foreach (TabPage p in GlobalController._SelectTabControl.Controls)
- {
- if (p.Tag.ToString() == flowType.ToString() && flowType == IVRFlowType.normal)
- {
- MessageBox.Show("每个流程文件中只允许有一个普通流程!");
- return;
- }
- if (p.Tag.ToString() == flowType.ToString() && flowType == IVRFlowType.sub)
- {
- MessageBox.Show("每个流程文件中只允许有一个子流程!");
- return;
- }
- }
- FlowEditorCanvas f = new FlowEditorCanvas();
- f.Dock = DockStyle.Fill;
- f.MouseUp += new MouseEventHandler(f_MouseUp);
- f.MouseMove += new MouseEventHandler(f_MouseMove);
- f.Name = GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Count.ToString();
- tab1.Text = (typeof(IVRFlowType).GetField(flowType.ToString()).GetCustomAttributes(false).Last() as DescriptionAttribute).Description;
-
- GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID = f.Name, FlowName = tab1.Text });
- tab1.Controls.Add(f);
- GlobalController._SelectTabControl.Controls.Add(tab1);
- GlobalController._SelectTabControl.SelectedTab = tab1;
- GlobalController._SelectCanvas = f;
- }
- #endregion
- /// <summary>
- /// 双击IVR控件打开IVR控件属性窗口
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void Control_DoubleClick(object sender, EventArgs e)
- {
- ShowNodeProperty((sender as FlowNodeControl).FlowNode);
-
- }
- /// <summary>
- /// 鼠标移动 改变鼠标形状
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void f_MouseMove(object sender, MouseEventArgs e)
- {
- if (GlobalController.CheckCreateNode())
- Cursor = Cursors.SizeAll;
- else
- {
- Cursor = Cursors.Arrow;
- base.OnMouseMove(e);
- }
- }
- private string _FilePath;
- /// <summary>
- /// 菜单栏菜单事件处理
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- switch ((sender as ToolStripItem).Text)
- {
- case "新建项目":
- CreateBaseTabPage(); break;
- case "子流程": CreateIVRFlow(IVRFlowType.sub); break;
- case "普通流程": CreateIVRFlow(IVRFlowType.normal); break;
- case "自动流程": CreateIVRFlow(IVRFlowType.auto); break;
- case "打开":
- case "打开(Ctrl+O)":
- KeyAndMenuHandle("Control O"); break;
- case "保存":
- case "保存(Ctrl+S)":
- KeyAndMenuHandle("Control S"); break;
- case "另存":
- /* SaveFileDialog svf = new SaveFileDialog();
- svf.Filter= "XML文件|*.xml";
- if(svf.ShowDialog()== System.Windows.Forms.DialogResult.OK)
- {
- //这里填写保存的位置和数据
- }*///2017-4-27注释掉Control SAVEAS
- KeyAndMenuHandle("Control SAVEAS");
- break;
- case "删除当前流程":
- if (MessageBox.Show("确定要删除" + GlobalController._SelectTabControl.SelectedTab.Text + "吗?", "消息提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
- {
- GlobalController._SelectTabControl.Controls.Remove(GlobalController._SelectTabControl.SelectedTab);
- }
- break;
- case "关闭当前项目":
- this.tabControl1.Controls.Remove(this.tabControl1.SelectedTab);
- //GlobalController._SelectTabControl.Controls.Remove(GlobalController._SelectTabControl.SelectedTab);
- //GlobalController.IVRCancas.Remove(this.tabControl1.SelectedTab.Name);
- break;
- case "退出": Application.Exit(); break;
-
- }
- }
-
- /// <summary>
- /// 双击流程树形结构
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- GlobalController._SelectTabControl.SelectedTab = (e.Node.Tag as TabPage);
- this.treeView1.SelectedNode = e.Node;
- }
- private void ctlMenu1_Load(object sender, EventArgs e)
- {
- }
- }
- }
|