DataFieldSelector.cs
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:17k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. namespace OThinker.H3.WorkSheet
  7. {
  8. /// <summary>
  9. /// DataFieldSelector 的摘要说明。
  10. /// </summary>
  11. public class DataFieldSelector : System.Windows.Forms.Form
  12. {
  13. private System.Windows.Forms.Button btnOk;
  14. public System.Windows.Forms.Button btnCancel;
  15. private System.Windows.Forms.Panel panel1;
  16. /// <summary>
  17. /// 必需的设计器变量。
  18. /// </summary>
  19. private System.ComponentModel.Container components = null;
  20. private const string TempFileName = "Temp_H3_DesignWorkSheet.tmp";
  21. // 工作流管理器
  22.         private OThinker.H3.WorkflowTemplate.IWorkflowTemplateManager WorkflowManager = new OThinker.H3.Services.WorkflowManager();
  23. // 获得上次使用的工作流的名称版本等信息
  24. private string LastPackage = null;
  25. private string LastName = null;
  26.         private int LastVersion = OThinker.H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion;
  27. // 错误提示
  28. private const string ErrorMessage = "无法连接到服务器!可能由于:1、服务器未启动;2、数据库未启动;3、不具有权限。";
  29. private System.Windows.Forms.Panel panel2;
  30. private System.Windows.Forms.Panel panel3;
  31. private System.Windows.Forms.TreeView tvDataField;
  32. private System.Windows.Forms.Panel panel5;
  33. private System.Windows.Forms.Panel panel6;
  34. private System.Windows.Forms.ComboBox cmbWorkflowPackage;
  35. private System.Windows.Forms.ComboBox cmbWorkflowName;
  36. private System.Windows.Forms.ComboBox cmbWorkflowVersion;
  37. private System.Windows.Forms.Panel panel4;
  38. private System.Windows.Forms.Panel panel7;
  39. private System.Windows.Forms.Label label1;
  40. private System.Windows.Forms.Label label2;
  41. private System.Windows.Forms.Label label3;
  42. private const string ErrorTitle = "错误";
  43. public DataFieldSelector()
  44. {
  45. //
  46. // Windows 窗体设计器支持所必需的
  47. //
  48. InitializeComponent();
  49. // 检查该文件是否存在
  50. if(System.IO.File.Exists(TempFileName))
  51. {
  52. try
  53. {
  54. System.IO.StreamReader stmTmp = new System.IO.StreamReader(TempFileName);
  55. this.LastPackage = stmTmp.ReadLine();
  56. this.LastName = stmTmp.ReadLine();
  57. this.LastVersion = int.Parse(stmTmp.ReadLine());
  58. stmTmp.Close();
  59. }
  60. catch
  61. {
  62. try
  63. {
  64. // 如果出现异常说明该文件不能使用,删除他
  65. System.IO.File.Delete(TempFileName);
  66. }
  67. catch
  68. {
  69. }
  70. }
  71. }
  72. // 当前引擎内的所有流程类型
  73. string[] catalogs = null;
  74. try
  75. {
  76.                 catalogs = this.WorkflowManager.GetWorkflowPackages();
  77. }
  78. catch
  79. {
  80. System.Windows.Forms.MessageBox.Show(ErrorMessage, ErrorTitle);
  81. this.Close();
  82. }
  83. // 添加一个空项
  84. if(catalogs != null)
  85. {
  86. foreach(string processCatalog in catalogs)
  87. {
  88. this.cmbWorkflowPackage.Items.Add(processCatalog);
  89. }
  90. }
  91. int index = -1;
  92. if(
  93. this.LastPackage != null && 
  94. (index = this.cmbWorkflowPackage.Items.IndexOf(this.LastPackage)) != -1)
  95. {
  96. this.cmbWorkflowPackage.SelectedIndex = index;
  97. }
  98. else if(this.cmbWorkflowPackage.Items.Count > 0)
  99. {
  100. this.cmbWorkflowPackage.SelectedIndex = 0;
  101. }
  102. }
  103. /// <summary>
  104. /// 清理所有正在使用的资源。
  105. /// </summary>
  106. protected override void Dispose( bool disposing )
  107. {
  108. if( disposing )
  109. {
  110. if(components != null)
  111. {
  112. components.Dispose();
  113. }
  114. }
  115. base.Dispose( disposing );
  116. }
  117. #region Windows 窗体设计器生成的代码
  118. /// <summary>
  119. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  120. /// 此方法的内容。
  121. /// </summary>
  122. private void InitializeComponent()
  123. {
  124.             this.btnOk = new System.Windows.Forms.Button();
  125.             this.btnCancel = new System.Windows.Forms.Button();
  126.             this.panel1 = new System.Windows.Forms.Panel();
  127.             this.panel2 = new System.Windows.Forms.Panel();
  128.             this.panel5 = new System.Windows.Forms.Panel();
  129.             this.panel7 = new System.Windows.Forms.Panel();
  130.             this.cmbWorkflowVersion = new System.Windows.Forms.ComboBox();
  131.             this.cmbWorkflowName = new System.Windows.Forms.ComboBox();
  132.             this.cmbWorkflowPackage = new System.Windows.Forms.ComboBox();
  133.             this.panel4 = new System.Windows.Forms.Panel();
  134.             this.label3 = new System.Windows.Forms.Label();
  135.             this.label2 = new System.Windows.Forms.Label();
  136.             this.label1 = new System.Windows.Forms.Label();
  137.             this.panel6 = new System.Windows.Forms.Panel();
  138.             this.panel3 = new System.Windows.Forms.Panel();
  139.             this.tvDataField = new System.Windows.Forms.TreeView();
  140.             this.panel1.SuspendLayout();
  141.             this.panel2.SuspendLayout();
  142.             this.panel5.SuspendLayout();
  143.             this.panel7.SuspendLayout();
  144.             this.panel4.SuspendLayout();
  145.             this.panel3.SuspendLayout();
  146.             this.SuspendLayout();
  147.             // 
  148.             // btnOk
  149.             // 
  150.             this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
  151.             this.btnOk.Location = new System.Drawing.Point(48, 8);
  152.             this.btnOk.Name = "btnOk";
  153.             this.btnOk.Size = new System.Drawing.Size(56, 23);
  154.             this.btnOk.TabIndex = 4;
  155.             this.btnOk.Text = "确定(&O)";
  156.             this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
  157.             // 
  158.             // btnCancel
  159.             // 
  160.             this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  161.             this.btnCancel.Location = new System.Drawing.Point(216, 8);
  162.             this.btnCancel.Name = "btnCancel";
  163.             this.btnCancel.Size = new System.Drawing.Size(56, 23);
  164.             this.btnCancel.TabIndex = 5;
  165.             this.btnCancel.Text = "取消(&C)";
  166.             // 
  167.             // panel1
  168.             // 
  169.             this.panel1.Controls.Add(this.btnCancel);
  170.             this.panel1.Controls.Add(this.btnOk);
  171.             this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
  172.             this.panel1.Location = new System.Drawing.Point(0, 390);
  173.             this.panel1.Name = "panel1";
  174.             this.panel1.Size = new System.Drawing.Size(344, 40);
  175.             this.panel1.TabIndex = 6;
  176.             // 
  177.             // panel2
  178.             // 
  179.             this.panel2.Controls.Add(this.panel5);
  180.             this.panel2.Controls.Add(this.panel6);
  181.             this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
  182.             this.panel2.Location = new System.Drawing.Point(0, 0);
  183.             this.panel2.Name = "panel2";
  184.             this.panel2.Size = new System.Drawing.Size(344, 64);
  185.             this.panel2.TabIndex = 7;
  186.             // 
  187.             // panel5
  188.             // 
  189.             this.panel5.Controls.Add(this.panel7);
  190.             this.panel5.Controls.Add(this.panel4);
  191.             this.panel5.Dock = System.Windows.Forms.DockStyle.Fill;
  192.             this.panel5.Location = new System.Drawing.Point(0, 0);
  193.             this.panel5.Name = "panel5";
  194.             this.panel5.Size = new System.Drawing.Size(344, 64);
  195.             this.panel5.TabIndex = 7;
  196.             // 
  197.             // panel7
  198.             // 
  199.             this.panel7.Controls.Add(this.cmbWorkflowVersion);
  200.             this.panel7.Controls.Add(this.cmbWorkflowName);
  201.             this.panel7.Controls.Add(this.cmbWorkflowPackage);
  202.             this.panel7.Dock = System.Windows.Forms.DockStyle.Fill;
  203.             this.panel7.Location = new System.Drawing.Point(56, 0);
  204.             this.panel7.Name = "panel7";
  205.             this.panel7.Size = new System.Drawing.Size(288, 64);
  206.             this.panel7.TabIndex = 11;
  207.             // 
  208.             // cmbWorkflowVersion
  209.             // 
  210.             this.cmbWorkflowVersion.Dock = System.Windows.Forms.DockStyle.Top;
  211.             this.cmbWorkflowVersion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  212.             this.cmbWorkflowVersion.ItemHeight = 12;
  213.             this.cmbWorkflowVersion.Location = new System.Drawing.Point(0, 40);
  214.             this.cmbWorkflowVersion.Name = "cmbWorkflowVersion";
  215.             this.cmbWorkflowVersion.Size = new System.Drawing.Size(288, 20);
  216.             this.cmbWorkflowVersion.TabIndex = 3;
  217.             this.cmbWorkflowVersion.SelectedIndexChanged += new System.EventHandler(this.cmbWorkflowVersion_SelectedIndexChanged);
  218.             // 
  219.             // cmbWorkflowName
  220.             // 
  221.             this.cmbWorkflowName.Dock = System.Windows.Forms.DockStyle.Top;
  222.             this.cmbWorkflowName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  223.             this.cmbWorkflowName.ItemHeight = 12;
  224.             this.cmbWorkflowName.Location = new System.Drawing.Point(0, 20);
  225.             this.cmbWorkflowName.Name = "cmbWorkflowName";
  226.             this.cmbWorkflowName.Size = new System.Drawing.Size(288, 20);
  227.             this.cmbWorkflowName.TabIndex = 2;
  228.             this.cmbWorkflowName.SelectedIndexChanged += new System.EventHandler(this.cmbWorkflowName_SelectedIndexChanged);
  229.             // 
  230.             // cmbWorkflowPackage
  231.             // 
  232.             this.cmbWorkflowPackage.Dock = System.Windows.Forms.DockStyle.Top;
  233.             this.cmbWorkflowPackage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  234.             this.cmbWorkflowPackage.ItemHeight = 12;
  235.             this.cmbWorkflowPackage.Location = new System.Drawing.Point(0, 0);
  236.             this.cmbWorkflowPackage.Name = "cmbWorkflowPackage";
  237.             this.cmbWorkflowPackage.Size = new System.Drawing.Size(288, 20);
  238.             this.cmbWorkflowPackage.TabIndex = 1;
  239.             this.cmbWorkflowPackage.SelectedIndexChanged += new System.EventHandler(this.cmbWorkflowPackage_SelectedIndexChanged);
  240.             // 
  241.             // panel4
  242.             // 
  243.             this.panel4.Controls.Add(this.label3);
  244.             this.panel4.Controls.Add(this.label2);
  245.             this.panel4.Controls.Add(this.label1);
  246.             this.panel4.Dock = System.Windows.Forms.DockStyle.Left;
  247.             this.panel4.Location = new System.Drawing.Point(0, 0);
  248.             this.panel4.Name = "panel4";
  249.             this.panel4.Size = new System.Drawing.Size(56, 64);
  250.             this.panel4.TabIndex = 10;
  251.             // 
  252.             // label3
  253.             // 
  254.             this.label3.Dock = System.Windows.Forms.DockStyle.Top;
  255.             this.label3.Location = new System.Drawing.Point(0, 40);
  256.             this.label3.Name = "label3";
  257.             this.label3.Size = new System.Drawing.Size(56, 20);
  258.             this.label3.TabIndex = 2;
  259.             this.label3.Text = "模板版本";
  260.             // 
  261.             // label2
  262.             // 
  263.             this.label2.Dock = System.Windows.Forms.DockStyle.Top;
  264.             this.label2.Location = new System.Drawing.Point(0, 20);
  265.             this.label2.Name = "label2";
  266.             this.label2.Size = new System.Drawing.Size(56, 20);
  267.             this.label2.TabIndex = 1;
  268.             this.label2.Text = "模板名称";
  269.             // 
  270.             // label1
  271.             // 
  272.             this.label1.Dock = System.Windows.Forms.DockStyle.Top;
  273.             this.label1.Location = new System.Drawing.Point(0, 0);
  274.             this.label1.Name = "label1";
  275.             this.label1.Size = new System.Drawing.Size(56, 20);
  276.             this.label1.TabIndex = 0;
  277.             this.label1.Text = "模板类型";
  278.             // 
  279.             // panel6
  280.             // 
  281.             this.panel6.Dock = System.Windows.Forms.DockStyle.Fill;
  282.             this.panel6.Location = new System.Drawing.Point(0, 0);
  283.             this.panel6.Name = "panel6";
  284.             this.panel6.Size = new System.Drawing.Size(344, 64);
  285.             this.panel6.TabIndex = 11;
  286.             // 
  287.             // panel3
  288.             // 
  289.             this.panel3.Controls.Add(this.tvDataField);
  290.             this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
  291.             this.panel3.Location = new System.Drawing.Point(0, 64);
  292.             this.panel3.Name = "panel3";
  293.             this.panel3.Size = new System.Drawing.Size(344, 326);
  294.             this.panel3.TabIndex = 8;
  295.             // 
  296.             // tvDataField
  297.             // 
  298.             this.tvDataField.Dock = System.Windows.Forms.DockStyle.Fill;
  299.             this.tvDataField.Location = new System.Drawing.Point(0, 0);
  300.             this.tvDataField.Name = "tvDataField";
  301.             this.tvDataField.Size = new System.Drawing.Size(344, 326);
  302.             this.tvDataField.TabIndex = 0;
  303.             // 
  304.             // DataFieldSelector
  305.             // 
  306.             this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  307.             this.ClientSize = new System.Drawing.Size(344, 430);
  308.             this.Controls.Add(this.panel3);
  309.             this.Controls.Add(this.panel2);
  310.             this.Controls.Add(this.panel1);
  311.             this.MaximizeBox = false;
  312.             this.Name = "DataFieldSelector";
  313.             this.ShowIcon = false;
  314.             this.ShowInTaskbar = false;
  315.             this.Text = "数据项选择器";
  316.             this.panel1.ResumeLayout(false);
  317.             this.panel2.ResumeLayout(false);
  318.             this.panel5.ResumeLayout(false);
  319.             this.panel7.ResumeLayout(false);
  320.             this.panel4.ResumeLayout(false);
  321.             this.panel3.ResumeLayout(false);
  322.             this.ResumeLayout(false);
  323. }
  324. #endregion
  325. private void cmbWorkflowPackage_SelectedIndexChanged(object sender, System.EventArgs e)
  326. {
  327. this.cmbWorkflowName.Items.Clear();
  328. this.cmbWorkflowVersion.Items.Clear();
  329. this.tvDataField.Nodes.Clear();
  330. // 当前引擎内的所有流程类型
  331. string[] names = null;
  332. try
  333. {
  334. names = this.WorkflowManager.GetWorkflowNames(this.cmbWorkflowPackage.Text, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
  335. }
  336. catch
  337. {
  338. System.Windows.Forms.MessageBox.Show(ErrorMessage, ErrorTitle);
  339. }
  340. // 添加一个空项
  341. if(names != null)
  342. {
  343. foreach(string name in names)
  344. {
  345. this.cmbWorkflowName.Items.Add(name);
  346. }
  347. }
  348. int index = -1;
  349. if(this.LastName != null && (index = this.cmbWorkflowName.Items.IndexOf(this.LastName)) != -1)
  350. {
  351. this.cmbWorkflowName.SelectedIndex = index;
  352. }
  353. else if(this.cmbWorkflowName.Items.Count > 0)
  354. {
  355. this.cmbWorkflowName.SelectedIndex = 0;
  356. }
  357. }
  358. private void cmbWorkflowName_SelectedIndexChanged(object sender, System.EventArgs e)
  359. {
  360. this.cmbWorkflowVersion.Items.Clear();
  361. this.tvDataField.Nodes.Clear();
  362. // 当前引擎内的所有流程类型
  363. int[] versions = null;
  364. try
  365. {
  366. versions = this.WorkflowManager.GetWorkflowVersions(
  367. this.cmbWorkflowPackage.Text, 
  368. this.cmbWorkflowName.Text);
  369. }
  370. catch
  371. {
  372. System.Windows.Forms.MessageBox.Show(ErrorMessage, ErrorTitle);
  373. }
  374. // 添加一个空项
  375. if(versions != null)
  376. {
  377. foreach(int version in versions)
  378. {
  379. this.cmbWorkflowVersion.Items.Add(version.ToString());
  380. }
  381. }
  382. int index = -1;
  383.             if (this.LastVersion != H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion && (index = this.cmbWorkflowVersion.Items.IndexOf(this.LastVersion.ToString())) != -1)
  384. {
  385. this.cmbWorkflowVersion.SelectedIndex = index;
  386. }
  387. else if(this.cmbWorkflowVersion.Items.Count > 0)
  388. {
  389. this.cmbWorkflowVersion.SelectedIndex = 0;
  390. }
  391. }
  392. private void cmbWorkflowVersion_SelectedIndexChanged(object sender, System.EventArgs e)
  393. {
  394. this.tvDataField.Nodes.Clear();
  395. TreeNode root = new TreeNode("所有数据");
  396. this.tvDataField.Nodes.Add(root);
  397. // 将系统数据添加进去
  398. root.Nodes.Add(OThinker.H3.Data.Keywords.ParserFactory.GetDataTreeNode());
  399. root.Expand();
  400. // 添加流程模板数据
  401. H3.Data.WorkflowDataItem[] items = null;
  402. try
  403. {
  404.                 H3.WorkflowTemplate.WorkflowTemplate workflow 
  405. = this.WorkflowManager.GetWorkflow(
  406. this.cmbWorkflowPackage.Text, 
  407. this.cmbWorkflowName.Text, 
  408. int.Parse(this.cmbWorkflowVersion.Text));
  409. items = workflow.DataItems;
  410. }
  411. catch
  412. {
  413. System.Windows.Forms.MessageBox.Show(ErrorMessage, ErrorTitle);
  414. return;
  415. }
  416. root.Nodes.Add("流程数据");
  417. root.Nodes[1].Expand();
  418. if(items != null)
  419. {
  420. foreach(H3.Data.WorkflowDataItem item in items)
  421. {
  422. root.Nodes[1].Nodes.Add(item.ItemName);
  423. }
  424. }
  425. }
  426. public string SelctedDataField
  427. {
  428. get
  429. {
  430. if(this.tvDataField.SelectedNode == null)
  431. {
  432. return null;
  433. }
  434. else
  435. {
  436. return this.tvDataField.SelectedNode.Text;
  437. }
  438. }
  439. }
  440. private void btnOk_Click(object sender, System.EventArgs e)
  441. {
  442. try
  443. {
  444. if(System.IO.File.Exists(TempFileName))
  445. {
  446. System.IO.File.Delete(TempFileName);
  447. }
  448. System.IO.StreamWriter stmTmp = new System.IO.StreamWriter(TempFileName);
  449. stmTmp.WriteLine(this.cmbWorkflowPackage.Text);
  450. stmTmp.WriteLine(this.cmbWorkflowName.Text);
  451. stmTmp.WriteLine(this.cmbWorkflowVersion.Text);
  452. stmTmp.Close();
  453. }
  454. catch
  455. {
  456. }
  457. }
  458. }
  459. }