1243 lines
60 KiB
C#
1243 lines
60 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using SuperMap.RealEstate.CoreFrameWork;
|
||
using SuperMap.RealEstate.FrameWork.Business;
|
||
using SuperMap.RealEstate.Enums;
|
||
using SuperMap.RealEstate.Plugin;
|
||
using SuperMap.RealEstate.ServiceModel;
|
||
using SuperMap.RealEstate.ServiceModel.Enums;
|
||
using SuperMap.RealEstate.WorkFlow;
|
||
using SuperMap.RealEstate.WorkFlow.Instance;
|
||
using SuperMap.RealEstate.WorkFlow.Instance.Business;
|
||
using Instance = SuperMap.RealEstate.WorkFlow.Instance;
|
||
using Support = SuperMap.RealEstate.WorkFlow.Support.Business;
|
||
|
||
namespace MobileServicePlatform.Common
|
||
{
|
||
/// <summary />
|
||
public partial class InstanceHelper
|
||
{
|
||
/// <summary />
|
||
public const string Guid_AcceptProInst = "SR01";
|
||
/// <summary />
|
||
public const string Guid_Material = "SR02";
|
||
/// <summary />
|
||
public const string Guid_LinkMan = "SR03";
|
||
/// <summary />
|
||
public const string Guid_Consignor = "SR04";
|
||
///// <summary />
|
||
//public const string Enum_Certificate_Type_CID = "1001";
|
||
/// <summary />
|
||
public const string Enum_Certificate_Type_BusinessLicence = "3001";
|
||
|
||
#region CreateProInst 创建流程实例,活动实例、当前活动实例
|
||
/// <summary>
|
||
/// 创建流程实例,活动实例、当前活动实例
|
||
/// </summary>
|
||
/// <param name="Page"></param>
|
||
/// <param name="ProDef_ID_Encrypt"></param>
|
||
/// <returns></returns>
|
||
public static string CreateProInst(Transaction _Transaction, User _User, string ProDef_ID_Encrypt, string RDivision_Code)
|
||
{
|
||
Support.ProDef _ProDef = new Support.ProDef(_Transaction);
|
||
_ProDef.ProDef_ID_Encrypt = ProDef_ID_Encrypt;
|
||
if (!_ProDef.Select())
|
||
{
|
||
throw new Exception("流程不存在!");
|
||
}
|
||
List<Support.ActDef> _ActDefCollection = _ProDef.GetActDefCollection(ActDefType.ProcessStart);
|
||
if (_ActDefCollection.Count == 0)
|
||
{
|
||
throw new Exception("流程" + _ProDef.ProDef_Name + "未定义开始节点!");
|
||
}
|
||
else if (_ActDefCollection.Count > 1)
|
||
{
|
||
throw new Exception("流程" + _ProDef.ProDef_Name + "定义了多个开始节点!");
|
||
}
|
||
Support.ActDef _ActDef = _ActDefCollection[0];
|
||
//判断是否具有权限
|
||
Support.UserRole _UserRole = new Support.UserRole(_Transaction);
|
||
_UserRole.AddSearchParameter("User_ID", _User.User_ID);
|
||
_UserRole.AddSearchParameter("Role_ID", _ActDef.ActEntDef.Role_ID.Value);
|
||
if (!_UserRole.Search())
|
||
{
|
||
throw new Exception("您可能无权受理" + _ProDef.ProDef_Name + "!");
|
||
}
|
||
|
||
DateTime _DateTime = DateTime.Now;
|
||
ProInst _ProInst = new ProInst(_Transaction);
|
||
//复制流程
|
||
_ProInst.CopyFrom(_ProDef);//, _ProInst);
|
||
_ProInst.ProInst_StartDate = DateTime.Now;
|
||
_ProInst.ProInst_State = ProInstState.Normal;
|
||
_ProInst.ProInst_Type = ProInstType.Normal;
|
||
_ProInst.ProInst_StartDate = _DateTime;
|
||
if (_ProDef.Enabled_Division == 1)
|
||
{
|
||
string _Division_Code = RDivision_Code;
|
||
if (string.IsNullOrEmpty(_Division_Code))
|
||
{
|
||
if (_User.User_CityAuthority.IndexOf(",") < 0)
|
||
_Division_Code = _User.User_CityAuthority;
|
||
}
|
||
if (string.IsNullOrEmpty(_Division_Code))
|
||
{
|
||
throw new Exception("启用城区的流程必须传递城区参数!");
|
||
}
|
||
if (_User.User_EnabledCityAuthority == 1 && !(" " + _User.User_CityAuthority + " ").Contains(" " + _Division_Code + " "))
|
||
{
|
||
throw new Exception("您不具有当前服务区的受理权限!");
|
||
}
|
||
_ProInst.Division_Code_BaseValue = int.Parse(_Division_Code);
|
||
}
|
||
_ProInst.ProInst_EndDate = SupportHelper.GetEndDate(_DateTime, _ProDef.ProDef_TimeLimit.Value, _Transaction);
|
||
if (_ProInst.Department_Code.HasValue)
|
||
{
|
||
_ProInst.Department_Name = DictionaryHelper.GetFieldEnumName("Department_Code",
|
||
_ProInst.Department_Code.ToString(), _Transaction);
|
||
}
|
||
_ProInst.Insert();
|
||
ActInst _ActInst = new ActInst(_ProInst);
|
||
_ActInst.CopyFrom(_ProInst);//, _ActInst);
|
||
_ActInst.CopyFrom(_ActDef);//, _ActInst);
|
||
_ActInst.ActInst_Name = _ActDef.ActDef_Name;
|
||
_ActInst.ActInst_PositionX = _ActDef.ActDef_PositionX;
|
||
_ActInst.ActInst_PositionY = _ActDef.ActDef_PositionY;
|
||
_ActInst.User_ID = _User.User_ID;
|
||
_ActInst.User_Name = _User.User_Name;
|
||
//显示用户归属岗位
|
||
UserType _UserType = new UserType(_Transaction);
|
||
_UserType.UserType_ID = _User.UserType_ID;
|
||
if (_UserType.Select())
|
||
{
|
||
_ActInst.User_Name += "【" + _UserType.UserType_Name + "】";
|
||
}
|
||
_ActInst.ActInst_State = ActInstState.Normal;
|
||
_ActInst.ActInst_Type = ActInstType.Accept;
|
||
_ActInst.ActInst_StartDate = _DateTime;
|
||
_ActInst.ActInst_WorkDate = _DateTime;
|
||
_ActInst.Data_PutInStorage = 0;
|
||
_ActInst.ActInst_EndDate = SupportHelper.GetEndDate(_DateTime, _ActDef.ActDef_TimeLimit.Value, _Transaction);
|
||
_ActInst.Department_Code = _ActDef.Department_Code;
|
||
if (_ActInst.Department_Code.HasValue)
|
||
{
|
||
_ActInst.Department_Name = DictionaryHelper.GetFieldEnumName("Department_Code",
|
||
_ActInst.Department_Code.ToString(), _Transaction);
|
||
}
|
||
else
|
||
{
|
||
_ActInst.Department_Name = "";
|
||
}
|
||
_ActInst.Insert();
|
||
|
||
_Transaction.LoggingInfo.LogTransaction_Model = LogTransaction_Model.PageWorkFlow.ToInt16();
|
||
_Transaction.LoggingInfo.LogTransaction_Name = LogTransaction_Model.PageWorkFlow.ToDescription() + "_" + _ProInst.ProDef_Name;
|
||
_Transaction.LoggingInfo.LogTransaction_KeyValue = "";//.Value.ToString();
|
||
_Transaction.LoggingInfo.ProInst_ID = _ProInst.ProInst_ID.Value;
|
||
_Transaction.LoggingInfo.ActInst_ID = _ActInst.ActInst_ID;
|
||
_Transaction.LoggingInfo.ActInst_Name = _ActInst.ActInst_Name;
|
||
_Transaction.LoggingInfo.Component_ID = LoggingInfoDefaultState.Init.ToInt32();
|
||
_Transaction.LoggingInfo.Component_Name = LoggingInfoDefaultState.Init.ToDescription();
|
||
_ProInst.ServiceClient.UpdateLogTransaction(_Transaction.LoggingInfo);
|
||
NowActInst _NowActInst = new NowActInst(_Transaction);
|
||
_NowActInst.CopyFrom(_ActInst);
|
||
_NowActInst.CopyFrom(_ProInst);
|
||
_NowActInst.Role_ID = _ActDef.ActEntDef.Role_ID;
|
||
_NowActInst.NowActInst_Locked = 1;
|
||
_NowActInst.Insert();
|
||
_Transaction.AutoCommit();
|
||
return _NowActInst.ProInst_ID.ToEncrypt();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建流程实例,活动实例、当前活动实例
|
||
/// </summary>
|
||
/// <param name="Page"></param>
|
||
/// <param name="ProDef_ID_Encrypt"></param>
|
||
/// <param name="ProInst_ID_Encrypt"></param>
|
||
/// <param name="ProInst_Name">流程名称自定义</param>
|
||
/// <param name="CreateProinstCode">是否创建受理号</param>
|
||
/// <param name="AutoCommit">是否提交事务</param>
|
||
/// <param name="_Transaction"></param>
|
||
/// <returns></returns>
|
||
public static NowActInst CreateProInst(User _User, string ProDef_ID_Encrypt, out string ProInst_ID_Encrypt,
|
||
string ProInst_Name = "", bool CreateProinstCode = true, bool AutoCommit = true, Transaction _Transaction = null)
|
||
{
|
||
//if (_Transaction != null)
|
||
// Page.Transaction = _Transaction;
|
||
//else
|
||
// Page.Transaction = new Transaction();
|
||
ProInst_ID_Encrypt = "";
|
||
Support.ProDef _ProDef = new Support.ProDef(_Transaction);
|
||
_ProDef.ProDef_ID_Encrypt = ProDef_ID_Encrypt;
|
||
if (!_ProDef.Select())
|
||
{
|
||
throw new Exception("流程不存在!");
|
||
}
|
||
List<Support.ActDef> _ActDefCollection = _ProDef.GetActDefCollection(ActDefType.ProcessStart);
|
||
if (_ActDefCollection.Count == 0)
|
||
{
|
||
throw new Exception("流程" + _ProDef.ProDef_Name + "未定义开始节点!");
|
||
}
|
||
else if (_ActDefCollection.Count > 1)
|
||
{
|
||
throw new Exception("流程" + _ProDef.ProDef_Name + "定义了多个开始节点!");
|
||
}
|
||
Support.ActDef _ActDef = _ActDefCollection[0];
|
||
//判断是否具有权限
|
||
Support.UserRole _UserRole = new Support.UserRole(_Transaction);
|
||
_UserRole.AddSearchParameter("User_ID", _User.User_ID);
|
||
_UserRole.AddSearchParameter("Role_ID", _ActDef.ActEntDef.Role_ID.Value);
|
||
if (!_UserRole.Search())
|
||
{
|
||
throw new Exception("您可能无权受理" + _ProDef.ProDef_Name + "!");
|
||
}
|
||
|
||
DateTime _DateTime = DateTime.Now;
|
||
ProInst _ProInst = new ProInst(_Transaction);
|
||
//复制流程
|
||
_ProInst.CopyFrom(_ProDef);//, _ProInst);
|
||
_ProInst.ProInst_Name = ProInst_Name;
|
||
_ProInst.ProInst_StartDate = DateTime.Now;
|
||
_ProInst.ProInst_State = ProInstState.Normal;
|
||
_ProInst.ProInst_Type = ProInstType.Normal;
|
||
_ProInst.ProInst_StartDate = _DateTime;
|
||
_ProInst.ProInst_EndDate = SupportHelper.GetEndDate(_DateTime, _ProDef.ProDef_TimeLimit.Value, _Transaction);
|
||
|
||
if (_ProInst.Department_Code.HasValue)
|
||
{
|
||
try
|
||
{
|
||
//这里枚举不知道是什么问题
|
||
_ProInst.Department_Name = DictionaryHelper.GetFieldEnumName("Department_Code",
|
||
_ProInst.Department_Code.ToString(), _Transaction);
|
||
}
|
||
catch { }
|
||
}
|
||
if (CreateProinstCode)
|
||
{
|
||
_ProInst.ProInst_Code = CreateAcceptCode(_ProInst);
|
||
}
|
||
_ProInst.Insert();
|
||
|
||
ProInst_ID_Encrypt = _ProInst.ProInst_ID_Encrypt;
|
||
|
||
|
||
ActInst _ActInst = new ActInst(_ProInst);
|
||
_ActInst.CopyFrom(_ProInst);//, _ActInst);
|
||
_ActInst.CopyFrom(_ActDef);//, _ActInst);
|
||
|
||
_ActInst.ActInst_Name = _ActDef.ActDef_Name;
|
||
_ActInst.ActInst_PositionX = _ActDef.ActDef_PositionX;
|
||
_ActInst.ActInst_PositionY = _ActDef.ActDef_PositionY;
|
||
_ActInst.User_ID = _User.User_ID;
|
||
_ActInst.User_Name = _User.User_Name;
|
||
//显示用户归属岗位
|
||
UserType _UserType = new UserType(_Transaction);
|
||
_UserType.UserType_ID = _User.UserType_ID;
|
||
if (_UserType.Select())
|
||
{
|
||
_ActInst.User_Name += "【" + _UserType.UserType_Name + "】";
|
||
}
|
||
_ActInst.ActInst_State = ActInstState.Normal;
|
||
_ActInst.ActInst_Type = ActInstType.Accept;
|
||
_ActInst.ActInst_StartDate = _DateTime;
|
||
_ActInst.ActInst_WorkDate = _DateTime;
|
||
_ActInst.Data_PutInStorage = 0;
|
||
_ActInst.ActInst_EndDate = SupportHelper.GetEndDate(_DateTime, _ActDef.ActDef_TimeLimit.Value, _Transaction);
|
||
_ActInst.Department_Code = _ActDef.Department_Code;
|
||
if (_ActInst.Department_Code.HasValue)
|
||
{
|
||
_ActInst.Department_Name = DictionaryHelper.GetFieldEnumName("Department_Code",
|
||
_ActInst.Department_Code.ToString(), _Transaction);
|
||
}
|
||
else
|
||
{
|
||
_ActInst.Department_Name = "";
|
||
}
|
||
_ActInst.Insert();
|
||
|
||
_Transaction.LoggingInfo.LogTransaction_Model = LogTransaction_Model.PageWorkFlow.ToInt16();
|
||
_Transaction.LoggingInfo.LogTransaction_Name = LogTransaction_Model.PageWorkFlow.ToDescription() + "_" + _ProInst.ProDef_Name;
|
||
_Transaction.LoggingInfo.LogTransaction_KeyValue = "";//.Value.ToString();
|
||
//Page.Transaction.LoggingInfo.Modify_LogTransaction_KeyValue = true;
|
||
_Transaction.LoggingInfo.ProInst_ID = _ProInst.ProInst_ID.Value;
|
||
_Transaction.LoggingInfo.ActInst_ID = _ActInst.ActInst_ID;
|
||
_Transaction.LoggingInfo.ActInst_Name = _ActInst.ActInst_Name;
|
||
_Transaction.LoggingInfo.Component_ID = LoggingInfoDefaultState.Init.ToInt32();
|
||
_Transaction.LoggingInfo.Component_Name = LoggingInfoDefaultState.Init.ToDescription();
|
||
_ProInst.ServiceClient.UpdateLogTransaction(_Transaction.LoggingInfo);
|
||
|
||
|
||
NowActInst _NowActInst = new NowActInst(_Transaction);
|
||
_NowActInst.CopyFrom(_ActInst);
|
||
_NowActInst.CopyFrom(_ProInst);
|
||
_NowActInst.Role_ID = _ActDef.ActEntDef.Role_ID;
|
||
_NowActInst.NowActInst_Locked = 1;
|
||
_NowActInst.Insert();
|
||
if (AutoCommit)
|
||
{
|
||
_Transaction.AutoCommit();
|
||
}
|
||
return _NowActInst;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region CreateAcceptCode 创建受理编号
|
||
/// <summary>
|
||
/// 创建受理编号
|
||
/// </summary>
|
||
/// <param name="proInst"></param>
|
||
/// <returns></returns>
|
||
public static string CreateAcceptCode(ProInst proInst)
|
||
{
|
||
if (!string.IsNullOrEmpty(proInst.ProInst_Code))
|
||
{
|
||
if (proInst.ProDef.ProCode_Type == 0)
|
||
{
|
||
return EnumHelper.ToValue(proInst.ProInst_Type) +
|
||
proInst.ProInst_Code.Substring(proInst.ProInst_Code.IndexOf("-"));
|
||
}
|
||
else
|
||
{
|
||
return EnumHelper.ToValue(proInst.ProInst_Type) + proInst.ProDef.ProCode_Type.ToString() +
|
||
proInst.ProInst_Code.Substring(proInst.ProInst_Code.IndexOf("-"));
|
||
}
|
||
}
|
||
DateTime _Date = DateTime.Now.Date;
|
||
List<string> _Result = new List<string>();
|
||
string _SequenceValue = string.Empty;
|
||
int _SequenceFixLength = 0;
|
||
|
||
if (proInst.ProDef.ProCode_Type == 0)
|
||
{
|
||
//全局模式不显示
|
||
//办件类型
|
||
_Result.Add(EnumHelper.ToValue(proInst.ProInst_Type));
|
||
}
|
||
else
|
||
{
|
||
//办件类型+编号类型(私有)
|
||
_Result.Add(EnumHelper.ToValue(proInst.ProInst_Type) + proInst.ProDef.ProCode_Type.ToString());
|
||
}
|
||
string _SequenceName = "seq_code";
|
||
|
||
if (proInst.ProDef.ProCode_Type.Value == 0)
|
||
{
|
||
//全局编号模式
|
||
_SequenceName += "_glb_full";
|
||
if (proInst.ProDef.ProCode_Mode.Value == 0)
|
||
//预留无区分分类补齐
|
||
_SequenceFixLength = proInst.Operation_Type_BaseValue.ToString().Length + 1;
|
||
else if (proInst.ProDef.ProCode_Mode.Value == 1)
|
||
//添加业务类型
|
||
_SequenceValue = proInst.Operation_Type_BaseValue.ToString();
|
||
else if (proInst.ProDef.ProCode_Mode.Value == 2)
|
||
//添加流程内码
|
||
_SequenceValue = proInst.ProDef_ID.ToString();
|
||
else
|
||
throw new Exception("错误的编号呈现类型");
|
||
|
||
if (!string.IsNullOrEmpty(_SequenceValue))
|
||
{
|
||
if (proInst.ProDef.ProCode_Completed == 1)
|
||
{
|
||
_SequenceValue = _SequenceValue.PadLeft(proInst.Operation_Type_BaseValue.ToString().Length, '0');
|
||
}
|
||
_Result.Add(_SequenceValue);
|
||
}
|
||
}
|
||
else if (proInst.ProDef.ProCode_Type.Value == 1)
|
||
{
|
||
//私有编号模式
|
||
_SequenceName += "_prv";
|
||
if (proInst.ProDef.ProCode_Mode.Value == 0)
|
||
{
|
||
_SequenceName += "_full";
|
||
//预留无区分分类补齐
|
||
_SequenceFixLength = proInst.Operation_Type_BaseValue.ToString().Length + 1;
|
||
}
|
||
else if (proInst.ProDef.ProCode_Mode.Value == 1)
|
||
{
|
||
_SequenceName += "_oprt";
|
||
//添加业务类型
|
||
_SequenceValue = proInst.Operation_Type_BaseValue.ToString();
|
||
}
|
||
else if (proInst.ProDef.ProCode_Mode.Value == 2)
|
||
{
|
||
_SequenceName += "_prdf";
|
||
//添加流程内码
|
||
_SequenceValue = proInst.ProDef_ID.ToString();
|
||
}
|
||
else
|
||
throw new Exception("错误的编号呈现类型");
|
||
|
||
if (!string.IsNullOrEmpty(_SequenceValue))
|
||
{
|
||
if (proInst.ProDef.ProCode_Completed == 1)
|
||
{
|
||
_SequenceValue = _SequenceValue.PadLeft(proInst.Operation_Type_BaseValue.ToString().Length, '0');
|
||
}
|
||
_Result.Add(_SequenceValue);
|
||
}
|
||
}
|
||
else
|
||
throw new Exception("错误的收件编号类型");
|
||
|
||
if (proInst.ProDef.ProCode_ResetCycle.Value == 0)
|
||
{
|
||
//不重置
|
||
_SequenceName += "00000";
|
||
_Result.Add(_Date.ToString("yyyy"));
|
||
}
|
||
else if (proInst.ProDef.ProCode_ResetCycle.Value == 1)
|
||
{
|
||
//年度重置
|
||
_SequenceName += "_" + _Date.ToString("yy") + "000";
|
||
_Result.Add(_Date.ToString("yyyy"));
|
||
}
|
||
else if (proInst.ProDef.ProCode_ResetCycle.Value == 2)
|
||
{
|
||
//季度重置
|
||
_SequenceName += "_" + _Date.ToString("yy") + "" + (Math.Floor((_Date.Month - 1) / 3.0) + 1) + "00";
|
||
_Result.Add(_Date.ToString("yyyy") + (Math.Floor((_Date.Month - 1) / 3.0) + 1));
|
||
}
|
||
else if (proInst.ProDef.ProCode_ResetCycle.Value == 3)
|
||
{
|
||
//月度重置
|
||
_SequenceName += "_" + _Date.ToString("yy") + "" + (Math.Floor((_Date.Month - 1) / 3.0) + 1) + "" + _Date.ToString("MM");
|
||
_Result.Add(_Date.ToString("yyyy") + (Math.Floor((_Date.Month - 1) / 3.0) + 1) + _Date.ToString("MM"));
|
||
}
|
||
else
|
||
throw new Exception("错误的编号重置周期");
|
||
try
|
||
{
|
||
_SequenceValue = proInst.ExecuteDataTable("select " + _SequenceName + ".nextval from dual").Rows[0][0].ToString();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
//如果序列不存在,自动创建序列
|
||
if (ex.Message.StartsWith("ORA-02289"))
|
||
{
|
||
proInst.ServiceClient.ExecuteNonQuery("CREATE SEQUENCE " + _SequenceName +
|
||
" INCREMENT BY 1 START WITH 1 NOMAXVALUE NOMINVALUE NOCYCLE CACHE 5 NOORDER ", null);
|
||
_SequenceValue = proInst.ExecuteDataTable("select " + _SequenceName + ".nextval from dual").Rows[0][0].ToString();
|
||
}
|
||
else
|
||
throw ex;
|
||
}
|
||
if (proInst.ProDef.ProCode_Completed == 1)
|
||
{
|
||
//开始补齐
|
||
if (_SequenceValue.Length < 4)
|
||
_SequenceValue = _SequenceValue.PadLeft(4, '0');
|
||
if (proInst.ProDef.ProCode_ResetCycle.Value == 0)
|
||
//无区分类型,不重置状态下补齐
|
||
_SequenceValue = _SequenceValue.PadLeft("1011234".Length, '0');
|
||
}
|
||
if (proInst.ProDef.ProCode_ResetCycle.Value == 1)
|
||
_SequenceValue = _SequenceValue.PadLeft("1011234".Length, '0');
|
||
else if (proInst.ProDef.ProCode_ResetCycle.Value == 2)
|
||
_SequenceValue = _SequenceValue.PadLeft("011234".Length, '0');
|
||
else if (proInst.ProDef.ProCode_ResetCycle.Value == 3)
|
||
_SequenceValue = _SequenceValue.PadLeft("1234".Length, '0');
|
||
|
||
_Result.Add(_SequenceValue);
|
||
return string.Join("-", _Result.ToArray());// ProDateTime + "-" + ProInst_Type + "-" + _SequenceName;
|
||
}
|
||
#endregion
|
||
|
||
#region CheckOverRulePutInStorage 回退业务入库标志检查
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="SourceNowActInst"></param>
|
||
/// <param name="ToActInst_ID"></param>
|
||
/// <returns></returns>
|
||
public static bool CheckOverRulePutInStorage(NowActInst SourceNowActInst, long ToActInst_ID)
|
||
{
|
||
//非当前活动实例的其他实例 //+ " or ActInst_ID != " + ToActInst_ID + ")");
|
||
DataTable _DataTable = SourceNowActInst.ExecuteDataTable("select NowActInst_ID,ActDef_ID from T_NowActInst where ProInst_ID = " +
|
||
SourceNowActInst.ProInst_ID.Value + " and NowActInst_ID !=" + SourceNowActInst.NowActInst_ID.Value);
|
||
|
||
ActInst _ToActInst = new ActInst(SourceNowActInst);
|
||
_ToActInst.ActInst_ID = ToActInst_ID;
|
||
if (!_ToActInst.Select())
|
||
{
|
||
throw new Exception("目标环节不存在!");
|
||
}
|
||
|
||
NowActInst _OverRuleNowActInst;
|
||
foreach (DataRow _DataRow in _DataTable.Rows)
|
||
{
|
||
_OverRuleNowActInst = new NowActInst(_DataRow, SourceNowActInst);
|
||
if (!_OverRuleNowActInst.Select())
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (CheckNextActDef(SourceNowActInst.ProDef.RouteCollection, _ToActInst.ActDef_ID.Value, SourceNowActInst.ActDef_ID.Value) &&
|
||
CheckNextActDef(SourceNowActInst.ProDef.RouteCollection, _ToActInst.ActDef_ID.Value, (int)_DataRow["ActDef_ID"]))
|
||
{
|
||
if (!_OverRuleNowActInst.ActInst_ID.HasValue)
|
||
{
|
||
_OverRuleNowActInst.ActInst_ID = long.Parse(_OverRuleNowActInst.ActInst_Name);
|
||
}
|
||
if (SourceNowActInst.Data_PutInStorage == 1 && _OverRuleNowActInst.ActInst.Data_PutInStorage == 0)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region OverRule 回退业务
|
||
/// <summary>
|
||
/// 如果返回true,就是要处理入库
|
||
/// </summary>
|
||
/// <param name="SourceNowActInst"></param>
|
||
/// <param name="ToActInst_ID"></param>
|
||
/// <param name="Message"></param>
|
||
/// <returns></returns>
|
||
public static bool OverRule(NowActInst SourceNowActInst, long ToActInst_ID, ref string Message)
|
||
{
|
||
//判断目标活动的定义是否存在
|
||
ActInst _ToActInst = new ActInst(SourceNowActInst);
|
||
_ToActInst.ActInst_ID = ToActInst_ID;
|
||
if (!_ToActInst.Select())
|
||
{
|
||
throw new Exception("目标环节不存在!");
|
||
}
|
||
if (_ToActInst.ActDef == null)
|
||
{
|
||
throw new Exception("目标环节定义信息不存在!");
|
||
}
|
||
|
||
//非当前活动实例的其他实例 //+ " or ActInst_ID != " + ToActInst_ID + ")");
|
||
DataTable _DataTable = SourceNowActInst.ExecuteDataTable("select NowActInst_ID,ActDef_ID from T_NowActInst where ProInst_ID = " +
|
||
SourceNowActInst.ProInst_ID.Value + " and NowActInst_ID !=" + SourceNowActInst.NowActInst_ID.Value);
|
||
|
||
DateTime _DateTime = DateTime.Now;
|
||
//写入活动实例数据
|
||
SourceNowActInst.ActInst.CopyFrom(SourceNowActInst);
|
||
SourceNowActInst.ActInst.ActInst_FinishDate = _DateTime;
|
||
SourceNowActInst.ActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
SourceNowActInst.ActInst.ActInst_Type = ActInstType.OverRule;
|
||
SourceNowActInst.ActInst.ActInst_Desc = "回退到「" + _ToActInst.ActInst_Name + "」给「" + _ToActInst.User_Name + "」";
|
||
SourceNowActInst.ActInst.Update();
|
||
|
||
NowActInst _NowActInst = new NowActInst(SourceNowActInst);
|
||
ActInst _ActInst = new ActInst(SourceNowActInst);
|
||
_NowActInst.AddSearchParameter("ActInst_ID", ToActInst_ID);
|
||
_NowActInst.AddSearchParameter("ProInst_ID", SourceNowActInst.ProInst_ID);
|
||
if (!_NowActInst.Search())
|
||
{
|
||
//开始写入转出的数据
|
||
_ActInst.CopyFrom(_ToActInst);
|
||
//_ActInst.CopyFrom(_ToActInst.ActDef, false);
|
||
//ObjectHelper.Copy(_ToActInst, _ActInst);
|
||
_ActInst.ActInst_State = ActInstState.OverRule;
|
||
//判断是否为受理
|
||
if (_ToActInst.ActDef_Type == SuperMap.RealEstate.Enums.ActDefType.ProcessStart)
|
||
{
|
||
_ActInst.ActInst_Type = ActInstType.Accept;
|
||
}
|
||
else
|
||
{
|
||
_ActInst.ActInst_Type = ActInstType.Transaction;
|
||
}
|
||
|
||
_ActInst.ActInst_StartDate = _DateTime;
|
||
_ActInst.ActInst_EndDate = SupportHelper.GetEndDate(_DateTime, _ToActInst.ActDef.ActDef_TimeLimit.Value, _ActInst.Transaction);
|
||
_ActInst.Enabled_Statistics = SourceNowActInst.ProInst.Enabled_Statistics;
|
||
_ActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
_ActInst.ActInst_ID = null;
|
||
//_ActInst.User_ID = _ToActInst.User_ID;
|
||
//_ActInst.User_Name = _ToActInst.User_Name;
|
||
_ActInst.Insert();
|
||
|
||
//插入路由
|
||
Route _RouteInst = new Route(SourceNowActInst);
|
||
_RouteInst.Route_Name = "回退";// "回退到" + _ActInst.ActInst_Name;
|
||
_RouteInst.ActInst_ID = SourceNowActInst.ActInst.ActInst_ID;
|
||
_RouteInst.NextActInst_ID = _ActInst.ActInst_ID;
|
||
_RouteInst.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_RouteInst.Insert();
|
||
|
||
//插入当前实例
|
||
_NowActInst.ResetProperty();
|
||
//_NowActInst.CopyFrom(SourceNowActInst.ProInst);
|
||
//_NowActInst.CopyFrom(_ActInst, false);
|
||
_NowActInst.CopyFrom(SourceNowActInst.ProInst);
|
||
_NowActInst.CopyFrom(_ActInst);
|
||
_NowActInst.Role_ID = _ToActInst.ActDef.ActEntDef.Role_ID;
|
||
_NowActInst.FromActInst_ID = SourceNowActInst.ActInst_ID.Value;
|
||
_NowActInst.FromUser_ID = SourceNowActInst.User_ID;
|
||
_NowActInst.FromUser_Name = SourceNowActInst.User_Name;
|
||
//_NowActInst.NowActInst_Desc = SourceNowActInst.User_Name + "从「" + SourceNowActInst.ActInst.ActInst_Name + "」回退给您「" + _DateTime.ToString("MM-dd HH:mm") + "」;\r\n";
|
||
_NowActInst.NowActInst_Desc = "「" + _DateTime.ToString("MM-dd HH:mm") + "」由「" +
|
||
SourceNowActInst.User_Name + "」从「" + SourceNowActInst.ActInst.ActInst_Name + "」回退;\r\n";
|
||
_NowActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
_NowActInst.NowActInst_ID = null;
|
||
_NowActInst.Insert();
|
||
}
|
||
else
|
||
{
|
||
_ActInst.Select(ToActInst_ID);
|
||
_ActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
_ActInst.Update();
|
||
//插入路由
|
||
Route _RouteInst = new Route(SourceNowActInst);
|
||
_RouteInst.Route_Name = "回退";// "回退到" + _ActInst.ActInst_Name;
|
||
_RouteInst.ActInst_ID = SourceNowActInst.ActInst.ActInst_ID;
|
||
_RouteInst.NextActInst_ID = _ActInst.ActInst_ID;
|
||
_RouteInst.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_RouteInst.Insert();
|
||
//更新当前实例
|
||
//_NowActInst.NowActInst_Desc += SourceNowActInst.User_Name + "从「" + SourceNowActInst.ActInst.ActInst_Name +
|
||
// "」回退给您「" + _DateTime.ToString("MM-dd HH:mm") + "」;\r\n";
|
||
_NowActInst.NowActInst_Desc += "「" + _DateTime.ToString("MM-dd HH:mm") + "」由「" +
|
||
SourceNowActInst.User_Name + "」从「" + SourceNowActInst.ActInst.ActInst_Name + "」回退;\r\n";
|
||
_NowActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
_NowActInst.Update();
|
||
for (int i = _DataTable.Rows.Count - 1; i >= 0; i--)
|
||
{
|
||
if ((int)_DataTable.Rows[i]["NowActInst_ID"] == _NowActInst.NowActInst_ID.Value)
|
||
{
|
||
_DataTable.Rows.RemoveAt(i);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (_DataTable.Rows.Count == 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
bool _result = false;
|
||
//List<string> ListActDefID = new List<string>();
|
||
//ListActDefID.Add(_DataTable.Rows.Count.ToString());
|
||
|
||
//处理并发的其他支线的业务回退
|
||
NowActInst _OverRuleNowActInst;
|
||
foreach (DataRow _DataRow in _DataTable.Rows)
|
||
{
|
||
_OverRuleNowActInst = new NowActInst(_DataRow, SourceNowActInst);
|
||
if (!_OverRuleNowActInst.Select())
|
||
continue;
|
||
|
||
if (CheckNextActDef(_NowActInst.ProDef.RouteCollection, _ToActInst.ActDef_ID.Value, SourceNowActInst.ActDef_ID.Value) &&
|
||
CheckNextActDef(_NowActInst.ProDef.RouteCollection, _ToActInst.ActDef_ID.Value, (int)_DataRow["ActDef_ID"]))
|
||
{
|
||
if (!_OverRuleNowActInst.ActInst_ID.HasValue)
|
||
{
|
||
_OverRuleNowActInst.ActInst_ID = long.Parse(_OverRuleNowActInst.ActInst_Name);
|
||
_OverRuleNowActInst.ActInst.ActInst_Desc += _DateTime.ToString("MM月dd日HH点mm分") +
|
||
" 由「" + SourceNowActInst.User_Name + "」在「" + SourceNowActInst.ActInst.ActInst_Name +
|
||
"」强制回退到「" + _ActInst.ActInst_Name + "」给「" + _ActInst.User_Name + "」";
|
||
//ListActDefID.Add("ActInst_ID:"+_OverRuleNowActInst.ActInst_ID.ToString());
|
||
}
|
||
else
|
||
{
|
||
_OverRuleNowActInst.ActInst.CopyFrom(_OverRuleNowActInst);
|
||
_OverRuleNowActInst.ActInst.ActInst_Desc = _DateTime.ToString("MM月dd日HH点mm分") +
|
||
" 由「" + SourceNowActInst.User_Name + "」在「" + SourceNowActInst.ActInst.ActInst_Name +
|
||
"」强制回退到「" + _ActInst.ActInst_Name + "」给「" + _ActInst.User_Name + "」";
|
||
}
|
||
Message += "\r\n强制回退「" + _OverRuleNowActInst.ActInst.ActInst_Name + "」到「" + _ActInst.ActInst_Name + "」;";
|
||
_OverRuleNowActInst.ActInst.ActInst_Type = ActInstType.OverRule;
|
||
_OverRuleNowActInst.ActInst.Update();
|
||
////插入路由
|
||
Route _RouteInst = new Route(SourceNowActInst);
|
||
_RouteInst.Route_Name = "强制回退";// "回退到" + _ActInst.ActInst_Name;
|
||
_RouteInst.ActInst_ID = _OverRuleNowActInst.ActInst_ID;
|
||
_RouteInst.NextActInst_ID = _ActInst.ActInst_ID;
|
||
_RouteInst.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_RouteInst.Insert();
|
||
//ListActDefID.Add(_OverRuleNowActInst.ActInst.ActInst_Name);
|
||
_OverRuleNowActInst.Delete();
|
||
_result = true;
|
||
}
|
||
}
|
||
return _result;
|
||
//throw new Exception(string.Join(",", ListActDefID.ToArray()));
|
||
}
|
||
|
||
private static bool CheckNextActDef(List<Support.Route> RouteCollection, int FromActDef_ID, int ToActDef_ID)
|
||
{
|
||
foreach (Support.Route _Route in RouteCollection)
|
||
{
|
||
if (_Route.ActDef_ID != FromActDef_ID)
|
||
continue;
|
||
if (_Route.NextActDef_ID == ToActDef_ID)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
if (CheckNextActDef(RouteCollection, _Route.NextActDef_ID.Value, ToActDef_ID))//, ref CurrActDef))
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
#endregion
|
||
|
||
#region TurnOver 移交业务
|
||
/// <summary>
|
||
/// 移交业务
|
||
/// </summary>
|
||
/// <param name="SourceNowActInst"></param>
|
||
/// <param name="User_ID"></param>
|
||
/// <param name="User_Name"></param>
|
||
/// <returns></returns>
|
||
public static NowActInst TurnOver(NowActInst SourceNowActInst, string User_ID, string User_Name)
|
||
{
|
||
//创建一个新的活动实例
|
||
ActInst _ActInst = new ActInst(SourceNowActInst);
|
||
DateTime _DateTime = DateTime.Now;
|
||
_ActInst.CopyFrom(SourceNowActInst.ActInst);
|
||
_ActInst.ActInst_ID = null;
|
||
_ActInst.ActInst_State = ActInstState.TurnOver;
|
||
_ActInst.ActInst_StartDate = _DateTime;
|
||
_ActInst.ActInst_WorkDate = _DateTime;
|
||
//是否需要重置理论办结时间
|
||
_ActInst.ActInst_EndDate = SupportHelper.GetEndDate(_DateTime, SourceNowActInst.ActDef.ActDef_TimeLimit.Value, _ActInst.Transaction);
|
||
_ActInst.User_ID = int.Parse(User_ID);
|
||
_ActInst.User_Name = User_Name;
|
||
_ActInst.ActInst_State = ActInstState.TurnOver;
|
||
_ActInst.ActInst_Desc = "";
|
||
_ActInst.Insert();
|
||
|
||
//创建一个新的当前活动实例
|
||
NowActInst _NowActInst = new NowActInst(SourceNowActInst);
|
||
_NowActInst.CopyFrom(SourceNowActInst.ProInst);
|
||
_NowActInst.CopyFrom(_ActInst);
|
||
_NowActInst.User_ID = int.Parse(User_ID);
|
||
_NowActInst.User_Name = User_Name;
|
||
//ObjectHelper.Copy(SourceNowActInst.ProDef, _NowActInst);
|
||
_NowActInst.Role_ID = SourceNowActInst.Role_ID;
|
||
_NowActInst.NowActInst_ID = null;
|
||
_NowActInst.NowActInst_Desc = SourceNowActInst.User_Name + "移交给您「" + _DateTime.ToString("MM-dd HH:mm") + "」。";
|
||
_NowActInst.Insert();
|
||
|
||
//写入办结的活动实例内容
|
||
SourceNowActInst.ActInst.ActInst_FinishDate = _DateTime;
|
||
SourceNowActInst.ActInst.ActInst_Type = ActInstType.TurnOver;
|
||
SourceNowActInst.ActInst.ActInst_Desc = "移交给「" + User_Name + "」";
|
||
SourceNowActInst.ActInst.Update();
|
||
|
||
//写入路由
|
||
Route _Route = new Route(SourceNowActInst);
|
||
_Route.ActInst_ID = SourceNowActInst.ActInst_ID;
|
||
_Route.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_Route.NextActInst_ID = _ActInst.ActInst_ID;
|
||
_Route.Route_Name = "移交";
|
||
_Route.Route_Value = "移交";// "移交到" + _ActInst.ActInst_Name;
|
||
//_Route.Route_Value
|
||
_Route.Insert();
|
||
////删除当前活动实例
|
||
//SourceNowActInst.Delete();
|
||
return _NowActInst;
|
||
}
|
||
#endregion
|
||
|
||
#region Transfer 转出业务
|
||
/// <summary />
|
||
public static void Transfer(NowActInst SourceNowActInst, string NextActDef_ID_Encrypt,
|
||
string User_ID, string User_Name, ActDefType SourceActDefType)
|
||
{
|
||
if (SourceNowActInst.ActDef.RouteCollection.Count != 1)
|
||
throw new Exception("转出路由数量不正确,应该为一个路由条件。");
|
||
Support.ActDef _ActDef = new Support.ActDef(SourceNowActInst);
|
||
_ActDef.ActDef_ID_Encrypt = NextActDef_ID_Encrypt;
|
||
if (!_ActDef.Select())
|
||
{
|
||
throw new Exception("无法获取定义的活动信息。");
|
||
}
|
||
NowActInst _NowActInst;
|
||
ActInst _ActInst;
|
||
Route _RouteInst;
|
||
//int _User_ID = -1;
|
||
//if (!string.IsNullOrEmpty(User_ID))
|
||
// _User_ID = User_ID.ToDecryptInt32();// int.Parse(StringHelper.Decrypt(User_ID));
|
||
|
||
ActDefType _ActDefType = (ActDefType)Enum.Parse(typeof(ActDefType), _ActDef.ActDef_Type.Value.ToString());
|
||
DateTime _DateTime = DateTime.Now;
|
||
switch (_ActDefType)
|
||
{
|
||
case ActDefType.ActivityMerge:
|
||
//写入活动实例数据
|
||
SourceNowActInst.ActInst.CopyFrom(SourceNowActInst);
|
||
SourceNowActInst.ActInst.ActInst_FinishDate = _DateTime;
|
||
SourceNowActInst.ActInst.ActInst_Type = ActInstType.Transfer;
|
||
//入库数据状态
|
||
SourceNowActInst.ActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
SourceNowActInst.ActInst.Update();
|
||
//插入等待汇合的当前实例
|
||
_NowActInst = new NowActInst(SourceNowActInst);
|
||
_NowActInst.CopyFrom(SourceNowActInst.ProInst);
|
||
_NowActInst.CopyFrom(_ActDef);
|
||
_NowActInst.CopyFrom(SourceNowActInst.ProDef);
|
||
//_NowActInst.Role_ID = _ActDef.ActEntDef.Role_ID;
|
||
//_NowActInst.ActInst_ID = SourceNowActInst.ActInst_ID;
|
||
_NowActInst.NowActInst_ID = null;
|
||
_NowActInst.FromActInst_ID = SourceNowActInst.ActInst_ID.Value;//.ToString();
|
||
_NowActInst.FromUser_ID = SourceNowActInst.User_ID;
|
||
_NowActInst.FromUser_Name = SourceNowActInst.User_Name;
|
||
_NowActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
//临时存储下ActInst_ID
|
||
_NowActInst.ActInst_Name = SourceNowActInst.ActInst_ID.Value.ToString();
|
||
_NowActInst.Insert();
|
||
break;
|
||
case ActDefType.Activity:
|
||
//写入活动实例数据
|
||
SourceNowActInst.ActInst.CopyFrom(SourceNowActInst);
|
||
SourceNowActInst.ActInst.ActInst_FinishDate = _DateTime;
|
||
SourceNowActInst.ActInst.ActInst_Type = ActInstType.Transfer;
|
||
SourceNowActInst.ActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
SourceNowActInst.ActInst.Update();
|
||
//开始写入转出的数据
|
||
_ActInst = new ActInst(SourceNowActInst);
|
||
string userIdArr = User_ID.ToDecrypt();
|
||
if (!string.IsNullOrEmpty(userIdArr))
|
||
{
|
||
for (int i = 0; i < userIdArr.Split(",").Length; i++)
|
||
{
|
||
_ActInst.ResetProperty();
|
||
_ActInst.CopyFrom(_ActDef);
|
||
_ActInst.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_ActInst.ActInst_Name = _ActDef.ActDef_Name;
|
||
_ActInst.ActInst_PositionX = _ActDef.ActDef_PositionX;
|
||
_ActInst.ActInst_PositionY = _ActDef.ActDef_PositionY;
|
||
_ActInst.ActInst_StartDate = DateTime.Now;
|
||
_ActInst.ActInst_State = ActInstState.Normal;
|
||
_ActInst.ActInst_Type = ActInstType.Transaction;
|
||
_ActInst.ActInst_StartDate = _DateTime;
|
||
_ActInst.ActInst_EndDate = SupportHelper.GetEndDate(_DateTime, _ActDef.ActDef_TimeLimit.Value, _ActInst.Transaction);
|
||
_ActInst.Enabled_Statistics = SourceNowActInst.ProInst.Enabled_Statistics;
|
||
_ActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
_ActInst.ActInst_ID = null;
|
||
//if (_User_ID > -1)
|
||
//{
|
||
// _ActInst.User_ID = _User_ID;
|
||
// _ActInst.User_Name = User_Name;
|
||
//}
|
||
_ActInst.User_ID = Convert.ToInt32(userIdArr.Split(",")[i]);
|
||
_ActInst.User_Name = User_Name.Split(",")[i];
|
||
_ActInst.Insert();
|
||
}
|
||
}
|
||
|
||
//插入路由
|
||
_RouteInst = new Route(SourceNowActInst);
|
||
//_RouteInst.Route_Name = "转出到" + _ActInst.ActInst_Name;
|
||
_RouteInst.ActInst_ID = SourceNowActInst.ActInst_ID;
|
||
_RouteInst.NextActInst_ID = _ActInst.ActInst_ID;
|
||
_RouteInst.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_RouteInst.Insert();
|
||
|
||
//插入等待中的汇合路由
|
||
if (SourceActDefType == ActDefType.ActivityMerge)
|
||
{
|
||
List<NowActInst> _NowActInstMergeCollection = SourceNowActInst.FillCollection(
|
||
"where ActDef_ID = " + SourceNowActInst.ActDef.RouteCollection[0].NextActDef_ID.Value +
|
||
" and ProInst_ID=" + SourceNowActInst.ProInst_ID.Value.ToString());
|
||
NowActInst _NowActInstMerge = null;
|
||
Route _RouteMerge = null;
|
||
for (int i = _NowActInstMergeCollection.Count - 1; i >= 0; i--)
|
||
{
|
||
_NowActInstMerge = _NowActInstMergeCollection[i];
|
||
_RouteMerge = new Route(SourceNowActInst);
|
||
_RouteMerge.ActInst_ID = long.Parse(_NowActInstMerge.ActInst_Name);
|
||
//_RouteMerge.Route_Name = "转出到" + _ActInst.ActInst_Name;
|
||
_RouteMerge.NextActInst_ID = _ActInst.ActInst_ID;
|
||
_RouteMerge.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_RouteMerge.Insert();
|
||
_NowActInstMerge.Delete();
|
||
}
|
||
}
|
||
|
||
//插入当前实例
|
||
_NowActInst = new NowActInst(SourceNowActInst);
|
||
_NowActInst.CopyFrom(SourceNowActInst.ProInst);
|
||
_NowActInst.CopyFrom(_ActInst);
|
||
_NowActInst.CopyFrom(SourceNowActInst.ProDef);
|
||
_NowActInst.Role_ID = _ActDef.ActEntDef.Role_ID;
|
||
_NowActInst.NowActInst_ID = null;
|
||
_NowActInst.FromActInst_ID = SourceNowActInst.ActInst_ID.Value;//.ToString();
|
||
_NowActInst.FromUser_ID = SourceNowActInst.User_ID;
|
||
_NowActInst.FromUser_Name = SourceNowActInst.User_Name;
|
||
_NowActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
_NowActInst.Insert();
|
||
break;
|
||
case ActDefType.ProcessEnd:
|
||
//写入活动实例
|
||
SourceNowActInst.ActInst.CopyFrom(SourceNowActInst);
|
||
SourceNowActInst.ActInst.ActInst_FinishDate = _DateTime;
|
||
SourceNowActInst.ActInst.ActInst_Type = ActInstType.Transfer;
|
||
SourceNowActInst.ActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
SourceNowActInst.ActInst.Update();
|
||
//创建办结实例
|
||
_ActInst = new ActInst(SourceNowActInst);
|
||
_ActInst.CopyFrom(_ActDef);
|
||
_ActInst.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_ActInst.ActInst_Name = _ActDef.ActDef_Name;
|
||
_ActInst.ActInst_PositionX = _ActDef.ActDef_PositionX;
|
||
_ActInst.ActInst_PositionY = _ActDef.ActDef_PositionY;
|
||
_ActInst.ActInst_State = ActInstState.Normal;
|
||
_ActInst.ActInst_Type = ActInstType.Transfer;
|
||
_ActInst.ActInst_StartDate = _DateTime;
|
||
_ActInst.ActInst_FinishDate = _DateTime;
|
||
_ActInst.ActInst_WorkDate = _DateTime;
|
||
_ActInst.ActInst_EndDate = _DateTime;
|
||
_ActInst.Enabled_Statistics = 0;
|
||
_ActInst.Data_PutInStorage = SourceNowActInst.ProInst.Data_PutInStorage;
|
||
_ActInst.ActInst_ID = null;
|
||
|
||
_ActInst.Insert();
|
||
//插入路由
|
||
_RouteInst = new Route(SourceNowActInst);
|
||
//_RouteInst.Route_Name = "转出到" + _ActInst.ActInst_Name;
|
||
_RouteInst.ActInst_ID = SourceNowActInst.ActInst_ID;
|
||
_RouteInst.NextActInst_ID = _ActInst.ActInst_ID;
|
||
_RouteInst.ProInst_ID = SourceNowActInst.ProInst_ID;
|
||
_RouteInst.Insert();
|
||
//写入流程实例
|
||
DataTable _DataTable = SourceNowActInst.ExecuteDataTable("select count(NowActInst_ID) from T_NowActInst " +
|
||
"where ProInst_ID=" + SourceNowActInst.ProInst_ID.Value + " and " +
|
||
"NowActInst_ID !=" + SourceNowActInst.NowActInst_ID.Value);
|
||
|
||
//if (((int)_DataTable.Rows[0][0]) == 0)
|
||
if (int.Parse(_DataTable.Rows[0][0].ToString()) == 0)
|
||
{
|
||
SourceNowActInst.ProInst.CopyFrom(SourceNowActInst.ActInst);
|
||
SourceNowActInst.ProInst.ProInst_FinishDate = _DateTime;
|
||
SourceNowActInst.ProInst.ProInst_State = SuperMap.RealEstate.Enums.ProInstState.Complete;
|
||
SourceNowActInst.ProInst.Update();
|
||
}
|
||
//SourceNowActInst.Delete();
|
||
//isProcessEnd = true;
|
||
break;
|
||
default:
|
||
throw new Exception("暂时只支持转到交互活动和终止路由。");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
/// <summary />
|
||
public static bool TransferBefore(NowActInst SourceNowActInst)
|
||
{
|
||
//当前活动实例之前的活动是否存在实例
|
||
DataTable _DataTable = SourceNowActInst.ExecuteDataTable("select NowActInst_ID,ActDef_ID from T_NowActInst where ProInst_ID = " +
|
||
SourceNowActInst.ProInst_ID.Value + " and NowActInst_ID != " + SourceNowActInst.NowActInst_ID.Value);
|
||
|
||
foreach (DataRow _DataRow in _DataTable.Rows)
|
||
{
|
||
if (!TransferBefore(SourceNowActInst.ProDef.RouteCollection, SourceNowActInst.ActDef_ID.Value, (int)_DataRow["ActDef_ID"]))
|
||
{
|
||
NowActInst _NowActInst = new NowActInst(_DataRow, SourceNowActInst);
|
||
if (!_NowActInst.Select())
|
||
{
|
||
throw new Exception("无法获取当前流程实例,编号为:" + _DataRow["NowActInst_ID"].ToString());
|
||
}
|
||
throw new Exception("业务曾回退,请等待「" + SourceNowActInst.User_Name + "」从「" + _NowActInst.ActInst_Name + "」转出。");
|
||
//return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
private static bool TransferBefore(List<Support.Route> RouteCollection, int CurrActDef_ID, int TargetActDef_ID)
|
||
{
|
||
foreach (Support.Route _Route in RouteCollection)
|
||
{
|
||
if (_Route.NextActDef_ID != CurrActDef_ID)
|
||
continue;
|
||
if (_Route.ActDef_ID == TargetActDef_ID)
|
||
{
|
||
return false;
|
||
}
|
||
if (!TransferBefore(RouteCollection, _Route.ActDef_ID.Value, TargetActDef_ID))
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
///// <summary>
|
||
/////
|
||
///// </summary>
|
||
///// <param name="ProInst"></param>
|
||
///// <param name="currActDef"></param>
|
||
///// <param name="ListActDef"></param>
|
||
///// <returns></returns>
|
||
static ActDefType GetSupportNextActDef(ProInst ProInst, Support.ActDef currActDef, out List<Support.ActDef> ListActDef)
|
||
{
|
||
ListActDef = new List<Support.ActDef>();
|
||
ActDefType _ActDefType = ActDefType.None;
|
||
|
||
if (currActDef.RouteCollection.Count > 1)
|
||
{
|
||
throw new Exception("过多转出路由定义,请检查流程定义。");
|
||
}
|
||
else if (currActDef.RouteCollection.Count == 0)
|
||
{
|
||
throw new Exception("未定义转出路由,请检查流程定义。");
|
||
}
|
||
|
||
foreach (Support.Route _RouteDef in currActDef.RouteCollection)
|
||
{
|
||
_ActDefType = _RouteDef.NextActDef.ActDef_Type.Value;//.ToString());
|
||
DateTime _DateTime = DateTime.Now;
|
||
switch (_ActDefType)
|
||
{
|
||
case ActDefType.ActivityMerge:
|
||
case ActDefType.ConditionOr:
|
||
case ActDefType.ConditionAnd:
|
||
//获取选择路由
|
||
ActDefType _ConditionOrActDefType = ActDefType.None;
|
||
List<Support.Route> _RouteCollection = _RouteDef.NextActDef.RouteCollection;
|
||
if (_ActDefType != ActDefType.ActivityMerge)
|
||
{
|
||
IWorkFlowResetRouteDataAction _IWorkFlowResetRouteDataAction = ResetRouteDataAction(_RouteDef.NextActDef);
|
||
if (_IWorkFlowResetRouteDataAction != null)
|
||
{
|
||
_RouteCollection = _IWorkFlowResetRouteDataAction.ResetRouteCollection(ProInst, _RouteCollection);
|
||
}
|
||
}
|
||
|
||
foreach (Support.Route _ConditionRoute in _RouteCollection)
|
||
{
|
||
_ConditionOrActDefType = _ConditionRoute.NextActDef.ActDef_Type.Value;
|
||
switch (_ConditionOrActDefType)
|
||
{
|
||
case ActDefType.Activity:
|
||
case ActDefType.ProcessEnd:
|
||
ListActDef.Add(_ConditionRoute.NextActDef);
|
||
break;
|
||
default:
|
||
throw new Exception("路由模式,暂时只支持交互活动,请修改流程定义的路由指向。");
|
||
}
|
||
}
|
||
|
||
return _ActDefType;
|
||
//break;
|
||
case ActDefType.Activity:
|
||
case ActDefType.ProcessEnd:
|
||
//写入活动实例
|
||
ListActDef.Add(_RouteDef.NextActDef);
|
||
break;
|
||
default:
|
||
throw new Exception("暂不支持 " + _ActDefType.ToString() + "模式!");
|
||
}
|
||
}
|
||
return _ActDefType;
|
||
}
|
||
|
||
|
||
/// <summary />
|
||
public static ActDefType GetNextActDef(NowActInst SourceNowActInst, out List<Support.ActDef> ListActDef, out string ErrorString)
|
||
{
|
||
ErrorString = string.Empty;
|
||
ActDefType _ActDefType = GetSupportNextActDef(SourceNowActInst.ProInst, SourceNowActInst.ActDef, out ListActDef);
|
||
switch (_ActDefType)
|
||
{
|
||
case ActDefType.ActivityMerge:
|
||
Support.ActDef _NextActDef = SourceNowActInst.ActDef.RouteCollection[0].NextActDef;
|
||
List<int> _ActivityMerge = new List<int>();
|
||
//找到合并前的所有ActDef_ID
|
||
FindBeforeMergeActDefID(SourceNowActInst, _NextActDef.ActDef_ID.Value, _ActivityMerge);
|
||
//排除自己
|
||
_ActivityMerge.Remove(SourceNowActInst.ActDef_ID.Value);
|
||
//查看是否有实例
|
||
if (SourceNowActInst.GetCount("where ActDef_ID in (" + string.Join(",", _ActivityMerge.ToArray()) + ")" +
|
||
" and ProInst_ID=" + SourceNowActInst.ProInst_ID.Value) > 0)
|
||
{
|
||
//如果有实例,先到汇合活动状态等待。
|
||
ListActDef.Clear();
|
||
_NextActDef.ActDef_Name += "[等待其他环节办结]";
|
||
ListActDef.Add(_NextActDef);
|
||
}
|
||
break;
|
||
}
|
||
return _ActDefType;
|
||
}
|
||
private static void FindBeforeMergeActDefID(NowActInst SourceNowActInst, int ActivityMerge_ID, List<int> _ActivityMerge)
|
||
{
|
||
foreach (Support.Route _Route in SourceNowActInst.ProDef.RouteCollection)
|
||
{
|
||
if (_Route.NextActDef_ID == ActivityMerge_ID)
|
||
{
|
||
if ((_Route.ActDef.ActDef_Type.Value == ActDefType.Activity) ||
|
||
(_Route.ActDef.ActDef_Type.Value == ActDefType.ProcessStart))
|
||
{
|
||
if (!_ActivityMerge.Contains(_Route.ActDef_ID.Value))
|
||
_ActivityMerge.Add(_Route.ActDef_ID.Value);
|
||
}
|
||
FindBeforeMergeActDefID(SourceNowActInst, _Route.ActDef_ID.Value, _ActivityMerge);
|
||
}
|
||
}
|
||
}
|
||
|
||
#region ResetRouteDataAction 获取路由的扩展对象
|
||
/// <summary />
|
||
public static IWorkFlowResetRouteDataAction ResetRouteDataAction(Support.ActDef CurrActDef)
|
||
{
|
||
if (string.IsNullOrEmpty(CurrActDef.ActDef_FileName))
|
||
return null;
|
||
if (string.IsNullOrEmpty(CurrActDef.ActDef_ClassName))
|
||
return null;
|
||
string _ClassName = CurrActDef.ActDef_ClassName;
|
||
string _FileName = CurrActDef.ActDef_FileName;
|
||
if (_FileName.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
|
||
_FileName = _FileName.Substring(0, _FileName.Length - 4);
|
||
List<string> _InstClassCollection = new List<string>();
|
||
if (_ClassName.StartsWith("RealEstate."))
|
||
{
|
||
_InstClassCollection.Add("SuperMap." + _ClassName);
|
||
}
|
||
else if (!_ClassName.StartsWith("SuperMap.RealEstate."))
|
||
{
|
||
if (_ClassName.StartsWith(_FileName))
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _ClassName);
|
||
else
|
||
{
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _FileName + "." + _ClassName);
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _ClassName);
|
||
}
|
||
}
|
||
|
||
object _Obj = null;
|
||
Exception _Exception = null;
|
||
foreach (string _InstClass in _InstClassCollection)
|
||
{
|
||
try
|
||
{
|
||
_Obj = PluginManager.CreateInstance(_FileName, _InstClass);
|
||
break;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_Exception = ex;
|
||
}
|
||
}
|
||
if (_Obj is SuperMap.RealEstate.WorkFlow.Instance.IWorkFlowResetRouteDataAction)
|
||
{
|
||
return _Obj as SuperMap.RealEstate.WorkFlow.Instance.IWorkFlowResetRouteDataAction;
|
||
}
|
||
else
|
||
throw new Exception("路由的扩展对象,必须基于IWorkFlowResetRouteDataAction接口。", _Exception);
|
||
}
|
||
#endregion
|
||
|
||
#region GetActInstDataAction 获取活动的接口
|
||
/// <summary />
|
||
public static IWorkFlowActInstDataAction GetActInstDataAction(NowActInst _NowActInst)
|
||
{
|
||
if (string.IsNullOrEmpty(_NowActInst.ActDef.ActDef_FileName))
|
||
return null;
|
||
if (string.IsNullOrEmpty(_NowActInst.ActDef.ActDef_ClassName))
|
||
return null;
|
||
string _ClassName = _NowActInst.ActDef.ActDef_ClassName;
|
||
string _FileName = _NowActInst.ActDef.ActDef_FileName;
|
||
if (_FileName.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
|
||
_FileName = _FileName.Substring(0, _FileName.Length - 4);
|
||
List<string> _InstClassCollection = new List<string>();
|
||
if (_ClassName.StartsWith("RealEstate."))
|
||
{
|
||
_InstClassCollection.Add("SuperMap." + _ClassName);
|
||
}
|
||
else if (!_ClassName.StartsWith("SuperMap.RealEstate."))
|
||
{
|
||
if (_ClassName.StartsWith(_FileName))
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _ClassName);
|
||
else
|
||
{
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _FileName + "." + _ClassName);
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _ClassName);
|
||
}
|
||
}
|
||
|
||
object _Obj = null;
|
||
Exception _Exception = null;
|
||
foreach (string _InstClass in _InstClassCollection)
|
||
{
|
||
try
|
||
{
|
||
_Obj = PluginManager.CreateInstance(_FileName, _InstClass);
|
||
break;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_Exception = ex;
|
||
}
|
||
}
|
||
if (_Obj is Instance.IWorkFlowActInstDataAction)
|
||
{
|
||
return _Obj as Instance.IWorkFlowActInstDataAction;
|
||
}
|
||
else
|
||
throw new Exception("活动的扩展对象,必须基于IWorkFlowActInstDataAction接口。", _Exception);
|
||
}
|
||
#endregion
|
||
|
||
#region GetProInstDataAction 获取流程的接口
|
||
/// <summary />
|
||
public static IWorkFlowProInstDataAction GetProInstDataAction(NowActInst _NowActInst)
|
||
{
|
||
if (string.IsNullOrEmpty(_NowActInst.ProDef.ProDef_FileName))
|
||
throw new Exception("执行操作失败,流程配置中未定义扩展文件!");
|
||
if (string.IsNullOrEmpty(_NowActInst.ProDef.ProDef_ClassName))
|
||
throw new Exception("执行操作失败,流程配置中未定义扩展对象!");
|
||
string _ClassName = _NowActInst.ProDef.ProDef_ClassName;
|
||
string _FileName = _NowActInst.ProDef.ProDef_FileName;
|
||
if (_FileName.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
|
||
_FileName = _FileName.Substring(0, _FileName.Length - 4);
|
||
//SuperMap.RealEstate.RealEstate.WorkFlow.WebSite.WorkFlow.Transact.DemoDataAction
|
||
List<string> _InstClassCollection = new List<string>();
|
||
if (_ClassName.StartsWith("RealEstate."))
|
||
{
|
||
_InstClassCollection.Add("SuperMap." + _ClassName);
|
||
}
|
||
else if (!_ClassName.StartsWith("SuperMap.RealEstate"))
|
||
{
|
||
if (_ClassName.StartsWith(_FileName))
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _ClassName);
|
||
else
|
||
{
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _FileName + "." + _ClassName);
|
||
_InstClassCollection.Add("SuperMap.RealEstate." + _ClassName);
|
||
}
|
||
}
|
||
|
||
object _Obj = null;
|
||
Exception _Exception = null;
|
||
foreach (string _InstClass in _InstClassCollection)
|
||
{
|
||
try
|
||
{
|
||
_Obj = PluginManager.CreateInstance(_FileName, _InstClass);
|
||
break;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_Exception = ex;
|
||
}
|
||
}
|
||
if (_Obj is Instance.IWorkFlowProInstDataAction)
|
||
return _Obj as Instance.IWorkFlowProInstDataAction;
|
||
else
|
||
throw new Exception("流程的扩展对象,必须基于IWorkFlowProInstDataAction接口。", _Exception);
|
||
}
|
||
#endregion
|
||
}
|
||
} |