⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startflow.cs

📁 工作流引擎
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using WorkFlow.util;

namespace WorkFlow.flow
{
	/// <summary>
	/// CreatProject 的摘要说明。
	/// </summary>
	public class StartFlow : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox cbbFlow;
		private System.Windows.Forms.Button btnConfirm;
		private System.Windows.Forms.Button btnClose;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox tbProjectName;

		private SqlConnection  conn;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.DateTimePicker dateTimePicker1;

		private int userAutoId = -1;

		public StartFlow()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			//this.dateTimePicker1.Value.Date.AddDays(3);
			//this.dateTimePicker1.Refresh();
			

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			this.dateTimePicker1.Value = DateTime.Now.AddDays(3);
		}

		/// <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.label1 = new System.Windows.Forms.Label();
			this.cbbFlow = new System.Windows.Forms.ComboBox();
			this.btnConfirm = new System.Windows.Forms.Button();
			this.btnClose = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.tbProjectName = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(24, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(91, 17);
			this.label1.TabIndex = 1;
			this.label1.Text = "选择流程模板:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// cbbFlow
			// 
			this.cbbFlow.Location = new System.Drawing.Point(144, 20);
			this.cbbFlow.Name = "cbbFlow";
			this.cbbFlow.Size = new System.Drawing.Size(144, 20);
			this.cbbFlow.TabIndex = 2;
			// 
			// btnConfirm
			// 
			this.btnConfirm.BackColor = System.Drawing.SystemColors.Control;
			this.btnConfirm.Location = new System.Drawing.Point(48, 120);
			this.btnConfirm.Name = "btnConfirm";
			this.btnConfirm.TabIndex = 5;
			this.btnConfirm.Text = "确定";
			this.btnConfirm.Click += new System.EventHandler(this.btnConfirm_Click);
			// 
			// btnClose
			// 
			this.btnClose.BackColor = System.Drawing.SystemColors.Control;
			this.btnClose.Location = new System.Drawing.Point(160, 120);
			this.btnClose.Name = "btnClose";
			this.btnClose.TabIndex = 6;
			this.btnClose.Text = "关闭";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(24, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(91, 17);
			this.label2.TabIndex = 7;
			this.label2.Text = "填写流程名称:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// tbProjectName
			// 
			this.tbProjectName.Location = new System.Drawing.Point(144, 56);
			this.tbProjectName.Name = "tbProjectName";
			this.tbProjectName.Size = new System.Drawing.Size(144, 21);
			this.tbProjectName.TabIndex = 8;
			this.tbProjectName.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 88);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(120, 16);
			this.label3.TabIndex = 9;
			this.label3.Text = "选择流程结束时间:";
			// 
			// dateTimePicker1
			// 
			this.dateTimePicker1.Location = new System.Drawing.Point(144, 88);
			this.dateTimePicker1.Name = "dateTimePicker1";
			this.dateTimePicker1.Size = new System.Drawing.Size(144, 21);
			this.dateTimePicker1.TabIndex = 10;
			// 
			// CreatProject
			// 
			this.AcceptButton = this.btnConfirm;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.AliceBlue;
			this.ClientSize = new System.Drawing.Size(320, 158);
			this.Controls.Add(this.dateTimePicker1);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.tbProjectName);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnConfirm);
			this.Controls.Add(this.cbbFlow);
			this.MaximizeBox = false;
			this.Name = "CreatProject";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "创建新流程";
			this.Load += new System.EventHandler(this.CreatProject_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void btnConfirm_Click(object sender, System.EventArgs e)
		{
			if(this.tbProjectName.Text.Trim().Equals(""))
			{
				MessageBox.Show("请填写所创建的流程名称!","提示!");
				return;
			}
			if(MessageBox.Show("是否确定要创建此流程?","提示!",MessageBoxButtons.YesNo)==DialogResult.No)
				return;
			int flowid = ((ComboItem)this.cbbFlow.SelectedItem).Value;
			try
			{
				string select = " select max(autoid) from t_flow";
				string id = Database.ExecuteScalar(conn,select).ToString();
                int projectId=int.Parse((id==null||id.Equals(""))?"0":id+1);
                //给新创建的流程一个编号
				ArrayList sqlList = new ArrayList();
				//流程基本信息存入t_flow表
				string insert = " insert into t_flow(autoid, flowid, title, status, begindate,enddate)"+
					" values("+projectId+", "+flowid+", '"+(this.tbProjectName.Text+"("+MainForm.getRealName()+",编号:"+projectId+")")+"', 0, getdate(),CONVERT(varchar, '"+this.dateTimePicker1.Value.ToString()+"',120))";
				sqlList.Add(insert);
				//流程步骤信息存入 t_flowstep表
				insert = " insert into t_flowstep(projectid, seq, operatorid, status)"+
					" select "+projectId+", seq, (case seq when 1 then "+userAutoId+" else  null end), 0 from t_flowstepmodeldef where flowid = "+flowid;				
				sqlList.Add(insert);
				if(Database.ExecuteNonQuery(conn, sqlList))
				{
					MessageBox.Show("流程创建成功,请继续完成下面的步骤!","提示!");
					FinishFlow ff=new FinishFlow();
					ff.dataGrid1.DataBindings.Clear();
					ff.setUserMustDo();
					ff.ShowDialog();
					this.Close();
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
				return;
			}
		}

		private void CreatProject_Load(object sender, System.EventArgs e)
		{
			try
			{
				userAutoId = MainForm.getUserAutoID();

				Console.WriteLine("userAutoId:"+userAutoId);

				if(conn==null)
					conn = MainForm.getConnection();

				using(SqlCommand cmd = conn.CreateCommand())
				{
					string sql = " select distinct a.autoid, a.name, b.userid from t_flowmodeldef a, t_flowstepmodeldef b"+
						" where a.status = 0 and a.autoid = b.flowid and b.seq = 1 order by a.autoid";
					cmd.CommandText=sql;
					Console.WriteLine(sql);
					using(SqlDataReader reader = cmd.ExecuteReader())
					{
						while(reader.Read())
						{
							int id = reader.GetInt32(0);
							string name = reader.GetString(1);
							string list = reader.GetString(2);
							Console.WriteLine("list:"+list);

							if(isExists(list))
							{
								this.cbbFlow.Items.Add(new ComboItem(name,id));
							}
						}
					}
				}

				if(this.cbbFlow.Items.Count==0)
				{
					MessageBox.Show("您还没有权限创建任何流程!","提示!");
					return;
				}

				this.cbbFlow.SelectedIndex = 0;
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
				return;
			}
		}

		private bool isExists(string list)
		{
			string[] ids = list.Split(',');
			
			string struser=userAutoId+"";
			
			for(int i=0;i<ids.Length;i++)
			{
				Console.WriteLine("userAutoId:"+userAutoId+":ids[i]:"+ids[i]);
				if(struser.Equals(ids[i]))
				{
					
					return true;
				}
			}

			return false;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -