DataFieldSelector.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:17k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace OThinker.H3.WorkSheet
- {
- /// <summary>
- /// DataFieldSelector 的摘要说明。
- /// </summary>
- public class DataFieldSelector : System.Windows.Forms.Form
- {
- private System.Windows.Forms.Button btnOk;
- public System.Windows.Forms.Button btnCancel;
- private System.Windows.Forms.Panel panel1;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- private const string TempFileName = "Temp_H3_DesignWorkSheet.tmp";
- // 工作流管理器
- private OThinker.H3.WorkflowTemplate.IWorkflowTemplateManager WorkflowManager = new OThinker.H3.Services.WorkflowManager();
- // 获得上次使用的工作流的名称版本等信息
- private string LastPackage = null;
- private string LastName = null;
- private int LastVersion = OThinker.H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion;
- // 错误提示
- private const string ErrorMessage = "无法连接到服务器!可能由于:1、服务器未启动;2、数据库未启动;3、不具有权限。";
- private System.Windows.Forms.Panel panel2;
- private System.Windows.Forms.Panel panel3;
- private System.Windows.Forms.TreeView tvDataField;
- private System.Windows.Forms.Panel panel5;
- private System.Windows.Forms.Panel panel6;
- private System.Windows.Forms.ComboBox cmbWorkflowPackage;
- private System.Windows.Forms.ComboBox cmbWorkflowName;
- private System.Windows.Forms.ComboBox cmbWorkflowVersion;
- private System.Windows.Forms.Panel panel4;
- private System.Windows.Forms.Panel panel7;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- private const string ErrorTitle = "错误";
- public DataFieldSelector()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- // 检查该文件是否存在
- if(System.IO.File.Exists(TempFileName))
- {
- try
- {
- System.IO.StreamReader stmTmp = new System.IO.StreamReader(TempFileName);
- this.LastPackage = stmTmp.ReadLine();
- this.LastName = stmTmp.ReadLine();
- this.LastVersion = int.Parse(stmTmp.ReadLine());
- stmTmp.Close();
- }
- catch
- {
- try
- {
- // 如果出现异常说明该文件不能使用,删除他
- System.IO.File.Delete(TempFileName);
- }
- catch
- {
- }
- }
- }
- // 当前引擎内的所有流程类型
- string[] catalogs = null;
- try
- {
- catalogs = this.WorkflowManager.GetWorkflowPackages();
- }
- catch
- {
- System.Windows.Forms.MessageBox.Show(ErrorMessage, ErrorTitle);
- this.Close();
- }
- // 添加一个空项
- if(catalogs != null)
- {
- foreach(string processCatalog in catalogs)
- {
- this.cmbWorkflowPackage.Items.Add(processCatalog);
- }
- }
- int index = -1;
- if(
- this.LastPackage != null &&
- (index = this.cmbWorkflowPackage.Items.IndexOf(this.LastPackage)) != -1)
- {
- this.cmbWorkflowPackage.SelectedIndex = index;
- }
- else if(this.cmbWorkflowPackage.Items.Count > 0)
- {
- this.cmbWorkflowPackage.SelectedIndex = 0;
- }
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.btnOk = new System.Windows.Forms.Button();
- this.btnCancel = new System.Windows.Forms.Button();
- this.panel1 = new System.Windows.Forms.Panel();
- this.panel2 = new System.Windows.Forms.Panel();
- this.panel5 = new System.Windows.Forms.Panel();
- this.panel7 = new System.Windows.Forms.Panel();
- this.cmbWorkflowVersion = new System.Windows.Forms.ComboBox();
- this.cmbWorkflowName = new System.Windows.Forms.ComboBox();
- this.cmbWorkflowPackage = new System.Windows.Forms.ComboBox();
- this.panel4 = new System.Windows.Forms.Panel();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label1 = new System.Windows.Forms.Label();
- this.panel6 = new System.Windows.Forms.Panel();
- this.panel3 = new System.Windows.Forms.Panel();
- this.tvDataField = new System.Windows.Forms.TreeView();
- this.panel1.SuspendLayout();
- this.panel2.SuspendLayout();
- this.panel5.SuspendLayout();
- this.panel7.SuspendLayout();
- this.panel4.SuspendLayout();
- this.panel3.SuspendLayout();
- this.SuspendLayout();
- //
- // btnOk
- //
- this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.btnOk.Location = new System.Drawing.Point(48, 8);
- this.btnOk.Name = "btnOk";
- this.btnOk.Size = new System.Drawing.Size(56, 23);
- this.btnOk.TabIndex = 4;
- this.btnOk.Text = "确定(&O)";
- this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
- //
- // btnCancel
- //
- this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this.btnCancel.Location = new System.Drawing.Point(216, 8);
- this.btnCancel.Name = "btnCancel";
- this.btnCancel.Size = new System.Drawing.Size(56, 23);
- this.btnCancel.TabIndex = 5;
- this.btnCancel.Text = "取消(&C)";
- //
- // panel1
- //
- this.panel1.Controls.Add(this.btnCancel);
- this.panel1.Controls.Add(this.btnOk);
- this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.panel1.Location = new System.Drawing.Point(0, 390);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(344, 40);
- this.panel1.TabIndex = 6;
- //
- // panel2
- //
- this.panel2.Controls.Add(this.panel5);
- this.panel2.Controls.Add(this.panel6);
- this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
- this.panel2.Location = new System.Drawing.Point(0, 0);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(344, 64);
- this.panel2.TabIndex = 7;
- //
- // panel5
- //
- this.panel5.Controls.Add(this.panel7);
- this.panel5.Controls.Add(this.panel4);
- this.panel5.Dock = System.Windows.Forms.DockStyle.Fill;
- this.panel5.Location = new System.Drawing.Point(0, 0);
- this.panel5.Name = "panel5";
- this.panel5.Size = new System.Drawing.Size(344, 64);
- this.panel5.TabIndex = 7;
- //
- // panel7
- //
- this.panel7.Controls.Add(this.cmbWorkflowVersion);
- this.panel7.Controls.Add(this.cmbWorkflowName);
- this.panel7.Controls.Add(this.cmbWorkflowPackage);
- this.panel7.Dock = System.Windows.Forms.DockStyle.Fill;
- this.panel7.Location = new System.Drawing.Point(56, 0);
- this.panel7.Name = "panel7";
- this.panel7.Size = new System.Drawing.Size(288, 64);
- this.panel7.TabIndex = 11;
- //
- // cmbWorkflowVersion
- //
- this.cmbWorkflowVersion.Dock = System.Windows.Forms.DockStyle.Top;
- this.cmbWorkflowVersion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.cmbWorkflowVersion.ItemHeight = 12;
- this.cmbWorkflowVersion.Location = new System.Drawing.Point(0, 40);
- this.cmbWorkflowVersion.Name = "cmbWorkflowVersion";
- this.cmbWorkflowVersion.Size = new System.Drawing.Size(288, 20);
- this.cmbWorkflowVersion.TabIndex = 3;
- this.cmbWorkflowVersion.SelectedIndexChanged += new System.EventHandler(this.cmbWorkflowVersion_SelectedIndexChanged);
- //
- // cmbWorkflowName
- //
- this.cmbWorkflowName.Dock = System.Windows.Forms.DockStyle.Top;
- this.cmbWorkflowName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.cmbWorkflowName.ItemHeight = 12;
- this.cmbWorkflowName.Location = new System.Drawing.Point(0, 20);
- this.cmbWorkflowName.Name = "cmbWorkflowName";
- this.cmbWorkflowName.Size = new System.Drawing.Size(288, 20);
- this.cmbWorkflowName.TabIndex = 2;
- this.cmbWorkflowName.SelectedIndexChanged += new System.EventHandler(this.cmbWorkflowName_SelectedIndexChanged);
- //
- // cmbWorkflowPackage
- //
- this.cmbWorkflowPackage.Dock = System.Windows.Forms.DockStyle.Top;
- this.cmbWorkflowPackage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.cmbWorkflowPackage.ItemHeight = 12;
- this.cmbWorkflowPackage.Location = new System.Drawing.Point(0, 0);
- this.cmbWorkflowPackage.Name = "cmbWorkflowPackage";
- this.cmbWorkflowPackage.Size = new System.Drawing.Size(288, 20);
- this.cmbWorkflowPackage.TabIndex = 1;
- this.cmbWorkflowPackage.SelectedIndexChanged += new System.EventHandler(this.cmbWorkflowPackage_SelectedIndexChanged);
- //
- // panel4
- //
- this.panel4.Controls.Add(this.label3);
- this.panel4.Controls.Add(this.label2);
- this.panel4.Controls.Add(this.label1);
- this.panel4.Dock = System.Windows.Forms.DockStyle.Left;
- this.panel4.Location = new System.Drawing.Point(0, 0);
- this.panel4.Name = "panel4";
- this.panel4.Size = new System.Drawing.Size(56, 64);
- this.panel4.TabIndex = 10;
- //
- // label3
- //
- this.label3.Dock = System.Windows.Forms.DockStyle.Top;
- this.label3.Location = new System.Drawing.Point(0, 40);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(56, 20);
- this.label3.TabIndex = 2;
- this.label3.Text = "模板版本";
- //
- // label2
- //
- this.label2.Dock = System.Windows.Forms.DockStyle.Top;
- this.label2.Location = new System.Drawing.Point(0, 20);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(56, 20);
- this.label2.TabIndex = 1;
- this.label2.Text = "模板名称";
- //
- // label1
- //
- this.label1.Dock = System.Windows.Forms.DockStyle.Top;
- this.label1.Location = new System.Drawing.Point(0, 0);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(56, 20);
- this.label1.TabIndex = 0;
- this.label1.Text = "模板类型";
- //
- // panel6
- //
- this.panel6.Dock = System.Windows.Forms.DockStyle.Fill;
- this.panel6.Location = new System.Drawing.Point(0, 0);
- this.panel6.Name = "panel6";
- this.panel6.Size = new System.Drawing.Size(344, 64);
- this.panel6.TabIndex = 11;
- //
- // panel3
- //
- this.panel3.Controls.Add(this.tvDataField);
- this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
- this.panel3.Location = new System.Drawing.Point(0, 64);
- this.panel3.Name = "panel3";
- this.panel3.Size = new System.Drawing.Size(344, 326);
- this.panel3.TabIndex = 8;
- //
- // tvDataField
- //
- this.tvDataField.Dock = System.Windows.Forms.DockStyle.Fill;
- this.tvDataField.Location = new System.Drawing.Point(0, 0);
- this.tvDataField.Name = "tvDataField";
- this.tvDataField.Size = new System.Drawing.Size(344, 326);
- this.tvDataField.TabIndex = 0;
- //
- // DataFieldSelector
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(344, 430);
- this.Controls.Add(this.panel3);
- this.Controls.Add(this.panel2);
- this.Controls.Add(this.panel1);
- this.MaximizeBox = false;
- this.Name = "DataFieldSelector";
- this.ShowIcon = false;
- this.ShowInTaskbar = false;
- this.Text = "数据项选择器";
- this.panel1.ResumeLayout(false);
- this.panel2.ResumeLayout(false);
- this.panel5.ResumeLayout(false);
- this.panel7.ResumeLayout(false);
- this.panel4.ResumeLayout(false);
- this.panel3.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- private void cmbWorkflowPackage_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- this.cmbWorkflowName.Items.Clear();
- this.cmbWorkflowVersion.Items.Clear();
- this.tvDataField.Nodes.Clear();
- // 当前引擎内的所有流程类型
- string[] names = null;
- try
- {
- names = this.WorkflowManager.GetWorkflowNames(this.cmbWorkflowPackage.Text, OThinker.H3.WorkflowTemplate.WorkflowState.Unspecified);
- }
- catch
- {
- System.Windows.Forms.MessageBox.Show(ErrorMessage, ErrorTitle);
- }
- // 添加一个空项
- if(names != null)
- {
- foreach(string name in names)
- {
- this.cmbWorkflowName.Items.Add(name);
- }
- }
- int index = -1;
- if(this.LastName != null && (index = this.cmbWorkflowName.Items.IndexOf(this.LastName)) != -1)
- {
- this.cmbWorkflowName.SelectedIndex = index;
- }
- else if(this.cmbWorkflowName.Items.Count > 0)
- {
- this.cmbWorkflowName.SelectedIndex = 0;
- }
- }
- private void cmbWorkflowName_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- this.cmbWorkflowVersion.Items.Clear();
- this.tvDataField.Nodes.Clear();
- // 当前引擎内的所有流程类型
- int[] versions = null;
- try
- {
- versions = this.WorkflowManager.GetWorkflowVersions(
- this.cmbWorkflowPackage.Text,
- this.cmbWorkflowName.Text);
- }
- catch
- {
- System.Windows.Forms.MessageBox.Show(ErrorMessage, ErrorTitle);
- }
- // 添加一个空项
- if(versions != null)
- {
- foreach(int version in versions)
- {
- this.cmbWorkflowVersion.Items.Add(version.ToString());
- }
- }
- int index = -1;
- if (this.LastVersion != H3.WorkflowTemplate.WorkflowTemplate.NullWorkflowVersion && (index = this.cmbWorkflowVersion.Items.IndexOf(this.LastVersion.ToString())) != -1)
- {
- this.cmbWorkflowVersion.SelectedIndex = index;
- }
- else if(this.cmbWorkflowVersion.Items.Count > 0)
- {
- this.cmbWorkflowVersion.SelectedIndex = 0;
- }
- }
- private void cmbWorkflowVersion_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- this.tvDataField.Nodes.Clear();
- TreeNode root = new TreeNode("所有数据");
- this.tvDataField.Nodes.Add(root);
- // 将系统数据添加进去
- root.Nodes.Add(OThinker.H3.Data.Keywords.ParserFactory.GetDataTreeNode());
- root.Expand();
- // 添加流程模板数据
- H3.Data.WorkflowDataItem[] items = null;
- try
- {
- H3.WorkflowTemplate.WorkflowTemplate workflow
- = this.WorkflowManager.GetWorkflow(
- this.cmbWorkflowPackage.Text,
- this.cmbWorkflowName.Text,
- int.Parse(this.cmbWorkflowVersion.Text));
- items = workflow.DataItems;
- }
- catch
- {
- System.Windows.Forms.MessageBox.Show(ErrorMessage, ErrorTitle);
- return;
- }
- root.Nodes.Add("流程数据");
- root.Nodes[1].Expand();
- if(items != null)
- {
- foreach(H3.Data.WorkflowDataItem item in items)
- {
- root.Nodes[1].Nodes.Add(item.ItemName);
- }
- }
- }
- public string SelctedDataField
- {
- get
- {
- if(this.tvDataField.SelectedNode == null)
- {
- return null;
- }
- else
- {
- return this.tvDataField.SelectedNode.Text;
- }
- }
- }
- private void btnOk_Click(object sender, System.EventArgs e)
- {
- try
- {
- if(System.IO.File.Exists(TempFileName))
- {
- System.IO.File.Delete(TempFileName);
- }
- System.IO.StreamWriter stmTmp = new System.IO.StreamWriter(TempFileName);
- stmTmp.WriteLine(this.cmbWorkflowPackage.Text);
- stmTmp.WriteLine(this.cmbWorkflowName.Text);
- stmTmp.WriteLine(this.cmbWorkflowVersion.Text);
- stmTmp.Close();
- }
- catch
- {
- }
- }
- }
- }