ivr流程编辑器

FrmMain.cs 53KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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. canvas.AddALine(GetNewFlowLineFail(), canvas.NodeList.Find(a => a.ID == line.StartNodeID), canvas.NodeList.Find(a => a.ID == line.EndNodeID));
  327. }
  328. }
  329. tb.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
  330. this.tabControl1.SelectedTab = tab1;
  331. MessageBox.Show(msg.Message);
  332. }
  333. break;
  334. case "Control Oemplus":
  335. case "Control Add":
  336. foreach (FlowLine f in GlobalController._SelectCanvas.LineList)
  337. {
  338. f.Control.LineWidth += 1;
  339. }
  340. foreach (FlowNode f in GlobalController._SelectCanvas.NodeList)
  341. {
  342. f.Control.Width += 10;
  343. f.Control.Height += 10;
  344. // canvas.ResetNodeLines(f);
  345. }
  346. this.Refresh();
  347. break;
  348. case "Control Subtract":
  349. case "Control OemMinus":
  350. foreach (FlowLine f in GlobalController._SelectCanvas.LineList)
  351. {
  352. f.Control.LineWidth += -1;
  353. }
  354. foreach (FlowNode f in GlobalController._SelectCanvas.NodeList)
  355. {
  356. f.Control.Width += -10;
  357. f.Control.Height += -10;
  358. // ResetNodeLines(f);
  359. }
  360. this.Refresh();
  361. break;
  362. case "Control ControlKey": break;
  363. case "None Delete":
  364. if (MessageBox.Show("是否要删除选中的节点?", "消息提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  365. {
  366. if (GlobalController._SelectCanvas.SelectedLines != null)
  367. foreach (FlowLine f in GlobalController._SelectCanvas.SelectedLines)
  368. {
  369. GlobalController._SelectCanvas.DelLine(f, true, true);
  370. }
  371. if (GlobalController._SelectCanvas.SelectedNodes != null)
  372. foreach (FlowNode f in GlobalController._SelectCanvas.SelectedNodes)
  373. {
  374. GlobalController._SelectCanvas.DelNode(f);
  375. GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows[GlobalController._SelectCanvas.Name].IVRFlowNode.Remove(f as IVRControlBase);
  376. }
  377. } break;
  378. default: MessageBox.Show("组合键无效!"); break;
  379. }
  380. }
  381. #region 菜单栏点击事件转换为快捷键事件
  382. /// <summary>
  383. /// 菜单栏点击事件转换为快捷键事件
  384. /// </summary>
  385. /// <param name="sender"></param>
  386. /// <param name="e"></param>
  387. public void OnMenuItemClick(object sender, EventArgs e)
  388. {
  389. switch (sender.GetType().GetProperty("Text").GetValue(sender, null).ToString())
  390. {
  391. case "全选":
  392. case "全选(Ctrl+A)":
  393. KeyAndMenuHandle("Control A"); break;
  394. case "复制":
  395. case "复制(Ctrl+C)":
  396. KeyAndMenuHandle("Control C"); break;
  397. case "粘贴":
  398. case "粘贴(Ctrl+V)":
  399. KeyAndMenuHandle("Control V"); break;
  400. case "删除":
  401. case "删除(Delete)":
  402. KeyAndMenuHandle("None Delete"); break;
  403. case "放大":
  404. case "放大(Ctrl++)":
  405. KeyAndMenuHandle("Control Oemplus"); break;
  406. case "缩小":
  407. case "缩小(Ctrl+-)":
  408. KeyAndMenuHandle("Control OemMinus"); break;
  409. }
  410. }
  411. #endregion
  412. #endregion
  413. /// <summary>
  414. /// 画布双击事件
  415. /// </summary>
  416. /// <param name="f"></param>
  417. private void flowEditorCanvas1_DoubleClick(FlowNode f)
  418. {
  419. ShowNodeProperty(f);
  420. }
  421. #region 绑定右键菜单
  422. /// <summary>
  423. /// 绑定右键菜单
  424. /// </summary>
  425. private void BindSelectContextMenuControl()
  426. {
  427. if(this.tabControl1.Controls.Count>0)
  428. foreach (Control c in this.tabControl1.SelectedTab.Controls)
  429. {
  430. if (c.GetType() == typeof(TabControl))
  431. {
  432. GlobalController._SelectTabControl = (c as TabControl);
  433. (c as TabControl).SelectedTab.Controls[0].ContextMenu = _Menu;
  434. GlobalController._SelectCanvas = ((c as TabControl).SelectedTab.Controls[0] as FlowEditorCanvas);
  435. BindTreeNodes(GlobalController._SelectTabControl.Controls);
  436. }
  437. }
  438. }
  439. #endregion
  440. /// <summary>
  441. /// 绑定流程的树形结构
  442. /// </summary>
  443. /// <param name="con"></param>
  444. private void BindTreeNodes(Control.ControlCollection con)
  445. {
  446. this.treeView1.Nodes.Clear();
  447. this.treeView1.ImageList = GlobalController.ControlImageList;
  448. TreeNode t;
  449. foreach (TabPage o in con)
  450. {
  451. switch ((IVRFlowType)o.Tag)
  452. {
  453. case IVRFlowType.auto:
  454. t = new TreeNode() { Text = o.Text, SelectedImageKey= "OverFlow.gif", ImageKey = "OverFlow.gif" };
  455. t.Tag = o;
  456. this.treeView1.Nodes.Add(t);
  457. break;
  458. case IVRFlowType.normal:
  459. t = new TreeNode() { Text = o.Text, SelectedImageKey = "RotorFlow.gif", ImageKey = "RotorFlow.gif" };
  460. t.Tag = o;
  461. this.treeView1.Nodes.Add(t);
  462. break;
  463. case IVRFlowType.sub:
  464. t = new TreeNode() { Text = o.Text, SelectedImageKey = "SubFlowOver.gif", ImageKey = "SubFlowOver.gif" };
  465. t.Tag = o;
  466. this.treeView1.Nodes.Add(t);
  467. break;
  468. }
  469. }
  470. }
  471. /// <summary>
  472. /// 流程选择事件
  473. /// </summary>
  474. /// <param name="sender"></param>
  475. /// <param name="e"></param>
  476. private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
  477. {
  478. BindSelectContextMenuControl();
  479. }
  480. /// <summary>
  481. /// 捕捉鼠标按下事件
  482. /// </summary>
  483. /// <param name="sender"></param>
  484. /// <param name="e"></param>
  485. private void FrmMain_KeyDown(object sender, KeyEventArgs e)
  486. {
  487. KeyAndMenuHandle(e.Modifiers + " " + e.KeyCode);
  488. }
  489. #region 加载时初始化的空白页和新建空白项目时调用
  490. /// <summary>
  491. /// 初始化的空白标签
  492. /// </summary>
  493. public void CreateBaseTabPage()
  494. {
  495. TabPage t = new TabPage() { Dock = DockStyle.Fill };
  496. t.Text = "空白标签";
  497. this.tabControl1.Controls.Add(t);
  498. this.tabControl1.SelectedTab = t;
  499. TabControl tab = new TabControl() { Dock = DockStyle.Fill };
  500. tab.Name = GlobalController.IVRCancas.Count.ToString();
  501. GlobalController.IVRCancas.Add(tab.Name, new IVRCanvas());
  502. tab.SelectedIndexChanged += new EventHandler(tabControl_SelectedIndexChanged);
  503. TabPage tab1 = new TabPage();
  504. FlowEditorCanvas f = new FlowEditorCanvas(); GlobalController._SelectCanvas = f;
  505. f.Dock = DockStyle.Fill;
  506. f.MouseUp += new MouseEventHandler(f_MouseUp);
  507. f.MouseMove += new MouseEventHandler(f_MouseMove);
  508. tab1.Controls.Add(f);
  509. tab1.Tag = IVRFlowType.normal;
  510. tab1.Text = "普通流程";
  511. f.Name = GlobalController.IVRCancas[tab.Name].IVRFlows.Count.ToString();
  512. GlobalController.IVRCancas[tab.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID=f.Name, FlowName=tab1.Text});
  513. TabPage tab2 = new TabPage();
  514. f = new FlowEditorCanvas();
  515. f.Dock = DockStyle.Fill;
  516. f.MouseUp += new MouseEventHandler(f_MouseUp);
  517. f.MouseMove += new MouseEventHandler(f_MouseMove);
  518. tab2.Controls.Add(f);
  519. tab2.Text = "自动流程";
  520. tab2.Tag = IVRFlowType.auto;
  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 = tab2.Text });
  523. TabPage tab3 = 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. f.Name = GlobalController.IVRCancas[tab.Name].IVRFlows.Count.ToString();
  529. tab3.Text = "子流程";
  530. GlobalController.IVRCancas[tab.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID = f.Name, FlowName = tab3.Text });
  531. tab3.Controls.Add(f);
  532. tab3.Tag = IVRFlowType.sub;
  533. t.Controls.Add(tab);
  534. tab.Controls.Add(tab1);
  535. tab.Controls.Add(tab2);
  536. tab.Controls.Add(tab3);
  537. BindTreeNodes(tab.Controls);
  538. tab.SelectedTab = tab1;
  539. GlobalController._SelectTabControl = tab;
  540. }
  541. #endregion
  542. #region 鼠标弹起事件,监测是否创建控件以及创建控件
  543. void f_MouseUp(object sender, MouseEventArgs e)
  544. {
  545. if (GlobalController.CheckCreateNode())
  546. {
  547. int id=0;
  548. if((sender as FlowEditorCanvas).NodeList!=null&&(sender as FlowEditorCanvas).NodeList.Count!=0)
  549. id = (sender as FlowEditorCanvas).NodeList.Max(a =>Int32.Parse(a.ID));
  550. //string nodekind= (sender as FlowEditorCanvas).NodeList.Max(a =>a.Control .NodeName);
  551. IVRControlBase node = GlobalController.CreateNode((id+1).ToString());
  552. node.Pos = (id + 1).ToString();
  553. Point p = new Point(0, 0);
  554. p = (sender as FlowEditorCanvas).PointToClient(p);
  555. Point CurcorPoint = new Point(Cursor.Position.X + p.X, Cursor.Position.Y + p.Y);
  556. node.CenterPoint = CurcorPoint;
  557. node.Control.DoubleClick += new EventHandler(Control_DoubleClick);
  558. node .Image = GlobalController.ControlImageList.Images[NodePic[node .Name]];//2017-5-11
  559. //2017-5-8添加,用于选择下一端口时用
  560. if (node.Note==null||node.Note == "")
  561. {
  562. node.Note = node.Name+" "+node .Pos;
  563. }
  564. GlobalController.SetCurrentCancasIVRControlBase(node);
  565. (sender as FlowEditorCanvas).AddANode(node);
  566. }
  567. }
  568. #endregion
  569. #region 创建新的连接线
  570. /// <summary>
  571. /// 创建新连线
  572. /// </summary>
  573. /// <returns></returns>
  574. private FlowLine GetNewFlowLine()
  575. {
  576. FlowLine line1 = new FlowLine();
  577. line1.LineColor = Color.Lime ;
  578. line1.SelectedLineColor = Color.Blue ;
  579. line1.LineWidth = 1;
  580. return line1;
  581. }
  582. #endregion
  583. //2017-5-9
  584. #region 创建新的失败连接线
  585. /// <summary>
  586. /// 创建新连线
  587. /// </summary>
  588. /// <returns></returns>
  589. private FlowLine GetNewFlowLineFail()
  590. {
  591. FlowLine line1 = new FlowLine();
  592. line1.LineColor = Color.Red;
  593. line1.SelectedLineColor = Color.Blue;
  594. line1.LineWidth = 1;
  595. return line1;
  596. }
  597. #endregion
  598. #region 遍历所有IVR控件并根据控件类型显示不同的属性并在确定后重绘
  599. private void ShowNodeProperty(FlowNode obj)
  600. {
  601. var ivr = (obj as IVRControlBase);
  602. var ctl=ivr.CtlProperty;
  603. ivr.IVRFlows = GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Values.ToList();
  604. FrmProPretity frm = new FrmProPretity(ref ivr);
  605. frm.Text = ivr.Name;
  606. if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  607. {
  608. if (ivr.InputPortList != null)
  609. for (int i = ivr.InputPortList.Count; i > 0; i--)
  610. {
  611. GlobalController._SelectCanvas.DelLine(ivr.InputPortList[i-1].Line, true, true);
  612. ivr.RemoveInputPort(ivr.InputPortList[i-1]);
  613. }
  614. if (ivr.GetType() == typeof(IVRStartNode))
  615. {
  616. var iVRStartNode = ivr as IVRStartNode;
  617. if (iVRStartNode.Next != null && iVRStartNode.Next != ivr && iVRStartNode.Next.Pos != "0")
  618. {
  619. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStartNode.Next);
  620. }
  621. }
  622. else if (ivr.GetType() == typeof(IVRTransfeOut))//ivr.GetType() == typeof(IVROutbound)||//2017-4-27修改
  623. {
  624. var iVROutbound = ivr as IVRTransfeOut;
  625. if (iVROutbound.SuccessPos != null && iVROutbound.SuccessPos != ivr && iVROutbound.SuccessPos.Pos != "0")
  626. {
  627. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVROutbound.SuccessPos);
  628. }
  629. if (iVROutbound.FailPos != null && iVROutbound.FailPos != ivr && iVROutbound.FailPos.Pos != "0")
  630. {
  631. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVROutbound.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  632. }
  633. }
  634. //2017-4-27 添加
  635. else if (ivr.GetType() == typeof(IVROutbound))
  636. {
  637. var iVROutbound = ivr as IVROutbound;
  638. if (iVROutbound.SuccessPos != null && iVROutbound.SuccessPos != ivr && iVROutbound.SuccessPos.Pos != "0")
  639. {
  640. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVROutbound.SuccessPos);
  641. }
  642. if (iVROutbound.FailPos != null && iVROutbound.FailPos != ivr && iVROutbound.FailPos.Pos != "0")
  643. {
  644. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVROutbound.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  645. }
  646. }
  647. else if (ivr.GetType() == typeof(IVRDefinevar))
  648. {
  649. var iVRDefinevar = (ivr as IVRDefinevar);
  650. if (iVRDefinevar.Next != null && iVRDefinevar.Next != ivr && iVRDefinevar.Next.Pos != "0")
  651. {
  652. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRDefinevar.Next);
  653. }
  654. }
  655. else if (ivr.GetType() == typeof(IVRSubflow))
  656. {
  657. var iVRSubflow = (ivr as IVRSubflow);
  658. if (iVRSubflow.Next != null && iVRSubflow.Next != ivr && iVRSubflow.Next.Pos != "0")
  659. {
  660. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSubflow.Next);
  661. }
  662. }
  663. else if (ivr.GetType() == typeof(IVRAudioDTMF))
  664. {
  665. var iVRAudioDTMF = (ivr as IVRAudioDTMF);
  666. if (iVRAudioDTMF.SuccessPos != null && iVRAudioDTMF.SuccessPos != ivr && iVRAudioDTMF.SuccessPos.Pos != "0")
  667. {
  668. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRAudioDTMF.SuccessPos);
  669. }
  670. if (iVRAudioDTMF.FailPos != null && iVRAudioDTMF.FailPos != ivr && iVRAudioDTMF.FailPos.Pos != "0")
  671. {
  672. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRAudioDTMF.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  673. }
  674. if (iVRAudioDTMF.HangupPos != null && iVRAudioDTMF.HangupPos != ivr && iVRAudioDTMF.HangupPos.Pos != "0")
  675. {
  676. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRAudioDTMF.HangupPos);
  677. }
  678. }
  679. else if (ivr.GetType() == typeof(IVRSendfax) || ivr.GetType() == typeof(IVRRecvfax))
  680. {
  681. var iVRSendfax = (ivr as IVRSendfax);
  682. if (iVRSendfax.SuccessPos != null && iVRSendfax.SuccessPos != ivr && iVRSendfax.SuccessPos.Pos != "0")
  683. {
  684. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSendfax.SuccessPos);
  685. }
  686. if (iVRSendfax.FailPos != null && iVRSendfax.FailPos != ivr && iVRSendfax.FailPos.Pos != "0")
  687. {
  688. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRSendfax.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  689. }
  690. if (iVRSendfax.HangupPos != null && iVRSendfax.HangupPos != ivr && iVRSendfax.HangupPos.Pos != "0")
  691. {
  692. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSendfax.HangupPos);
  693. }
  694. }
  695. else if (ivr.GetType() == typeof(IVRLeaveWord))
  696. {
  697. var iVRLeaveWord = (ivr as IVRLeaveWord);
  698. if (iVRLeaveWord.TimeoutPos != null && iVRLeaveWord.TimeoutPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
  699. {
  700. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.TimeoutPos);
  701. }
  702. if (iVRLeaveWord.HangupPos != null && iVRLeaveWord.HangupPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
  703. {
  704. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.HangupPos);
  705. }
  706. if (iVRLeaveWord.FinishPos != null && iVRLeaveWord.FinishPos != ivr && iVRLeaveWord.TimeoutPos.Pos != "0")
  707. {
  708. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRLeaveWord.FinishPos);
  709. }
  710. }
  711. else if (ivr.GetType() == typeof(IVRQueue))
  712. {
  713. var iVRQueue = (ivr as IVRQueue);
  714. if (iVRQueue.HangupPos != null && iVRQueue.HangupPos != ivr && iVRQueue.HangupPos.Pos != "0")
  715. {
  716. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.HangupPos);
  717. }
  718. if (iVRQueue.SuccessPos != null && iVRQueue.SuccessPos != ivr && iVRQueue.SuccessPos.Pos != "0")
  719. {
  720. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.SuccessPos);
  721. }
  722. if (iVRQueue.NoAgentPos != null && iVRQueue.NoAgentPos != ivr && iVRQueue.NoAgentPos.Pos != "0")
  723. {
  724. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.NoAgentPos);
  725. }
  726. if (iVRQueue.NoFreePos != null && iVRQueue.NoFreePos != ivr && iVRQueue.NoFreePos.Pos != "0")
  727. {
  728. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRQueue.NoFreePos);
  729. }
  730. }
  731. else if (ivr.GetType() == typeof(IVRContinueQueue))
  732. {
  733. var iVRContinueQueue = (ivr as IVRContinueQueue);
  734. if (iVRContinueQueue.TimeoutPos != null && iVRContinueQueue.TimeoutPos != ivr && iVRContinueQueue.TimeoutPos.Pos != "0")
  735. {
  736. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.TimeoutPos);
  737. }
  738. if (iVRContinueQueue.HangupPos != null && iVRContinueQueue.HangupPos != ivr && iVRContinueQueue.HangupPos.Pos != "0")
  739. {
  740. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.HangupPos);
  741. }
  742. if (iVRContinueQueue.SuccessPos != null && iVRContinueQueue.SuccessPos != ivr && iVRContinueQueue.SuccessPos.Pos != "0")
  743. {
  744. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRContinueQueue.SuccessPos);
  745. }
  746. }
  747. else if (ivr.GetType() == typeof(IVRCancelQueue))
  748. {
  749. var iVRCancelQueue = (ivr as IVRCancelQueue);
  750. if (iVRCancelQueue.Next != null && iVRCancelQueue.Next != ivr && iVRCancelQueue.Next.Pos != "0")
  751. {
  752. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCancelQueue.Next);
  753. }
  754. }
  755. else if (ivr.GetType() == typeof(IVRTurnagent))
  756. {
  757. var iVRTurnagent = (ivr as IVRTurnagent);
  758. if (iVRTurnagent.FailPos != null && iVRTurnagent.FailPos != ivr && iVRTurnagent.FailPos.Pos != "0")
  759. {
  760. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRTurnagent.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  761. }
  762. if (iVRTurnagent.HangupPos != null && iVRTurnagent.HangupPos != ivr && iVRTurnagent.HangupPos.Pos != "0")
  763. {
  764. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTurnagent.HangupPos);
  765. }
  766. if (iVRTurnagent.SuccessPos != null && iVRTurnagent.SuccessPos != ivr && iVRTurnagent.SuccessPos.Pos != "0")
  767. {
  768. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTurnagent.SuccessPos);
  769. }
  770. }
  771. else if (ivr.GetType() == typeof(IVRCompare))
  772. {
  773. var iVRCompare = (ivr as IVRCompare);
  774. if (iVRCompare.TruePos != null && iVRCompare.TruePos != ivr && iVRCompare.TruePos.Pos != "0")
  775. {
  776. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCompare.TruePos);
  777. }
  778. if (iVRCompare.FalsePos != null && iVRCompare.FalsePos != ivr && iVRCompare.FalsePos.Pos != "0")
  779. {
  780. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCompare.FalsePos);
  781. }
  782. }
  783. else if (ivr.GetType() == typeof(IVRCalculate))
  784. {
  785. var iVRCalculate = (ivr as IVRCalculate);
  786. if (iVRCalculate.Next != null && iVRCalculate.Next != ivr && iVRCalculate.Next.Pos != "0")
  787. {
  788. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRCalculate.Next);
  789. }
  790. }
  791. else if (ivr.GetType() == typeof(IVRStringop))
  792. {
  793. var iVRStringop = (ivr as IVRStringop);
  794. if (iVRStringop.Next != null && iVRStringop.Next != ivr && iVRStringop.Next.Pos != "0")
  795. {
  796. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.Next);
  797. }
  798. if (iVRStringop.TruePos != null && iVRStringop.TruePos != ivr && iVRStringop.TruePos.Pos != "0")
  799. {
  800. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.TruePos);
  801. }
  802. if (iVRStringop.FalsePos != null && iVRStringop.FalsePos != ivr && iVRStringop.FalsePos.Pos != "0")
  803. {
  804. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRStringop.FalsePos);
  805. }
  806. }
  807. else if (ivr.GetType() == typeof(IVRSql))
  808. {
  809. var iVRSql = (ivr as IVRSql);
  810. if (iVRSql.SuccessPos != null && iVRSql.SuccessPos != ivr && iVRSql.SuccessPos.Pos != "0")
  811. {
  812. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSql.SuccessPos);
  813. }
  814. if (iVRSql.FailPos != null && iVRSql.FailPos != ivr && iVRSql.FailPos.Pos != "0")
  815. {
  816. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRSql.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  817. }
  818. }
  819. else if (ivr.GetType() == typeof(IVRRecordSet))
  820. {
  821. var iVRRecordSet = (ivr as IVRRecordSet);
  822. if (iVRRecordSet.LPos != null && iVRRecordSet.LPos != ivr && iVRRecordSet.LPos.Pos != "0")
  823. {
  824. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.LPos);
  825. }
  826. if (iVRRecordSet.EPos != null && iVRRecordSet.EPos != ivr && iVRRecordSet.EPos.Pos != "0")
  827. {
  828. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.EPos);
  829. }
  830. if (iVRRecordSet.GPos != null && iVRRecordSet.GPos != ivr && iVRRecordSet.GPos.Pos != "0")
  831. {
  832. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRRecordSet.GPos);
  833. }
  834. }
  835. else if (ivr.GetType() == typeof(IVRTimer))
  836. {
  837. var iVRTimer = (ivr as IVRTimer);
  838. if (iVRTimer.Next != null && iVRTimer.Next != ivr && iVRTimer.Next.Pos != "0")
  839. {
  840. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRTimer.Next);
  841. }
  842. }
  843. else if (ivr.GetType() == typeof(IVRBranch))
  844. {
  845. var iVRBranch = (ivr as IVRBranch);
  846. if (iVRBranch.DefaultPos != null && iVRBranch.DefaultPos != ivr && iVRBranch.DefaultPos.Pos != "0")
  847. {
  848. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRBranch.DefaultPos);
  849. }
  850. foreach (IVRBranchVar branch in iVRBranch.Branch)
  851. {
  852. if (branch.Pos != "0")
  853. {
  854. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, GlobalController._SelectCanvas.NodeList.Where(a => a.ID == branch.Pos).First());
  855. }
  856. }
  857. }
  858. else if (ivr.GetType() == typeof(IVRSocket))
  859. {
  860. var iVRSocket = (ivr as IVRSocket);
  861. if (iVRSocket.SuccessPos != null && iVRSocket.SuccessPos != ivr && iVRSocket.SuccessPos.Pos != "0")
  862. {
  863. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRSocket.SuccessPos);
  864. }
  865. if (iVRSocket.FailPos != null && iVRSocket.FailPos != ivr && iVRSocket.FailPos.Pos != "0")
  866. {
  867. GlobalController._SelectCanvas.AddALine(GetNewFlowLineFail(), ivr, iVRSocket.FailPos);//2017-5-9将GetNewFlowLine改为GetNewFlowLineFail
  868. }
  869. }
  870. //2017-5-2 添加解决挂机及其下节点之间不划线的问题
  871. else if (ivr.GetType() == typeof(IVRHangUp))
  872. {
  873. var iVRHangup = ivr as IVRHangUp;
  874. if (iVRHangup.Next != null && iVRHangup.Next != ivr && iVRHangup.Next.Pos != "0")
  875. {
  876. GlobalController._SelectCanvas.AddALine(GetNewFlowLine(), ivr, iVRHangup.Next);
  877. }
  878. }
  879. }
  880. }
  881. #endregion
  882. #region 创建流程编辑器
  883. private void CreateIVRFlow(IVRFlowType flowType)
  884. {
  885. TabPage tab1 = new TabPage();
  886. tab1.Tag = flowType;
  887. // if( GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].)
  888. foreach (TabPage p in GlobalController._SelectTabControl.Controls)
  889. {
  890. if (p.Tag.ToString() == flowType.ToString() && flowType == IVRFlowType.normal)
  891. {
  892. MessageBox.Show("每个流程文件中只允许有一个普通流程!");
  893. return;
  894. }
  895. if (p.Tag.ToString() == flowType.ToString() && flowType == IVRFlowType.sub)
  896. {
  897. MessageBox.Show("每个流程文件中只允许有一个子流程!");
  898. return;
  899. }
  900. }
  901. FlowEditorCanvas f = new FlowEditorCanvas();
  902. f.Dock = DockStyle.Fill;
  903. f.MouseUp += new MouseEventHandler(f_MouseUp);
  904. f.MouseMove += new MouseEventHandler(f_MouseMove);
  905. f.Name = GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Count.ToString();
  906. tab1.Text = (typeof(IVRFlowType).GetField(flowType.ToString()).GetCustomAttributes(false).Last() as DescriptionAttribute).Description;
  907. GlobalController.IVRCancas[GlobalController._SelectTabControl.Name].IVRFlows.Add(f.Name, new IVRFlowInfo() { FlowID = f.Name, FlowName = tab1.Text });
  908. tab1.Controls.Add(f);
  909. GlobalController._SelectTabControl.Controls.Add(tab1);
  910. GlobalController._SelectTabControl.SelectedTab = tab1;
  911. GlobalController._SelectCanvas = f;
  912. }
  913. #endregion
  914. /// <summary>
  915. /// 双击IVR控件打开IVR控件属性窗口
  916. /// </summary>
  917. /// <param name="sender"></param>
  918. /// <param name="e"></param>
  919. void Control_DoubleClick(object sender, EventArgs e)
  920. {
  921. ShowNodeProperty((sender as FlowNodeControl).FlowNode);
  922. }
  923. /// <summary>
  924. /// 鼠标移动 改变鼠标形状
  925. /// </summary>
  926. /// <param name="sender"></param>
  927. /// <param name="e"></param>
  928. void f_MouseMove(object sender, MouseEventArgs e)
  929. {
  930. if (GlobalController.CheckCreateNode())
  931. Cursor = Cursors.SizeAll;
  932. else
  933. {
  934. Cursor = Cursors.Arrow;
  935. base.OnMouseMove(e);
  936. }
  937. }
  938. private string _FilePath;
  939. /// <summary>
  940. /// 菜单栏菜单事件处理
  941. /// </summary>
  942. /// <param name="sender"></param>
  943. /// <param name="e"></param>
  944. private void ToolStripMenuItem_Click(object sender, EventArgs e)
  945. {
  946. switch ((sender as ToolStripItem).Text)
  947. {
  948. case "新建项目":
  949. CreateBaseTabPage(); break;
  950. case "子流程": CreateIVRFlow(IVRFlowType.sub); break;
  951. case "普通流程": CreateIVRFlow(IVRFlowType.normal); break;
  952. case "自动流程": CreateIVRFlow(IVRFlowType.auto); break;
  953. case "打开":
  954. case "打开(Ctrl+O)":
  955. KeyAndMenuHandle("Control O"); break;
  956. case "保存":
  957. case "保存(Ctrl+S)":
  958. KeyAndMenuHandle("Control S"); break;
  959. case "另存":
  960. /* SaveFileDialog svf = new SaveFileDialog();
  961. svf.Filter= "XML文件|*.xml";
  962. if(svf.ShowDialog()== System.Windows.Forms.DialogResult.OK)
  963. {
  964. //这里填写保存的位置和数据
  965. }*///2017-4-27注释掉Control SAVEAS
  966. KeyAndMenuHandle("Control SAVEAS");
  967. break;
  968. case "删除当前流程":
  969. if (MessageBox.Show("确定要删除" + GlobalController._SelectTabControl.SelectedTab.Text + "吗?", "消息提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
  970. {
  971. GlobalController._SelectTabControl.Controls.Remove(GlobalController._SelectTabControl.SelectedTab);
  972. }
  973. break;
  974. case "关闭当前项目":
  975. this.tabControl1.Controls.Remove(this.tabControl1.SelectedTab);
  976. //GlobalController._SelectTabControl.Controls.Remove(GlobalController._SelectTabControl.SelectedTab);
  977. //GlobalController.IVRCancas.Remove(this.tabControl1.SelectedTab.Name);
  978. break;
  979. case "退出": Application.Exit(); break;
  980. }
  981. }
  982. /// <summary>
  983. /// 双击流程树形结构
  984. /// </summary>
  985. /// <param name="sender"></param>
  986. /// <param name="e"></param>
  987. private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  988. {
  989. GlobalController._SelectTabControl.SelectedTab = (e.Node.Tag as TabPage);
  990. this.treeView1.SelectedNode = e.Node;
  991. }
  992. private void ctlMenu1_Load(object sender, EventArgs e)
  993. {
  994. }
  995. }
  996. }