WorkFlowSettingDialog.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. using PaintDotNet.Base.SettingModel;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.Data.Param;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace PaintDotNet.Setting
  15. {
  16. /// <summary>
  17. /// 设置->工作流程
  18. /// </summary>
  19. internal class WorkFlowSettingDialog : PdnBaseForm
  20. {
  21. #region 控件
  22. private GroupBox groupBox1;
  23. private Button cancelBtn;
  24. private Button saveBtn;
  25. private Button button2;
  26. private Button button1;
  27. private GroupBox groupBox2;
  28. private Button button3;
  29. private GroupBox groupBox3;
  30. private Button button4;
  31. private Button button5;
  32. private Button button6;
  33. private TreeView treeView1;
  34. private TreeView treeView2;
  35. #endregion
  36. /// <summary>
  37. /// 工作空间
  38. /// </summary>
  39. private AppWorkspace appWorkspace;
  40. /// <summary>
  41. /// 新增、重命名的弹窗
  42. /// </summary>
  43. private CreateNameDialog createNameDialog;
  44. /// <summary>
  45. /// 工作流程model
  46. /// </summary>
  47. private WorkFlowModel workFlowModel = Startup.instance.workFlowModel;
  48. /// <summary>
  49. /// 右侧树形菜单
  50. /// </summary>
  51. private ToolStripItemCollection collection;
  52. /// <summary>
  53. /// 是否新建工作流程
  54. /// </summary>
  55. private bool create = true;
  56. private string txtPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";
  57. private string[] menuIdArr;
  58. public WorkFlowSettingDialog(AppWorkspace appWorkspace)
  59. {
  60. this.appWorkspace = appWorkspace;
  61. InitializeComponent();
  62. InitializeLanguageText();
  63. InitVisibleMenuId();
  64. this.button3.Enabled = false;
  65. this.button4.Enabled = false;
  66. InitializeTreeEvent();
  67. InitializeLeftTreeData();
  68. InitializeRightTreeData();
  69. }
  70. /// <summary>
  71. /// 获取txt文件中已保存的菜单可用id
  72. /// </summary>
  73. private void InitVisibleMenuId()
  74. {
  75. if (System.IO.File.Exists(txtPath))
  76. {
  77. string str = System.IO.File.ReadAllText(txtPath);
  78. if (str.IndexOf(',') != -1)
  79. {
  80. menuIdArr = str.Split(',');
  81. }
  82. else
  83. {
  84. if (!string.IsNullOrEmpty(str))
  85. {
  86. menuIdArr = new string[] { str };
  87. }
  88. }
  89. }
  90. }
  91. /// <summary>
  92. /// 初始化treeview的事件
  93. /// </summary>
  94. private void InitializeTreeEvent()
  95. {
  96. this.treeView1.HideSelection = false;
  97. this.treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;
  98. this.treeView1.DrawNode += new DrawTreeNodeEventHandler(this.treeView_DrawNode);
  99. this.treeView1.Invalidated += new InvalidateEventHandler(this.treeView1_InvalidateEvent);
  100. this.treeView2.HideSelection = false;
  101. this.treeView2.DrawMode = TreeViewDrawMode.OwnerDrawText;
  102. this.treeView2.DrawNode += new DrawTreeNodeEventHandler(this.treeView_DrawNode);
  103. this.treeView2.Invalidated += new InvalidateEventHandler(this.treeView2_InvalidateEvent);
  104. }
  105. /// <summary>
  106. /// treeView1的重绘事件
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. private void treeView1_InvalidateEvent(object sender, InvalidateEventArgs e)
  111. {
  112. if (this.treeView2.SelectedNode != null)
  113. {
  114. if (this.treeView2.SelectedNode.Tag == null)
  115. this.button3.Enabled = true;
  116. }
  117. if (this.treeView1.SelectedNode != null)
  118. {
  119. if (this.treeView1.SelectedNode.Nodes.Count > 0)
  120. {
  121. this.button3.Enabled = false;
  122. }
  123. }
  124. }
  125. /// <summary>
  126. /// treeView2的重绘事件
  127. /// </summary>
  128. /// <param name="sender"></param>
  129. /// <param name="e"></param>
  130. private void treeView2_InvalidateEvent(object sender, InvalidateEventArgs e)
  131. {
  132. this.button1.Enabled = true;
  133. if (this.treeView1.SelectedNode != null)
  134. {
  135. if (this.treeView1.SelectedNode.Nodes.Count == 0)
  136. {
  137. this.button3.Enabled = true;
  138. }
  139. }
  140. this.button4.Enabled = false;
  141. this.cancelBtn.Enabled = true;
  142. if (this.treeView2.SelectedNode != null)
  143. {
  144. if (this.treeView2.SelectedNode.Tag != null)
  145. {
  146. this.button1.Enabled = false;
  147. this.button3.Enabled = false;
  148. this.button4.Enabled = true;
  149. this.cancelBtn.Enabled = false;
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// 自定义绘制
  155. /// 参考https://www.cnblogs.com/JiYF/p/6693503.html
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
  160. {
  161. /**用默认颜色
  162. e.DrawDefault = true;
  163. return;
  164. **/
  165. //以下是自定义颜色
  166. if ((e.State & TreeNodeStates.Selected) != 0)
  167. {
  168. //演示为绿底白字
  169. e.Graphics.FillRectangle(Brushes.Green, e.Node.Bounds);
  170. Font nodeFont = e.Node.NodeFont;
  171. if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
  172. e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
  173. }
  174. else
  175. {
  176. e.DrawDefault = true;
  177. }
  178. if ((e.State & TreeNodeStates.Focused) != 0)
  179. {
  180. using (Pen focusPen = new Pen(Color.Black))
  181. {
  182. focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  183. Rectangle focusBounds = e.Node.Bounds;
  184. focusBounds.Size = new Size(focusBounds.Width - 1,
  185. focusBounds.Height - 1);
  186. e.Graphics.DrawRectangle(focusPen, focusBounds);
  187. }
  188. }
  189. }
  190. /// <summary>
  191. /// 初始化左侧工作流程菜单
  192. /// </summary>
  193. private void InitializeLeftTreeData()
  194. {
  195. if (workFlowModel != null && workFlowModel.Flows != null)
  196. {
  197. for (int i = 0; i < this.workFlowModel.Flows.Count; i++)
  198. {
  199. TreeNode anime = new TreeNode(this.workFlowModel.Flows[i].Name);
  200. for (int j = 0; j < this.workFlowModel.Flows[i].Menus.Count; j++)
  201. {
  202. TreeNode child = new TreeNode();
  203. child.Text = this.workFlowModel.Flows[i].Menus[j].Name;
  204. child.Name = this.workFlowModel.Flows[i].Menus[j].Description;
  205. child.Tag = this.workFlowModel.Flows[i].Menus[j].Id;
  206. anime.Nodes.Add(child);
  207. }
  208. this.treeView2.Nodes.Add(anime);
  209. }
  210. }
  211. }
  212. /// <summary>
  213. /// 初始化右侧树形菜单数据
  214. /// </summary>
  215. private void InitializeRightTreeData()
  216. {
  217. this.collection = this.appWorkspace.ToolBar.MainMenu.Items;
  218. TreeNode anime = new TreeNode(PdnResources.GetString("Menu.menu.Text"));
  219. this.RecursiveData(collection, anime);
  220. anime.Expand();
  221. this.treeView1.Nodes.Add(anime);
  222. }
  223. /// <summary>
  224. /// 递归进行数据组织
  225. /// </summary>
  226. private void RecursiveData(ToolStripItemCollection collection, TreeNode anime)
  227. {
  228. //for (int i = 0; i < toolStripItemCollection.Count; i++)
  229. //{
  230. // //排除掉最近打开的文件,或者可以用数字id判断更准确
  231. // if (!toolStripItemCollection[i].Name.Equals("OpenRecent") && !toolStripItemCollection[i].Name.Equals("CameraSelection"))
  232. // {
  233. // if (toolStripItemCollection[i].GetType() != typeof(ToolStripSeparator) && ((PdnMenuItem)toolStripItemCollection[i]).CanShowInSenseShield)
  234. // {
  235. // TreeNode node = new TreeNode();
  236. // node.Name = toolStripItemCollection[i].Name;
  237. // node.Text = toolStripItemCollection[i].Text;
  238. // node.Tag = ((PdnMenuItem)toolStripItemCollection[i]).MenuId;
  239. // anime.Nodes.Add(node);
  240. // RecursiveData(((PdnMenuItem)toolStripItemCollection[i]).DropDownItems, node);
  241. // }
  242. // }
  243. //}
  244. for (int i = 0; i < collection.Count; i++)
  245. {
  246. TreeNode node = new TreeNode(/*collection[i].Text*/);
  247. if (collection[i] is PdnMenuItem)
  248. {
  249. PdnMenuItem item = (PdnMenuItem)collection[i];
  250. if (!item.CanShowInSenseShield)
  251. continue;
  252. node.Tag = item.MenuId;
  253. if (menuIdArr != null && menuIdArr.Length > 0)
  254. {
  255. if (Array.IndexOf(menuIdArr, item.MenuId.ToString()) != -1)
  256. {
  257. node.Name = collection[i].Name;
  258. node.Text = collection[i].Text;
  259. node.Tag = ((PdnMenuItem)collection[i]).MenuId;
  260. node.Checked = true;
  261. }
  262. else
  263. {
  264. node.Checked = false;
  265. }
  266. }
  267. if (node.Checked)
  268. {
  269. anime.Nodes.Add(node);
  270. }
  271. if (collection[i].Name.Equals("OpenRecent") || collection[i].Name.Equals("CameraSelection"))
  272. continue;
  273. RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node);
  274. }
  275. }
  276. }
  277. private void InitializeLanguageText()
  278. {
  279. this.Text = PdnResources.GetString("Menu.Setting.WorkFlowSetting.Text");
  280. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  281. this.button2.Text = PdnResources.GetString("Menu.File.Save.Text");
  282. this.button1.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  283. this.cancelBtn.Text = PdnResources.GetString("Menu.Rename.text");
  284. this.saveBtn.Text = PdnResources.GetString("Menu.Add.text");
  285. this.groupBox2.Text = PdnResources.GetString("Menu.Set.workprocess.Theworkflowismaintained.text");
  286. this.button3.Text = "< " + PdnResources.GetString("Menu.Addto.text");
  287. this.groupBox3.Text = PdnResources.GetString("Menu.Availablefunctions.text");
  288. this.button4.Text = PdnResources.GetString("Menu.Moveout.text") + " >";
  289. this.button5.Text = PdnResources.GetString("Menu.LabelAction.MoveUpAction.Text");
  290. this.button6.Text = PdnResources.GetString("Menu.LabelAction.MoveDownAction.Text");
  291. }
  292. private void InitializeComponent()
  293. {
  294. this.groupBox1 = new System.Windows.Forms.GroupBox();
  295. this.button2 = new System.Windows.Forms.Button();
  296. this.button1 = new System.Windows.Forms.Button();
  297. this.cancelBtn = new System.Windows.Forms.Button();
  298. this.saveBtn = new System.Windows.Forms.Button();
  299. this.groupBox2 = new System.Windows.Forms.GroupBox();
  300. this.treeView2 = new System.Windows.Forms.TreeView();
  301. this.button3 = new System.Windows.Forms.Button();
  302. this.groupBox3 = new System.Windows.Forms.GroupBox();
  303. this.treeView1 = new System.Windows.Forms.TreeView();
  304. this.button4 = new System.Windows.Forms.Button();
  305. this.button5 = new System.Windows.Forms.Button();
  306. this.button6 = new System.Windows.Forms.Button();
  307. this.groupBox1.SuspendLayout();
  308. this.groupBox2.SuspendLayout();
  309. this.groupBox3.SuspendLayout();
  310. this.SuspendLayout();
  311. //
  312. // groupBox1
  313. //
  314. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  315. | System.Windows.Forms.AnchorStyles.Right)));
  316. this.groupBox1.Controls.Add(this.button2);
  317. this.groupBox1.Controls.Add(this.button1);
  318. this.groupBox1.Controls.Add(this.cancelBtn);
  319. this.groupBox1.Controls.Add(this.saveBtn);
  320. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  321. this.groupBox1.Name = "groupBox1";
  322. this.groupBox1.Size = new System.Drawing.Size(508, 58);
  323. this.groupBox1.TabIndex = 3;
  324. this.groupBox1.TabStop = false;
  325. this.groupBox1.Text = "操作";
  326. //
  327. // button2
  328. //
  329. this.button2.Location = new System.Drawing.Point(420, 19);
  330. this.button2.Name = "button2";
  331. this.button2.Size = new System.Drawing.Size(75, 23);
  332. this.button2.TabIndex = 3;
  333. this.button2.Text = "保存";
  334. this.button2.UseVisualStyleBackColor = true;
  335. this.button2.Click += new System.EventHandler(this.button2_Click);
  336. //
  337. // button1
  338. //
  339. this.button1.Location = new System.Drawing.Point(339, 19);
  340. this.button1.Name = "button1";
  341. this.button1.Size = new System.Drawing.Size(75, 23);
  342. this.button1.TabIndex = 2;
  343. this.button1.Text = "删除";
  344. this.button1.UseVisualStyleBackColor = true;
  345. this.button1.Click += new System.EventHandler(this.button1_Click);
  346. //
  347. // cancelBtn
  348. //
  349. this.cancelBtn.Anchor = System.Windows.Forms.AnchorStyles.Right;
  350. this.cancelBtn.Location = new System.Drawing.Point(258, 19);
  351. this.cancelBtn.Name = "cancelBtn";
  352. this.cancelBtn.Size = new System.Drawing.Size(75, 23);
  353. this.cancelBtn.TabIndex = 1;
  354. this.cancelBtn.Text = "重命名";
  355. this.cancelBtn.UseVisualStyleBackColor = true;
  356. this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click);
  357. //
  358. // saveBtn
  359. //
  360. this.saveBtn.Anchor = System.Windows.Forms.AnchorStyles.Right;
  361. this.saveBtn.Location = new System.Drawing.Point(177, 19);
  362. this.saveBtn.Name = "saveBtn";
  363. this.saveBtn.Size = new System.Drawing.Size(75, 23);
  364. this.saveBtn.TabIndex = 0;
  365. this.saveBtn.Text = "新增";
  366. this.saveBtn.UseVisualStyleBackColor = true;
  367. this.saveBtn.Click += new System.EventHandler(this.saveBtn_Click);
  368. //
  369. // groupBox2
  370. //
  371. this.groupBox2.Controls.Add(this.treeView2);
  372. this.groupBox2.Location = new System.Drawing.Point(13, 77);
  373. this.groupBox2.Name = "groupBox2";
  374. this.groupBox2.Size = new System.Drawing.Size(200, 483);
  375. this.groupBox2.TabIndex = 4;
  376. this.groupBox2.TabStop = false;
  377. this.groupBox2.Text = "已维护工作流程";
  378. //
  379. // treeView2
  380. //
  381. this.treeView2.Location = new System.Drawing.Point(7, 21);
  382. this.treeView2.Name = "treeView2";
  383. this.treeView2.Size = new System.Drawing.Size(187, 456);
  384. this.treeView2.TabIndex = 0;
  385. this.treeView2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView2_MouseDown);
  386. //
  387. // button3
  388. //
  389. this.button3.Location = new System.Drawing.Point(230, 100);
  390. this.button3.Name = "button3";
  391. this.button3.Size = new System.Drawing.Size(75, 23);
  392. this.button3.TabIndex = 5;
  393. this.button3.Text = "添加";
  394. this.button3.UseVisualStyleBackColor = true;
  395. this.button3.Click += new System.EventHandler(this.button3_Click);
  396. //
  397. // groupBox3
  398. //
  399. this.groupBox3.Controls.Add(this.treeView1);
  400. this.groupBox3.Location = new System.Drawing.Point(320, 77);
  401. this.groupBox3.Name = "groupBox3";
  402. this.groupBox3.Size = new System.Drawing.Size(200, 483);
  403. this.groupBox3.TabIndex = 6;
  404. this.groupBox3.TabStop = false;
  405. this.groupBox3.Text = "可用功能";
  406. //
  407. // treeView1
  408. //
  409. this.treeView1.Location = new System.Drawing.Point(7, 21);
  410. this.treeView1.Name = "treeView1";
  411. this.treeView1.Size = new System.Drawing.Size(187, 456);
  412. this.treeView1.TabIndex = 0;
  413. this.treeView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView1_MouseDown);
  414. //
  415. // button4
  416. //
  417. this.button4.Location = new System.Drawing.Point(230, 130);
  418. this.button4.Name = "button4";
  419. this.button4.Size = new System.Drawing.Size(75, 23);
  420. this.button4.TabIndex = 7;
  421. this.button4.Text = "移出";
  422. this.button4.UseVisualStyleBackColor = true;
  423. this.button4.Click += new System.EventHandler(this.button4_Click);
  424. //
  425. // button5
  426. //
  427. this.button5.Location = new System.Drawing.Point(230, 160);
  428. this.button5.Name = "button5";
  429. this.button5.Size = new System.Drawing.Size(75, 23);
  430. this.button5.TabIndex = 8;
  431. this.button5.Text = "向上移动";
  432. this.button5.UseVisualStyleBackColor = true;
  433. this.button5.Click += new System.EventHandler(this.button5_Click);
  434. //
  435. // button6
  436. //
  437. this.button6.Location = new System.Drawing.Point(230, 190);
  438. this.button6.Name = "button6";
  439. this.button6.Size = new System.Drawing.Size(75, 23);
  440. this.button6.TabIndex = 9;
  441. this.button6.Text = "向下移动";
  442. this.button6.UseVisualStyleBackColor = true;
  443. this.button6.Click += new System.EventHandler(this.button6_Click);
  444. //
  445. // WorkFlowSettingDialog
  446. //
  447. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  448. this.ClientSize = new System.Drawing.Size(533, 572);
  449. this.Controls.Add(this.button6);
  450. this.Controls.Add(this.button5);
  451. this.Controls.Add(this.button4);
  452. this.Controls.Add(this.groupBox3);
  453. this.Controls.Add(this.button3);
  454. this.Controls.Add(this.groupBox2);
  455. this.Controls.Add(this.groupBox1);
  456. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  457. this.MaximizeBox = false;
  458. this.MinimizeBox = false;
  459. this.Name = "WorkFlowSettingDialog";
  460. this.Text = "工作流程";
  461. this.Controls.SetChildIndex(this.groupBox1, 0);
  462. this.Controls.SetChildIndex(this.groupBox2, 0);
  463. this.Controls.SetChildIndex(this.button3, 0);
  464. this.Controls.SetChildIndex(this.groupBox3, 0);
  465. this.Controls.SetChildIndex(this.button4, 0);
  466. this.Controls.SetChildIndex(this.button5, 0);
  467. this.Controls.SetChildIndex(this.button6, 0);
  468. this.groupBox1.ResumeLayout(false);
  469. this.groupBox2.ResumeLayout(false);
  470. this.groupBox3.ResumeLayout(false);
  471. this.ResumeLayout(false);
  472. }
  473. /// <summary>
  474. /// 新建
  475. /// </summary>
  476. /// <param name="sender"></param>
  477. /// <param name="e"></param>
  478. private void saveBtn_Click(object sender, EventArgs e)
  479. {
  480. create = true;
  481. createNameDialog = new CreateNameDialog(this);
  482. createNameDialog.StartPosition = FormStartPosition.CenterParent;
  483. createNameDialog.ShowDialog();
  484. }
  485. /// <summary>
  486. /// 重命名
  487. /// </summary>
  488. /// <param name="sender"></param>
  489. /// <param name="e"></param>
  490. private void cancelBtn_Click(object sender, EventArgs e)
  491. {
  492. if (this.treeView2.SelectedNode != null)
  493. {
  494. create = false;
  495. createNameDialog = new CreateNameDialog(this);
  496. createNameDialog.SetTextBoxValue(this.treeView2.SelectedNode.Text);
  497. createNameDialog.StartPosition = FormStartPosition.CenterParent;
  498. createNameDialog.ShowDialog();
  499. }
  500. else
  501. MessageBox.Show(PdnResources.GetString("Menu.leaseselectaworkflowthathasbeenma.Text"));
  502. }
  503. /// <summary>
  504. /// 删除
  505. /// </summary>
  506. /// <param name="sender"></param>
  507. /// <param name="e"></param>
  508. private void button1_Click(object sender, EventArgs e)
  509. {
  510. if (this.treeView2.SelectedNode != null)
  511. {
  512. if (MessageBox.Show(PdnResources.GetString("Menu.reyousureyouwanttodeletetheselectedwo.Text") + "?", PdnResources.GetString("Menu.Thisdeletioncannotberecovered.text"), MessageBoxButtons.YesNo) == DialogResult.Yes)
  513. {
  514. this.treeView2.Nodes.Remove(this.treeView2.SelectedNode);
  515. }
  516. }
  517. else
  518. MessageBox.Show(PdnResources.GetString("Menu.erearenomaintainedworkflowstodel.Text"));
  519. }
  520. /// <summary>
  521. /// 保存
  522. /// </summary>
  523. /// <param name="sender"></param>
  524. /// <param name="e"></param>
  525. private void button2_Click(object sender, EventArgs e)
  526. {
  527. workFlowModel.Flows.Clear();
  528. for (int i = 0; i < this.treeView2.Nodes.Count; i++)
  529. {
  530. WorkFlowModel.Flow flow = new WorkFlowModel.Flow();
  531. flow.Menus = new List<WorkFlowModel.Flow.Item>();
  532. flow.Name = this.treeView2.Nodes[i].Text;
  533. if (this.treeView2.Nodes[i].Nodes.Count > 0)
  534. {
  535. for (int j = 0; j < this.treeView2.Nodes[i].Nodes.Count; j++)
  536. {
  537. WorkFlowModel.Flow.Item item = new WorkFlowModel.Flow.Item();
  538. item.Id = (int)(this.treeView2.Nodes[i].Nodes[j].Tag);
  539. item.Name = this.treeView2.Nodes[i].Nodes[j].Text;
  540. item.Description = this.treeView2.Nodes[i].Nodes[j].Name;
  541. flow.Menus.Add(item);
  542. }
  543. }
  544. workFlowModel.Flows.Add(flow);
  545. }
  546. string userInfoXml = XmlSerializeHelper.XmlSerialize<WorkFlowModel>(workFlowModel);
  547. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\WorkFlow.xml";
  548. if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create))
  549. {
  550. Startup.instance.workFlowModel = workFlowModel;
  551. if (this.appWorkspace.workFlowDialog != null)
  552. {
  553. this.appWorkspace.workFlowDialog.InitializeWorkFlow();
  554. }
  555. this.Close();
  556. }
  557. else
  558. {
  559. MessageBox.Show(PdnResources.GetString("Menu.Workflowsavefailed.Text"));
  560. }
  561. }
  562. /// <summary>
  563. /// 获取新建窗口里面输入的名称
  564. /// </summary>
  565. /// <param name="name"></param>
  566. public override void GetCreateName(string name)
  567. {
  568. if (!name.Equals(""))
  569. {
  570. if (create) //新增
  571. {
  572. this.treeView2.Nodes.Add(new TreeNode(name));
  573. }
  574. else //重命名
  575. {
  576. if (this.treeView2.SelectedNode != null)
  577. {
  578. this.treeView2.SelectedNode.Text = name;
  579. }
  580. }
  581. createNameDialog.Close();
  582. }
  583. else
  584. {
  585. MessageBox.Show(PdnResources.GetString("Menu.leaseenterworkflowname.Text"));
  586. }
  587. }
  588. /// <summary>
  589. /// 添加
  590. /// </summary>
  591. /// <param name="sender"></param>
  592. /// <param name="e"></param>
  593. private void button3_Click(object sender, EventArgs e)
  594. {
  595. if (this.treeView1.SelectedNode != null && this.treeView2.SelectedNode != null)
  596. {
  597. TreeNode child = new TreeNode();
  598. child.Text = this.treeView1.SelectedNode.Text;//显示的名称 多语言
  599. child.Name = this.treeView1.SelectedNode.Name;//唯一标识 英文
  600. child.Tag = this.treeView1.SelectedNode.Tag;//唯一标识 数字
  601. this.treeView2.SelectedNode.Nodes.Add(child);
  602. }
  603. }
  604. /// <summary>
  605. /// 移出
  606. /// </summary>
  607. /// <param name="sender"></param>
  608. /// <param name="e"></param>
  609. private void button4_Click(object sender, EventArgs e)
  610. {
  611. if (this.treeView2.SelectedNode != null)
  612. {
  613. this.treeView2.Nodes.Remove(this.treeView2.SelectedNode);
  614. this.treeView2.Refresh();
  615. }
  616. }
  617. /// <summary>
  618. /// 向上移动
  619. /// </summary>
  620. /// <param name="sender"></param>
  621. /// <param name="e"></param>
  622. private void button5_Click(object sender, EventArgs e)
  623. {
  624. if (this.treeView2.SelectedNode != null)
  625. {
  626. if (this.treeView2.SelectedNode.Parent != null)
  627. {
  628. int index = this.treeView2.SelectedNode.Parent.Nodes.IndexOf(this.treeView2.SelectedNode);
  629. if (index > 0)
  630. {
  631. TreeNode prenode = (TreeNode)this.treeView2.SelectedNode.PrevNode.Clone();
  632. this.treeView2.SelectedNode.Parent.Nodes.Insert(index + 1, prenode);
  633. this.treeView2.Nodes.Remove(this.treeView2.SelectedNode.PrevNode);
  634. }
  635. }
  636. else
  637. {
  638. int index = this.treeView2.Nodes.IndexOf(this.treeView2.SelectedNode);
  639. if (index > 0)
  640. {
  641. TreeNode prenode = (TreeNode)this.treeView2.SelectedNode.PrevNode.Clone();
  642. this.treeView2.Nodes.Insert(index + 1, prenode);
  643. this.treeView2.Nodes.Remove(this.treeView2.SelectedNode.PrevNode);
  644. }
  645. }
  646. this.treeView2.Refresh();
  647. }
  648. }
  649. /// <summary>
  650. /// 向下移动
  651. /// </summary>
  652. /// <param name="sender"></param>
  653. /// <param name="e"></param>
  654. private void button6_Click(object sender, EventArgs e)
  655. {
  656. if (this.treeView2.SelectedNode != null)
  657. {
  658. if (this.treeView2.SelectedNode.Parent != null)
  659. {
  660. int index = this.treeView2.SelectedNode.Parent.Nodes.IndexOf(this.treeView2.SelectedNode);
  661. if (index < this.treeView2.SelectedNode.Parent.Nodes.Count - 1)
  662. {
  663. TreeNode prenode = (TreeNode)this.treeView2.SelectedNode.NextNode.Clone();
  664. this.treeView2.SelectedNode.Parent.Nodes.Insert(index, prenode);
  665. this.treeView2.Nodes.Remove(this.treeView2.SelectedNode.NextNode);
  666. }
  667. }
  668. else
  669. {
  670. int index = this.treeView2.Nodes.IndexOf(this.treeView2.SelectedNode);
  671. if (index < this.treeView2.Nodes.Count - 1)
  672. {
  673. TreeNode prenode = (TreeNode)this.treeView2.SelectedNode.NextNode.Clone();
  674. this.treeView2.Nodes.Insert(index, prenode);
  675. this.treeView2.Nodes.Remove(this.treeView2.SelectedNode.NextNode);
  676. }
  677. }
  678. this.treeView2.Refresh();
  679. }
  680. }
  681. /// <summary>
  682. /// 左侧工作流程鼠标按下事件
  683. /// </summary>
  684. /// <param name="sender"></param>
  685. /// <param name="e"></param>
  686. private void treeView2_MouseDown(object sender, MouseEventArgs e)
  687. {
  688. if ((sender as TreeView) != null)
  689. {
  690. this.treeView2.SelectedNode = this.treeView2.GetNodeAt(e.X, e.Y);
  691. this.treeView2.Refresh();
  692. }
  693. }
  694. /// <summary>
  695. /// 右侧功能列表鼠标按下事件
  696. /// </summary>
  697. /// <param name="sender"></param>
  698. /// <param name="e"></param>
  699. private void treeView1_MouseDown(object sender, MouseEventArgs e)
  700. {
  701. if ((sender as TreeView) != null)
  702. {
  703. this.treeView1.SelectedNode = this.treeView1.GetNodeAt(e.X, e.Y);
  704. this.treeView1.Refresh();
  705. }
  706. }
  707. }
  708. }