ivr流程编辑器

FrmMain.cs 46KB

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