ivr流程编辑器

FrmMain.cs 53KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using HySoft.FlowEditor;
  10. using HySoft.IVRFlowEditor.Utility;
  11. using HySoft.IVRFlowEditor.IVRControl;
  12. using HySoft.IVRFlowEditor.Propretity;
  13. using System.Reflection;
  14. using HySoft.IVRFlowEditor.Model;
  15. using HySoft.IVRFlowEditor.IVRControlUtility;
  16. using IVRFlowEditor.IVRControlUtility;
  17. namespace IVRFlowUI
  18. {
  19. public partial class FrmMain : Form
  20. {
  21. public FrmMain()
  22. {
  23. InitializeComponent();
  24. CreateBaseTabPage();
  25. _Menu = new System.Windows.Forms.ContextMenu();
  26. BindRightMeun();
  27. BindSelectContextMenuControl();
  28. BindPic();
  29. }
  30. //2017-5-11绑定图标
  31. #region 绑定图标
  32. Dictionary<string, string> NodePic = new Dictionary<string, string>();
  33. private void BindPic()
  34. {
  35. #region 2019-7-25 注释掉
  36. NodePic.Add("开始", "answer.gif");
  37. NodePic.Add("外呼号码", "dial.gif");
  38. NodePic.Add("呼叫转移", "trans.gif");
  39. NodePic.Add("变量", "var.gif");
  40. NodePic.Add("跳转子流程", "SubFlow.gif");
  41. NodePic.Add("放音收按键", "dtmf.gif");
  42. NodePic.Add("传真发送", "StringOperate.gif");
  43. NodePic.Add("传真接收", "StringOperate.gif");
  44. NodePic.Add("留言", "record.gif");
  45. NodePic.Add("请求排队", "WaitQueue.gif");
  46. NodePic.Add("继续排队", "QueueWait.gif");
  47. NodePic.Add("取消排队", "DropQueue.gif");
  48. NodePic.Add("转人工", "CreateData.gif");
  49. NodePic.Add("数据比较", "if.gif");
  50. NodePic.Add("算数运算", "CountCal.gif");
  51. NodePic.Add("分支节点", "case.gif");
  52. NodePic.Add("字符串操作", "StringOperate.gif");
  53. NodePic.Add("数据库读写", "DataBase.gif");
  54. NodePic.Add("数据集映射", "ParseData.gif");
  55. NodePic.Add("定时器", "timer.gif");
  56. NodePic.Add("SOCKET通讯", "AskQueue.gif");
  57. NodePic.Add("挂机", "onhook.gif");
  58. NodePic.Add("结束", "onhook.gif");
  59. #endregion
  60. NodePic.Add("CELL_START", "answer.gif");
  61. NodePic.Add("CELL_CALL", "dial.gif");
  62. NodePic.Add("CELL_TRANSFEROUT", "trans.gif");
  63. NodePic.Add("CELL_DEFINEVAR", "var.gif");
  64. NodePic.Add("CELL_SUBFLOW", "SubFlow.gif");
  65. NodePic.Add("CELL_AUDIODTMF", "dtmf.gif");
  66. NodePic.Add("CELL_SENDFAX", "StringOperate.gif");
  67. NodePic.Add("CELL_RECVFAX", "StringOperate.gif");
  68. NodePic.Add("CELL_LEAVEWORD", "record.gif");
  69. NodePic.Add("CELL_QUEUE", "WaitQueue.gif");
  70. NodePic.Add("CELL_CONTINUEQUEUE", "QueueWait.gif");
  71. NodePic.Add("CELL_CANCELQUEUE", "DropQueue.gif");
  72. NodePic.Add("CELL_TURNAGENT", "CreateData.gif");
  73. NodePic.Add("CELL_COMPARE", "if.gif");
  74. NodePic.Add("CELL_CALCULATE", "CountCal.gif");
  75. NodePic.Add("CELL_BRANCH", "case.gif");
  76. NodePic.Add("CELL_STRINGOP", "StringOperate.gif");
  77. NodePic.Add("CELL_SQL", "DataBase.gif");
  78. NodePic.Add("CELL_RECORDSET", "ParseData.gif");
  79. NodePic.Add("CELL_TIMER", "timer.gif");
  80. NodePic.Add("CELL_SOCKET", "AskQueue.gif");
  81. NodePic.Add("CELL_HANGUP", "onhook.gif");
  82. NodePic.Add("CELL_END", "onhook.gif");
  83. }
  84. #endregion
  85. #region 绑定菜单栏事件
  86. private ContextMenu _Menu;
  87. /// <summary>
  88. /// 绑定右键菜单
  89. /// </summary>
  90. private void BindRightMeun()
  91. {
  92. MenuItem menuCheckAll = new MenuItem("全选(Ctrl+A)", new EventHandler(OnMenuItemClick));
  93. _Menu.MenuItems.Add(menuCheckAll);
  94. MenuItem menuCopy = new MenuItem("复制(Ctrl+C)", new EventHandler(OnMenuItemClick));
  95. _Menu.MenuItems.Add(menuCopy);
  96. MenuItem menuPaste = new MenuItem("粘贴(Ctrl+V)", new EventHandler(OnMenuItemClick));
  97. _Menu.MenuItems.Add(menuPaste);
  98. MenuItem menuDelete = new MenuItem("删除(Delete)", new EventHandler(OnMenuItemClick));
  99. _Menu.MenuItems.Add(menuDelete);
  100. MenuItem menuAdd = new MenuItem("放大(Ctrl++)", new EventHandler(OnMenuItemClick));
  101. _Menu.MenuItems.Add(menuAdd);
  102. MenuItem menuOemplus = new MenuItem("缩小(Ctrl+-)", new EventHandler(OnMenuItemClick));
  103. _Menu.MenuItems.Add(menuOemplus);
  104. }
  105. #endregion
  106. #region 鼠标右键菜单以及快捷键处理
  107. private List<FlowNode> CopyNodes;
  108. private List<FlowLine> CopyLines;
  109. /// <summary>
  110. /// 右键菜单和快捷键转换成命令字符统一进行相应的处理的函数
  111. /// </summary>
  112. /// <param name="type"></param>
  113. private void KeyAndMenuHandle(string type)
  114. {
  115. switch (type)
  116. {
  117. case "Control C":
  118. CopyLines = CopyLines == null ? CopyLines = new List<FlowLine>() : CopyLines;
  119. CopyLines.Clear();
  120. CopyNodes = CopyNodes == null ? CopyNodes = new List<FlowNode>() : CopyNodes;
  121. CopyNodes.Clear();
  122. if (GlobalController._SelectCanvas.SelectedLines != null)
  123. foreach (FlowLine f in GlobalController._SelectCanvas.SelectedLines)
  124. {
  125. FlowLine o = new FlowLine();
  126. o.LineColor = f.LineColor;
  127. o.Name = f.Name;
  128. o.Note = f.Note;
  129. o.SelectedLineColor = f.SelectedLineColor;
  130. o.Control.LineWidth = f.Control.LineWidth;
  131. o.HeadNodePort = f.HeadNodePort;
  132. o.TailNodePort = f.TailNodePort;
  133. CopyLines.Add(o);
  134. }
  135. if (GlobalController._SelectCanvas.SelectedNodes != null)
  136. foreach (FlowNode f in GlobalController._SelectCanvas.SelectedNodes)
  137. {
  138. ConstructorInfo ci = f.GetType().GetConstructor(new List<Type>{typeof(String),}.ToArray());
  139. IVRControlBase o = ci.Invoke(new List<object>{ f.Name+"_1"}.ToArray()) as IVRControlBase;
  140. // FlowNode o = new FlowNode(f.Size);
  141. o.Control.Size = f.Size;
  142. o.Name = f.Name + "_1";
  143. o.CenterPoint = f.CenterPoint;
  144. o.Image = f.Image;
  145. foreach (NodePort n in f.InputPortList)
  146. o.AddInputPort(n);
  147. foreach (NodePort n in f.OutputPortList)
  148. o.AddOutputPort(n);
  149. o.SelectedImage = f.SelectedImage;
  150. this.CopyNodes.Add(o);
  151. }
  152. break;
  153. case "Control A":
  154. GlobalController._SelectCanvas.SetSelectedNodes(GlobalController._SelectCanvas.NodeList.ToArray());
  155. GlobalController._SelectCanvas.SetSelectedLines(GlobalController._SelectCanvas.LineList.ToArray());
  156. break;
  157. case "Control V":
  158. if (CopyNodes != null)
  159. {
  160. foreach (IVRControlBase f in CopyNodes)
  161. {
  162. f.Pos = GlobalController._SelectCanvas.NodeList.Count.ToString();
  163. f.Control.DoubleClick += new EventHandler(Control_DoubleClick);
  164. GlobalController.SetCurrentCancasIVRControlBase(f);
  165. GlobalController._SelectCanvas.AddANode(f);
  166. }
  167. GlobalController._SelectCanvas.SetSelectedNodes(CopyNodes.ToArray());
  168. }
  169. if (CopyLines != null)
  170. {
  171. foreach (FlowLine f in CopyLines)
  172. {
  173. GlobalController._SelectCanvas.AddALine(f, this.CopyNodes.Find(a => a.InputPortList.Contains(f.HeadNodePort)), this.CopyNodes.Find(a => a.OutputPortList.Contains(f.TailNodePort)));
  174. }
  175. GlobalController._SelectCanvas.SetSelectedLines(CopyLines.ToArray());
  176. }
  177. CopyLines.Clear();
  178. CopyNodes.Clear();
  179. break;
  180. case "Control S":
  181. SaveFileDialog svf = new SaveFileDialog();
  182. svf.Filter = "XML文件|*.xml";
  183. svf.InitialDirectory = Application.StartupPath;
  184. //2017-4-26
  185. #region 直接按原文件名进行保存
  186. bool pd = false;
  187. string fp = this.tabControl1.SelectedTab.Text;
  188. if (this.tabControl1.SelectedTab.Text != "空白标签")
  189. {
  190. int ffp = fp.IndexOf(".xml");
  191. int startindex = fp.LastIndexOf("\\");
  192. int leng = ffp - startindex - 1;
  193. string fn = fp.Substring(startindex + 1, leng);
  194. svf.FileName = this.tabControl1.SelectedTab.Text;//fn;
  195. pd = true;
  196. }
  197. else
  198. {
  199. if (svf.ShowDialog() == DialogResult.OK)
  200. {
  201. pd = true;
  202. }
  203. }
  204. #endregion
  205. if(pd==true)//if (svf.ShowDialog() == DialogResult.OK)
  206. {
  207. List<IVRFlowSerializerInfo> f = new List<IVRFlowSerializerInfo>();
  208. foreach(TabPage tp in this.tabControl1.SelectedTab.Controls[0].Controls)
  209. {
  210. FlowEditorCanvas ct = (FlowEditorCanvas)tp.Controls[0];
  211. //f.Add(new IVRFlowSerializerInfo() { IVR_Name = tp.Name, IVR_Text=tp.Text, IVRFlowType = (IVRFlowType) tp.Tag, IVRControl = new List<IVRControlBase>() }); //2019-7-25 注释掉
  212. f.Add(new IVRFlowSerializerInfo() { IVR_Text = tp.Text, IVRFlowType = (IVRFlowType)tp.Tag, IVRControl = new List<IVRControlBase>() });
  213. for (int i=0;i<ct.NodeList.Count;i++)
  214. {
  215. if (ct.NodeList[i].ID!="0")
  216. f[f.Count-1].IVRControl.Add((IVRControlBase)ct.NodeList[i]);
  217. }
  218. }
  219. MessageInfo msg =GlobalController.GetSerializerHandle().SaveFileInfo(svf.FileName, f);
  220. MessageBox.Show(msg.Message);
  221. this.tabControl1.SelectedTab.Text = svf.FileName;
  222. }
  223. break;
  224. //2017-4-27
  225. case "Control SAVEAS":
  226. SaveFileDialog svfa = new SaveFileDialog();
  227. svfa.Filter = "XML文件|*.xml";
  228. svfa.InitialDirectory = Application.StartupPath;
  229. if (svfa.ShowDialog() == DialogResult.OK)
  230. {
  231. List<IVRFlowSerializerInfo> f = new List<IVRFlowSerializerInfo>();
  232. foreach (TabPage tp in this.tabControl1.SelectedTab.Controls[0].Controls)
  233. {
  234. FlowEditorCanvas ct = (FlowEditorCanvas)tp.Controls[0];
  235. //f.Add(new IVRFlowSerializerInfo() { IVR_Name = tp.Name, IVR_Text = tp.Text, IVRFlowType = (IVRFlowType)tp.Tag, IVRControl = new List<IVRControlBase>() });//2019-7-25 注释掉
  236. f.Add(new IVRFlowSerializerInfo() { IVR_Text = tp.Text, IVRFlowType = (IVRFlowType)tp.Tag, IVRControl = new List<IVRControlBase>() });
  237. for (int i = 0; i < ct.NodeList.Count; i++)
  238. {
  239. if (ct.NodeList[i].ID != "0")
  240. f[f.Count - 1].IVRControl.Add((IVRControlBase)ct.NodeList[i]);
  241. }
  242. }
  243. MessageInfo msg = GlobalController.GetSerializerHandle().SaveFileInfo(svfa.FileName, f);
  244. MessageBox.Show(msg.Message);
  245. this.tabControl1.SelectedTab.Text = svfa.FileName;
  246. }
  247. break;
  248. case "Control O":
  249. OpenFileDialog opf = new OpenFileDialog();
  250. opf.Filter = "XML文件|*.xml";
  251. opf.InitialDirectory = Application.StartupPath;
  252. if (opf.ShowDialog() == DialogResult.OK)
  253. {
  254. List<IVRFlowSerializerInfo> f = new List<IVRFlowSerializerInfo>();
  255. MessageInfo msg = GlobalController.GetSerializerHandle().OpenFileInfo(opf.FileName, ref f);
  256. if (!msg.State)
  257. {
  258. MessageBox.Show(msg.Message);
  259. return;
  260. }
  261. if (f == null || f.Count == 0)
  262. {
  263. MessageBox.Show("没有解析到数据内容!");
  264. return;
  265. }
  266. TabPage tab1 = new TabPage();
  267. tab1.Text = opf.FileName;//获取带路径的文件名
  268. //string filen = opf.SafeFileName;//不带路径的文件名(包含扩展名)
  269. //string fn = System.IO .Path.GetFileNameWithoutExtension(@opf.FileName);//不带路径的文件名(不含扩展名)
  270. tab1.Name = this.tabControl1.Controls.Count.ToString();
  271. GlobalController.IVRCancas.Remove(tab1.Name);//2017-4-27添加,解决关闭再打开同一个项目时报错的问题
  272. GlobalController.IVRCancas.Add(tab1.Name, new IVRCanvas());
  273. TabControl tb = new TabControl();
  274. tb.Dock = DockStyle.Fill;
  275. tb.Name = this.tabControl1.Controls.Count.ToString();
  276. tb.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
  277. tab1.Controls.Add(tb);
  278. this.tabControl1.Controls.Add(tab1);
  279. foreach (IVRFlowSerializerInfo ivrflow in f)
  280. {
  281. TabPage tab=new TabPage(ivrflow.IVR_Name);
  282. tab.Name =ivrflow.IVR_Name;
  283. tab.Tag = ivrflow.IVRFlowType;
  284. tab.Text = ivrflow.IVR_Text;
  285. FlowEditorCanvas canvas = new FlowEditorCanvas();
  286. canvas.Name = tab.Name = GlobalController.IVRCancas[tb.Name].IVRFlows.Count.ToString();
  287. GlobalController.IVRCancas[tb.Name].IVRFlows.Add(canvas.Name, new IVRFlowInfo() { FlowID = canvas.Name, FlowName = tab.Text });
  288. canvas.Dock = DockStyle.Fill;
  289. canvas.MouseUp += new MouseEventHandler(f_MouseUp);
  290. canvas.MouseMove += new MouseEventHandler(f_MouseMove);
  291. tab.Controls.Add(canvas);
  292. tb.Controls.Add(tab);
  293. tb.SelectedTab = tab;
  294. GlobalController._SelectTabControl = tb;
  295. GlobalController._SelectCanvas = canvas;
  296. foreach (IVRControlBase ivrControl in ivrflow.IVRControl)
  297. {
  298. ivrControl.Control.DoubleClick += new EventHandler(Control_DoubleClick);
  299. //2017-5-11测试添加图片显示
  300. ivrControl.Image = GlobalController.ControlImageList.Images[NodePic[ivrControl.Name ]];
  301. canvas.AddANode(ivrControl);
  302. GlobalController.SetCurrentCancasIVRControlBase(ivrControl);
  303. }
  304. GlobalController.SetFlowVar(ivrflow.IVRVar);
  305. foreach (LineInfo line in ivrflow.LineNodes)
  306. {
  307. if (canvas.NodeList.Find(a => a.ID == line.StartNodeID).GetType().GetProperty(line.AttributeName) != null)
  308. 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);
  309. if (line.StartNodeID != null && line.StartNodeID != "" && line.EndNodeID != null && line.EndNodeID != "")
  310. {
  311. if (canvas.NodeList.Find(a => a.ID == line.StartNodeID) != null && canvas.NodeList.Find(a => a.ID == line.EndNodeID) != null)
  312. {
  313. canvas.AddALine(GetNewFlowLine(), canvas.NodeList.Find(a => a.ID == line.StartNodeID), canvas.NodeList.Find(a => a.ID == line.EndNodeID));
  314. }
  315. else
  316. {
  317. MessageBox.Show("流程文件中有不存在的节点"+ line.StartNodeID+ "或"+line.EndNodeID);
  318. }
  319. }
  320. }
  321. //2017-5-9
  322. foreach (LineInfo line in ivrflow.FailLineNodes)
  323. {
  324. if (canvas.NodeList.Find(a => a.ID == line.StartNodeID).GetType().GetProperty(line.AttributeName) != null)
  325. 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);
  326. if (line.StartNodeID != null && line.StartNodeID != "" && line.EndNodeID != null && line.EndNodeID != "")
  327. {
  328. if (canvas.NodeList.Find(a => a.ID == line.StartNodeID) != null && canvas.NodeList.Find(a => a.ID == line.EndNodeID) != null)
  329. {
  330. canvas.AddALine(GetNewFlowLineFail(), canvas.NodeList.Find(a => a.ID == line.StartNodeID), canvas.NodeList.Find(a => a.ID == line.EndNodeID));
  331. }
  332. else
  333. {
  334. MessageBox.Show("流程文件中有不存在的节点" + line.StartNodeID + "或" + line.EndNodeID);
  335. }
  336. }
  337. }
  338. }
  339. tb.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
  340. this.tabControl1.SelectedTab = tab1;
  341. MessageBox.Show(msg.Message);
  342. }
  343. break;
  344. case "Control Oemplus":
  345. case "Control Add":
  346. foreach (FlowLine f in GlobalController._SelectCanvas.LineList)
  347. {
  348. f.Control.LineWidth += 1;
  349. }
  350. foreach (FlowNode f in GlobalController._SelectCanvas.NodeList)
  351. {
  352. f.Control.Width += 10;
  353. f.Control.Height += 10;
  354. // canvas.ResetNodeLines(f);
  355. }
  356. this.Refresh();
  357. break;
  358. case "Control Subtract":
  359. case "Control OemMinus":
  360. foreach (FlowLine f in GlobalController._SelectCanvas.LineList)
  361. {
  362. f.Control.LineWidth += -1;
  363. }
  364. foreach (FlowNode f in GlobalController._SelectCanvas.NodeList)
  365. {
  366. f.Control.Width += -10;
  367. f.Control.Height += -10;
  368. // ResetNodeLines(f);
  369. }
  370. this.Refresh();
  371. break;
  372. case "Control ControlKey": break;
  373. case "None Delete":
  374. if (MessageBox.Show("是否要删除选中的节点?", "消息提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  375. {
  376. if (GlobalController._SelectCanvas.SelectedLines != null)
  377. foreach (FlowLine f in GlobalController._SelectCanvas.SelectedLines)
  378. {
  379. GlobalController._SelectCanvas.DelLine(f, true, true);
  380. }
  381. if (GlobalController._SelectCanvas.SelectedNodes != null)
  382. foreach (FlowNode f in GlobalController._SelectCanvas.SelectedNodes)
  383. {
  384. GlobalController._SelectCanvas.DelNode(f);
  385. GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows[GlobalController._SelectCanvas.Name].IVRFlowNode.Remove(f as IVRControlBase);
  386. }
  387. } break;
  388. default: MessageBox.Show("组合键无效!"); break;
  389. }
  390. }
  391. #region 菜单栏点击事件转换为快捷键事件
  392. /// <summary>
  393. /// 菜单栏点击事件转换为快捷键事件
  394. /// </summary>
  395. /// <param name="sender"></param>
  396. /// <param name="e"></param>
  397. public void OnMenuItemClick(object sender, EventArgs e)
  398. {
  399. switch (sender.GetType().GetProperty("Text").GetValue(sender, null).ToString())
  400. {
  401. case "全选":
  402. case "全选(Ctrl+A)":
  403. KeyAndMenuHandle("Control A"); break;
  404. case "复制":
  405. case "复制(Ctrl+C)":
  406. KeyAndMenuHandle("Control C"); break;
  407. case "粘贴":
  408. case "粘贴(Ctrl+V)":
  409. KeyAndMenuHandle("Control V"); break;
  410. case "删除":
  411. case "删除(Delete)":
  412. KeyAndMenuHandle("None Delete"); break;
  413. case "放大":
  414. case "放大(Ctrl++)":
  415. KeyAndMenuHandle("Control Oemplus"); break;
  416. case "缩小":
  417. case "缩小(Ctrl+-)":
  418. KeyAndMenuHandle("Control OemMinus"); break;
  419. }
  420. }
  421. #endregion
  422. #endregion
  423. /// <summary>
  424. /// 画布双击事件
  425. /// </summary>
  426. /// <param name="f"></param>
  427. private void flowEditorCanvas1_DoubleClick(FlowNode f)
  428. {
  429. ShowNodeProperty(f);
  430. }
  431. #region 绑定右键菜单
  432. /// <summary>
  433. /// 绑定右键菜单
  434. /// </summary>
  435. private void BindSelectContextMenuControl()
  436. {
  437. if(this.tabControl1.Controls.Count>0)
  438. foreach (Control c in this.tabControl1.SelectedTab.Controls)
  439. {
  440. if (c.GetType() == typeof(TabControl))
  441. {
  442. GlobalController._SelectTabControl = (c as TabControl);
  443. (c as TabControl).SelectedTab.Controls[0].ContextMenu = _Menu;
  444. GlobalController._SelectCanvas = ((c as TabControl).SelectedTab.Controls[0] as FlowEditorCanvas);
  445. BindTreeNodes(GlobalController._SelectTabControl.Controls);
  446. }
  447. }
  448. }
  449. #endregion
  450. /// <summary>
  451. /// 绑定流程的树形结构
  452. /// </summary>
  453. /// <param name="con"></param>
  454. private void BindTreeNodes(Control.ControlCollection con)
  455. {
  456. this.treeView1.Nodes.Clear();
  457. this.treeView1.ImageList = GlobalController.ControlImageList;
  458. TreeNode t;
  459. foreach (TabPage o in con)
  460. {
  461. switch ((IVRFlowType)o.Tag)
  462. {
  463. case IVRFlowType.auto:
  464. t = new TreeNode() { Text = o.Text, SelectedImageKey= "OverFlow.gif", ImageKey = "OverFlow.gif" };
  465. t.Tag = o;
  466. this.treeView1.Nodes.Add(t);
  467. break;
  468. case IVRFlowType.normal:
  469. t = new TreeNode() { Text = o.Text, SelectedImageKey = "RotorFlow.gif", ImageKey = "RotorFlow.gif" };
  470. t.Tag = o;
  471. this.treeView1.Nodes.Add(t);
  472. break;
  473. case IVRFlowType.sub:
  474. t = new TreeNode() { Text = o.Text, SelectedImageKey = "SubFlowOver.gif", ImageKey = "SubFlowOver.gif" };
  475. t.Tag = o;
  476. this.treeView1.Nodes.Add(t);
  477. break;
  478. }
  479. }
  480. }
  481. /// <summary>
  482. /// 流程选择事件
  483. /// </summary>
  484. /// <param name="sender"></param>
  485. /// <param name="e"></param>
  486. private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
  487. {
  488. BindSelectContextMenuControl();
  489. }
  490. /// <summary>
  491. /// 捕捉鼠标按下事件
  492. /// </summary>
  493. /// <param name="sender"></param>
  494. /// <param name="e"></param>
  495. private void FrmMain_KeyDown(object sender, KeyEventArgs e)
  496. {
  497. KeyAndMenuHandle(e.Modifiers + " " + e.KeyCode);
  498. }
  499. #region 加载时初始化的空白页和新建空白项目时调用
  500. /// <summary>
  501. /// 初始化的空白标签
  502. /// </summary>
  503. public void CreateBaseTabPage()
  504. {
  505. TabPage t = new TabPage() { Dock = DockStyle.Fill };
  506. t.Text = "空白标签";
  507. this.tabControl1.Controls.Add(t);
  508. this.tabControl1.SelectedTab = t;
  509. TabControl tab = new TabControl() { Dock = DockStyle.Fill };
  510. tab.Name = GlobalController.IVRCancas.Count.ToString();
  511. GlobalController.IVRCancas.Add(tab.Name, new IVRCanvas());
  512. tab.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
  513. TabPage tab1 = new TabPage();
  514. FlowEditorCanvas f = new FlowEditorCanvas(); GlobalController._SelectCanvas = f;
  515. f.Dock = DockStyle.Fill;
  516. f.MouseUp += new MouseEventHandler(f_MouseUp);
  517. f.MouseMove += new MouseEventHandler(f_MouseMove);
  518. tab1.Controls.Add(f);
  519. tab1.Tag = IVRFlowType.normal;
  520. tab1.Text = "普通流程";
  521. f.Name = GlobalController.IVRCancas[tab.Name].IVRFlows.Count.ToString();
  522. GlobalController.IVRCancas[tab.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID=f.Name, FlowName=tab1.Text});
  523. TabPage tab2 = new TabPage();
  524. f = new FlowEditorCanvas();
  525. f.Dock = DockStyle.Fill;
  526. f.MouseUp += new MouseEventHandler(f_MouseUp);
  527. f.MouseMove += new MouseEventHandler(f_MouseMove);
  528. tab2.Controls.Add(f);
  529. tab2.Text = "自动流程";
  530. tab2.Tag = IVRFlowType.auto;
  531. f.Name = GlobalController.IVRCancas[tab.Name].IVRFlows.Count.ToString();
  532. GlobalController.IVRCancas[tab.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID = f.Name, FlowName = tab2.Text });
  533. TabPage tab3 = new TabPage();
  534. f = new FlowEditorCanvas();
  535. f.Dock = DockStyle.Fill;
  536. f.MouseUp += new MouseEventHandler(f_MouseUp);
  537. f.MouseMove += new MouseEventHandler(f_MouseMove);
  538. f.Name = GlobalController.IVRCancas[tab.Name].IVRFlows.Count.ToString();
  539. tab3.Text = "子流程";
  540. GlobalController.IVRCancas[tab.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID = f.Name, FlowName = tab3.Text });
  541. tab3.Controls.Add(f);
  542. tab3.Tag = IVRFlowType.sub;
  543. t.Controls.Add(tab);
  544. tab.Controls.Add(tab1);
  545. tab.Controls.Add(tab2);
  546. tab.Controls.Add(tab3);
  547. BindTreeNodes(tab.Controls);
  548. tab.SelectedTab = tab1;
  549. GlobalController._SelectTabControl = tab;
  550. }
  551. #endregion
  552. #region 鼠标弹起事件,监测是否创建控件以及创建控件
  553. void f_MouseUp(object sender, MouseEventArgs e)
  554. {
  555. if (GlobalController.CheckCreateNode())
  556. {
  557. int id=0;
  558. if((sender as FlowEditorCanvas).NodeList!=null&&(sender as FlowEditorCanvas).NodeList.Count!=0)
  559. id = (sender as FlowEditorCanvas).NodeList.Max(a =>Int32.Parse(a.ID));
  560. //string nodekind= (sender as FlowEditorCanvas).NodeList.Max(a =>a.Control .NodeName);
  561. IVRControlBase node = GlobalController.CreateNode((id+1).ToString());
  562. node.Pos = (id + 1).ToString();
  563. Point p = new Point(0, 0);
  564. p = (sender as FlowEditorCanvas).PointToClient(p);
  565. Point CurcorPoint = new Point(Cursor.Position.X + p.X, Cursor.Position.Y + p.Y);
  566. node.CenterPoint = CurcorPoint;
  567. node.Control.DoubleClick += new EventHandler(Control_DoubleClick);
  568. node .Image = GlobalController.ControlImageList.Images[NodePic[node .Name]];//2017-5-11
  569. //2017-5-8添加,用于选择下一端口时用
  570. if (node.Note==null||node.Note == "")
  571. {
  572. node.Note = node.Name+" "+node .Pos;
  573. }
  574. GlobalController.SetCurrentCancasIVRControlBase(node);
  575. (sender as FlowEditorCanvas).AddANode(node);
  576. }
  577. }
  578. #endregion
  579. #region 创建新的连接线
  580. /// <summary>
  581. /// 创建新连线
  582. /// </summary>
  583. /// <returns></returns>
  584. private FlowLine GetNewFlowLine()
  585. {
  586. FlowLine line1 = new FlowLine();
  587. line1.LineColor = Color.Lime ;
  588. line1.SelectedLineColor = Color.Blue ;
  589. line1.LineWidth = 1;
  590. return line1;
  591. }
  592. #endregion
  593. //2017-5-9
  594. #region 创建新的失败连接线
  595. /// <summary>
  596. /// 创建新连线
  597. /// </summary>
  598. /// <returns></returns>
  599. private FlowLine GetNewFlowLineFail()
  600. {
  601. FlowLine line1 = new FlowLine();
  602. line1.LineColor = Color.Red;
  603. line1.SelectedLineColor = Color.Blue;
  604. line1.LineWidth = 1;
  605. return line1;
  606. }
  607. #endregion
  608. #region 遍历所有IVR控件并根据控件类型显示不同的属性并在确定后重绘
  609. private void ShowNodeProperty(FlowNode obj)
  610. {
  611. var ivr = (obj as IVRControlBase);
  612. var ctl=ivr.CtlProperty;
  613. ivr.IVRFlows = GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Values.ToList();
  614. FrmProPretity frm = new FrmProPretity(ref ivr);
  615. frm.Text = ivr.Name;
  616. if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  617. {
  618. if (ivr.InputPortList != null)
  619. for (int i = ivr.InputPortList.Count; i > 0; i--)
  620. {
  621. GlobalController._SelectCanvas.DelLine(ivr.InputPortList[i-1].Line, true, true);
  622. ivr.RemoveInputPort(ivr.InputPortList[i-1]);
  623. }
  624. if (ivr.GetType() == typeof(IVRStartNode))
  625. {
  626. var iVRStartNode = ivr as IVRStartNode;
  627. if (iVRStartNode.Next != null && iVRStartNode.Next != ivr && iVRStartNode.Next.Pos != "0")
  628. {
  629. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStartNode.Next);
  630. }
  631. }
  632. else if (ivr.GetType() == typeof(IVRTransfeOut))//ivr.GetType() == typeof(IVROutbound)||//2017-4-27修改
  633. {
  634. var iVROutbound = ivr as IVRTransfeOut;
  635. if (iVROutbound.SuccessPos != null && iVROutbound.SuccessPos != ivr && iVROutbound.SuccessPos.Pos != "0")
  636. {
  637. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVROutbound.SuccessPos);
  638. }
  639. if (iVROutbound.FailPos != null && iVROutbound.FailPos != ivr && iVROutbound.FailPos.Pos != "0")
  640. {
  641. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVROutbound.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  642. }
  643. }
  644. //2017-4-27 添加
  645. else if (ivr.GetType() == typeof(IVROutbound))
  646. {
  647. var iVROutbound = ivr as IVROutbound;
  648. if (iVROutbound.SuccessPos != null && iVROutbound.SuccessPos != ivr && iVROutbound.SuccessPos.Pos != "0")
  649. {
  650. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVROutbound.SuccessPos);
  651. }
  652. if (iVROutbound.FailPos != null && iVROutbound.FailPos != ivr && iVROutbound.FailPos.Pos != "0")
  653. {
  654. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVROutbound.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  655. }
  656. }
  657. else if (ivr.GetType() == typeof(IVRDefinevar))
  658. {
  659. var iVRDefinevar = (ivr as IVRDefinevar);
  660. if (iVRDefinevar.Next != null && iVRDefinevar.Next != ivr && iVRDefinevar.Next.Pos != "0")
  661. {
  662. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRDefinevar.Next);
  663. }
  664. }
  665. else if (ivr.GetType() == typeof(IVRSubflow))
  666. {
  667. var iVRSubflow = (ivr as IVRSubflow);
  668. if (iVRSubflow.Next != null && iVRSubflow.Next != ivr && iVRSubflow.Next.Pos != "0")
  669. {
  670. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSubflow.Next);
  671. }
  672. }
  673. else if (ivr.GetType() == typeof(IVRAudioDTMF))
  674. {
  675. var iVRAudioDTMF = (ivr as IVRAudioDTMF);
  676. if (iVRAudioDTMF.SuccessPos != null && iVRAudioDTMF.SuccessPos != ivr && iVRAudioDTMF.SuccessPos.Pos != "0")
  677. {
  678. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRAudioDTMF.SuccessPos);
  679. }
  680. if (iVRAudioDTMF.FailPos != null && iVRAudioDTMF.FailPos != ivr && iVRAudioDTMF.FailPos.Pos != "0")
  681. {
  682. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRAudioDTMF.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  683. }
  684. if (iVRAudioDTMF.HangupPos != null && iVRAudioDTMF.HangupPos != ivr && iVRAudioDTMF.HangupPos.Pos != "0")
  685. {
  686. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRAudioDTMF.HangupPos);
  687. }
  688. }
  689. else if (ivr.GetType() == typeof(IVRSendfax) || ivr.GetType() == typeof(IVRRecvfax))
  690. {
  691. var iVRSendfax = (ivr as IVRSendfax);
  692. if (iVRSendfax.SuccessPos != null && iVRSendfax.SuccessPos != ivr && iVRSendfax.SuccessPos.Pos != "0")
  693. {
  694. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSendfax.SuccessPos);
  695. }
  696. if (iVRSendfax.FailPos != null && iVRSendfax.FailPos != ivr && iVRSendfax.FailPos.Pos != "0")
  697. {
  698. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRSendfax.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  699. }
  700. if (iVRSendfax.HangupPos != null && iVRSendfax.HangupPos != ivr && iVRSendfax.HangupPos.Pos != "0")
  701. {
  702. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSendfax.HangupPos);
  703. }
  704. }
  705. else if (ivr.GetType() == typeof(IVRLeaveWord))
  706. {
  707. var iVRLeaveWord = (ivr as IVRLeaveWord);
  708. if (iVRLeaveWord.TimeoutPos != null && iVRLeaveWord.TimeoutPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
  709. {
  710. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.TimeoutPos);
  711. }
  712. if (iVRLeaveWord.HangupPos != null && iVRLeaveWord.HangupPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
  713. {
  714. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.HangupPos);
  715. }
  716. if (iVRLeaveWord.FinishPos != null && iVRLeaveWord.FinishPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
  717. {
  718. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.FinishPos);
  719. }
  720. }
  721. else if (ivr.GetType() == typeof(IVRQueue))
  722. {
  723. var iVRQueue = (ivr as IVRQueue);
  724. if (iVRQueue.HangupPos != null && iVRQueue.HangupPos != ivr && iVRQueue.HangupPos.Pos != "0")
  725. {
  726. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.HangupPos);
  727. }
  728. if (iVRQueue.SuccessPos != null && iVRQueue.SuccessPos != ivr && iVRQueue.SuccessPos.Pos != "0")
  729. {
  730. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.SuccessPos);
  731. }
  732. if (iVRQueue.NoAgentPos != null && iVRQueue.NoAgentPos != ivr && iVRQueue.NoAgentPos.Pos != "0")
  733. {
  734. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.NoAgentPos);
  735. }
  736. if (iVRQueue.NoFreePos != null && iVRQueue.NoFreePos != ivr && iVRQueue.NoFreePos.Pos != "0")
  737. {
  738. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.NoFreePos);
  739. }
  740. }
  741. else if (ivr.GetType() == typeof(IVRContinueQueue))
  742. {
  743. var iVRContinueQueue = (ivr as IVRContinueQueue);
  744. if (iVRContinueQueue.TimeoutPos != null && iVRContinueQueue.TimeoutPos != ivr && iVRContinueQueue.TimeoutPos.Pos != "0")
  745. {
  746. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.TimeoutPos);
  747. }
  748. if (iVRContinueQueue.HangupPos != null && iVRContinueQueue.HangupPos != ivr && iVRContinueQueue.HangupPos.Pos != "0")
  749. {
  750. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.HangupPos);
  751. }
  752. if (iVRContinueQueue.SuccessPos != null && iVRContinueQueue.SuccessPos != ivr && iVRContinueQueue.SuccessPos.Pos != "0")
  753. {
  754. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.SuccessPos);
  755. }
  756. }
  757. else if (ivr.GetType() == typeof(IVRCancelQueue))
  758. {
  759. var iVRCancelQueue = (ivr as IVRCancelQueue);
  760. if (iVRCancelQueue.Next != null && iVRCancelQueue.Next != ivr && iVRCancelQueue.Next.Pos != "0")
  761. {
  762. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCancelQueue.Next);
  763. }
  764. }
  765. else if (ivr.GetType() == typeof(IVRTurnagent))
  766. {
  767. var iVRTurnagent = (ivr as IVRTurnagent);
  768. if (iVRTurnagent.FailPos != null && iVRTurnagent.FailPos != ivr && iVRTurnagent.FailPos.Pos != "0")
  769. {
  770. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRTurnagent.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  771. }
  772. if (iVRTurnagent.HangupPos != null && iVRTurnagent.HangupPos != ivr && iVRTurnagent.HangupPos.Pos != "0")
  773. {
  774. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTurnagent.HangupPos);
  775. }
  776. if (iVRTurnagent.SuccessPos != null && iVRTurnagent.SuccessPos != ivr && iVRTurnagent.SuccessPos.Pos != "0")
  777. {
  778. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTurnagent.SuccessPos);
  779. }
  780. }
  781. else if (ivr.GetType() == typeof(IVRCompare))
  782. {
  783. var iVRCompare = (ivr as IVRCompare);
  784. if (iVRCompare.TruePos != null && iVRCompare.TruePos != ivr && iVRCompare.TruePos.Pos != "0")
  785. {
  786. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCompare.TruePos);
  787. }
  788. if (iVRCompare.FalsePos != null && iVRCompare.FalsePos != ivr && iVRCompare.FalsePos.Pos != "0")
  789. {
  790. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCompare.FalsePos);
  791. }
  792. }
  793. else if (ivr.GetType() == typeof(IVRCalculate))
  794. {
  795. var iVRCalculate = (ivr as IVRCalculate);
  796. if (iVRCalculate.Next != null && iVRCalculate.Next != ivr && iVRCalculate.Next.Pos != "0")
  797. {
  798. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCalculate.Next);
  799. }
  800. }
  801. else if (ivr.GetType() == typeof(IVRStringop))
  802. {
  803. var iVRStringop = (ivr as IVRStringop);
  804. if (iVRStringop.Next != null && iVRStringop.Next != ivr && iVRStringop.Next.Pos != "0")
  805. {
  806. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.Next);
  807. }
  808. if (iVRStringop.TruePos != null && iVRStringop.TruePos != ivr && iVRStringop.TruePos.Pos != "0")
  809. {
  810. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.TruePos);
  811. }
  812. if (iVRStringop.FalsePos != null && iVRStringop.FalsePos != ivr && iVRStringop.FalsePos.Pos != "0")
  813. {
  814. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.FalsePos);
  815. }
  816. }
  817. else if (ivr.GetType() == typeof(IVRSql))
  818. {
  819. var iVRSql = (ivr as IVRSql);
  820. if (iVRSql.SuccessPos != null && iVRSql.SuccessPos != ivr && iVRSql.SuccessPos.Pos != "0")
  821. {
  822. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSql.SuccessPos);
  823. }
  824. if (iVRSql.FailPos != null && iVRSql.FailPos != ivr && iVRSql.FailPos.Pos != "0")
  825. {
  826. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRSql.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  827. }
  828. }
  829. else if (ivr.GetType() == typeof(IVRRecordSet))
  830. {
  831. var iVRRecordSet = (ivr as IVRRecordSet);
  832. if (iVRRecordSet.LPos != null && iVRRecordSet.LPos != ivr && iVRRecordSet.LPos.Pos != "0")
  833. {
  834. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.LPos);
  835. }
  836. if (iVRRecordSet.EPos != null && iVRRecordSet.EPos != ivr && iVRRecordSet.EPos.Pos != "0")
  837. {
  838. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.EPos);
  839. }
  840. if (iVRRecordSet.GPos != null && iVRRecordSet.GPos != ivr && iVRRecordSet.GPos.Pos != "0")
  841. {
  842. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.GPos);
  843. }
  844. }
  845. else if (ivr.GetType() == typeof(IVRTimer))
  846. {
  847. var iVRTimer = (ivr as IVRTimer);
  848. if (iVRTimer.Next != null && iVRTimer.Next != ivr && iVRTimer.Next.Pos != "0")
  849. {
  850. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTimer.Next);
  851. }
  852. }
  853. else if (ivr.GetType() == typeof(IVRBranch))
  854. {
  855. var iVRBranch = (ivr as IVRBranch);
  856. if (iVRBranch.DefaultPos != null && iVRBranch.DefaultPos != ivr && iVRBranch.DefaultPos.Pos != "0")
  857. {
  858. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRBranch.DefaultPos);
  859. }
  860. foreach (IVRBranchVar branch in iVRBranch.Branch)
  861. {
  862. if (branch.Pos != "0")
  863. {
  864. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, GlobalController._SelectCanvas.NodeList.Where(a => a.ID == branch.Pos).First());
  865. }
  866. }
  867. }
  868. else if (ivr.GetType() == typeof(IVRSocket))
  869. {
  870. var iVRSocket = (ivr as IVRSocket);
  871. if (iVRSocket.SuccessPos != null && iVRSocket.SuccessPos != ivr && iVRSocket.SuccessPos.Pos != "0")
  872. {
  873. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSocket.SuccessPos);
  874. }
  875. if (iVRSocket.FailPos != null && iVRSocket.FailPos != ivr && iVRSocket.FailPos.Pos != "0")
  876. {
  877. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRSocket.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  878. }
  879. }
  880. //2017-5-2 添加解决挂机及其下节点之间不划线的问题
  881. else if (ivr.GetType() == typeof(IVRHangUp))
  882. {
  883. var iVRHangup = ivr as IVRHangUp;
  884. if (iVRHangup.Next != null && iVRHangup.Next != ivr && iVRHangup.Next.Pos != "0")
  885. {
  886. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRHangup.Next);
  887. }
  888. }
  889. }
  890. }
  891. #endregion
  892. #region 创建流程编辑器
  893. private void CreateIVRFlow(IVRFlowType flowType)
  894. {
  895. TabPage tab1 = new TabPage();
  896. tab1.Tag = flowType;
  897. // if( GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].)
  898. foreach (TabPage p in GlobalController._SelectTabControl.Controls)
  899. {
  900. if (p.Tag.ToString() == flowType.ToString() && flowType == IVRFlowType.normal)
  901. {
  902. MessageBox.Show("每个流程文件中只允许有一个普通流程!");
  903. return;
  904. }
  905. if (p.Tag.ToString() == flowType.ToString() && flowType == IVRFlowType.sub)
  906. {
  907. MessageBox.Show("每个流程文件中只允许有一个子流程!");
  908. return;
  909. }
  910. }
  911. FlowEditorCanvas f = new FlowEditorCanvas();
  912. f.Dock = DockStyle.Fill;
  913. f.MouseUp += new MouseEventHandler(f_MouseUp);
  914. f.MouseMove += new MouseEventHandler(f_MouseMove);
  915. f.Name = GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Count.ToString();
  916. tab1.Text = (typeof(IVRFlowType).GetField(flowType.ToString()).GetCustomAttributes(false).Last() as DescriptionAttribute).Description;
  917. GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID = f.Name, FlowName = tab1.Text });
  918. tab1.Controls.Add(f);
  919. GlobalController._SelectTabControl.Controls.Add(tab1);
  920. GlobalController._SelectTabControl.SelectedTab = tab1;
  921. GlobalController._SelectCanvas = f;
  922. }
  923. #endregion
  924. /// <summary>
  925. /// 双击IVR控件打开IVR控件属性窗口
  926. /// </summary>
  927. /// <param name="sender"></param>
  928. /// <param name="e"></param>
  929. void Control_DoubleClick(object sender, EventArgs e)
  930. {
  931. ShowNodeProperty((sender as FlowNodeControl).FlowNode);
  932. }
  933. /// <summary>
  934. /// 鼠标移动 改变鼠标形状
  935. /// </summary>
  936. /// <param name="sender"></param>
  937. /// <param name="e"></param>
  938. void f_MouseMove(object sender, MouseEventArgs e)
  939. {
  940. if (GlobalController.CheckCreateNode())
  941. Cursor = Cursors.SizeAll;
  942. else
  943. {
  944. Cursor = Cursors.Arrow;
  945. base.OnMouseMove(e);
  946. }
  947. }
  948. private string _FilePath;
  949. /// <summary>
  950. /// 菜单栏菜单事件处理
  951. /// </summary>
  952. /// <param name="sender"></param>
  953. /// <param name="e"></param>
  954. private void ToolStripMenuItem_Click(object sender, EventArgs e)
  955. {
  956. switch ((sender as ToolStripItem).Text)
  957. {
  958. case "新建项目":
  959. CreateBaseTabPage(); break;
  960. case "子流程": CreateIVRFlow(IVRFlowType.sub); break;
  961. case "普通流程": CreateIVRFlow(IVRFlowType.normal); break;
  962. case "自动流程": CreateIVRFlow(IVRFlowType.auto); break;
  963. case "打开":
  964. case "打开(Ctrl+O)":
  965. KeyAndMenuHandle("Control O"); break;
  966. case "保存":
  967. case "保存(Ctrl+S)":
  968. KeyAndMenuHandle("Control S"); break;
  969. case "另存":
  970. /* SaveFileDialog svf = new SaveFileDialog();
  971. svf.Filter= "XML文件|*.xml";
  972. if(svf.ShowDialog()== System.Windows.Forms.DialogResult.OK)
  973. {
  974. //这里填写保存的位置和数据
  975. }*///2017-4-27注释掉Control SAVEAS
  976. KeyAndMenuHandle("Control SAVEAS");
  977. break;
  978. case "删除当前流程":
  979. if (MessageBox.Show("确定要删除" + GlobalController._SelectTabControl.SelectedTab.Text + "吗?", "消息提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  980. {
  981. GlobalController._SelectTabControl.Controls.Remove(GlobalController._SelectTabControl.SelectedTab);
  982. }
  983. break;
  984. case "关闭当前项目":
  985. this.tabControl1.Controls.Remove(this.tabControl1.SelectedTab);
  986. //GlobalController._SelectTabControl.Controls.Remove(GlobalController._SelectTabControl.SelectedTab);
  987. //GlobalController.IVRCancas.Remove(this.tabControl1.SelectedTab.Name);
  988. break;
  989. case "退出": Application.Exit(); break;
  990. }
  991. }
  992. /// <summary>
  993. /// 双击流程树形结构
  994. /// </summary>
  995. /// <param name="sender"></param>
  996. /// <param name="e"></param>
  997. private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  998. {
  999. GlobalController._SelectTabControl.SelectedTab = (e.Node.Tag as TabPage);
  1000. this.treeView1.SelectedNode = e.Node;
  1001. }
  1002. private void ctlMenu1_Load(object sender, EventArgs e)
  1003. {
  1004. }
  1005. }
  1006. }