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 ;
using DSWeb.MvcShipping.DAL.MsSysParamSet ;
using DSWeb.Areas.MvcShipping.Helper ;
using DSWeb.Areas.SysMng.DAL.SysTask ;
namespace DSWeb.Areas.CommMng.DAL
{
public class WorkFlowDAL
{
#region [操作工作流] 开始工作流过程
static public Resultmb WorkFlowStart ( string WorkFlowName , string BSNO , string USERID , string BILLNO )
{
var strSql = new StringBuilder ( ) ;
var result = new Resultmb ( ) ;
var _r = WorkFlowDAL . GetWorkFlowmb ( WorkFlowName , USERID ) ;
WorkFlowmb _workflow = new WorkFlowmb ( ) ;
if ( _r . Success ) _workflow = ( WorkFlowmb ) _r . Data ;
else
{
result . Success = false ;
result . Message = _r . Message ;
return result ;
}
var workflowID = _workflow . GID ;
var TYPENO = _workflow . TYPE ;
var AutoFinish = _workflow . isAuto ;
var islast = false ;
if ( AutoFinish = = "1" ) islast = true ;
if ( AutoFinish = = "0" ) //不是自动审核通过
{
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],CREATETIME) values('" + BSNO + "','" + workflowID + "', " ) ;
strSql . Append ( " dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),'0','1',null,null,0,null,null,null,null,'" + USERID + "'," + TYPENO + ",getdate()) " ) ;
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],CREATETIME) values('" + BSNO + "','" + workflowID + "', " ) ;
strSql . Append ( " dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),'0','1',null,null,1,null,null,null,null,'" + USERID + "'," + TYPENO + ",getdate()) " ) ;
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 ) ;
}
private static Resultmb setWorkFlowStart ( StringBuilder strSql , string WORKFLOWID , string OP , string BSNO , Boolean islast , string BILLNO )
{
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 , BILLNO ) ;
//SaveMessage(_Message);
}
}
return _Result ;
}
static public Resultmb WorkFlowStart ( string WorkFlowName , string BSNO , string USERID , string BILLNO , string GID , string URL , string workflowidstr = "" , string MSG = "" )
{
var strSql = new StringBuilder ( ) ;
var workflowID = "" ;
var TYPENO = "" ;
var AutoFinish = "0" ;
var _Result = new Resultmb ( ) ;
var _workflow = new WorkFlowmb ( ) ;
if ( workflowidstr = = "" | | workflowidstr = = "no" )
{
var _r = GetWorkFlowmb ( WorkFlowName , USERID ) ;
if ( _r . Success ) _workflow = ( WorkFlowmb ) _r . Data ;
else {
_Result . Success = false ;
_Result . Message = _r . Message ;
return _Result ;
}
workflowID = _workflow . GID ;
TYPENO = _workflow . TYPE ;
AutoFinish = _workflow . isAuto ;
}
else
{
_workflow = GetWorkFlow ( workflowidstr ) [ 0 ] ;
workflowID = _workflow . GID ;
TYPENO = _workflow . TYPE ;
AutoFinish = _workflow . isAuto ;
}
if ( workflowID = = "" )
{
_Result . Success = false ;
_Result . Message = "该工作流程还未设置工作流,请联系管理员" ;
return _Result ;
}
var islast = false ;
if ( AutoFinish = = "1" ) islast = true ;
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],CREATETIME) values('" + BSNO + "','" + workflowID + "', " ) ;
strSql . Append ( " dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),'0','1',null,null,0,null,null,null,null,'" + USERID + "'," + TYPENO + ",getdate()) " ) ;
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],CREATETIME) values('" + BSNO + "','" + workflowID + "', " ) ;
strSql . Append ( " dbo.[GetNextStep]('" + workflowID + "','" + BSNO + "','1'),'0','1',null,null,1,null,null,null,null,'" + USERID + "'," + TYPENO + ",getdate()) " ) ;
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 , MSG ) ;
}
private static Resultmb setWorkFlowStart ( StringBuilder strSql , string WORKFLOWID , string OP , string BSNO , Boolean islast , string BILLNO , string GID , string URL , string MSG = "" )
{
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 , MSG ) ;
//SaveMessage(_Message);
}
}
return _Result ;
}
/// <summary>
/// 撤回工作流 会清空这个BSNO的workflow_using数据
/// </summary>
/// <param name="WorkFlowName"></param>
/// <param name="BSNO"></param>
/// <param name="USERID"></param>
/// <returns></returns>
static public Resultmb WorkFlowReset ( string WorkFlowName , string BSNO , string USERID )
{
var strSql = new StringBuilder ( ) ;
var workflowID = GetBSNOWorkFlowID ( WorkFlowName , BSNO ) [ 0 ] . GID ;
if ( workflowID = = "" )
{
var Result = new Resultmb ( ) ;
Result . Success = true ;
Result . Message = "" ;
return Result ;
}
//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 ");
strSql . Append ( " declare @workflowID varchar(50) " ) ;
strSql . Append ( " set @workflowID = [dbo].[GetWorkFlowID]('" + NAME + "','" + USERID + "') " ) ;
strSql . Append ( " select @workflowID workflowid, " ) ;
strSql . Append ( " [NAME] name,type " ) ;
strSql . Append ( " ,case when(select count(*) from workflow_step where (workflowid = @workflowID " ) ;
strSql . Append ( " and groupid = 0))> 0 then 1 else 0 end isAuto " ) ; //如果能自动完成 则isAuto=1
strSql . Append ( " from workflow where gid = @workflowID " ) ;
return SetWorkFlowID ( strSql ) ;
}
static public List < WorkFlowmb > GetWorkFlow ( string WorkFlowID )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " select GID workflowid, " ) ;
strSql . Append ( " [NAME] name, type" ) ;
strSql . Append ( " ,case when(select count(*) from workflow_step where (workflowid = '" + WorkFlowID + "' " ) ;
strSql . Append ( " and groupid = 0))> 0 then 1 else 0 end isAuto " ) ; //如果能自动完成 则isAuto=1
strSql . Append ( " from workflow where GID='" + WorkFlowID + "'" ) ;
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 ");
//strSql.Append(" ,case when(select count(*) from workflow_step where (workflowid = [dbo].[GetBSNOWorkFlowID]('" + NAME + "','" + BSNO + "') ");
//strSql.Append(" and groupid = 0))> 0 then 1 else 0 end isAuto ");//如果能自动完成 则isAuto=1
//return SetWorkFlowID(strSql);
strSql . Append ( " declare @workflowid varchar(50) " ) ;
strSql . Append ( " set @workflowid = [dbo].[GetBSNOWorkFlowID]('" + NAME + "','" + BSNO + "') " ) ;
strSql . Append ( " select @workflowid workflowid, " ) ;
strSql . Append ( " '" + NAME + "' as name,(select type from workflow where gid= @workflowid ) type " ) ;
strSql . Append ( " ,case when(select count(*) from workflow_step where (workflowid = @workflowid " ) ;
strSql . Append ( " and groupid = 0))> 0 then 1 else 0 end isAuto " ) ; //如果能自动完成 则isAuto=1
return SetWorkFlowID ( strSql ) ;
}
static public List < WorkFlowmb > GetBSNOWorkFlowID ( string NAME , string BSNO , DbTransaction tran )
{
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 ");
//strSql.Append(" ,case when(select count(*) from workflow_step where (workflowid = [dbo].[GetBSNOWorkFlowID]('" + NAME + "','" + BSNO + "') ");
//strSql.Append(" and groupid = 0))> 0 then 1 else 0 end isAuto ");//如果能自动完成 则isAuto=1
//return SetWorkFlowID(strSql);
strSql . Append ( " declare @workflowid varchar(50) " ) ;
strSql . Append ( " set @workflowid = [dbo].[GetBSNOWorkFlowID]('" + NAME + "','" + BSNO + "') " ) ;
strSql . Append ( " select @workflowid workflowid, " ) ;
strSql . Append ( " '" + NAME + "' as name,(select type from workflow where gid= @workflowid ) type " ) ;
strSql . Append ( " ,case when(select count(*) from workflow_step where (workflowid = @workflowid " ) ;
strSql . Append ( " and groupid = 0))> 0 then 1 else 0 end isAuto " ) ; //如果能自动完成 则isAuto=1
return SetWorkFlowID ( strSql , tran ) ;
}
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" ] ) ;
data . isAuto = Convert . ToString ( reader [ "isAuto" ] ) ;
# endregion
bodyList . Add ( data ) ;
}
reader . Close ( ) ;
}
return bodyList ;
}
private static List < WorkFlowmb > SetWorkFlowID ( StringBuilder strSql , DbTransaction tran )
{
var bodyList = new List < WorkFlowmb > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( tran , 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" ] ) ;
data . isAuto = Convert . ToString ( reader [ "isAuto" ] ) ;
# endregion
bodyList . Add ( data ) ;
}
reader . Close ( ) ;
}
return bodyList ;
}
static public DBResult GetWorkFlowmb ( string NAME , string USERID ) {
var result = new DBResult ( ) ;
var _r = GetWorkFlowID ( NAME , USERID ) ;
if ( _r . Count > 0 )
{
result . Success = true ;
result . Data = _r [ 0 ] ;
}
else {
result . SetErrorInfo ( $"未找到可用的工作流,请确认已为该用户所在的公司设定这个类型的工作流。参考信息:《工作流类型:{NAME},用户ID: {USERID}》" ) ;
}
return result ;
}
# 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 [查询]获取该用户,在该工作流中 目前可以操作的业务编号列表
////
/// <summary>
/// [查询] 获取该用户,在该工作流中 目前可以操作的业务编号列表 不指定步骤组号
/// </summary>
/// <param name="WorkFlowID"></param>
/// <param name="USERID"></param>
/// <returns></returns>
static public List < WorkFlow_Usingmb > GetWorkFlowBSNOList ( string WorkFlowID , string USERID )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " select BSNO,WORKFLOWID,STEPNO from workflow_using where workflowid='" + WorkFlowID + "' and stepno in( " ) ;
strSql . Append ( " select stepno from workflow_step where WORKFLOWID = '" + WorkFlowID + "' and AUDITOR = '" + USERID + "') " ) ;
return SetWorkFlowState ( strSql ) ;
}
/// <summary>
/// [查询] 获取该用户,在该工作流中 目前可以操作的业务编号列表 指定步骤组号
/// </summary>
/// <param name="WorkFlowID"></param>
/// <param name="StepNo"></param>
/// <param name="USERID"></param>
/// <returns></returns>
static public List < WorkFlow_Usingmb > GetWorkFlowBSNOList ( string WorkFlowID , int StepNo , string USERID )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " select BSNO,WORKFLOWID,STEPNO from workflow_using where workflowid='" + WorkFlowID + "' and stepno in( " ) ;
strSql . Append ( " select stepno from workflow_step where WORKFLOWID = '" + WorkFlowID + "' and AUDITOR = '" + USERID + "') and stepno=" + StepNo . ToString ( ) + " " ) ;
return SetWorkFlowState ( strSql ) ;
}
static public List < WorkFlow_Usingmb > GetWorkFlowBSNOListByName ( string WorkFlowName , string USERID )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " declare @workflowID varchar(50) " ) ;
strSql . Append ( " set @workflowID = [dbo].[GetWorkFlowID]('" + WorkFlowName + "','" + USERID + "') " ) ;
strSql . Append ( " select BSNO,WORKFLOWID,STEPNO from workflow_using where workflowid=@workflowID and stepno in( " ) ;
strSql . Append ( " select stepno from workflow_step where WORKFLOWID = @workflowID and AUDITOR = '" + USERID + "') " ) ;
return SetWorkFlowState ( strSql ) ;
}
static public List < WorkFlow_Usingmb > GetWorkFlowBSNOListByName ( string WorkFlowName , int StepNo , string USERID )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " declare @workflowID varchar(50) " ) ;
strSql . Append ( " set @workflowID = [dbo].[GetWorkFlowID]('" + WorkFlowName + "','" + USERID + "') " ) ;
strSql . Append ( " select BSNO,WORKFLOWID,STEPNO from workflow_using where workflowid=@workflowID and stepno in( " ) ;
strSql . Append ( " select stepno from workflow_step where WORKFLOWID = @workflowID and AUDITOR = '" + USERID + "') and stepno=" + StepNo . ToString ( ) + " " ) ;
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 ) ;
}
/// <summary>
/// 看工作流目前的步骤组 可以用来查看工作流是否在审核流程中
/// </summary>
/// <param name="WORKFLOWID"></param>
/// <param name="BSNO"></param>
/// <returns></returns>
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 ) ;
}
/// <summary>
/// 看一个BSNO在指定WORKFLOWID的工作流中 是否处于已被审核过的状态
/// 返回true 表示存在一个“具有 这个bsno 这个WORKFLOWID的 finished=0(还未结束) 的workflow_using记录”
/// 而且存在至少一个“workflow_do.audittime大于workflow_using.createtime”的workflow_do
/// </summary>
/// <param name="WORKFLOWID"></param>
/// <param name="BSNO"></param>
/// <returns></returns>
static public bool GetBSNOWORKFLOWIDinAudit ( string WORKFLOWID , string BSNO )
{
var strSql = new StringBuilder ( ) ;
strSql . Append ( " select (select count (*) from workflow_do where Billno=workflow_using.BSNO and workflowid=workflow_using.workflowid and audittime>=workflow_using.createtime) name,stepno,currentid GROUPID,'' auditor,'' showname,bsno billno from workflow_using where FINISHED = 0 and bsno = '" + BSNO + "' and workflowid = '" + WORKFLOWID + "' " ) ;
var resultlist = SetBSNOWorkFlow ( strSql ) ;
if ( resultlist . Count < = 0 ) return false ;
else
{
var result = resultlist [ 0 ] ;
if ( Convert . ToInt32 ( result . NAME ) > 0 )
{
return true ;
}
else
return false ;
}
}
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 , string BILLNO )
{
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 ( WorkFlowID , GROUPID , BSNO , USERID ) ;
return DoInsertWorkFlowDo ( WorkFlowID , USERID , BSNO , islast , StepList , BILLNO ) ;
}
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 ;
if ( WorkFlowID = = "" )
{
var _Result = new Resultmb ( ) ;
_Result . Success = false ;
_Result . Message = "" ;
return _Result ;
}
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 ( WorkFlowID , GROUPID , BSNO , USERID ) ;
return DoInsertWorkFlowDo ( WorkFlowID , USERID , BSNO , islast , StepList , BILLNO , GID , URL ) ;
}
static public Resultmb InsertWorkFlowDo ( string WORKFLOWNAME , string BSNO , string USERID , DbTransaction tran , string BILLNO )
{
var strSql = new StringBuilder ( ) ;
var WorkFlowID = GetBSNOWorkFlowID ( WORKFLOWNAME , BSNO , tran ) [ 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 ( WorkFlowID , GROUPID , BSNO , USERID , tran ) ;
return DoInsertWorkFlowDo ( WorkFlowID , USERID , BSNO , islast , StepList , tran , BILLNO ) ;
}
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 , tran ) [ 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 ( WorkFlowID , GROUPID , 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 , string BILLNO )
{
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 ( " ,isfinish,BSNO,feeid,feestatus,DOQUERYSQL,isdelete,deletestep,deleteoperator,deletestepno,operator,applicant) " ) ; ////
strSql . Append ( " select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID " ) ;
strSql . Append ( " ,0,'','','','','0','','','','',''" ) ; ////
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 ) ;
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 ( " ,isfinish,BSNO,feeid,feestatus,DOQUERYSQL,isdelete,deletestep,deleteoperator,deletestepno,operator,applicant) " ) ; ////
strSql . Append ( " select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID " ) ;
strSql . Append ( " ,0,'','','','','0','','','','',''" ) ; ////
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 , string BILLNO )
{
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 ( " ,isfinish,BSNO,feeid,feestatus,DOQUERYSQL,isdelete,deletestep,deleteoperator,deletestepno,operator,applicant) " ) ; ////
strSql . Append ( " select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID " ) ;
strSql . Append ( " ,0,'','','','','0','','','','',''" ) ; ////
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 ) ;
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 ( " ,isfinish,BSNO,feeid,feestatus,DOQUERYSQL,isdelete,deletestep,deleteoperator,deletestepno,operator,applicant) " ) ; ////
strSql . Append ( " select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),stepno,islast,GROUPID " ) ;
strSql . Append ( " ,0,'','','','','0','','','','',''" ) ; ////
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 , string BILLNO )
{ //将操作记入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 ( ) , BILLNO ) ;
}
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 , string BILLNO )
{ //将操作记入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 ( ) , BILLNO ) ;
}
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 [操作工作流]工作流驳回 如果驳回后回到最初状态, 则清空这个BSNO的workflow_using数据
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,BSNO,FEEID,FEESTATUS,DOQUERYSQL,STEPNO,ISFINISH,DELETEOPERATOR,DELETESTEPNO,OPERATOR,ISALLFINISH,APPLICANT,GROUPID) " ) ;
strSql . Append ( " select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),1,stepno,'','','','','',0,'','','',0,'','' " ) ;
strSql . Append ( " from workflow_step where workflowid=@WorkFlowID and groupid=dbo.getmingroupid_2('" + workflowID + "','" + USERID + "') " ) ;
strSql . Append ( " and auditor='" + USERID + "'" ) ;
strSql . Append ( " delete from workflow_using where workflowid='" + workflowID + "' and bsno='" + BSNO + "' " ) ;
//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 , string WORKFLOWID = "" )
{
//20150304 首先判断是否有权限进行驳回
//判断依据为workflow_do里面存在未删除的记录 其 workflowid billno(bsno)与当前值相同 ,stepno 和groupid与该用户有交集
//或此userid对此workflowid有允许自动通过的权限
if ( WORKFLOWID = = "" | | WORKFLOWID = = "no" )
WORKFLOWID = GetBSNOWorkFlowID ( WORKFLOWNAME , BSNO ) [ 0 ] . GID ;
if ( WORKFLOWID = = "" )
{
var _Result = new Resultmb ( ) ;
_Result . Success = false ;
_Result . Message = "" ;
return _Result ;
}
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( DbConnection connection = db . CreateConnection ( ) )
{
connection . Open ( ) ;
try
{
if ( WORKFLOWID ! = "no" & & WORKFLOWID ! = "" )
{
var _sql = " select * from workflow_do where (ISDELETE IS NULL OR ISDELETE=0) and " ;
_sql = _sql + " Billno='" + BSNO + "' and workflowid='" + WORKFLOWID + "'and " ;
_sql = _sql + " Auditor='" + USERID + "' " ;
_sql = _sql + " union all select gid,'','','','','','','','','','','','','','','','','','','' " ;
_sql = _sql + " from workflow_step where WORKFLOWID='" + WORKFLOWID + "' " ;
_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='" + WORKFLOWID + "' " ;
_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 ;
}
}
else
{
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' " ; //20170802hxt 20200629dy
//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 = WORKFLOWID ;
if ( workflowID = = "no" | | WORKFLOWID = = "" ) 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,BSNO,FEEID,FEESTATUS,DOQUERYSQL,STEPNO,ISFINISH,DELETEOPERATOR,DELETESTEPNO,OPERATOR,ISALLFINISH,APPLICANT,GROUPID) " ) ;
strSql . Append ( " select newid(),workflowid,gid,'" + BSNO + "',auditor,getdate(),1,stepno,'','','','','',0,'','','',0,'','' " ) ;
strSql . Append ( " from workflow_step where workflowid=@WorkFlowID and groupid=dbo.getmingroupid_2('" + workflowID + "','" + USERID + "') " ) ;
strSql . Append ( " and auditor='" + USERID + "'" ) ;
strSql . Append ( " delete from workflow_using where workflowid='" + workflowID + "' and bsno='" + BSNO + "' " ) ;
//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 WORKFLOWID , string GROUPID , 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 WORKFLOWID , string GROUPID , 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 ; }
}
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 , string BILLNO )
{
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 + "')+']'+' 单号:" + BILLNO + "') 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" ] ) ;
data . ISSEND = "0" ;
}
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 , string MSG = "" )
{
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 + "," + MSG + "') 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" ] ) ;
data . ISSEND = "0" ;
}
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" ] ) ;
data . ISSEND = "0" ;
}
reader . Close ( ) ;
}
return data ;
}
# endregion
#region 审核步骤组 通过时 通知下一步审核人
static public int PushMessage ( string WORKFLOWID , string BSNO , string GROUDPID , string BILLNO )
{
//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 ) ;
T_ALL_DA T_ALL_DA = new EntityDA . T_ALL_DA ( ) ;
var CT = T_ALL_DA . GetStrSQL ( "CT" , "select count(*) CT from user_msg_set WHERE USERID='" + Message . RECEIVER + "' and WORKFLOWTYPE_NAME='" + Message . NAME + "'" ) ;
if ( CT = = "0" )
{
var USEDINGDINGMSG = MsSysParamSetDAL . GetData ( "PARAMNAME='USEDINGDINGMSG'" ) . PARAMVALUE ;
if ( USEDINGDINGMSG = = "1" )
{
DingTalkHelper . SendMessage ( Message . RECEIVER , Message . MESSAGECONTENT ) ;
}
try
{
bool suessce = new ChatHub ( ) . SendMessage ( head . RECEIVER , head . GID ) ;
}
catch ( Exception e )
{
}
}
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result . Success ,
Message = result . Message ,
Data = ""
} ;
return jsonRespose . Success ;
}
# endregion
#region 通用 提交 撤回 审核 驳回
#region 提交审核和撤销审核 目前是固化状态的方式,将来期望改成与任务状态联动的形式
/// <summary>
/// AuditInfomb的参数包括
/// </summary>
/// <param name="AuditInfo"></param>
/// <param name="extracmd"></param>
/// <returns></returns>
public static DBResult SubmitAudit ( AuditInfomb AuditInfo , string extracmd = "" )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
Resultmb WorkResult = WorkFlowDAL . WorkFlowStart ( AuditInfo . WORKFLOWNAME , AuditInfo . BSNO , AuditInfo . USERID , AuditInfo . BSNO , AuditInfo . BSNO , "" ) ;
if ( WorkResult . Success )
{
result = ChangeBillWorkflow ( AuditInfo , tran , WorkResult . islast , db , extracmd ) ;
if ( result . Success = = true )
{
tran . Commit ( ) ;
result . Message = "提交审核成功!" ;
}
else
{
//tran.Rollback();
//result.Success = false;
//result.Message = "提交审核错误!";
result . Message = "提交审核错误!" + result . Message ;
}
}
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "提交审核错误,请重试或联系系统管理员" ;
return result ;
}
}
return result ;
}
public static DBResult SubmitAuditBack ( AuditInfomb AuditInfo , string extracmd = "" )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
var tran = conn . BeginTransaction ( ) ;
try
{
Resultmb WorkResult = WorkFlowDAL . WorkFlowReset ( AuditInfo . WORKFLOWNAME , AuditInfo . BSNO , AuditInfo . USERID ) ;
result = ChangeBillWorkflow ( AuditInfo , tran , WorkResult . islast , db , extracmd ) ;
if ( result . Success = = true )
{
tran . Commit ( ) ;
result . Message = "撤回提交成功!" ;
}
else
{
//tran.Rollback();
//result.Success = false;
//result.Message = "提交审核错误!";
result . Message = "已经审核或部分审核 不允许撤回!" + result . Message ;
}
}
catch ( Exception )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = "提交审核错误,请重试或联系系统管理员" ;
return result ;
}
}
return result ;
}
# endregion
#region 审核或驳回
public static DBResult Audit ( AuditInfomb AuditInfo , string extracmd = "" )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
try
{
if ( AuditInfo . BSNOArray . Count ( ) > 0 )
{
foreach ( var BSNO in AuditInfo . BSNOArray )
{
var tran = conn . BeginTransaction ( ) ;
Resultmb WorkResult = WorkFlowDAL . InsertWorkFlowDo ( AuditInfo . WORKFLOWNAME , BSNO , AuditInfo . USERID , tran , BSNO ) ;
if ( WorkResult . Success )
{
result = ChangeBillWorkflow ( AuditInfo , tran , WorkResult . islast , db , extracmd ) ;
if ( result . Success = = true )
{
tran . Commit ( ) ;
result . Message = "审核通过!" ;
}
else
{
//tran.Rollback();
//result.Success = false;
//result.Message = "提交审核错误!";
result . Message = "审核失败!" + result . Message ;
}
}
else
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = WorkResult . Message ;
}
}
}
result = new DBResult ( ) ;
result . Success = true ;
result . Message = "审核通过" ;
}
catch ( Exception e )
{
result . Success = false ;
result . Message = "审核出现错误,请重试或联系系统管理员:" + e . Message ;
return result ;
}
}
result . Success = true ;
result . Message = "审核通过" ;
return result ;
}
/// <summary>
/// 在extracmd里面写 reason = '驳回理由' ,并给REASON参数传递一次驳回理由
/// </summary>
/// <param name="AuditInfo"></param>
/// <param name="extracmd"></param>
/// <returns></returns>
public static DBResult AuditBack ( AuditInfomb AuditInfo , string extracmd , string REASON )
{
var result = new DBResult ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( var conn = db . CreateConnection ( ) )
{
conn . Open ( ) ;
try
{
if ( AuditInfo . BSNOArray . Count ( ) > 0 )
{
foreach ( var BSNO in AuditInfo . BSNOArray )
{
var tran = conn . BeginTransaction ( ) ;
Resultmb WorkResult = WorkFlowDAL . DeleteWorkFlowDo ( AuditInfo . WORKFLOWNAME , BSNO , AuditInfo . USERID , REASON ) ;
if ( WorkResult . Success )
{
result = ChangeBillWorkflow ( AuditInfo , tran , WorkResult . islast , db , extracmd ) ;
if ( result . Success = = true )
{
tran . Commit ( ) ;
result . Message = "驳回成功!" ;
}
else
{
//tran.Rollback();
//result.Success = false;
//result.Message = "提交审核错误!";
result . Message = "驳回失败!" + result . Message ;
}
}
else
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = WorkResult . Message ;
}
}
}
result = new DBResult ( ) ;
result . Success = true ;
result . Message = "驳回成功" ;
}
catch ( Exception e )
{
result . Success = false ;
result . Message = "驳回出现错误,请重试或联系系统管理员:" + e . Message ;
return result ;
}
}
result . Success = true ;
result . Message = "驳回成功" ;
return result ;
}
# endregion
/// <summary>
/// 实际修改业务的状态
/// </summary>
/// <param name="AuditInfo"></param>
/// <param name="tran"></param>
/// <param name="islast"></param>
/// <param name="db"></param>
/// <returns></returns>
private static DBResult ChangeBillWorkflow ( AuditInfomb AuditInfo , DbTransaction tran , bool islast , Database db , string extracmd = "" )
{
var result = new DBResult ( true , "" , null ) ;
try
{
var cmdupdate_base = "update {0} set {1}={2} where {3} in({4}) and {5}={6}" ;
if ( ! string . IsNullOrEmpty ( extracmd . Trim ( ) ) ) {
cmdupdate_base = "update {0} set {1}={2}," + extracmd + " where {3} in({4}) and {5}={6}" ;
}
var cmdupdate = "" ;
if ( islast = = true )
{ //update tablename set STATEFIELDNAME=TOSTATE where BSNOFIELDNAME=BSNO and STATEFIELDNAME=FROMSTATE
cmdupdate = string . Format ( cmdupdate_base
, AuditInfo . TABLENAME
, AuditInfo . STATEFIELDNAME , AuditInfo . LASTSTATE
, AuditInfo . BSNOFIELDNAME , AuditInfo . BSNOListStr
, AuditInfo . STATEFIELDNAME , AuditInfo . FROMSTATE
) ;
}
else
{
cmdupdate = string . Format ( cmdupdate_base
, AuditInfo . TABLENAME
, AuditInfo . STATEFIELDNAME , AuditInfo . TOSTATE
, AuditInfo . BSNOFIELDNAME , AuditInfo . BSNOListStr
, AuditInfo . STATEFIELDNAME , AuditInfo . FROMSTATE
) ;
}
DbCommand dc = db . GetSqlStringCommand ( cmdupdate ) ;
db . ExecuteNonQuery ( dc , tran ) ;
return result ;
}
catch ( Exception e )
{
tran . Rollback ( ) ;
result . Success = false ;
result . Message = e . Message ;
return result ;
}
}
# endregion
}
}