|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Web;
|
|
|
using System.Web.Mvc;
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
using DSWeb.TruckMng.Helper;
|
|
|
using HcUtility.Comm;
|
|
|
using DSWeb.TruckMng.Helper.Repository;
|
|
|
using DSWeb.Areas.Import.Models.XXH;
|
|
|
using System.Data.Common;
|
|
|
using DSWeb.EntityDA;
|
|
|
using DSWeb.Areas.OA.Models.WorkFlow;
|
|
|
using System.Data.SqlClient;
|
|
|
using WebSqlHelper;
|
|
|
using DSWeb.TruckMng.Comm.Cookie;
|
|
|
using DSWeb.Areas.Mobile.DAL;
|
|
|
|
|
|
namespace DSWeb.Areas.CommMng.DAL
|
|
|
{
|
|
|
public class WorkFlowDAL
|
|
|
{
|
|
|
#region [操作工作流] 开始工作流过程
|
|
|
static public Resultmb WorkFlowStart(string WorkFlowName, string BSNO, string USERID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var _workflow= GetWorkFlowID(WorkFlowName, USERID)[0];
|
|
|
var workflowID = _workflow.GID;
|
|
|
var TYPENO = _workflow.TYPE;
|
|
|
if (workflowID == "") {
|
|
|
var _Result = new Resultmb();
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = "该工作流程还未设置工作流,请联系管理员";
|
|
|
return _Result;
|
|
|
}
|
|
|
var islast = WorkFlowDAL.GetAutoFinish(workflowID, USERID);
|
|
|
|
|
|
if (islast==false)//不是自动审核通过
|
|
|
{
|
|
|
strSql.Append(" if (select bsno from workflow_using where bsno='" + BSNO + "' and TYPENO=" + TYPENO + ") is NULL ");
|
|
|
strSql.Append(" insert into workflow_using ([BSNO],[WORKFLOWID],[STEPNO],[PreviousSTEPID],[CurrentID],[rejector_id],[reject_time],[FINISHED] ");
|
|
|
strSql.Append(" ,[ISDELETE],[DELETEUSER],[DELETETIME],[Reason],[OP],[TYPENO]) values('" + BSNO + "','" + workflowID + "', ");
|
|
|
strSql.Append(" dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),'0','1',null,null,0,null,null,null,null,'" + USERID + "',"+TYPENO+") ");
|
|
|
strSql.Append(" else update workflow_using set stepno=dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),currentid=1,op='" + USERID + "',finished='0',workflowid='" + workflowID + "' ");
|
|
|
strSql.Append(" where bsno='" + BSNO + "' and TYPENO="+TYPENO+" ");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" if (select bsno from workflow_using where bsno='" + BSNO + "' and TYPENO=" + TYPENO + ") is NULL ");
|
|
|
strSql.Append(" insert into workflow_using ([BSNO],[WORKFLOWID],[STEPNO],[PreviousSTEPID],[CurrentID],[rejector_id],[reject_time],[FINISHED] ");
|
|
|
strSql.Append(" ,[ISDELETE],[DELETEUSER],[DELETETIME],[Reason],[OP],[TYPENO]) values('" + BSNO + "','" + workflowID + "', ");
|
|
|
strSql.Append(" dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),'0','1',null,null,1,null,null,null,null,'" + USERID + "'," + TYPENO + ") ");
|
|
|
strSql.Append(" else update workflow_using set stepno=0,currentid=0,op='" + USERID + "',finished=1,workflowid='" + workflowID + "' ");
|
|
|
strSql.Append(" where bsno='" + BSNO + "' and TYPENO=" + TYPENO + " ");
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return setWorkFlowStart(strSql, workflowID, USERID, BSNO, islast);
|
|
|
}
|
|
|
private static Resultmb setWorkFlowStart(StringBuilder strSql, string WORKFLOWID, string OP, string BSNO, Boolean islast)
|
|
|
{
|
|
|
var _count = 0;
|
|
|
var _Result = new Resultmb();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = ee.Message;
|
|
|
return _Result;
|
|
|
}
|
|
|
|
|
|
if (_count == 0)
|
|
|
{
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = "没有影响数据,可能是已经提交或未设置工作流";
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_Result.Success = true;
|
|
|
_Result.Message = "新工作流程产生成功";
|
|
|
_Result.totalCount = _count;
|
|
|
_Result.islast = islast;
|
|
|
}
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
var RECEIVER = GetAuditor(WORKFLOWID, "1");
|
|
|
|
|
|
//向每个审核人发送消息
|
|
|
|
|
|
|
|
|
foreach (var _RC in RECEIVER)
|
|
|
{
|
|
|
//var _Message =
|
|
|
StartMessage(WORKFLOWID, OP, _RC.GID, BSNO);
|
|
|
//SaveMessage(_Message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return _Result;
|
|
|
}
|
|
|
|
|
|
static public Resultmb WorkFlowStart ( string WorkFlowName, string BSNO, string USERID, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var _workflow = GetWorkFlowID(WorkFlowName, USERID)[0];
|
|
|
var workflowID = _workflow.GID;
|
|
|
var TYPENO = _workflow.TYPE;
|
|
|
if (workflowID == "")
|
|
|
{
|
|
|
var _Result = new Resultmb();
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = "该工作流程还未设置工作流,请联系管理员";
|
|
|
return _Result;
|
|
|
}
|
|
|
var islast = WorkFlowDAL.GetAutoFinish(workflowID, USERID);
|
|
|
|
|
|
|
|
|
if (islast == false)//不是自动审核通过
|
|
|
{
|
|
|
strSql.Append(" if (select bsno from workflow_using where bsno='" + BSNO + "' and TYPENO=" + TYPENO + ") is NULL ");
|
|
|
strSql.Append(" insert into workflow_using ([BSNO],[WORKFLOWID],[STEPNO],[PreviousSTEPID],[CurrentID],[rejector_id],[reject_time],[FINISHED] ");
|
|
|
strSql.Append(" ,[ISDELETE],[DELETEUSER],[DELETETIME],[Reason],[OP],[TYPENO]) values('" + BSNO + "','" + workflowID + "', ");
|
|
|
strSql.Append(" dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),'0','1',null,null,0,null,null,null,null,'" + USERID + "'," + TYPENO + ") ");
|
|
|
strSql.Append(" else update workflow_using set stepno=dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),currentid=1,op='" + USERID + "',finished='0',workflowid='" + workflowID + "' ");
|
|
|
strSql.Append(" where bsno='" + BSNO + "' and TYPENO=" + TYPENO + " ");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" if (select bsno from workflow_using where bsno='" + BSNO + "' and TYPENO=" + TYPENO + ") is NULL ");
|
|
|
strSql.Append(" insert into workflow_using ([BSNO],[WORKFLOWID],[STEPNO],[PreviousSTEPID],[CurrentID],[rejector_id],[reject_time],[FINISHED] ");
|
|
|
strSql.Append(" ,[ISDELETE],[DELETEUSER],[DELETETIME],[Reason],[OP],[TYPENO]) values('" + BSNO + "','" + workflowID + "', ");
|
|
|
strSql.Append(" dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),'0','1',null,null,1,null,null,null,null,'" + USERID + "'," + TYPENO + ") ");
|
|
|
strSql.Append(" else update workflow_using set stepno=0,currentid=0,op='" + USERID + "',finished=1,workflowid='" + workflowID + "' ");
|
|
|
strSql.Append(" where bsno='" + BSNO + "' and TYPENO=" + TYPENO + " ");
|
|
|
}
|
|
|
|
|
|
return setWorkFlowStart(strSql, workflowID, USERID, BSNO, islast,BILLNO,GID,URL);
|
|
|
}
|
|
|
|
|
|
private static Resultmb setWorkFlowStart ( StringBuilder strSql, string WORKFLOWID, string OP, string BSNO, Boolean islast, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
var _count = 0;
|
|
|
var _Result = new Resultmb();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = ee.Message;
|
|
|
}
|
|
|
|
|
|
if (_count == 0)
|
|
|
{
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = "没有影响数据,可能是已经提交或未设置工作流";
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_Result.Success = true;
|
|
|
_Result.Message = "新工作流程产生成功";
|
|
|
_Result.totalCount = _count;
|
|
|
_Result.islast = islast;
|
|
|
}
|
|
|
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
|
|
|
var RECEIVER = GetAuditor(WORKFLOWID, "1");
|
|
|
|
|
|
//向每个审核人发送消息
|
|
|
foreach (var _RC in RECEIVER)
|
|
|
{
|
|
|
//var _Message =
|
|
|
StartMessage(WORKFLOWID, OP, _RC.GID, BSNO, BILLNO, GID, URL);
|
|
|
//SaveMessage(_Message);
|
|
|
}
|
|
|
}
|
|
|
return _Result;
|
|
|
}
|
|
|
|
|
|
|
|
|
//撤回
|
|
|
static public Resultmb WorkFlowReset(string WorkFlowName, string BSNO, string USERID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var workflowID = GetBSNOWorkFlowID(WorkFlowName, BSNO)[0].GID;
|
|
|
//strSql.Append(" delete from [workflow_using] where cargo_id in( " + cargo_id + ")");
|
|
|
strSql.Append(" delete from workflow_using where bsno='" + BSNO + "' and workflowid='" + workflowID + "'");
|
|
|
//strSql.Append(" from import_cargo where id in( " + cargo_id + ")");
|
|
|
|
|
|
//return setWorkFlowStart(strSql, workflowID, "", BSNO,false);//ExecuteNonQuery
|
|
|
|
|
|
var _Result = new Resultmb();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
_Result.totalCount = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = ee.Message;
|
|
|
}
|
|
|
return _Result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region [查询]通过工作流名字和员工编号查找工作流编号 List<WorkFlowmb> GetWorkFlowID(string NAME, string USERID)
|
|
|
|
|
|
static public List<WorkFlowmb> GetWorkFlowID(string NAME, string USERID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select [dbo].[GetWorkFlowID]('" + NAME + "','" + USERID + "') workflowid, ");
|
|
|
strSql.Append(" ( select name from workflow where gid= [dbo].[GetWorkFlowID]('" + NAME + "','" + USERID + "') ) name,(select type from workflow where gid= [dbo].[GetWorkFlowID]('" + NAME + "','" + USERID + "') ) type ");
|
|
|
return SetWorkFlowID(strSql);
|
|
|
}
|
|
|
static public List<WorkFlowmb> GetBSNOWorkFlowID(string NAME, string BSNO)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select [dbo].[GetBSNOWorkFlowID]('" + NAME + "','" + BSNO + "') workflowid, ");
|
|
|
strSql.Append(" '" + NAME + "' as name,(select type from workflow where gid= [dbo].[GetBSNOWorkFlowID]('" + NAME + "','" + BSNO + "') ) type ");
|
|
|
return SetWorkFlowID(strSql);
|
|
|
}
|
|
|
private static List<WorkFlowmb> SetWorkFlowID(StringBuilder strSql)
|
|
|
{
|
|
|
var bodyList = new List<WorkFlowmb>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
WorkFlowmb data = new WorkFlowmb();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["WORKFLOWID"]);
|
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
|
data.TYPE = Convert.ToString(reader["type"]);
|
|
|
#endregion
|
|
|
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
return bodyList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region [查询]通过WORKFLOWID查找workflow_step的内容
|
|
|
/*
|
|
|
static public List<WorkFlowStepmb> GetWorkFlowStep(string WorkFlowName, string UserID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select * from workflow_step where WORKFLOWID = ");
|
|
|
strSql.Append(" dbo.getworkflowid('" + WorkFlowName + "','" + UserID + "') ");
|
|
|
strSql.Append(" and AUDITOR='" + UserID + "' order by STEPNO");
|
|
|
|
|
|
return SetWorkFlowStep(strSql);
|
|
|
}*/
|
|
|
static public List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> GetWorkFlowStep ( string WORKFLOWID, string UserID )
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select * from workflow_step where WORKFLOWID = '" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" and AUDITOR='" + UserID + "' order by STEPNO");
|
|
|
|
|
|
return SetWorkFlowStep(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> SetWorkFlowStep ( StringBuilder strSql )
|
|
|
{
|
|
|
var bodyList = new List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
DSWeb.Areas.CommMng.Models.WorkFlowStepmb data = new DSWeb.Areas.CommMng.Models.WorkFlowStepmb();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
|
data.STEPNO = Convert.ToString(reader["STEPNO"]);
|
|
|
data.NEEDALLPASS = Convert.ToString(reader["NEEDALLPASS"]);
|
|
|
data.ISMUST = Convert.ToString(reader["ISMUST"]);
|
|
|
data.ISLAST = Convert.ToString(reader["ISLAST"]);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
return bodyList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region [查询]获取该用户,在该工作流程的该步骤中 可以操作的业务编号列表
|
|
|
|
|
|
static public List<WorkFlow_Usingmb> GetWorkFlowBSNOList(string WorkFlowID, int StepNo, string USERID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select bx.*,wd.* from oa_baoxiao bx left join workflow_do wd on bx.bxgid=wd.billno ");
|
|
|
strSql.Append(" where workflowid='" + WorkFlowID + "' ");
|
|
|
strSql.Append(" and stepno in (" + StepNo.ToString() + ") ");
|
|
|
//strSql.Append(" and (wd.isdelete is null or wd.isdelete=0 ) ");
|
|
|
return SetWorkFlowState(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<WorkFlow_Usingmb> SetWorkFlowState(StringBuilder strSql)
|
|
|
{
|
|
|
var bodyList = new List<WorkFlow_Usingmb>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
WorkFlow_Usingmb data = new WorkFlow_Usingmb();
|
|
|
#region Set DB data to Object
|
|
|
data.BSNO = Convert.ToString(reader["BSNO"]);
|
|
|
data.WORKFLOWID = Convert.ToString(reader["WORKFLOWID"]);
|
|
|
data.STEPNO = Convert.ToString(reader["STEPNO"]);/*
|
|
|
data.REJECTOR_ID = Convert.ToString(reader["REJECTOR_ID"]);
|
|
|
data.REJECT_TIME = Convert.ToString(reader["REJECT_TIME"]);
|
|
|
data.FINISHED = Convert.ToString(reader["FINISHED"]);
|
|
|
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
|
|
|
data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]);
|
|
|
data.DELETETIME = Convert.ToString(reader["DELETETIME"]);*/
|
|
|
#endregion
|
|
|
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
return bodyList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region [查询]根据业务BSNO获取工作流状态
|
|
|
|
|
|
static public List<BSNOWorkFlowStatemb> GetBSNOWorkFlow(string WORKFLOWID, string BSNO)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select name,wd.stepno,wd.groupid,wd.auditor,u.showname,wd.billno from ");
|
|
|
strSql.Append(" (select *, ROW_NUMBER() over(partition by groupid,stepno order by createtime ) as rowNum ");
|
|
|
strSql.Append(" from workflow_step where workflowid='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" ) ranked ");
|
|
|
strSql.Append(" left join workflow_do wd on (wd.workflowid='" + WORKFLOWID + "' and wd.isdelete is null) ");
|
|
|
strSql.Append(" and wd.stepno=ranked.stepno and wd.billno='" + BSNO + "' ");
|
|
|
strSql.Append(" left join [user] U on u.gid=wd.auditor and wd.groupid=ranked.groupid ");
|
|
|
strSql.Append(" where ranked.rowNum <= 1 ");
|
|
|
strSql.Append(" order by ranked.groupid,ranked.stepno, ranked.createtime ");
|
|
|
|
|
|
return SetBSNOWorkFlow(strSql);
|
|
|
}
|
|
|
static public List<BSNOWorkFlowStatemb> GetBSNOWorkFlow(string WORKFLOWID, string BSNO, DbTransaction tran)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select name,wd.stepno,wd.groupid,wd.auditor,u.showname,wd.billno from ");
|
|
|
strSql.Append(" (select *, ROW_NUMBER() over(partition by groupid,stepno order by createtime ) as rowNum ");
|
|
|
strSql.Append(" from workflow_step where workflowid='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" ) ranked ");
|
|
|
strSql.Append(" left join workflow_do wd on (wd.workflowid='" + WORKFLOWID + "' and wd.isdelete is null) ");
|
|
|
strSql.Append(" and wd.stepno=ranked.stepno and wd.billno='" + BSNO + "' ");
|
|
|
strSql.Append(" left join [user] U on u.gid=wd.auditor and wd.groupid=ranked.groupid ");
|
|
|
strSql.Append(" where ranked.rowNum <= 1 ");
|
|
|
strSql.Append(" order by ranked.groupid,ranked.stepno, ranked.createtime ");
|
|
|
|
|
|
return SetBSNOWorkFlow(strSql, tran);
|
|
|
}
|
|
|
static public List<BSNOWorkFlowStatemb> GetBSNOGROUPID ( string WORKFLOWID, string BSNO )
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select '' name,stepno,currentid GROUPID,'' auditor,'' showname,bsno billno ");
|
|
|
strSql.Append(" from workflow_using where WORKFLOWID='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" and bsno='" + BSNO + "' ");
|
|
|
|
|
|
return SetBSNOWorkFlow(strSql);
|
|
|
}
|
|
|
static public List<BSNOWorkFlowStatemb> GetBSNOGROUPID(string WORKFLOWID, string BSNO, DbTransaction tran)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select '' name,stepno,currentid GROUPID,'' auditor,'' showname,bsno billno ");
|
|
|
strSql.Append(" from workflow_using where WORKFLOWID='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" and bsno='" + BSNO + "' ");
|
|
|
|
|
|
return SetBSNOWorkFlow(strSql, tran);
|
|
|
}
|
|
|
private static List<BSNOWorkFlowStatemb> SetBSNOWorkFlow ( StringBuilder strSql )
|
|
|
{
|
|
|
var bodyList = new List<BSNOWorkFlowStatemb>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
BSNOWorkFlowStatemb data = new BSNOWorkFlowStatemb();
|
|
|
#region Set DB data to Object
|
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
|
data.STEPNO = Convert.ToString(reader["STEPNO"]);
|
|
|
data.GROUPID = Convert.ToString(reader["GROUPID"]);
|
|
|
data.AUDITOR = Convert.ToString(reader["AUDITOR"]);
|
|
|
data.SHOWNAME = Convert.ToString(reader["SHOWNAME"]);
|
|
|
data.BILLNO = Convert.ToString(reader["BILLNO"]);
|
|
|
#endregion
|
|
|
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
return bodyList;
|
|
|
}
|
|
|
|
|
|
private static List<BSNOWorkFlowStatemb> SetBSNOWorkFlow(StringBuilder strSql, DbTransaction tran)
|
|
|
{
|
|
|
var bodyList = new List<BSNOWorkFlowStatemb>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
BSNOWorkFlowStatemb data = new BSNOWorkFlowStatemb();
|
|
|
#region Set DB data to Object
|
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
|
data.STEPNO = Convert.ToString(reader["STEPNO"]);
|
|
|
data.GROUPID = Convert.ToString(reader["GROUPID"]);
|
|
|
data.AUDITOR = Convert.ToString(reader["AUDITOR"]);
|
|
|
data.SHOWNAME = Convert.ToString(reader["SHOWNAME"]);
|
|
|
data.BILLNO = Convert.ToString(reader["BILLNO"]);
|
|
|
#endregion
|
|
|
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
return bodyList;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region [操作工作流] 插入workflowDo表(工作流动作,推进工作流向下流动)
|
|
|
|
|
|
|
|
|
static public Resultmb InsertWorkFlowDo(string WORKFLOWNAME, string BSNO, string USERID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var WorkFlowID = GetBSNOWorkFlowID(WORKFLOWNAME, BSNO)[0].GID;
|
|
|
|
|
|
var _state = GetBSNOGROUPID(WorkFlowID, BSNO)[0];
|
|
|
var STEPNO = _state.STEPNO;
|
|
|
var GROUPID = _state.GROUPID;
|
|
|
|
|
|
strSql.Append(" select power(2,stepno) stepno_2,stepno,groupid,islast from workflow_step ");
|
|
|
strSql.Append(" where workflowid='" + WorkFlowID + "' ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and groupid=" + GROUPID + " and (select " + STEPNO + "&power(2,stepno))>0 ");
|
|
|
var StepList = GetWorkFlowStepNO(strSql);
|
|
|
if (StepList.Count == 0) {
|
|
|
var result= new Resultmb();
|
|
|
result.Success=false;
|
|
|
result.Message = result.Message + ("无权限进行审核 ");//工作流代码[" + WorkFlowID + "] 业务编号[" + BSNO + "]");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
var islast = WorkFlowDAL.GetWorkFlowFinal_BSNO(WORKFLOWNAME, BSNO, USERID);
|
|
|
return DoInsertWorkFlowDo(WorkFlowID, USERID, BSNO, islast, StepList);
|
|
|
}
|
|
|
|
|
|
static public Resultmb InsertWorkFlowDo ( string WORKFLOWNAME, string BSNO, string USERID, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var WorkFlowID = GetBSNOWorkFlowID(WORKFLOWNAME, BSNO)[0].GID;
|
|
|
|
|
|
var _state = GetBSNOGROUPID(WorkFlowID, BSNO)[0];
|
|
|
var STEPNO = _state.STEPNO;
|
|
|
var GROUPID = _state.GROUPID;
|
|
|
|
|
|
strSql.Append(" select power(2,stepno) stepno_2,stepno,groupid,islast from workflow_step ");
|
|
|
strSql.Append(" where workflowid='" + WorkFlowID + "' ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and groupid=" + GROUPID + " and (select " + STEPNO + "&power(2,stepno))>0 ");
|
|
|
var StepList = GetWorkFlowStepNO(strSql);
|
|
|
if (StepList.Count == 0)
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
result.Success = false;
|
|
|
result.Message = result.Message + ("无权限进行审核 ");//工作流代码[" + WorkFlowID + "] 业务编号[" + BSNO + "]");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
var islast = WorkFlowDAL.GetWorkFlowFinal_BSNO(WORKFLOWNAME, BSNO, USERID);
|
|
|
return DoInsertWorkFlowDo(WorkFlowID, USERID, BSNO, islast, StepList, BILLNO, GID, URL );
|
|
|
}
|
|
|
|
|
|
static public Resultmb InsertWorkFlowDo ( string WORKFLOWNAME, string BSNO, string USERID, DbTransaction tran )
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var WorkFlowID = GetBSNOWorkFlowID(WORKFLOWNAME, BSNO)[0].GID;
|
|
|
|
|
|
var _state = GetBSNOGROUPID(WorkFlowID, BSNO,tran)[0];
|
|
|
var STEPNO = _state.STEPNO;
|
|
|
var GROUPID = _state.GROUPID;
|
|
|
|
|
|
strSql.Append(" select power(2,stepno) stepno_2,stepno,groupid,islast from workflow_step ");
|
|
|
strSql.Append(" where workflowid='" + WorkFlowID + "' ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and groupid=" + GROUPID + " and (select " + STEPNO + "&power(2,stepno))>0 ");
|
|
|
var StepList = GetWorkFlowStepNO(strSql);
|
|
|
if (StepList.Count == 0)
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
result.Success = false;
|
|
|
result.Message = result.Message + ("无权限进行审核 ");//工作流代码[" + WorkFlowID + "] 业务编号[" + BSNO + "]");
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
var islast = WorkFlowDAL.GetWorkFlowFinal_BSNO(WORKFLOWNAME, BSNO, USERID,tran);
|
|
|
return DoInsertWorkFlowDo(WorkFlowID, USERID, BSNO, islast, StepList, tran);
|
|
|
}
|
|
|
static public Resultmb InsertWorkFlowDo(string WORKFLOWNAME, string BSNO, string USERID, DbTransaction tran, string BILLNO, string GID, string URL)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var WorkFlowID = GetBSNOWorkFlowID(WORKFLOWNAME, BSNO)[0].GID;
|
|
|
if (WorkFlowID == "")
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
result.Success = false;
|
|
|
result.Message = result.Message + ("无权限进行审核 ");//工作流代码[" + WorkFlowID + "] 业务编号[" + BSNO + "]");
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var _state = GetBSNOGROUPID(WorkFlowID, BSNO, tran)[0];
|
|
|
var STEPNO = _state.STEPNO;
|
|
|
var GROUPID = _state.GROUPID;
|
|
|
|
|
|
strSql.Append(" select power(2,stepno) stepno_2,stepno,groupid,islast from workflow_step ");
|
|
|
strSql.Append(" where workflowid='" + WorkFlowID + "' ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and groupid=" + GROUPID + " and (select " + STEPNO + "&power(2,stepno))>0 ");
|
|
|
var StepList = GetWorkFlowStepNO(strSql);
|
|
|
if (StepList.Count == 0)
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
result.Success = false;
|
|
|
result.Message = result.Message + ("无权限进行审核 ");//工作流代码[" + WorkFlowID + "] 业务编号[" + BSNO + "]");
|
|
|
return result;
|
|
|
}
|
|
|
var islast = WorkFlowDAL.GetWorkFlowFinal_BSNO(WORKFLOWNAME, BSNO, USERID, tran);
|
|
|
return DoInsertWorkFlowDo(WorkFlowID, USERID, BSNO, islast, StepList, tran, BILLNO, GID, URL);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private static List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> GetWorkFlowStepNO ( StringBuilder strSql )
|
|
|
{
|
|
|
//var headList = new List<WorkFlowStepNOmb>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
var bodyList = new List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb>();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
DSWeb.Areas.CommMng.Models.WorkFlowStepmb data = new DSWeb.Areas.CommMng.Models.WorkFlowStepmb();
|
|
|
#region Set DB data to Object
|
|
|
|
|
|
data.STEPNO = Convert.ToString(reader["STEPNO"]);
|
|
|
data.GROUPID = Convert.ToString(reader["GROUPID"]);
|
|
|
data.ISLAST = Convert.ToString(reader["ISLAST"]);
|
|
|
#endregion
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return bodyList;
|
|
|
}
|
|
|
/*
|
|
|
private static int DoInsertWorkFlowDo(string WorkFlowName, string DEPTGID, string USERID, string BSNO, List<WorkFlowStepmb> StepList)
|
|
|
{
|
|
|
var _count = 0;
|
|
|
var islast = 0;
|
|
|
for(int i=0;i<StepList.Count;i++)
|
|
|
{
|
|
|
var stepno = StepList[i].STEPNO;
|
|
|
var GROUPID = StepList[i].GROUPID;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID=dbo.getworkflowid('" + WorkFlowName + "','" + DEPTGID + "') ");
|
|
|
strSql.Append(" insert into workflow_do (GID,workflowid,stepid,billno,auditor,audittime,stepno,isallfinish,GROUPID) ");
|
|
|
strSql.Append(" select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID ");
|
|
|
strSql.Append(" from workflow_step where workflowid=@WorkFlowID ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and stepno ='" + stepno + "' and groupid='" + GROUPID + "' ");
|
|
|
|
|
|
PushUsing(WorkFlowName, DEPTGID, BSNO, USERID, stepno, GROUPID);
|
|
|
_count = _count+db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
if (StepList[i].ISLAST == "True")
|
|
|
{
|
|
|
islast = 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return islast;
|
|
|
}*/
|
|
|
|
|
|
//1
|
|
|
private static Resultmb DoInsertWorkFlowDo ( string WORKFLOWID, string USERID, string BSNO, Boolean islast
|
|
|
, List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> StepList )
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
var _count = 0;
|
|
|
|
|
|
for (int i = 0; i < StepList.Count; i++)
|
|
|
{
|
|
|
var stepno = StepList[i].STEPNO;
|
|
|
var GROUPID = StepList[i].GROUPID;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" insert into workflow_do (GID,workflowid,stepid,billno,auditor,audittime,stepno,isallfinish,GROUPID) ");
|
|
|
strSql.Append(" select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID ");
|
|
|
strSql.Append(" from workflow_step where workflowid=@WorkFlowID ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and stepno ='" + stepno + "' and groupid='" + GROUPID + "' ");
|
|
|
|
|
|
result= PushUsing(WORKFLOWID, BSNO, USERID, stepno, GROUPID,islast);
|
|
|
if (result.Success != true) {//推进workflow_using的状态
|
|
|
result.Message = result.Message + (" 工作流代码[" + WORKFLOWID + "] 业务编号[" + BSNO + "] 步骤组代码[" + GROUPID + "] 步骤代码[" + stepno+"]");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{//向workflow_do写入操作日志
|
|
|
_count = _count + db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "写入日志出错 "+ee.Message+ " 工作流代码[" + WORKFLOWID + "] 业务编号[" + BSNO + "] 步骤组代码[" + GROUPID + "] 步骤代码[" + stepno+"]";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (result.Success == false)
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Message = "全部成功";
|
|
|
result.islast = islast;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//return islast;
|
|
|
}
|
|
|
|
|
|
//2
|
|
|
private static Resultmb DoInsertWorkFlowDo ( string WORKFLOWID, string USERID, string BSNO, Boolean islast
|
|
|
, List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> StepList, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
var _count = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
//using (var conn = db.CreateConnection())
|
|
|
//{
|
|
|
//conn.Open();
|
|
|
//var tran = conn.BeginTransaction();
|
|
|
|
|
|
for (int i = 0; i < StepList.Count; i++)
|
|
|
{
|
|
|
var stepno = StepList[i].STEPNO;
|
|
|
var GROUPID = StepList[i].GROUPID;
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" insert into workflow_do (GID,workflowid,stepid,billno,auditor,audittime,stepno,isallfinish,GROUPID) ");
|
|
|
strSql.Append(" select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID ");
|
|
|
strSql.Append(" from workflow_step where workflowid=@WorkFlowID ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and stepno ='" + stepno + "' and groupid='" + GROUPID + "' ");
|
|
|
|
|
|
result = PushUsing(WORKFLOWID, BSNO, USERID, stepno, GROUPID, islast, BILLNO, GID, URL);
|
|
|
if (result.Success != true)
|
|
|
{//推进workflow_using的状态
|
|
|
result.Message = result.Message + (" 工作流代码[" + WORKFLOWID + "] 业务编号[" + BSNO + "] 步骤组代码[" + GROUPID + "] 步骤代码[" + stepno + "]");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{//向workflow_do写入操作日志
|
|
|
_count = _count + db.ExecuteNonQuery(CommandType.Text, strSql.ToString() );
|
|
|
//db.ExecuteNonQuery(cmdupdate, tran);
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "写入日志出错 " + ee.Message + " 工作流代码[" + WORKFLOWID + "] 业务编号[" + BSNO + "] 步骤组代码[" + GROUPID + "] 步骤代码[" + stepno + "]";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (result.Success == false)
|
|
|
{
|
|
|
//tran.Rollback();
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//tran.Commit();
|
|
|
result.Message = "全部成功";
|
|
|
result.islast = islast;
|
|
|
return result;
|
|
|
}
|
|
|
//}
|
|
|
|
|
|
//return islast;
|
|
|
}
|
|
|
|
|
|
//3 含事务
|
|
|
private static Resultmb DoInsertWorkFlowDo ( string WORKFLOWID, string USERID, string BSNO, Boolean islast
|
|
|
, List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> StepList, DbTransaction tran )
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
var _count = 0;
|
|
|
|
|
|
for (int i = 0; i < StepList.Count; i++)
|
|
|
{
|
|
|
var stepno = StepList[i].STEPNO;
|
|
|
var GROUPID = StepList[i].GROUPID;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" insert into workflow_do (GID,workflowid,stepid,billno,auditor,audittime,stepno,isallfinish,GROUPID) ");
|
|
|
strSql.Append(" select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID ");
|
|
|
strSql.Append(" from workflow_step where workflowid=@WorkFlowID ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and stepno ='" + stepno + "' and groupid='" + GROUPID + "' ");
|
|
|
|
|
|
result = PushUsing(WORKFLOWID, BSNO, USERID, stepno, GROUPID, islast, tran);
|
|
|
if (result.Success != true)
|
|
|
{//推进workflow_using的状态
|
|
|
result.Message = result.Message + (" 工作流代码[" + WORKFLOWID + "] 业务编号[" + BSNO + "] 步骤组代码[" + GROUPID + "] 步骤代码[" + stepno + "]");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{//向workflow_do写入操作日志
|
|
|
_count = _count + db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "写入日志出错 " + ee.Message + " 工作流代码[" + WORKFLOWID + "] 业务编号[" + BSNO + "] 步骤组代码[" + GROUPID + "] 步骤代码[" + stepno + "]";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (result.Success == false)
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Message = "全部成功";
|
|
|
result.islast = islast;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//return islast;
|
|
|
}
|
|
|
private static Resultmb DoInsertWorkFlowDo(string WORKFLOWID, string USERID, string BSNO, Boolean islast
|
|
|
, List<DSWeb.Areas.CommMng.Models.WorkFlowStepmb> StepList, DbTransaction tran, string BILLNO, string GID, string URL)
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
var _count = 0;
|
|
|
|
|
|
for (int i = 0; i < StepList.Count; i++)
|
|
|
{
|
|
|
var stepno = StepList[i].STEPNO;
|
|
|
var GROUPID = StepList[i].GROUPID;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" insert into workflow_do (GID,workflowid,stepid,billno,auditor,audittime,stepno,isallfinish,GROUPID) ");
|
|
|
strSql.Append(" select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID ");
|
|
|
strSql.Append(" from workflow_step where workflowid=@WorkFlowID ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and stepno ='" + stepno + "' and groupid='" + GROUPID + "' ");
|
|
|
|
|
|
result = PushUsing(WORKFLOWID, BSNO, USERID, stepno, GROUPID, islast, tran, BILLNO, GID, URL);
|
|
|
if (result.Success != true)
|
|
|
{//推进workflow_using的状态
|
|
|
result.Message = result.Message + (" 工作流代码[" + WORKFLOWID + "] 业务编号[" + BSNO + "] 步骤组代码[" + GROUPID + "] 步骤代码[" + stepno + "]");
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{//向workflow_do写入操作日志
|
|
|
_count = _count + db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "写入日志出错 " + ee.Message + " 工作流代码[" + WORKFLOWID + "] 业务编号[" + BSNO + "] 步骤组代码[" + GROUPID + "] 步骤代码[" + stepno + "]";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (result.Success == false)
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Message = "全部成功";
|
|
|
result.islast = islast;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//return islast;
|
|
|
}
|
|
|
|
|
|
static private Resultmb PushUsing(string WORKFLOWID, string BSNO, string USERID, string STEPNO, string GROUPID,Boolean islast)
|
|
|
{//将操作记入WorkFlow_Using 如果该groupid的步骤都执行完毕,推进至下一阶段
|
|
|
var _result= new Resultmb();
|
|
|
var stepno=0;
|
|
|
var strSql_0 = new StringBuilder();//如果using的stepno集合中包含stepno 则将其去除
|
|
|
var strSql = new StringBuilder();
|
|
|
var strSql_2 = new StringBuilder();
|
|
|
|
|
|
strSql_0.Append(" select (select stepno from workflow_using ");
|
|
|
strSql_0.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "') & power(2," + STEPNO + ") stepno ");
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql_0.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
stepno = Convert.ToInt32(reader["stepno"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
if (stepno > 0)
|
|
|
{
|
|
|
|
|
|
//strSql.Append(" begin ");
|
|
|
strSql.Append(" update workflow_using set ");
|
|
|
strSql.Append(" stepno=stepno-power(2," + STEPNO + "),currentid=" + GROUPID + " ");
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "' ");
|
|
|
//strSql.Append(" end ");
|
|
|
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
|
|
|
//Database db = DatabaseFactory.CreateDatabase();
|
|
|
var _count= SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
|
|
|
if (_count <= 0)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "推进工作流出错 " ;
|
|
|
sqlTran.Rollback();
|
|
|
return _result;
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Database db3 = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
strSql_2.Append(" select stepno from workflow_using ");
|
|
|
strSql_2.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "' ");
|
|
|
using (IDataReader reader = db3.ExecuteReader( CommandType.Text, strSql_2.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
stepno = Convert.ToInt32(reader["stepno"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
if (_result.Success == true && stepno == 0)
|
|
|
{//如果本步骤全都执行完了
|
|
|
var nextGROUPID = GetNextGROUP(WORKFLOWID, STEPNO, GROUPID, USERID);
|
|
|
|
|
|
strSql = new StringBuilder();
|
|
|
strSql.Append(" update workflow_using set stepno=dbo.getnextstep('" + WORKFLOWID + "','" + BSNO + "'," + nextGROUPID + "),");
|
|
|
strSql.Append(" currentid=" + nextGROUPID);
|
|
|
if (islast)
|
|
|
{
|
|
|
strSql.Append(" ,finished=1 ");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" ,finished=0 ");
|
|
|
}
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" and bsno='" + BSNO + "' ");
|
|
|
//Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
var _count = SqlHelper.ExecuteNonQuery(sqlTran,CommandType.Text, strSql.ToString());
|
|
|
//db.ExecuteNonQuery(CommandType.Text, strSql.ToString());//CommandType.Text, , tran
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "推进步骤组出错 " + ee.Message;
|
|
|
sqlTran.Rollback();
|
|
|
}
|
|
|
|
|
|
//var message=new SYSMessagemb();
|
|
|
//message.NAME=WORKFLOWID;
|
|
|
|
|
|
PushMessage(WORKFLOWID, BSNO, nextGROUPID.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PassMessage(WORKFLOWID, BSNO, GROUPID, USERID);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
return _result;
|
|
|
}
|
|
|
|
|
|
static private Resultmb PushUsing ( string WORKFLOWID, string BSNO, string USERID, string STEPNO, string GROUPID, Boolean islast, string BILLNO, string GID, string URL )
|
|
|
{//将操作记入WorkFlow_Using 如果该groupid的步骤都执行完毕,推进至下一阶段
|
|
|
var _result = new Resultmb();
|
|
|
var stepno = 0;
|
|
|
var strSql_0 = new StringBuilder();//如果using的stepno集合中包含stepno 则将其去除
|
|
|
var strSql = new StringBuilder();
|
|
|
var strSql_2 = new StringBuilder();
|
|
|
|
|
|
strSql_0.Append(" select (select stepno from workflow_using ");
|
|
|
strSql_0.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "') & power(2," + STEPNO + ") stepno ");
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql_0.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
stepno = Convert.ToInt32(reader["stepno"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stepno > 0)
|
|
|
{
|
|
|
|
|
|
//strSql.Append(" begin ");
|
|
|
strSql.Append(" update workflow_using set ");
|
|
|
strSql.Append(" stepno=stepno-power(2," + STEPNO + "),currentid=" + GROUPID + " ");
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "' ");
|
|
|
//strSql.Append(" end ");
|
|
|
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
|
|
|
//Database db = DatabaseFactory.CreateDatabase();
|
|
|
var _count = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
|
|
|
|
|
|
if (_count <= 0)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "推进工作流出错 ";
|
|
|
sqlTran.Rollback();
|
|
|
return _result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Database db3 = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
strSql_2.Append(" select stepno from workflow_using ");
|
|
|
strSql_2.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "' ");
|
|
|
using (IDataReader reader = db3.ExecuteReader( CommandType.Text, strSql_2.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
stepno = Convert.ToInt32(reader["stepno"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
if (_result.Success == true && stepno == 0)
|
|
|
{//如果本步骤全都执行完了
|
|
|
var nextGROUPID = GetNextGROUP(WORKFLOWID, STEPNO, GROUPID, USERID);
|
|
|
|
|
|
strSql = new StringBuilder();
|
|
|
strSql.Append(" update workflow_using set stepno=dbo.getnextstep('" + WORKFLOWID + "','" + BSNO + "'," + nextGROUPID + "),");
|
|
|
strSql.Append(" currentid=" + nextGROUPID);
|
|
|
if (islast)
|
|
|
{
|
|
|
strSql.Append(" ,finished=1 ");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" ,finished=0 ");
|
|
|
}
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" and bsno='" + BSNO + "' ");
|
|
|
//Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
var _count = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString());
|
|
|
//db.ExecuteNonQuery(CommandType.Text, strSql.ToString());//CommandType.Text, , tran
|
|
|
sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "推进步骤组出错 " + ee.Message;
|
|
|
sqlTran.Rollback();
|
|
|
}
|
|
|
|
|
|
if (_result.Success == true)
|
|
|
{
|
|
|
if (islast)
|
|
|
{
|
|
|
RepeatMessage(WORKFLOWID, BSNO, nextGROUPID.ToString(), USERID, BILLNO, GID, URL);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PushMessage(WORKFLOWID, BSNO, nextGROUPID.ToString(), BILLNO, GID, URL);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PassMessage(WORKFLOWID, BSNO, GROUPID, USERID, BILLNO, GID, URL);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return _result;
|
|
|
}
|
|
|
|
|
|
static private Resultmb PushUsing ( string WORKFLOWID, string BSNO, string USERID, string STEPNO, string GROUPID
|
|
|
, Boolean islast ,DbTransaction tran)
|
|
|
{//将操作记入WorkFlow_Using 如果该groupid的步骤都执行完毕,推进至下一阶段
|
|
|
var _result = new Resultmb();
|
|
|
var stepno = 0;
|
|
|
var strSql_0 = new StringBuilder();//如果using的stepno集合中包含stepno 则将其去除
|
|
|
var strSql = new StringBuilder();
|
|
|
var strSql_2 = new StringBuilder();
|
|
|
|
|
|
strSql_0.Append(" select (select stepno from workflow_using ");
|
|
|
strSql_0.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "') & power(2," + STEPNO + ") stepno ");
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql_0.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
stepno = Convert.ToInt32(reader["stepno"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
if (stepno > 0)
|
|
|
{
|
|
|
|
|
|
//strSql.Append(" begin ");
|
|
|
strSql.Append(" update workflow_using set ");
|
|
|
strSql.Append(" stepno=stepno-power(2," + STEPNO + "),currentid=" + GROUPID + " ");
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "' ");
|
|
|
//strSql.Append(" end ");
|
|
|
|
|
|
//using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
//{
|
|
|
|
|
|
Database db2 = DatabaseFactory.CreateDatabase();
|
|
|
//db.ExecuteNonQuery(cmdupdate, tran)
|
|
|
var _count = db2.ExecuteNonQuery(tran,CommandType.Text, strSql.ToString() );
|
|
|
//SqlHelper.ExecuteNonQuery(tran, CommandType.Text, strSql.ToString(), null);
|
|
|
|
|
|
if (_count <= 0)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "推进工作流出错 ";
|
|
|
//sqlTran.Rollback();
|
|
|
return _result;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//sqlTran.Commit();
|
|
|
}
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
Database db3 = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
strSql_2.Append(" select stepno from workflow_using ");
|
|
|
strSql_2.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "' ");
|
|
|
using (IDataReader reader = db3.ExecuteReader(tran,CommandType.Text, strSql_2.ToString() ))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
stepno = Convert.ToInt32(reader["stepno"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
//using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
if (_result.Success == true && stepno == 0)
|
|
|
{//如果本步骤全都执行完了
|
|
|
var nextGROUPID = GetNextGROUP(WORKFLOWID, STEPNO, GROUPID, USERID);
|
|
|
|
|
|
strSql = new StringBuilder();
|
|
|
strSql.Append(" update workflow_using set stepno=dbo.getnextstep('" + WORKFLOWID + "','" + BSNO + "'," + nextGROUPID + "),");
|
|
|
strSql.Append(" currentid=" + nextGROUPID);
|
|
|
if (islast)
|
|
|
{
|
|
|
strSql.Append(" ,finished=1 ");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" ,finished=0 ");
|
|
|
}
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" and bsno='" + BSNO + "' ");
|
|
|
//Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
Database db4 = DatabaseFactory.CreateDatabase();
|
|
|
var _count = db4.ExecuteNonQuery(tran,CommandType.Text, strSql.ToString() );
|
|
|
//SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString());
|
|
|
//db.ExecuteNonQuery(CommandType.Text, strSql.ToString());//CommandType.Text, , tran
|
|
|
//sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "推进步骤组出错 " + ee.Message;
|
|
|
//sqlTran.Rollback();
|
|
|
}
|
|
|
|
|
|
//var message=new SYSMessagemb();
|
|
|
//message.NAME=WORKFLOWID;
|
|
|
PushMessage(WORKFLOWID, BSNO, nextGROUPID.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PassMessage(WORKFLOWID, BSNO, GROUPID, USERID);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return _result;
|
|
|
}
|
|
|
static private Resultmb PushUsing(string WORKFLOWID, string BSNO, string USERID, string STEPNO, string GROUPID
|
|
|
, Boolean islast, DbTransaction tran, string BILLNO, string GID, string URL)
|
|
|
{//将操作记入WorkFlow_Using 如果该groupid的步骤都执行完毕,推进至下一阶段
|
|
|
var _result = new Resultmb();
|
|
|
var stepno = 0;
|
|
|
var strSql_0 = new StringBuilder();//如果using的stepno集合中包含stepno 则将其去除
|
|
|
var strSql = new StringBuilder();
|
|
|
var strSql_2 = new StringBuilder();
|
|
|
|
|
|
strSql_0.Append(" select (select stepno from workflow_using ");
|
|
|
strSql_0.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "') & power(2," + STEPNO + ") stepno ");
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql_0.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
stepno = Convert.ToInt32(reader["stepno"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
if (stepno > 0)
|
|
|
{
|
|
|
|
|
|
//strSql.Append(" begin ");
|
|
|
strSql.Append(" update workflow_using set ");
|
|
|
strSql.Append(" stepno=stepno-power(2," + STEPNO + "),currentid=" + GROUPID + " ");
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "' ");
|
|
|
//strSql.Append(" end ");
|
|
|
|
|
|
//using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
//{
|
|
|
|
|
|
Database db2 = DatabaseFactory.CreateDatabase();
|
|
|
//db.ExecuteNonQuery(cmdupdate, tran)
|
|
|
var _count = db2.ExecuteNonQuery(tran, CommandType.Text, strSql.ToString());
|
|
|
//SqlHelper.ExecuteNonQuery(tran, CommandType.Text, strSql.ToString(), null);
|
|
|
|
|
|
if (_count <= 0)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "推进工作流出错 ";
|
|
|
//sqlTran.Rollback();
|
|
|
return _result;
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//sqlTran.Commit();
|
|
|
}
|
|
|
//}
|
|
|
}
|
|
|
|
|
|
Database db3 = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
strSql_2.Append(" select stepno from workflow_using ");
|
|
|
strSql_2.Append(" where WORKFLOWID='" + WORKFLOWID + "' and bsno='" + BSNO + "' ");
|
|
|
using (IDataReader reader = db3.ExecuteReader(tran, CommandType.Text, strSql_2.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
stepno = Convert.ToInt32(reader["stepno"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
|
|
|
//using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
|
{
|
|
|
if (_result.Success == true && stepno == 0)
|
|
|
{//如果本步骤全都执行完了
|
|
|
var nextGROUPID = GetNextGROUP(WORKFLOWID, STEPNO, GROUPID, USERID,tran);
|
|
|
|
|
|
strSql = new StringBuilder();
|
|
|
strSql.Append(" update workflow_using set stepno=dbo.getnextstep('" + WORKFLOWID + "','" + BSNO + "'," + nextGROUPID + "),");
|
|
|
strSql.Append(" currentid=" + nextGROUPID);
|
|
|
if (islast)
|
|
|
{
|
|
|
strSql.Append(" ,finished=1 ");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
strSql.Append(" ,finished=0 ");
|
|
|
}
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" and bsno='" + BSNO + "' ");
|
|
|
//Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
Database db4 = DatabaseFactory.CreateDatabase();
|
|
|
var _count = db4.ExecuteNonQuery(tran, CommandType.Text, strSql.ToString());
|
|
|
//SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString());
|
|
|
//db.ExecuteNonQuery(CommandType.Text, strSql.ToString());//CommandType.Text, , tran
|
|
|
//sqlTran.Commit();
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "推进步骤组出错 " + ee.Message;
|
|
|
//sqlTran.Rollback();
|
|
|
}
|
|
|
|
|
|
//var message=new SYSMessagemb();
|
|
|
//message.NAME=WORKFLOWID;
|
|
|
PushMessage(WORKFLOWID, BSNO, nextGROUPID.ToString(), BILLNO, GID, URL,tran);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PassMessage(WORKFLOWID, BSNO, GROUPID, USERID, BILLNO, GID, URL);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return _result;
|
|
|
}
|
|
|
|
|
|
static private int GetNextGROUP(string WORKFLOWID, string STEPNO, string GROUPID,string USERID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var Ns = 0;
|
|
|
strSql.Append(" select isnull((case nextgroup when '' then 0 else nextgroup end),0) as nextgroup from workflow_step ");
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" and groupid=" + GROUPID + " and stepno=" + STEPNO + " and auditor='" + USERID + "' ");
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Ns = Convert.ToInt32(reader["nextgroup"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return Ns;
|
|
|
}
|
|
|
static private int GetNextGROUP(string WORKFLOWID, string STEPNO, string GROUPID, string USERID, DbTransaction tran)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
var Ns = 0;
|
|
|
strSql.Append(" select isnull((case nextgroup when '' then 0 else nextgroup end),0) as nextgroup from workflow_step ");
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" and groupid=" + GROUPID + " and stepno=" + STEPNO + " and auditor='" + USERID + "' ");
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Ns = Convert.ToInt32(reader["nextgroup"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return Ns;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region [更改工作流]添加、修改和删除workflow_step时,对现有workflow_using做相应操作
|
|
|
|
|
|
#region 查询是否能够修改using和是否能够修改step
|
|
|
static public CanChangemb GetCanChange(string GID)//参数为workflow_step的GID
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @STEPNO int ");
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50) ");
|
|
|
strSql.Append(" declare @USERID varchar(50) declare @UsingCount int declare @StepCount int");
|
|
|
strSql.Append(" declare @GROUPID varchar(50) declare @changeusing bit declare @changeStep bit ");
|
|
|
strSql.Append(" set @STEPNO=(select STEPNO from workflow_step where gid='" + GID + "') ");
|
|
|
strSql.Append(" set @WORKFLOWID=(select WORKFLOWID from workflow_step where gid='" + GID + "') ");
|
|
|
strSql.Append(" set @USERID=(select auditor from workflow_step where gid='" + GID + "') ");
|
|
|
strSql.Append(" set @GROUPID=(select GROUPID from workflow_step where gid='" + GID + "') ");
|
|
|
strSql.Append(" set @USingCount=(select count(*) [count] from workflow_using ");
|
|
|
strSql.Append(" where workflowid=@WORKFLOWID and STEPNO=power(2,@STEPNO) ) ");
|
|
|
strSql.Append(" set @StepCount=(select count(*) [count] from workflow_step ");
|
|
|
strSql.Append(" where workflowid=@WORKFLOWID and STEPNO=power(2,@STEPNO) and auditor<>@USERID )");
|
|
|
strSql.Append(" if @USingCount>0 begin ");
|
|
|
strSql.Append(" set @changeusing=0 ");
|
|
|
strSql.Append(" set @changeStep=0 ");
|
|
|
strSql.Append(" end else if @StepCount>0 ");
|
|
|
strSql.Append(" begin ");
|
|
|
strSql.Append(" set @changeusing=0 ");
|
|
|
strSql.Append(" set @changeStep=1 ");
|
|
|
strSql.Append(" END else ");
|
|
|
strSql.Append(" begin ");
|
|
|
strSql.Append(" set @changeusing=1 ");
|
|
|
strSql.Append(" set @changeStep=1");
|
|
|
strSql.Append(" end ");
|
|
|
strSql.Append(" select @changeusing changeusing,@changeStep changeStep ");
|
|
|
return SetCanChange(strSql.ToString());
|
|
|
}
|
|
|
static private CanChangemb SetCanChange(string strSql)//参数为workflow_step的GID
|
|
|
{
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
var bodyList = new List<CanChangemb>();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
CanChangemb data = new CanChangemb();
|
|
|
#region Set DB data to Object
|
|
|
var ChangeStep = Convert.ToString(reader["ChangeStep"]);
|
|
|
var ChangeUsing = Convert.ToString(reader["ChangeUsing"]);
|
|
|
if (ChangeStep == "True")
|
|
|
{
|
|
|
data.ChangeStep = true;
|
|
|
}else data.ChangeStep = false;
|
|
|
if (ChangeUsing == "True")
|
|
|
{
|
|
|
data.ChangeUsing = true;
|
|
|
}
|
|
|
else data.ChangeUsing = false;
|
|
|
//data.ChangeStep = Convert.ToBoolean(reader["ChangeStep"]);
|
|
|
//data.ChangeUsing = Convert.ToBoolean(reader["ChangeUsing"]);
|
|
|
#endregion
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return bodyList[0];
|
|
|
}
|
|
|
#endregion
|
|
|
#region 增加workflow_step
|
|
|
static public Resultmb InsertStep(string WORKFLOWID, string USERID, string STEPNO, string GROUPID)
|
|
|
{
|
|
|
//workflowid,groupid相同的workflow_using数据列,合并新的stepno进入workflow_using.stepno
|
|
|
//类似驳回操作
|
|
|
var _result = new Resultmb();
|
|
|
var strSql = new StringBuilder();//如果using的stepno集合中包含stepno 则将其去除
|
|
|
strSql.Append(" if ((select count(*) from workflow_step ");//但如果有同步骤号的其他权限,则不改变当前状态
|
|
|
strSql.Append(" where WORKFLOWID='" + WORKFLOWID + "' and STEPNO ='" + STEPNO + "' and auditor<>'" + USERID + "' )=0) begin ");
|
|
|
strSql.Append(" update workflow_using set ");
|
|
|
strSql.Append(" stepno=stepno|power(2," + STEPNO + "),currentid='" + GROUPID + "' ");
|
|
|
strSql.Append(" where bsno in (select bsno from workflow_using where workflowid='"
|
|
|
+ WORKFLOWID + "' and currentid='" + GROUPID + "') and (stepno & power(2," + STEPNO + ")=0) ");
|
|
|
strSql.Append(" end ");
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
var _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
_result.Success = false;
|
|
|
_result.Message = "插入新步骤出错 " + ee.Message;
|
|
|
}
|
|
|
|
|
|
return _result;
|
|
|
}
|
|
|
#endregion
|
|
|
#region 删除workflow_step
|
|
|
static public Resultmb DelStep(string GID)//(string WORKFLOWID, string USERID, string STEPNO, string GROUPID)
|
|
|
{//删除工作步骤 类似推进工作流
|
|
|
var result=new Resultmb();
|
|
|
var _CanChange = GetCanChange(GID);
|
|
|
var strSql = new StringBuilder();
|
|
|
if (_CanChange.ChangeStep == false) {
|
|
|
result.Success=false;
|
|
|
result.Message = "不能修改,还有业务等待此步骤审核,请将这些业务审核通过或完全撤回后再修改";
|
|
|
}else {
|
|
|
//首先删除workflow_step 用此结果设定返回值
|
|
|
strSql.Append(" delete from workflow_step where gid='"+GID+"' ");
|
|
|
|
|
|
//根据情况判断是否修改using表
|
|
|
if (_CanChange.ChangeUsing == true)
|
|
|
{
|
|
|
strSql.Append(" declare @STEPNO varchar ");
|
|
|
strSql.Append(" declare @WORKFLOWID varchar ");
|
|
|
strSql.Append(" declare @USERID varchar ");
|
|
|
strSql.Append(" declare @GROUPID varchar ");
|
|
|
strSql.Append(" set @STEPNO=select STEPNO from workflow_step where gid='" + GID + "' ");
|
|
|
strSql.Append(" set @WORKFLOWID=select WORKFLOWID from workflow_step where gid='" + GID + "' ");
|
|
|
strSql.Append(" set @USERID=select auditor from workflow_step where gid='" + GID + "' ");
|
|
|
strSql.Append(" set @GROUPID=select GROUPID from workflow_step where gid='" + GID + "' ");
|
|
|
strSql.Append(" update workflow_using set ");
|
|
|
strSql.Append(" stepno=stepno-power(2,@STEPNO),currentid=@GROUPID ");
|
|
|
strSql.Append(" where workflowid=@WORKFLOWID ");
|
|
|
strSql.Append(" and currentid=@GROUPID ");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
var _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
result.Success = true;
|
|
|
result.totalCount = _count;
|
|
|
result.Message = "";
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "插入新步骤出错 " + ee.Message;
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 查询是否能够修改workflow_userPath
|
|
|
static public Boolean GetCanChange_UserPath(string USERID, string TYPENO, string NewWorkFlowID)//参数为workflow_step的GID
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append(" declare @USERID varchar(50) ");
|
|
|
strSql.Append(" declare @TYPE int ");
|
|
|
strSql.Append(" ,@NewWorkFlowID varchar(50) ");
|
|
|
strSql.Append(" set @USERID='" + USERID + "' ");
|
|
|
strSql.Append(" if (select count(*) from workflow_userpath where USERID=@USERID and WORKFLOWTYPENO='" + TYPENO + "')=0 ");
|
|
|
strSql.Append(" BEGIN ");
|
|
|
strSql.Append(" if (select count(*) from workflow where type='" + TYPENO + "' and ISdefault=1)=0 begin select 1 CanEdit ");
|
|
|
strSql.Append(" end else if (select count(*) from workflow_using where OP='" + USERID + "' ");
|
|
|
strSql.Append(" and workflowid in(select WorkflowID from workflow_userPath where USERID=@USERID and WORKFLOWTYPENO='" + TYPENO + "') and finished=0)>0 ");
|
|
|
strSql.Append(" begin select 0 CanEdit end else begin select 1 CanEdit end ");
|
|
|
strSql.Append(" END else BEGIN ");
|
|
|
strSql.Append(" if (select count(*) from workflow_using where OP='" + USERID + "' ");
|
|
|
strSql.Append(" and workflowid in(select WorkflowID from workflow_userPath where USERID=@USERID and WORKFLOWTYPENO='" + TYPENO + "') and finished=0)>0 ");
|
|
|
strSql.Append(" begin select 0 CanEdit end else begin select 1 CanEdit end END ");
|
|
|
|
|
|
return SetCanChange_UserPath(strSql.ToString());
|
|
|
}
|
|
|
static private Boolean SetCanChange_UserPath(string strSql)//参数为workflow_step的GID
|
|
|
{
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
var bodyList = new List<CanChangemb>();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
CanChangemb data = new CanChangemb();
|
|
|
#region Set DB data to Object
|
|
|
//var ChangeStep = Convert.ToString(reader["ChangeStep"]);
|
|
|
var ChangeUsing = Convert.ToString(reader["CanEdit"]);
|
|
|
/*if (ChangeStep == "True")
|
|
|
{
|
|
|
data.ChangeStep = true;
|
|
|
}
|
|
|
else data.ChangeStep = false;*/
|
|
|
if (ChangeUsing == "1")
|
|
|
{
|
|
|
data.ChangeUsing = true;
|
|
|
}
|
|
|
else data.ChangeUsing = false;
|
|
|
//data.ChangeStep = Convert.ToBoolean(reader["ChangeStep"]);
|
|
|
//data.ChangeUsing = Convert.ToBoolean(reader["ChangeUsing"]);
|
|
|
#endregion
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return bodyList[0].ChangeUsing;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region [操作工作流]工作流驳回
|
|
|
|
|
|
static public Resultmb DeleteWorkFlowDo(string WORKFLOWNAME, string BSNO, string USERID, string Reason)
|
|
|
{
|
|
|
//20150304 首先判断是否有权限进行驳回
|
|
|
//判断依据为workflow_do里面存在未删除的记录 其 workflowid billno(bsno)与当前值相同 ,stepno 和groupid与该用户有交集
|
|
|
//或此userid对此workflowid有允许自动通过的权限
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (DbConnection connection = db.CreateConnection())
|
|
|
{
|
|
|
connection.Open();
|
|
|
try
|
|
|
{
|
|
|
var _sql = " select * from workflow_do where (ISDELETE IS NULL OR ISDELETE=0) and ";
|
|
|
_sql = _sql + " Billno='" + BSNO + "' and workflowid=[dbo].[GetWorkFlowID]('" + WORKFLOWNAME + "','" + USERID + "') and ";
|
|
|
_sql = _sql + " Auditor='" + USERID + "' ";
|
|
|
_sql = _sql + " union all select gid,'','','','','','','','','','','','','','','','','','','' ";
|
|
|
_sql = _sql + " from workflow_step where WORKFLOWID=[dbo].[GetWorkFlowID]('" + WORKFLOWNAME + "','" + USERID + "') ";
|
|
|
_sql = _sql + " and auditor='" + USERID + "' and GROUPID='0' ";
|
|
|
//20150319 增加逻辑
|
|
|
//曾经自动审核通过的业务,在自动审核完成后业务流程发生了改变,改为人工审核。
|
|
|
//这时不再有“具有自动审核权限”的人,同时由于自动通过,也没有审核记录,因此按原逻辑是无法驳回的
|
|
|
//增加逻辑是:此业务已完结,而且此人在此工作流中具有审核权限,则有查询结果,即允许驳回。
|
|
|
_sql = _sql + " union all select s.gid,'','','','','','','','','','','','','','','','','','','' ";
|
|
|
_sql = _sql + " from workflow_step S left join workflow_using U on s.WORKFLOWID=u.WORKFLOWID and u.bsno='"+BSNO+"' and U.finished=1";
|
|
|
_sql = _sql + " where s.WORKFLOWID=[dbo].[GetWorkFlowID]('" + WORKFLOWNAME + "','" + USERID + "') ";
|
|
|
_sql = _sql + " and auditor='" + USERID + "' ";
|
|
|
var objcount = db.ExecuteScalar(CommandType.Text, _sql);
|
|
|
var _count = Convert.ToString(objcount);
|
|
|
if (string.IsNullOrEmpty(_count))
|
|
|
{
|
|
|
var _Result = new Resultmb();
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = "该用户没有权限驳回此业务";
|
|
|
return _Result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception exception)
|
|
|
{
|
|
|
var _Result = new Resultmb();
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = "查询workflow_do出错:" + exception.Message;
|
|
|
return _Result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
var workflowID = GetBSNOWorkFlowID(WORKFLOWNAME, BSNO)[0].GID;
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50),@GROUPID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID='" + workflowID + "' ");
|
|
|
//strSql.Append(" delete from workflow_do where workflowid=@WorkFlowID and auditor='" + USERID + "' and billno='" + BSNO + "'");
|
|
|
strSql.Append(" update workflow_do set isdelete=1, deletestep=stepno, audittime=dbo.trimtime(getdate()),auditor='" + USERID + "'");
|
|
|
strSql.Append(" where workflowid=@WorkFlowID and billno='" + BSNO + "' and isdelete is null");
|
|
|
|
|
|
strSql.Append(" insert into workflow_do (GID,workflowid,stepid,billno,auditor,audittime,isdelete,deletestep) ");
|
|
|
strSql.Append(" select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),1,stepno ");
|
|
|
strSql.Append(" from workflow_step where workflowid=@WorkFlowID and groupid=dbo.getmingroupid_2('" + workflowID + "','" + USERID + "') ");
|
|
|
strSql.Append(" and auditor='" + USERID + "'");
|
|
|
|
|
|
strSql.Append(" set @GROUPID=dbo.GetMinGroupID_2('" + workflowID + "','" + USERID + "') ");
|
|
|
strSql.Append(" update workflow_using set stepno=dbo.GetNextStep('" + workflowID + "','"+BSNO +"',@GROUPID),currentid=0, ");
|
|
|
strSql.Append(" reject_time=getdate(),reason=isnull(reason,'')+'" + Reason + "'+';',finished=0 ");
|
|
|
strSql.Append(" where workflowid=@WorkFlowID and bsno='" + BSNO + "' ");
|
|
|
//RefuseMessage(workflowID, BSNO, USERID, Reason);
|
|
|
//return DoDeleteWorkFlowDo(strSql.ToString());
|
|
|
|
|
|
var _r = DoDeleteWorkFlowDo(strSql.ToString());
|
|
|
if (_r.Success == true)
|
|
|
{
|
|
|
RefuseMessage(workflowID, BSNO, USERID, Reason);
|
|
|
}
|
|
|
|
|
|
return _r;
|
|
|
}
|
|
|
|
|
|
static public Resultmb DeleteWorkFlowDo ( string WORKFLOWNAME, string BSNO, string USERID, string Reason,string BILLNO,string GID,string URL )
|
|
|
{
|
|
|
//20150304 首先判断是否有权限进行驳回
|
|
|
//判断依据为workflow_do里面存在未删除的记录 其 workflowid billno(bsno)与当前值相同 ,stepno 和groupid与该用户有交集
|
|
|
//或此userid对此workflowid有允许自动通过的权限
|
|
|
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (DbConnection connection = db.CreateConnection())
|
|
|
{
|
|
|
connection.Open();
|
|
|
try
|
|
|
{
|
|
|
var _sql = " select * from workflow_do where (ISDELETE IS NULL OR ISDELETE=0) and ";
|
|
|
_sql = _sql + " Billno='" + BSNO + "' and workflowid=[dbo].[GetWorkFlowID]('" + WORKFLOWNAME + "','" + USERID + "') and ";
|
|
|
_sql = _sql + " Auditor='" + USERID + "' ";
|
|
|
_sql = _sql + " union all select gid,'','','','','','','','','','','','','','','','','','','' ";
|
|
|
_sql = _sql + " from workflow_step where WORKFLOWID=[dbo].[GetWorkFlowID]('" + WORKFLOWNAME + "','" + USERID + "') ";
|
|
|
//20170802hxt _sql = _sql + " and auditor='" + USERID + "' and GROUPID='0' ";
|
|
|
//20150319 增加逻辑
|
|
|
//曾经自动审核通过的业务,在自动审核完成后业务流程发生了改变,改为人工审核。
|
|
|
//这时不再有“具有自动审核权限”的人,同时由于自动通过,也没有审核记录,因此按原逻辑是无法驳回的
|
|
|
//增加逻辑是:此业务已完结,而且此人在此工作流中具有审核权限,则有查询结果,即允许驳回。
|
|
|
_sql = _sql + " union all select s.gid,'','','','','','','','','','','','','','','','','','','' ";
|
|
|
_sql = _sql + " from workflow_step S left join workflow_using U on s.WORKFLOWID=u.WORKFLOWID and u.bsno='" + BSNO + "' and U.finished=1";
|
|
|
_sql = _sql + " where s.WORKFLOWID=[dbo].[GetWorkFlowID]('" + WORKFLOWNAME + "','" + USERID + "') ";
|
|
|
_sql = _sql + " and auditor='" + USERID + "' ";
|
|
|
var objcount = db.ExecuteScalar(CommandType.Text, _sql);
|
|
|
var _count = Convert.ToString(objcount);
|
|
|
if (string.IsNullOrEmpty(_count))
|
|
|
{
|
|
|
var _Result = new Resultmb();
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = "该用户没有权限驳回此业务";
|
|
|
return _Result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception exception)
|
|
|
{
|
|
|
var _Result = new Resultmb();
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = "查询workflow_do出错:" + exception.Message;
|
|
|
return _Result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
var workflowID = GetBSNOWorkFlowID(WORKFLOWNAME, BSNO)[0].GID;
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50),@GROUPID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID='" + workflowID + "' ");
|
|
|
//strSql.Append(" delete from workflow_do where workflowid=@WorkFlowID and auditor='" + USERID + "' and billno='" + BSNO + "'");
|
|
|
strSql.Append(" update workflow_do set isdelete=1, deletestep=stepno, audittime=dbo.trimtime(getdate()),auditor='" + USERID + "'");
|
|
|
strSql.Append(" where workflowid=@WorkFlowID and billno='" + BSNO + "' and isdelete is null");
|
|
|
|
|
|
strSql.Append(" insert into workflow_do (GID,workflowid,stepid,billno,auditor,audittime,isdelete,deletestep) ");
|
|
|
strSql.Append(" select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),1,stepno ");
|
|
|
strSql.Append(" from workflow_step where workflowid=@WorkFlowID and groupid=dbo.getmingroupid_2('" + workflowID + "','" + USERID + "') ");
|
|
|
strSql.Append(" and auditor='" + USERID + "'");
|
|
|
|
|
|
strSql.Append(" set @GROUPID=dbo.GetMinGroupID_2('" + workflowID + "','" + USERID + "') ");
|
|
|
strSql.Append(" update workflow_using set stepno=dbo.GetNextStep('" + workflowID + "','" + BSNO + "',@GROUPID),currentid=0, ");
|
|
|
strSql.Append(" reject_time=getdate(),reason=isnull(reason,'')+'" + Reason + "'+';',finished=0 ");
|
|
|
strSql.Append(" where workflowid=@WorkFlowID and bsno='" + BSNO + "' ");
|
|
|
|
|
|
var _r= DoDeleteWorkFlowDo(strSql.ToString());
|
|
|
if (_r.Success == true)
|
|
|
{
|
|
|
RefuseMessage(workflowID, BSNO, USERID, Reason, BILLNO, GID, URL);
|
|
|
}
|
|
|
|
|
|
return _r;
|
|
|
}
|
|
|
|
|
|
private static Resultmb DoDeleteWorkFlowDo ( string strSql )
|
|
|
{
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
var result = new Resultmb();
|
|
|
try
|
|
|
{
|
|
|
db.ExecuteNonQuery(CommandType.Text, strSql);
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "撤销workflow_do工作流日志 " + ee.Message;
|
|
|
tran.Rollback();
|
|
|
}
|
|
|
|
|
|
if (result.Success == true)
|
|
|
{
|
|
|
tran.Commit();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 判断工作流权限是否为最终
|
|
|
/*
|
|
|
public static int GetWorkFlowFinal(string WorkFlowName, string DEPTGID, string USERID)
|
|
|
{//
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append(" select count(*) [Count] from workflow_step ");
|
|
|
strSql.Append(" where workflowid=dbo.getworkflowid('" + WorkFlowName + "','" + DEPTGID + "') ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and islast=1 ");
|
|
|
|
|
|
return SetWorkFlowFinal(strSql);
|
|
|
}*/
|
|
|
|
|
|
public static Boolean GetAutoFinish(string WORKFLOWID, string USERID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select count(*) count from workflow_step where ");
|
|
|
strSql.Append(" (workflowid='" + WORKFLOWID + "' and groupid=0) ");
|
|
|
//有人在步骤组0有权驳回 存在步骤组0的人步骤,该工作流可视为提交即自动通过
|
|
|
|
|
|
//或者
|
|
|
////自己有权在第一步审核通过
|
|
|
//strSql.Append(" or ( workflowid='" + WORKFLOWID + "' and groupid=1 and auditor='" + USERID + "' and islast=1)");
|
|
|
if (SetWorkFlowFinal(strSql) == 0)
|
|
|
{ return false; }
|
|
|
else { return true; }//允许自动审核通过
|
|
|
}
|
|
|
|
|
|
public static Boolean GetWorkFlowFinal_BSNO ( string WorkFlowName, string BSNO, string USERID )
|
|
|
{
|
|
|
//20170117 改成在当前步骤组内该用户是否具备最终审核权限
|
|
|
var WORKFLOWID = GetBSNOWorkFlowID(WorkFlowName, BSNO)[0].GID;
|
|
|
var GROUPIDList = GetBSNOGROUPID(WORKFLOWID, BSNO);
|
|
|
if (GROUPIDList.Count == 0) {
|
|
|
return false;
|
|
|
}
|
|
|
var GROUPID = GetBSNOGROUPID(WORKFLOWID, BSNO)[0].GROUPID;
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @LASTCOUNT int ");
|
|
|
strSql.Append(" set @LASTCOUNT=( select count(*) [Count] from workflow_step ");
|
|
|
strSql.Append(" where workflowid ='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and groupid='" + GROUPID + "' and islast=1 )");
|
|
|
//strSql.Append(" if (@LASTCOUNT=0) begin");
|
|
|
//strSql.Append(" set @LASTCOUNT=( select count(*) [Count] from workflow_step ");
|
|
|
//strSql.Append(" where workflowid =(select dbo.GetBSNOWorkflowid('" + WorkFlowName + "','" + BSNO + "'))) ");
|
|
|
//strSql.Append(" if (@LASTCOUNT=0) begin select 1 [count] end else begin select 0 [count] end ");
|
|
|
//strSql.Append(" end else begin select @LASTCOUNT [Count] end");
|
|
|
strSql.Append(" select @LASTCOUNT as Count ");
|
|
|
//if (SetWorkFlowFinal(strSql) > 1)
|
|
|
if (SetWorkFlowFinal(strSql) > 0)
|
|
|
{ return true; }
|
|
|
else { return false; }
|
|
|
}
|
|
|
public static Boolean GetWorkFlowFinal_BSNO(string WorkFlowName, string BSNO, string USERID, DbTransaction tran)
|
|
|
{
|
|
|
//20170117 改成在当前步骤组内该用户是否具备最终审核权限
|
|
|
var WORKFLOWID = GetBSNOWorkFlowID(WorkFlowName, BSNO)[0].GID;
|
|
|
var GROUPIDList = GetBSNOGROUPID(WORKFLOWID, BSNO,tran);
|
|
|
if (GROUPIDList.Count == 0)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
var GROUPID = GetBSNOGROUPID(WORKFLOWID, BSNO,tran)[0].GROUPID;
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @LASTCOUNT int ");
|
|
|
strSql.Append(" set @LASTCOUNT=( select count(*) [Count] from workflow_step ");
|
|
|
strSql.Append(" where workflowid ='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" and auditor='" + USERID + "' and groupid='" + GROUPID + "' and islast=1 )");
|
|
|
//strSql.Append(" if (@LASTCOUNT=0) begin");
|
|
|
//strSql.Append(" set @LASTCOUNT=( select count(*) [Count] from workflow_step ");
|
|
|
//strSql.Append(" where workflowid =(select dbo.GetBSNOWorkflowid('" + WorkFlowName + "','" + BSNO + "'))) ");
|
|
|
//strSql.Append(" if (@LASTCOUNT=0) begin select 1 [count] end else begin select 0 [count] end ");
|
|
|
//strSql.Append(" end else begin select @LASTCOUNT [Count] end");
|
|
|
strSql.Append(" select @LASTCOUNT as Count ");
|
|
|
//if (SetWorkFlowFinal(strSql) > 1)
|
|
|
if (SetWorkFlowFinal(strSql) > 0)
|
|
|
{ return true; }
|
|
|
else { return false; }
|
|
|
}
|
|
|
private static int SetWorkFlowFinal(StringBuilder strSql)
|
|
|
{
|
|
|
var Count = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Count = Convert.ToInt32(reader["Count"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
|
|
|
return Count;
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 从workflow_using表删除(工作流状态删除)
|
|
|
/*
|
|
|
static public int GetWorkFlowDo(string WorkFlowName, string DEPTGID, string BSNO)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID=(select dbo.getworkflowid('" + WorkFlowName + "','" + DEPTGID + "')) ");
|
|
|
strSql.Append(" select count(*) [count] from workflow_do ");
|
|
|
strSql.Append(" where workflowid=@WorkFlowID and bsno='" + BSNO + "' and isdelete is null ");
|
|
|
return SetWorkFlowDo(strSql.ToString());
|
|
|
}*/
|
|
|
|
|
|
//通过bsno和workflowid判断该业务是否存在未删除的操作记录
|
|
|
//如果存在(返回值大于0),一般来说上位操作将会据此禁止对此业务的修改。
|
|
|
static public int GetWorkFlowDo(string WORKFLOWID, string BSNO)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" select count(*) [count] from workflow_do ");
|
|
|
strSql.Append(" where workflowid=@WorkFlowID and bsno='" + BSNO + "' and isdelete is null ");
|
|
|
return SetWorkFlowDo(strSql.ToString());
|
|
|
}
|
|
|
private static int SetWorkFlowDo(string strSql)
|
|
|
{
|
|
|
var _count = 0;
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
_count = Convert.ToInt32(reader["count"]);
|
|
|
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return _count;
|
|
|
}
|
|
|
static public Resultmb DeleteWorkFlowUsing(string WorkFlowName, string BSNO, string USERID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50),@GROUPID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID=(select dbo.getworkflowid('" + WorkFlowName + "','" + BSNO + "')) ");
|
|
|
strSql.Append(" if (select count(*) from workflow_do where workflowid=@WorkFlowID and bsno='" + BSNO + "' and isdelete is null)=0");
|
|
|
strSql.Append(" begin delete workflow_using ");
|
|
|
strSql.Append(" where workflowid=@WorkFlowID and bsno='" + BSNO + "' end");//select '1' as candel
|
|
|
//strSql.Append(" else begin select '0' as candel end");
|
|
|
return DoDeleteWorkFlowUsing(strSql.ToString());
|
|
|
}/*
|
|
|
static public int DeleteWorkFlowUsing(string WORKFLOWID, string BSNO)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WorkFlowID varchar(50),@GROUPID varchar(50) ");
|
|
|
strSql.Append(" set @WorkFlowID='" + WORKFLOWID + "' ");
|
|
|
strSql.Append(" if (select count(*) from workflow_do where workflowid=@WorkFlowID and bsno='" + BSNO + "' and isdelete is null)=0");
|
|
|
strSql.Append(" begin delete workflow_using ");
|
|
|
strSql.Append(" where workflowid=@WorkFlowID and bsno='" + BSNO + "' select '1' as candel end");
|
|
|
strSql.Append(" else begin select '0' as candel end");
|
|
|
return DoDeleteWorkFlowUsing(strSql.ToString());
|
|
|
}*/
|
|
|
|
|
|
private static Resultmb DoDeleteWorkFlowUsing(string strSql)
|
|
|
{
|
|
|
var result = new Resultmb();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "删除workflow_using出错"+ee.Message;
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 通过workflowid和groupid来取得需要通知的操作人
|
|
|
|
|
|
static public List<Auditormb> GetAuditor(string WORKFLOWID, string GROUPID)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select ws.auditor,u.showname from workflow_step ws left join [user] u on u.gid=ws.auditor ");
|
|
|
strSql.Append(" where workflowid='" + WORKFLOWID + "' and groupid=" + GROUPID + " ");
|
|
|
|
|
|
return SetAuditor(strSql.ToString());
|
|
|
}
|
|
|
static public List<Auditormb> GetAuditor(string WORKFLOWID, string GROUPID, DbTransaction tran)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select ws.auditor,u.showname from workflow_step ws left join [user] u on u.gid=ws.auditor ");
|
|
|
strSql.Append(" where workflowid='" + WORKFLOWID + "' and groupid=" + GROUPID + " ");
|
|
|
|
|
|
return SetAuditor(strSql.ToString());
|
|
|
}
|
|
|
static public List<Auditormb> GetSender ( string WORKFLOWID, string BSNO )
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select wu.OP auditor,u.showname from workflow_using wu left join [user] u on u.gid=wu.OP ");
|
|
|
strSql.Append(" where workflowid='" + WORKFLOWID + "' and BSNO='" + BSNO + "' ");
|
|
|
|
|
|
return SetAuditor(strSql.ToString());
|
|
|
}
|
|
|
private static List<Auditormb> SetAuditor(string strSql)
|
|
|
{
|
|
|
var bodyList = new List<Auditormb>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Auditormb data = new Auditormb();
|
|
|
data.GID = Convert.ToString(reader["auditor"]);
|
|
|
data.NAME = Convert.ToString(reader["showname"]);
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
|
|
|
reader.Close();
|
|
|
}
|
|
|
return bodyList;
|
|
|
}
|
|
|
private static List<Auditormb> SetAuditor(string strSql, DbTransaction tran)
|
|
|
{
|
|
|
var bodyList = new List<Auditormb>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Auditormb data = new Auditormb();
|
|
|
data.GID = Convert.ToString(reader["auditor"]);
|
|
|
data.NAME = Convert.ToString(reader["showname"]);
|
|
|
bodyList.Add(data);
|
|
|
}
|
|
|
|
|
|
reader.Close();
|
|
|
}
|
|
|
return bodyList;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 审核通过时通知发起人
|
|
|
static public int PassMessage(string WORKFLOWID,string BSNO, string GROUDPID, string Auditor)
|
|
|
{
|
|
|
//var strSql = new StringBuilder();
|
|
|
var _count = 0;
|
|
|
/*
|
|
|
var strSql = new StringBuilder();
|
|
|
//Message.RECEIVER = Auditor.GID;
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50),@OP varchar(50),@BSNO varchar(50),@CURRENTID varchar(50),@STEPNAME varchar(100) ");
|
|
|
strSql.Append(" set @WORKFLOWID ='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" set @OP = (select OP from workflow_using where workflowid='" + WORKFLOWID + "' and bsno='" + BSNO + "')");
|
|
|
strSql.Append(" set @BSNO = '"+BSNO+"'");
|
|
|
strSql.Append(" set @CURRENTID = '" + GROUDPID + "'");
|
|
|
strSql.Append(" set @STEPNAME = (select top 1 description from workflow_step where workflowid=@workflowid and auditor='" + Auditor + "' and groupid='" + GROUDPID + "')");
|
|
|
strSql.Append(" select newid() GID,(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid=@WORKFLOWID) description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid='" + Auditor + "')+' 审核了['+(select DESCRIPTION from workflow ");
|
|
|
strSql.Append(" where gid=@WORKFLOWID)+']'+' 单号:'+@BSNO+' 步骤:'+@STEPNAME+'') messagecontent,null lastreadtime,@OP receiver, ");
|
|
|
strSql.Append(" 0 [type],(select top 1 TASKURL from workflow_step where workflowid=@WORKFLOWID and auditor='" + Auditor );
|
|
|
strSql.Append(" ' and GROUPID=@CURRENTID)+'?BSNO='+@BSNO taskurl,@BSNO taskid,0 isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
var _message = SetInsertMessage(strSql);
|
|
|
if (SaveMessage(_message)) { _count = 1; }
|
|
|
* */
|
|
|
return _count;
|
|
|
}
|
|
|
|
|
|
static public int PassMessage ( string WORKFLOWID, string BSNO, string GROUDPID, string Auditor, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
//var strSql = new StringBuilder();
|
|
|
var _count = 0;
|
|
|
/*
|
|
|
var strSql = new StringBuilder();
|
|
|
//Message.RECEIVER = Auditor.GID;
|
|
|
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50),@OP varchar(50),@BSNO varchar(50),@BILLNO varchar(50),@CURRENTID varchar(50),@STEPNAME varchar(100) ");
|
|
|
strSql.Append(" set @WORKFLOWID ='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" set @OP = (select OP from workflow_using where workflowid='" + WORKFLOWID + "' and bsno='" + BSNO + "')");
|
|
|
strSql.Append(" set @BSNO = '" + BSNO + "'");
|
|
|
strSql.Append(" set @BILLNO = '" + BILLNO + "'");
|
|
|
strSql.Append(" set @CURRENTID = '" + GROUDPID + "'");
|
|
|
strSql.Append(" set @STEPNAME = (select top 1 description from workflow_step where workflowid=@workflowid and auditor='" + Auditor + "' and groupid='" + GROUDPID + "')");
|
|
|
strSql.Append(" delete from sys_message where name=(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) and taskid='" + GID + "' and isread=0 ");
|
|
|
strSql.Append(" select newid() GID,(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid=@WORKFLOWID) description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid='" + Auditor + "')+' 审核了['+(select DESCRIPTION from workflow ");
|
|
|
strSql.Append(" where gid=@WORKFLOWID)+']'+' 单号:'+@BILLNO+' 步骤:'+@STEPNAME+'') messagecontent,null lastreadtime,@OP receiver, ");
|
|
|
strSql.Append(" 0 [type],'"+URL+"' taskurl,'"+GID+"' taskid,0 isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
var _message = SetInsertMessage(strSql, BILLNO, GID, URL );
|
|
|
if (SaveMessage(_message)) { _count = 1; }
|
|
|
* */
|
|
|
return _count;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 提交时通知审核人
|
|
|
static public int StartMessage(string WORKFLOWID, string OP, string RECEIVER,string BSNO)
|
|
|
{
|
|
|
var _count = 0;
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" select newid() GID,(select top 1 [name] from workflow_type where typeno=(select [type] from workflow where gid='" + WORKFLOWID + "')) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid='" + WORKFLOWID + "') description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid='" + OP + "')+' 提交了['+(select DESCRIPTION from workflow where gid='" + WORKFLOWID + "')+']'+' 单号:" + BSNO + "') messagecontent,null lastreadtime,'" + RECEIVER + "' receiver, ");
|
|
|
strSql.Append(" 0 [type],(select top 1 TASKURL from workflow_step where workflowid='" + WORKFLOWID + "' and auditor='" + RECEIVER + "' and GROUPID=1)+'?BSNO='+'" + BSNO + "' taskurl,'" + BSNO + "' taskid,null isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
|
|
|
var _message = SetInsertMessage(strSql);
|
|
|
if (SaveMessage(_message)) { _count = 1; }
|
|
|
}
|
|
|
return _count;
|
|
|
}
|
|
|
private static SYSMessagemb SetInsertMessage(StringBuilder strSql)
|
|
|
{
|
|
|
var data = new SYSMessagemb();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
|
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
|
|
|
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
|
|
|
data.ISREAD = Convert.ToString(reader["ISREAD"]);
|
|
|
data.READCOUNT = Convert.ToString(reader["READCOUNT"]);
|
|
|
data.MESSAGECONTENT = Convert.ToString(reader["MESSAGECONTENT"]);
|
|
|
data.LASTREADTIME = Convert.ToString(reader["LASTREADTIME"]);
|
|
|
data.RECEIVER = Convert.ToString(reader["RECEIVER"]);
|
|
|
data.TYPE = Convert.ToString(reader["TYPE"]);
|
|
|
data.TASKURL = Convert.ToString(reader["TASKURL"]);
|
|
|
data.TASKID = Convert.ToString(reader["TASKID"]);
|
|
|
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
|
|
|
data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]);
|
|
|
data.DELETETIME = Convert.ToString(reader["DELETETIME"]);
|
|
|
data.NUMBER = Convert.ToString(reader["NUMBER"]);
|
|
|
data.RECVTYPE = Convert.ToString(reader["RECVTYPE"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ee)
|
|
|
{
|
|
|
var _Result = new DBResult();
|
|
|
_Result.Success = false;
|
|
|
_Result.Message = ee.Message;
|
|
|
return data;
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
|
|
|
static public int StartMessage ( string WORKFLOWID, string OP, string RECEIVER, string BSNO, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
var _count = 0;
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" delete from sys_message where name=(select top 1 [name] from workflow_type where typeno=(select [type] from workflow where gid='" + WORKFLOWID + "')) and taskid='" + GID + "' and RECEIVER='" + RECEIVER + "' and isread=0 ");
|
|
|
strSql.Append(" select newid() GID,(select top 1 [name] from workflow_type where typeno=(select [type] from workflow where gid='" + WORKFLOWID + "')) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid='" + WORKFLOWID + "') description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid='" + OP + "')+' 提交了['+(select DESCRIPTION from workflow where gid='" + WORKFLOWID + "')+']'+' 单号:" + BILLNO + "') messagecontent,null lastreadtime,'" + RECEIVER + "' receiver, ");
|
|
|
strSql.Append(" 0 [type],'" + URL + "' taskurl,'" + GID + "' taskid,null isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
|
|
|
var _message = SetInsertMessage(strSql, BILLNO, GID, URL);
|
|
|
if (SaveMessage(_message)) { _count = 1; }
|
|
|
}
|
|
|
return _count;
|
|
|
}
|
|
|
private static SYSMessagemb SetInsertMessage ( StringBuilder strSql, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
var data = new SYSMessagemb();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
|
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
|
|
|
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
|
|
|
data.ISREAD = Convert.ToString(reader["ISREAD"]);
|
|
|
data.READCOUNT = Convert.ToString(reader["READCOUNT"]);
|
|
|
data.MESSAGECONTENT = Convert.ToString(reader["MESSAGECONTENT"]);
|
|
|
data.LASTREADTIME = Convert.ToString(reader["LASTREADTIME"]);
|
|
|
data.RECEIVER = Convert.ToString(reader["RECEIVER"]);
|
|
|
data.TYPE = Convert.ToString(reader["TYPE"]);
|
|
|
data.TASKURL = URL;
|
|
|
data.TASKID = GID;
|
|
|
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
|
|
|
data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]);
|
|
|
data.DELETETIME = Convert.ToString(reader["DELETETIME"]);
|
|
|
data.NUMBER = Convert.ToString(reader["NUMBER"]);
|
|
|
data.RECVTYPE = Convert.ToString(reader["RECVTYPE"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
private static SYSMessagemb SetInsertMessage(StringBuilder strSql, string BILLNO, string GID, string URL, DbTransaction tran)
|
|
|
{
|
|
|
var data = new SYSMessagemb();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(tran,CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
|
data.NAME = Convert.ToString(reader["NAME"]);
|
|
|
data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]);
|
|
|
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
|
|
|
data.ISREAD = Convert.ToString(reader["ISREAD"]);
|
|
|
data.READCOUNT = Convert.ToString(reader["READCOUNT"]);
|
|
|
data.MESSAGECONTENT = Convert.ToString(reader["MESSAGECONTENT"]);
|
|
|
data.LASTREADTIME = Convert.ToString(reader["LASTREADTIME"]);
|
|
|
data.RECEIVER = Convert.ToString(reader["RECEIVER"]);
|
|
|
data.TYPE = Convert.ToString(reader["TYPE"]);
|
|
|
data.TASKURL = URL;
|
|
|
data.TASKID = GID;
|
|
|
data.ISDELETE = Convert.ToString(reader["ISDELETE"]);
|
|
|
data.DELETEUSER = Convert.ToString(reader["DELETEUSER"]);
|
|
|
data.DELETETIME = Convert.ToString(reader["DELETETIME"]);
|
|
|
data.NUMBER = Convert.ToString(reader["NUMBER"]);
|
|
|
data.RECVTYPE = Convert.ToString(reader["RECVTYPE"]);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 审核步骤组 通过时 通知下一步审核人
|
|
|
static public int PushMessage(string WORKFLOWID, string BSNO, string GROUDPID)
|
|
|
{
|
|
|
//var strSql = new StringBuilder();
|
|
|
var _count = 0;
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg==null)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
var UserName = cookies.getCookie(CookieConstant.UserId);//登录组织
|
|
|
//var strSql = new StringBuilder();
|
|
|
|
|
|
|
|
|
var AuditorList = GetAuditor(WORKFLOWID, GROUDPID);//取得待通知人列表
|
|
|
foreach (var Auditor in AuditorList)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
//Message.RECEIVER = Auditor.GID;
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50),@OP varchar(50),@BSNO varchar(50),@CURRENTID varchar(50) ");
|
|
|
strSql.Append(" set @WORKFLOWID ='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" set @OP = '" + UserName + "'");
|
|
|
strSql.Append(" set @BSNO = '" + BSNO + "'");
|
|
|
strSql.Append(" set @CURRENTID = '" + GROUDPID + "'");
|
|
|
strSql.Append(" select newid() GID,(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid=@WORKFLOWID) description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid=@OP)+' 提交了['+(select DESCRIPTION from workflow where gid=@WORKFLOWID)+']'+' 单号:'+@BSNO+'') messagecontent,null lastreadtime,'" + Auditor.GID + "' receiver, ");
|
|
|
strSql.Append(" 0 [type],(select top 1 TASKURL from workflow_step where workflowid=@WORKFLOWID and auditor='" + Auditor.GID + "' and GROUPID=@CURRENTID)+'?BSNO='+@BSNO taskurl,@BSNO taskid,0 isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
var _message = SetInsertMessage(strSql);
|
|
|
if (SaveMessage(_message)) { _count = _count + 1; }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return _count;
|
|
|
}
|
|
|
|
|
|
static public int PushMessage(string WORKFLOWID, string BSNO, string GROUDPID, string BILLNO, string GID, string URL)
|
|
|
{
|
|
|
//var strSql = new StringBuilder();
|
|
|
var _count = 0;
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
|
|
|
var UserName = cookies.getCookie(CookieConstant.UserId);//登录组织
|
|
|
//var strSql = new StringBuilder();
|
|
|
|
|
|
|
|
|
var AuditorList = GetAuditor(WORKFLOWID, GROUDPID);//取得待通知人列表 此处应为
|
|
|
foreach (var Auditor in AuditorList)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
//Message.RECEIVER = Auditor.GID;
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50),@OP varchar(50),@BSNO varchar(50),@BILLNO varchar(50),@CURRENTID varchar(50) ");
|
|
|
strSql.Append(" set @WORKFLOWID ='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" set @OP = '" + UserName + "'");
|
|
|
strSql.Append(" set @BSNO = '" + BSNO + "'");
|
|
|
strSql.Append(" set @BILLNO = '" + BILLNO + "'");
|
|
|
strSql.Append(" set @CURRENTID = '" + GROUDPID + "'");
|
|
|
strSql.Append(" delete from sys_message where name=(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) and taskid='" + GID + "' and isread=0 ");
|
|
|
strSql.Append(" select newid() GID,(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid=@WORKFLOWID) description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid=@OP)+' 提交了['+(select DESCRIPTION from workflow where gid=@WORKFLOWID)+']'+' 单号:'+@BILLNO+'') messagecontent,null lastreadtime,'" + Auditor.GID + "' receiver, ");
|
|
|
strSql.Append(" 0 [type],(select top 1 TASKURL from workflow_step where workflowid=@WORKFLOWID and auditor='" + Auditor.GID + "' and GROUPID=@CURRENTID)+'?BSNO='+@BSNO taskurl,@BSNO taskid,0 isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
var _message = SetInsertMessage(strSql, BILLNO, GID, URL);
|
|
|
if (SaveMessage(_message)) { _count = _count + 1; }
|
|
|
}
|
|
|
}
|
|
|
return _count;
|
|
|
}
|
|
|
static public int PushMessage(string WORKFLOWID, string BSNO, string GROUDPID, string BILLNO, string GID, string URL, DbTransaction tran)
|
|
|
{
|
|
|
//var strSql = new StringBuilder();
|
|
|
var _count = 0;
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
|
|
|
var UserName = cookies.getCookie(CookieConstant.UserId);//登录组织
|
|
|
//var strSql = new StringBuilder();
|
|
|
|
|
|
|
|
|
var AuditorList = GetAuditor(WORKFLOWID, GROUDPID, tran);//取得待通知人列表 此处应为
|
|
|
foreach (var Auditor in AuditorList)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
//Message.RECEIVER = Auditor.GID;
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50),@OP varchar(50),@BSNO varchar(50),@BILLNO varchar(50),@CURRENTID varchar(50) ");
|
|
|
strSql.Append(" set @WORKFLOWID ='" + WORKFLOWID + "'");
|
|
|
strSql.Append(" set @OP = '" + UserName + "'");
|
|
|
strSql.Append(" set @BSNO = '" + BSNO + "'");
|
|
|
strSql.Append(" set @BILLNO = '" + BILLNO + "'");
|
|
|
strSql.Append(" set @CURRENTID = '" + GROUDPID + "'");
|
|
|
strSql.Append(" delete from sys_message where name=(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) and taskid='" + GID + "' and isread=0 ");
|
|
|
strSql.Append(" select newid() GID,(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid=@WORKFLOWID) description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid=@OP)+' 提交了['+(select DESCRIPTION from workflow where gid=@WORKFLOWID)+']'+' 单号:'+@BILLNO+'') messagecontent,null lastreadtime,'" + Auditor.GID + "' receiver, ");
|
|
|
strSql.Append(" 0 [type],(select top 1 TASKURL from workflow_step where workflowid=@WORKFLOWID and auditor='" + Auditor.GID + "' and GROUPID=@CURRENTID)+'?BSNO='+@BSNO taskurl,@BSNO taskid,0 isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
var _message = SetInsertMessage(strSql, BILLNO, GID, URL, tran);
|
|
|
if (SaveMessage(_message)) { _count = _count + 1; }
|
|
|
}
|
|
|
}
|
|
|
return _count;
|
|
|
}
|
|
|
|
|
|
static public int RepeatMessage ( string WORKFLOWID, string BSNO, string GROUDPID,string auditor_GID, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
//var strSql = new StringBuilder();
|
|
|
|
|
|
|
|
|
//var strSql = new StringBuilder();
|
|
|
var _count = 0;
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
var SenderList = GetSender(WORKFLOWID, BSNO);//取得待通知人列表 此处应为该工作流的提交人
|
|
|
foreach (var Sender in SenderList)
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
//Message.RECEIVER = Auditor.GID;
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50),@BSNO varchar(50),@CURRENTID varchar(50) ");
|
|
|
strSql.Append(" set @WORKFLOWID ='" + WORKFLOWID + "'");
|
|
|
//strSql.Append(" set @OP = '" + Sender.GID + "'");
|
|
|
strSql.Append(" set @BSNO = '" + BILLNO + "'");
|
|
|
strSql.Append(" set @CURRENTID = '" + GROUDPID + "'");
|
|
|
strSql.Append(" delete from sys_message where name=(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) and taskid='" + GID + "' and isread=0 ");
|
|
|
strSql.Append(" select newid() GID,(select [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid=@WORKFLOWID) description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid='" + auditor_GID + "')+' 通过了['+(select DESCRIPTION from workflow where gid=@WORKFLOWID)+']'+' 单号:'+@BSNO+'') messagecontent,null lastreadtime,'" + Sender.GID + "' receiver, ");
|
|
|
strSql.Append(" 0 [type],'" + URL + "' taskurl,@BSNO taskid,0 isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
var _message = SetInsertMessage(strSql, BILLNO, GID, URL);
|
|
|
if (SaveMessage(_message)) { _count = _count + 1; }
|
|
|
}
|
|
|
}
|
|
|
return _count;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 驳回时通知发起人
|
|
|
static public int RefuseMessage(string WORKFLOWID, string BSNO, string RefuseID, string Reason)
|
|
|
{
|
|
|
var _count = 0;
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50),@OP varchar(50),@BSNO varchar(50) ");
|
|
|
strSql.Append(" set @WORKFLOWID = '" + WORKFLOWID + "'");
|
|
|
strSql.Append(" set @OP = (select OP from workflow_using where workflowid='" + WORKFLOWID + "' and bsno='" + BSNO + "')");
|
|
|
strSql.Append(" set @BSNO = '" + BSNO + "'");
|
|
|
strSql.Append(" select newid() GID,(select top 1 [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid=@WORKFLOWID) description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid='" + RefuseID + "')+' 驳回了['+(select DESCRIPTION from workflow where gid=@WORKFLOWID)+'] ");
|
|
|
strSql.Append(" 原因'+'" + Reason + "') messagecontent,null lastreadtime,@OP receiver, ");
|
|
|
strSql.Append(" 0 [type],(select top 1 TASKURL from workflow_step where workflowid=@WORKFLOWID and auditor='" + RefuseID + "' )+'?BSNO='+@BSNO taskurl,@BSNO taskid,0 isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
|
|
|
var _message = SetInsertMessage(strSql);
|
|
|
if (SaveMessage(_message)) { _count = 1; }
|
|
|
}
|
|
|
return _count;
|
|
|
}
|
|
|
|
|
|
static public int RefuseMessage ( string WORKFLOWID, string BSNO, string RefuseID, string Reason, string BILLNO, string GID, string URL )
|
|
|
{
|
|
|
var _count = 0;
|
|
|
var cookies = new Cookies();
|
|
|
var WorkflowMsg = cookies.getCookie(CookieConstant.WorkflowMsg);//启用消息提示
|
|
|
if (WorkflowMsg == "1")
|
|
|
{
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(" declare @WORKFLOWID varchar(50),@OP varchar(50),@BSNO varchar(50) ");
|
|
|
strSql.Append(" set @WORKFLOWID = '" + WORKFLOWID + "'");
|
|
|
strSql.Append(" set @OP = (select OP from workflow_using where workflowid='" + WORKFLOWID + "' and bsno='" + BSNO + "')");
|
|
|
strSql.Append(" set @BSNO = '" + BSNO + "'");
|
|
|
strSql.Append(" delete from sys_message where name=(select top 1 [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) and taskid='" + GID + "' and isread=0 ");
|
|
|
strSql.Append(" select newid() GID,(select top 1 [name] from workflow_type where typeno=(select [type] from workflow where gid=@WORKFLOWID)) [name] ");
|
|
|
strSql.Append(" ,(select DESCRIPTION from workflow where gid=@WORKFLOWID) description,getdate() createtime,0 isread,0 readcount, ");
|
|
|
strSql.Append(" ((select showname from [user] where gid='" + RefuseID + "')+' 驳回了['+(select DESCRIPTION from workflow where gid=@WORKFLOWID)+'] 单号:" + BILLNO + ", ");
|
|
|
strSql.Append(" 原因'+'" + Reason + "') messagecontent,null lastreadtime,@OP receiver, ");
|
|
|
strSql.Append(" 0 [type],'" + URL + "' taskurl,'" + GID + "' taskid,0 isdelete,null deleteuser,null deletetime,0 [number],2 recvtype ");
|
|
|
|
|
|
var _message = SetInsertMessage(strSql, BILLNO, GID, URL);
|
|
|
if (SaveMessage(_message)) { _count = 1; }
|
|
|
}
|
|
|
return _count;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 保存信息
|
|
|
public static Boolean SaveMessage(SYSMessagemb Message)
|
|
|
{
|
|
|
var head = Message;
|
|
|
|
|
|
head.DbOperationType = DbOperationType.DbotIns;
|
|
|
head.ModelUIStatus = "I";
|
|
|
|
|
|
var modb = new ModelObjectRepository();
|
|
|
DBResult result = modb.Save(head);
|
|
|
|
|
|
//刷新父窗口上的父节点
|
|
|
var jsonRespose = new JsonResponse
|
|
|
{
|
|
|
Success = result.Success,
|
|
|
Message = result.Message,
|
|
|
Data = ""
|
|
|
};
|
|
|
|
|
|
return jsonRespose.Success;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
} |