using System.Collections; using System.Data; using System.Data.SqlClient; using Business.FileFlow.Entity; using Common; namespace Business.FileFlow.Vo { public class FlowVo { /// /// 参数赋值 /// /// 实体类FlowEty /// 参数数组 private SqlParameter[] SetPara(FlowEty flow) { return new[] { new SqlParameter("@id", flow.Id), new SqlParameter("@name", flow.Name), new SqlParameter("@actionIDs", flow.ActionIDs), new SqlParameter("@remark", flow.Remark), new SqlParameter("@delflag", flow.DelFlag), new SqlParameter("@addUserID", flow.AddUserId), new SqlParameter("@addtime", flow.AddTime), new SqlParameter("@updateUserID", flow.UpdateUserId), new SqlParameter("@lastTime", flow.LastTime) }; } /// /// 新增flow记录 /// /// 实体类FlowEty /// 成功返回空字符串,失败返回错误信息 public string InsertFlow(FlowEty flow) { var sql = "insert into flow(id,name,actionIDs,remark,delflag,addUserID,addtime,updateUserID,lastTime) values(@id,@name,@actionIDs,@remark,@delflag,@addUserID,@addtime,@updateUserID,@lastTime)"; return SqlHelper.ExecSql(sql, SetPara(flow)); } /// /// 获取全部流程信息 /// /// 查询字段 /// 数据表 public DataTable AllFlow(string searchText) { var sql = "select p.id,p.name,p.actionIDs,p.remark,p.lastTime,s.username as addusername ,ss.username as updateusername from flow p left join SysUser s on s.userid=p.addUserID left join SysUser ss on ss.userid=p.updateUserID where p.delflag ='false' "; if (!string.IsNullOrEmpty(searchText)) { //根据查询字段 进行查询 sql += string.Format( "and( p.name like '%{0}%' or p.remark like '%{0}%' or s.username like '%{0}%' or ss.username like '%{0}%')", searchText); } sql += " order by p.lastTime DESC"; return SqlHelper.ExecSqlDateTable(sql); } /// /// 更新流程信息 /// /// 实体类FlowEty /// 成功返回空字符串,失败返回错误信息 public string UpdateFlow(FlowEty flow) { var sq1 = "update flow set name=@name,actionIDs=@actionIDs,remark=@remark,lastTime=@lastTime,updateUserID=@updateUserID where id=@id"; return SqlHelper.ExecSql(sq1, SetPara(flow)); } /// /// 根据id删除流程信息 /// /// 流程id /// 成功返回空字符串,失败返回错误信息 public string DelFlow(string id) { var sql = "update flow set delflag='true' where id in (" + id + ")"; return SqlHelper.ExecSql(sql); } /// /// 根据流程id 获取某一步的操作ID /// /// 流程id /// 第几步 /// 操作id public string GetAction(string flowid) { string sql = "select actionIDs from flow where id=@id"; return SqlHelper.ExecSqlSc(sql, new SqlParameter("@id", flowid)); } /// /// 根据流程ID获取流程名字 /// /// /// public string GetFlowNameById(string flowid) { string sql = "select name from flow where id=@id"; return SqlHelper.ExecSqlSc(sql, new SqlParameter("@id", flowid)); } /// /// 根据id返回FlowEty实体类 /// /// flowid public FlowEty GetFlowById(string id) { var con = new SqlConnection(SqlHelper.ConStr); var cmd = new SqlCommand { Connection = con, CommandType = CommandType.Text, CommandText = "select * from flow where id=@id and delflag='false'" }; cmd.Parameters.AddWithValue("@id", id); var flow = new FlowEty(); try { con.Open(); } catch { return flow; } using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { if (!reader.HasRows) return flow; while (reader.Read()) { flow.Id = SqlHelper.ReaderString("id", reader); flow.Num = SqlHelper.ReaderInt("num", reader); flow.Name = SqlHelper.ReaderString("name", reader); flow.Remark = SqlHelper.ReaderString("remark", reader); flow.DelFlag = SqlHelper.ReaderBool("delflag", reader); flow.AddUserId = SqlHelper.ReaderString("addUserID", reader); flow.AddTime = SqlHelper.ReaderDateTime("addtime", reader); flow.UpdateUserId = SqlHelper.ReaderString("updateUserID", reader); flow.LastTime = SqlHelper.ReaderDateTime("lastTime", reader); flow.ActionIDs = SqlHelper.ReaderString("actionIDs", reader); } } return flow; } /// /// 根据actionID获取操作顺序名字 /// /// 流程的actionIDs /// 所有流程操作数据表 /// 流程操作顺序名字 public string ActionNString(string actionIDs ,DataTable actionTable) { Hashtable temphash = FlowAction(actionIDs); //保存流程操作的顺序号及名字 string actionName = string.Empty; for (int i = 0; i < temphash.Count; i++) //根据顺序号,组织流程操作名字 { DataRow[] temprow = actionTable.Select("id='" + temphash[i.ToString()] + "'"); actionName += temprow[0]["name"] + "-->"; } return actionName.Substring(0, actionName.Length - 3); } /// /// 根据actionID获取操作顺序名字 /// /// 流程的actionIDs /// 所有流程操作数据表 /// 当前执行步骤id /// 流程操作顺序名字 public string ActionNString(string actionIDs, DataTable actionTable,int now) { string actionName = string.Empty; Hashtable temphash = FlowAction(actionIDs); for (int i = 0; i < temphash.Count; i++) //根据顺序号,组织流程操作名字 { DataRow[] temprow = actionTable.Select("id='" + temphash[i.ToString()] + "'"); if (now == i) { actionName += "" + temprow[0]["name"] + "-->"; } else { actionName += temprow[0]["name"] + "-->"; } } return actionName.Substring(0, actionName.Length - 3); } /// /// 根据actionIDs分离对应的序号和操作id /// /// actionIDs /// Hashtable public Hashtable FlowAction(string actionIDs) { string[] temp = actionIDs.Split(','); var temphash = new Hashtable(); //保存流程操作的顺序号及名字 foreach (string s in temp) { string[] action = s.Split(':'); temphash[action[0]] = action[1]; } return temphash; } /// /// 根据操作步骤获取操作ID和名字 /// /// 流程操作ids /// 所有流程操作数据表 /// 步骤 /// ActionEty实体类 public ActionEty NowActionId(string actionIDs, DataTable actionTable, string now) { string[] temp = actionIDs.Split(','); var actionEty = new ActionEty(); //保存流程操作的顺序号及名字 foreach (string s in temp) { string[] action = s.Split(':'); if (action[0]==now) { DataRow[] temprow = actionTable.Select("id='" + action[1] + "'"); actionEty.Id = action[1]; //操作id actionEty.Name = temprow[0]["name"].ToString(); //操作名字 return actionEty; } } return actionEty; } } }