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

📄 flowmodeldef.cs

📁 工作流引擎
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			// btnClose
			// 
			this.btnClose.BackColor = System.Drawing.SystemColors.Control;
			this.btnClose.Location = new System.Drawing.Point(424, 444);
			this.btnClose.Name = "btnClose";
			this.btnClose.TabIndex = 5;
			this.btnClose.Text = "关闭";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// button4
			// 
			this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button4.Location = new System.Drawing.Point(336, 192);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(48, 23);
			this.button4.TabIndex = 7;
			this.button4.Text = "<全部";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// FlowManager
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.AliceBlue;
			this.ClientSize = new System.Drawing.Size(592, 478);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnConfirm);
			this.Controls.Add(this.btnNext);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.tbFlowName);
			this.Controls.Add(this.label1);
			this.Name = "FlowManager";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "添加流程模板";
			this.Load += new System.EventHandler(this.FlowManager_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox5.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void FlowManager_Load(object sender, System.EventArgs e)
		{
			try
			{
				if(conn==null)
					conn = MainForm.getConnection();
				setUserHash();//从数据库取出所有用户进Hashtable
				showtree();   //树型结构显示所有部门
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
				return;
			}
		}

		private void setUserHash() //取出所有用户,并放进hashtable
		{
			try
			{
				userHash = new Hashtable();
				string select = " select autoid, userid, name, depid, depcode from t_user where status = 1";
				using(SqlCommand cmd = conn.CreateCommand())
				{
					cmd.CommandText = select;

					using(SqlDataReader reader = cmd.ExecuteReader())
					{
						while(reader.Read())
						{
							int autoid = reader.GetInt32(0);
							string userid = reader.GetString(1);
							string name = reader.GetString(2);
							int depid = reader.GetInt32(3);
							string depcode = reader.GetString(4);							
							this.userHash.Add(new User(autoid, userid, name, depid, depcode),depcode);
						}
					}
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
				return;
			}
		}

		private void showtree() //递归 树型显示 部门结构
		{
			try
			{
				depHash = new Hashtable();
				string select = " select autoid,parentid,depcode,depname from t_dep where status=0 order by autoid";
				using(SqlCommand cmd = conn.CreateCommand())
				{
					cmd.CommandText = select;
					using(SqlDataReader reader = cmd.ExecuteReader())
					{
						while(reader.Read())
						{
							int autoid = reader.GetInt32(0);
							int parentid = reader.GetInt32(1);
							string depcode = reader.GetString(2);
							string depname = reader.GetString(3);
							Dep dep = new Dep(autoid,parentid,depcode,depname);//构造部门对象
							if(this.depHash.ContainsKey(dep.getParentID()))    //如果部门列表里面有该节点的父节点
							{
								ArrayList tmp = (ArrayList)depHash[dep.getParentID()];//取出父节点的子节点列表
								tmp.Add(dep);  //子节点列表加入本节点
								this.depHash.Remove(dep.getParentID());//部门列表移除父节点
								this.depHash.Add(dep.getParentID(),tmp);//加了新子节点的父节点加入部门列表
							}
							else //如果部门列表里面没有该节点的父节点,则把父节点加入节点列表
							{
								ArrayList tmp = new ArrayList();
								tmp.Add(dep);
								this.depHash.Add(dep.getParentID(),tmp);
							}
						}
					}
				}

				if(this.depHash.Count==0)
					return;				
				ArrayList root = (ArrayList)depHash[0L];
				Dep rootDep = (Dep)root[0];//生成根节点
				DepNode rootNode = new DepNode(rootDep.getDepName(),rootDep.getDepCode(),0);
				showNode(rootNode,rootDep.getID());//调用节点显示方法
				this.DepTree.Nodes.Add(rootNode);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
				return;
			}
		}
		private void showNode(DepNode curNode,long parentid) //递归显示所有部门节点
		{
			ArrayList tmp = (ArrayList)depHash[parentid];
			
			int count = depHash.Count;
			if(tmp==null)
				return;

			for(int i=0;i<tmp.Count;i++)
			{
				Dep tmpDep = (Dep)tmp[i];
				DepNode tmpNode = new DepNode(tmpDep.getDepName(),tmpDep.getDepCode(),1);
				curNode.Nodes.Add(tmpNode);
				if(depHash.ContainsKey(tmpDep.getID()))
					showNode(tmpNode,tmpDep.getID());
			}
			
		}

		private void DepTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			if(this.DepTree.SelectedNode==null)
				return;
			this.lbDepList.Items.Clear();//部门人员列表框的人员 清除掉
			string depcode = ((DepNode)this.DepTree.SelectedNode).getDepCode();
			//取得用户单击节点的部门编号
			foreach(User user in userHash.Keys)
			{//从userHash表中
				string tmpCode = (string)userHash[user];
				if(tmpCode.Length>=depcode.Length && tmpCode.Substring(0,depcode.Length).Equals(depcode))
				{
					this.lbDepList.Items.Add(user);
				}
			}
		}

		private bool isExists(User user)
		{
			if(this.lbUserList.Items.Count==0)
				return false;

			foreach(User tmpUser in this.lbUserList.Items)
			{
				if(tmpUser.Equals(user))
					return true;
			}

			return false;
		}

		private void menuItem1_Click(object sender, System.EventArgs e)//右键 添加选择的人员进 操作人员列表
		{
			if(this.lbDepList.Items.Count==0 || this.lbDepList.SelectedItem==null)
				return;

			User user = (User)this.lbDepList.SelectedItem;
			if(!isExists(user))
				this.lbUserList.Items.Add(user);
		}

		private void menuItem2_Click(object sender, System.EventArgs e) //右键 从操作人员列表里面 去除选中的人员
		{
			if(this.lbDepList.Items.Count==0 || this.lbDepList.SelectedItem==null)
				return;

			foreach(User user in this.lbDepList.Items)
			{
				if(!isExists(user))
					this.lbUserList.Items.Add(user);
			}
		}

		private void menuItem3_Click(object sender, System.EventArgs e) //右键 添加全部人员进操作人员列表
		{
			if(this.lbUserList.Items.Count==0 || this.lbUserList.SelectedItem==null)
				return;
			
			User user = (User)this.lbUserList.SelectedItem;
			this.lbUserList.Items.Remove(user);
		}

		private void menuItem4_Click(object sender, System.EventArgs e) //右键 从操作人员列表移除
		{
			if(this.lbUserList.Items.Count==0 || this.lbUserList.SelectedItem==null)
				return;

			this.lbUserList.Items.Clear();
		}

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

		private void btnNext_Click(object sender, System.EventArgs e) //保存当前步骤
		{
			if(MessageBox.Show("是否确认当前步骤的信息?","提示!",MessageBoxButtons.YesNo)==DialogResult.No)
				return;
			getSqlList();//把本步骤信息组织成sql语句保存进ArrayList列表
			resetGb(false);//步骤加1,步骤名称和操作人员列表清空
		}

		private void checkGb()   //判断当前步骤内容是否填全
		{
			if(this.step==1 && this.tbFlowName.Text.Trim()=="")
			{
				MessageBox.Show("请输入正确的模板名称!","提示!");
				this.tbFlowName.Focus();
				return;
			}

			if(this.tbStepName.Text.Trim()=="")
			{
				MessageBox.Show("请输入正确的步骤名称!","提示!");
				this.tbStepName.Focus();
				return;
			}

			if(this.lbUserList.Items.Count==0)
			{
				MessageBox.Show("请选择该步骤的操作员列表!","提示!");
				return;
			}
		}

		private void getSqlList() //组织定义模板步骤和流程模板的sql 语句
		{
			string sql = "";

			if(sqlList.Count==0)
			{
				sql = " select max(autoid) from t_flowmodeldef";
				string id=Database.ExecuteScalar(conn,sql).ToString();
				Console.WriteLine(id);
				flowid = int.Parse((id==null||id.Equals("null")||id.Equals(""))?"0":id)+1;
				sql = " insert into t_flowmodeldef values("+flowid+", '"+
					this.tbFlowName.Text+"', getdate(), "+MainForm.getUserAutoID()+", 0)";
				sqlList.Add(sql);
			}
			sql = " insert into t_flowstepmodeldef values("+flowid+", "	+
				this.tbStepSeq.Text+", '"+this.tbStepName.Text+"', '"+
				this.getUserList()+"', "+(this.cbNeed.Checked?1:0)+", 0)";
			sqlList.Add(sql);
		}

		private string getUserList() //从操作人员列表里面获得 该步骤的所有操作人员
		{
			StringBuilder sb = new StringBuilder();

			for(int i=0;i<this.lbUserList.Items.Count;i++)
			{
				User user = (User)this.lbUserList.Items[i];
				sb.Append(user.getAutoid());
				sb.Append(",");
			}

			string result = sb.ToString();
			
			return result.Substring(0,(result==null||result.Length==0)?0:(result.Length-1));
		}

		private void resetGb(bool isNew) //重设步骤的基本信息
		{
			if(isNew)
			{//是第一步
				this.tbFlowName.ReadOnly = false;
				this.tbFlowName.Clear();
				this.tbFlowName.Focus();
				this.step = 1;
			}
			else
			{//不是第一步 则步骤加一
				this.tbFlowName.ReadOnly = true;
				this.step += 1;
			}
			this.tbStepSeq.Text = this.step.ToString();
			this.cbNeed.Checked = false;
			this.lbDepList.Items.Clear();
			this.lbUserList.Items.Clear();	
			this.tbStepName.SelectAll();
			this.tbStepName.Focus();
		}

		private void btnConfirm_Click(object sender, System.EventArgs e)//单击完成按钮,完成全部步骤
		{
			
			if(this.step>=2)
			{//一个流程至少2步
				getSqlList();
				if(sqlList.Count==0)
					return;
				if(MessageBox.Show("是否确认该模板的所有信息?","提示!",MessageBoxButtons.YesNo)==DialogResult.No)
					return;  
				try
				{                    
					if(Database.ExecuteNonQuery(conn,sqlList))
					{//调用Database类的方法执行全部sql语句
						MessageBox.Show("该模板添加成功!","提示!");
						resetGb(true);//重新初始化步骤信息
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.ToString());
					return;
				}
			}
			else
			{
                MessageBox.Show("一个流程至少得有两步啊");
			}
		}

		private void button1_Click(object sender, System.EventArgs e)
			//添加选择的人员进 操作人员列表
		{
			if(this.lbDepList.SelectedItems.Count>0)
			{//如果用户在部门人员列表选择了人员
				for(int i=0;i<this.lbDepList.SelectedItems.Count;i++)
				{
					if(!this.lbUserList.Items.Contains(this.lbDepList.SelectedItems[i]))
						this.lbUserList.Items.Add(this.lbDepList.SelectedItems[i]);
					//添加选中人员进操作人员列表 添加前先判断该用户是否已经被添加进列表
				}
			}
			else
			{//如果没有选择,则把部门人员列表的第一个人员加进列表
				if(!this.lbUserList.Items.Contains(this.lbDepList.Items[0]))
					this.lbUserList.Items.Add(this.lbDepList.Items[0]);
			}
                		
		}

		private void button2_Click(object sender, System.EventArgs e) //从操作人员列表去除 选择的人员
		{
			if(this.lbUserList.SelectedItems.Count>0)
			{
				this.lbUserList.Items.Remove(this.lbUserList.SelectedItem);
			}
			else
			{
				this.lbUserList.Items.Remove(this.lbUserList.Items[0]);
			}
		}

		private void button3_Click(object sender, System.EventArgs e) //添加全部人员进操作人员列表
		{
			if(this.lbDepList.Items.Count>0)
			{
				for(int i=0;i<this.lbDepList.Items.Count;i++)
				{
					if(!this.lbUserList.Items.Contains(this.lbDepList.Items[i]))
						this.lbUserList.Items.Add(this.lbDepList.Items[i]);
				}
			}
		}

		private void button4_Click(object sender, System.EventArgs e) //从操作人员列表取出全部操作人员
		{
			this.lbUserList.Items.Clear();
		}
	}
}

⌨️ 快捷键说明

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