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; using IVRFlowEditor.IVRControlUtility; namespace IVRFlowUI { public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); CreateBaseTabPage(); _Menu = new System.Windows.Forms.ContextMenu(); BindRightMeun(); BindSelectContextMenuControl(); BindPic(); } //2017-5-11绑定图标 #region 绑定图标 Dictionary NodePic = new Dictionary(); private void BindPic() { #region 2019-7-25 注释掉 NodePic.Add("开始", "answer.gif"); NodePic.Add("外呼号码", "dial.gif"); NodePic.Add("呼叫转移", "trans.gif"); NodePic.Add("变量", "var.gif"); NodePic.Add("跳转子流程", "SubFlow.gif"); NodePic.Add("放音收按键", "dtmf.gif"); NodePic.Add("传真发送", "StringOperate.gif"); NodePic.Add("传真接收", "StringOperate.gif"); NodePic.Add("留言", "record.gif"); NodePic.Add("请求排队", "WaitQueue.gif"); NodePic.Add("继续排队", "QueueWait.gif"); NodePic.Add("取消排队", "DropQueue.gif"); NodePic.Add("转人工", "CreateData.gif"); NodePic.Add("数据比较", "if.gif"); NodePic.Add("算数运算", "CountCal.gif"); NodePic.Add("分支节点", "case.gif"); NodePic.Add("字符串操作", "StringOperate.gif"); NodePic.Add("数据库读写", "DataBase.gif"); NodePic.Add("数据集映射", "ParseData.gif"); NodePic.Add("定时器", "timer.gif"); NodePic.Add("SOCKET通讯", "AskQueue.gif"); NodePic.Add("挂机", "onhook.gif"); NodePic.Add("结束", "onhook.gif"); #endregion NodePic.Add("CELL_START", "answer.gif"); NodePic.Add("CELL_CALL", "dial.gif"); NodePic.Add("CELL_TRANSFEROUT", "trans.gif"); NodePic.Add("CELL_DEFINEVAR", "var.gif"); NodePic.Add("CELL_SUBFLOW", "SubFlow.gif"); NodePic.Add("CELL_AUDIODTMF", "dtmf.gif"); NodePic.Add("CELL_SENDFAX", "StringOperate.gif"); NodePic.Add("CELL_RECVFAX", "StringOperate.gif"); NodePic.Add("CELL_LEAVEWORD", "record.gif"); NodePic.Add("CELL_QUEUE", "WaitQueue.gif"); NodePic.Add("CELL_CONTINUEQUEUE", "QueueWait.gif"); NodePic.Add("CELL_CANCELQUEUE", "DropQueue.gif"); NodePic.Add("CELL_TURNAGENT", "CreateData.gif"); NodePic.Add("CELL_COMPARE", "if.gif"); NodePic.Add("CELL_CALCULATE", "CountCal.gif"); NodePic.Add("CELL_BRANCH", "case.gif"); NodePic.Add("CELL_STRINGOP", "StringOperate.gif"); NodePic.Add("CELL_SQL", "DataBase.gif"); NodePic.Add("CELL_RECORDSET", "ParseData.gif"); NodePic.Add("CELL_TIMER", "timer.gif"); NodePic.Add("CELL_SOCKET", "AskQueue.gif"); NodePic.Add("CELL_HANGUP", "onhook.gif"); NodePic.Add("CELL_END", "onhook.gif"); } #endregion #region 绑定菜单栏事件 private ContextMenu _Menu; /// /// 绑定右键菜单 /// 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 CopyNodes; private List CopyLines; /// /// 右键菜单和快捷键转换成命令字符统一进行相应的处理的函数 /// /// private void KeyAndMenuHandle(string type) { switch (type) { case "Control C": CopyLines = CopyLines == null ? CopyLines = new List() : CopyLines; CopyLines.Clear(); CopyNodes = CopyNodes == null ? CopyNodes = new List() : 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{typeof(String),}.ToArray()); IVRControlBase o = ci.Invoke(new List{ 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 f = new List(); 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() }); //2019-7-25 注释掉 f.Add(new IVRFlowSerializerInfo() { IVR_Text = tp.Text, IVRFlowType = (IVRFlowType)tp.Tag, IVRControl = new List() }); for (int i=0;i f = new List(); 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() });//2019-7-25 注释掉 f.Add(new IVRFlowSerializerInfo() { IVR_Text = tp.Text, IVRFlowType = (IVRFlowType)tp.Tag, IVRControl = new List() }); 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 f = new List(); 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); //2017-5-11测试添加图片显示 ivrControl.Image = GlobalController.ControlImageList.Images[NodePic[ivrControl.Name ]]; 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); if (line.StartNodeID != null && line.StartNodeID != "" && line.EndNodeID != null && line.EndNodeID != "") { if (canvas.NodeList.Find(a => a.ID == line.StartNodeID) != null && 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)); } else { MessageBox.Show("流程文件中有不存在的节点"+ line.StartNodeID+ "或"+line.EndNodeID); } } } //2017-5-9 foreach (LineInfo line in ivrflow.FailLineNodes) { 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(GetNewFlowLineFail(), 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 菜单栏点击事件转换为快捷键事件 /// /// 菜单栏点击事件转换为快捷键事件 /// /// /// 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 /// /// 画布双击事件 /// /// private void flowEditorCanvas1_DoubleClick(FlowNode f) { ShowNodeProperty(f); } #region 绑定右键菜单 /// /// 绑定右键菜单 /// 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 /// /// 绑定流程的树形结构 /// /// 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; } } } /// /// 流程选择事件 /// /// /// private void tabControl_SelectedIndexChanged(object sender, EventArgs e) { BindSelectContextMenuControl(); } /// /// 捕捉鼠标按下事件 /// /// /// private void FrmMain_KeyDown(object sender, KeyEventArgs e) { KeyAndMenuHandle(e.Modifiers + " " + e.KeyCode); } #region 加载时初始化的空白页和新建空白项目时调用 /// /// 初始化的空白标签 /// 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)); //string nodekind= (sender as FlowEditorCanvas).NodeList.Max(a =>a.Control .NodeName); 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); node .Image = GlobalController.ControlImageList.Images[NodePic[node .Name]];//2017-5-11 //2017-5-8添加,用于选择下一端口时用 if (node.Note==null||node.Note == "") { node.Note = node.Name+" "+node .Pos; } GlobalController.SetCurrentCancasIVRControlBase(node); (sender as FlowEditorCanvas).AddANode(node); } } #endregion #region 创建新的连接线 /// /// 创建新连线 /// /// private FlowLine GetNewFlowLine() { FlowLine line1 = new FlowLine(); line1.LineColor = Color.Lime ; line1.SelectedLineColor = Color.Blue ; line1.LineWidth = 1; return line1; } #endregion //2017-5-9 #region 创建新的失败连接线 /// /// 创建新连线 /// /// private FlowLine GetNewFlowLineFail() { FlowLine line1 = new FlowLine(); line1.LineColor = Color.Red; line1.SelectedLineColor = Color.Blue; 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(GetNewFlowLineFail(), ivr, iVROutbound.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail } } //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(GetNewFlowLineFail(), ivr, iVROutbound.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail } } 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(GetNewFlowLineFail(), ivr, iVRAudioDTMF.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail } 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(GetNewFlowLineFail(), ivr, iVRSendfax.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail } 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(GetNewFlowLineFail(), ivr, iVRTurnagent.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail } 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(GetNewFlowLineFail(), ivr, iVRSql.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail } } 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(GetNewFlowLineFail(), ivr, iVRSocket.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail } } //2017-5-2 添加解决挂机及其下节点之间不划线的问题 else if (ivr.GetType() == typeof(IVRHangUp)) { var iVRHangup = ivr as IVRHangUp; if (iVRHangup.Next != null && iVRHangup.Next != ivr && iVRHangup.Next.Pos != "0") { GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRHangup.Next); } } } } #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 /// /// 双击IVR控件打开IVR控件属性窗口 /// /// /// void Control_DoubleClick(object sender, EventArgs e) { ShowNodeProperty((sender as FlowNodeControl).FlowNode); } /// /// 鼠标移动 改变鼠标形状 /// /// /// void f_MouseMove(object sender, MouseEventArgs e) { if (GlobalController.CheckCreateNode()) Cursor = Cursors.SizeAll; else { Cursor = Cursors.Arrow; base.OnMouseMove(e); } } private string _FilePath; /// /// 菜单栏菜单事件处理 /// /// /// 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; } } /// /// 双击流程树形结构 /// /// /// 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) { } } }