/// <summary>
        /// 启动与工作流程相同类型流程,查询对应节点用户
        /// </summary>
        /// <param name="CompanyID">公司ID</param>
        /// <param name="ModelCode">模块代码</param>
        /// <param name="FlowGUID">待审批流GUID,新增时为空或者为StartFlow</param>
        /// <returns></returns>
        public DataResult GetAppUser( string CompanyID, string ModelCode, string FlowGUID, string xml)
        {
            Tracer.Debug("GetAppUser 启动与工作流程相同类型流程,查询对应节点用户 ModelCode=" + ModelCode + " FlowGUID=" + FlowGUID + " CompanyID=" + CompanyID);
            FlowUser user = SUser;
            DataResult GetAppUserResult = new DataResult();
            try
            {
                string StateName = null;

                if (FlowGUID == "" || FlowGUID == "StartFlow")
                {
                    StateName = "StartFlow";
                }
                else
                {
                    //根据待审批流程GUID,检索待审批状态节点代码
                    List<SMT.Workflow.Common.Model.FLOW_FLOWRECORDDETAIL_T> FlowRecord = FlowBLL.GetFlowInfo( "", FlowGUID, "", "", "", "", "", null);
                    if (FlowRecord == null)
                    {
                        GetAppUserResult.Err = "没有待处理的审核";
                        GetAppUserResult.UserInfo = null;
                        return GetAppUserResult;
                    }
                    StateName = FlowRecord[0].STATECODE;
                }

                //根据公司ID,模块代码获取配置的流程
                WorkflowInstance instance = null;
                Tracer.Debug("根据公司ID,模块代码获取配置的流程FlowBLL.GetFlowByModelName:OgrType='0'");

                List<SMT.Workflow.Common.Model.FLOW_MODELFLOWRELATION_T> MODELFLOWRELATION = FlowBLL.GetFlowByModelName( CompanyID, "", ModelCode, "0", ref user);

                if (MODELFLOWRELATION == null || MODELFLOWRELATION.Count == 0)
                {
                    GetAppUserResult.Err = "没有可使用的流程";
                    GetAppUserResult.UserInfo = null;
                    return GetAppUserResult;
                }
                SMT.Workflow.Common.Model.FLOW_FLOWDEFINE_T Xoml = MODELFLOWRELATION[0].FLOW_FLOWDEFINE_T;

                XmlReader readerxoml, readerule;
                StringReader strXoml = new StringReader(Xoml.LAYOUT);
                StringReader strRules = new StringReader(Xoml.RULES == null ? "" : Xoml.RULES);

                readerxoml = XmlReader.Create(strXoml);
                readerule = XmlReader.Create(strRules);

                WorkflowRuntime workflowRuntime = new WorkflowRuntime();
                workflowRuntime.StartRuntime();

                FlowEvent ExternalEvent = new FlowEvent();
                //ExternalDataExchangeService objService = new ExternalDataExchangeService();
                //workflowRuntime.AddService(objService);
                //objService.AddService(ExternalEvent);
                //TypeProvider typeProvider = new TypeProvider(null);
                //workflowRuntime.AddService(typeProvider);

                ////XmlReader readerxoml = XmlReader.Create(HttpContext.Current.Server.MapPath ("TestFlow.xml"));
                //// instance = workflowRuntime.CreateWorkflow(readerxoml);
                //if (Xoml.RULES == null)
                //    instance = workflowRuntime.CreateWorkflow(readerxoml);
                //else
                //    instance = workflowRuntime.CreateWorkflow(readerxoml, readerule, null);
                //// instance = workflowRuntime.CreateWorkflow(typeof(TestFlow));
                //instance.Start();
                //StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId);

                ////从实例中获取定义
                //if (1 == 2)
                //{
                //    System.Workflow.Activities.StateMachineWorkflowActivity smworkflow = new StateMachineWorkflowActivity();
                //    smworkflow = workflowinstance.StateMachineWorkflow;
                //    RuleDefinitions ruleDefinitions = smworkflow.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;
                //    WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer();

                //    StringBuilder xoml = new StringBuilder();
                //    StringBuilder rule = new StringBuilder();
                //    XmlWriter xmlWriter = XmlWriter.Create(xoml);
                //    XmlWriter ruleWriter = XmlWriter.Create(rule);
                //    markupSerializer.Serialize(xmlWriter, smworkflow);
                //    markupSerializer.Serialize(ruleWriter, ruleDefinitions);
                //    xmlWriter.Close();
                //    ruleWriter.Close();
                //    StringReader readxoml = new StringReader(xoml.ToString());
                //    StringReader readrule = new StringReader(rule.ToString());
                //    XmlReader readerxoml2 = XmlReader.Create(readxoml);
                //    XmlReader readerrule2 = XmlReader.Create(readrule);
                //    WorkflowInstance instance1 = workflowRuntime.CreateWorkflow(readerxoml2, readerrule2, null);
                //    instance1.Start();
                //    StateMachineWorkflowInstance workflowinstance1 = new StateMachineWorkflowInstance(workflowRuntime, instance1.InstanceId);
                //    workflowinstance1.SetState(StateName);
                //}
                //从实例中获取定义并启动新实例

                //跳转到节点StateName
                //workflowinstance.SetState(StateName);

                FlowDataType.FlowData FlowData = new FlowDataType.FlowData();
                FlowData.xml = xml;
                //  FlowData.Flow_FlowRecord_T = null;

                //ExternalEvent.OnDoFlow(instance.InstanceId, FlowData);//激发流程引擎流转到下一状态
                System.Threading.Thread.Sleep(1000);
                //PermissionServiceClient WcfPermissionService = new PermissionServiceClient();
                string CurrentStateName = ""; //workflowinstance.CurrentStateName == null ? "End" : //workflowinstance.CurrentStateName; //取得当前状态
                List<UserInfo> listUser = new List<UserInfo>();
                if (CurrentStateName != "End")
                {
                    if (CurrentStateName.Substring(0, 5) == "State")
                    {
                        CurrentStateName = CurrentStateName.Substring(5);
                    }
                    string roleID = new Guid(CurrentStateName).ToString("D");
                    List<T_SYS_USER> User = new List<T_SYS_USER>(); //WcfPermissionService.GetSysUserByRole(WFCurrentStateName); //检索本状态(角色)对应用户
                    using (SysUserRoleBLL bll = new SysUserRoleBLL())
                    {
                        IQueryable<T_SYS_USER> IQList = bll.GetSysUserByRole(roleID);
                        User = IQList == null ? null : IQList.ToList();
                    }
                    if (User != null)
                        for (int i = 0; i < User.Count(); i++)
                        {
                            UserInfo tmp = new UserInfo();
                            tmp.UserID = User[i].EMPLOYEEID;
                            tmp.UserName = User[i].EMPLOYEENAME;
                            listUser.Add(tmp);
                        }

                }
                else
                {
                    //已经到流程结束状态
                    UserInfo tmp = new UserInfo();
                    tmp.UserID = "End";
                    tmp.UserName = "******";

                    listUser.Add(tmp);
                }

                GetAppUserResult.UserInfo = listUser.Count > 0 ? listUser : null;

                if (GetAppUserResult.UserInfo == null)
                    GetAppUserResult.Err = "没有找到用户";

                return GetAppUserResult;
                // return listUser;

                //return workflowinstance.CurrentStateName == null ? "End" : workflowinstance.CurrentStateName;
            }
            catch (Exception ex)
            {
                GetAppUserResult.Err = ex.Message;
                GetAppUserResult.UserInfo = null;
                return GetAppUserResult;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 通过持久化服务查询下一处理人(对应SubmitFlow)
        /// </summary>
        /// <param name="WfRuntimeClone">持久化运行时</param>
        /// <param name="instanceClone">持久化实例</param>
        /// <param name="xml">条件XML</param>
        /// <param name="CurrentStateName">当前状态代码</param>
        /// <param name="DataResult">操作结果</param>
        public void GetUserByInstance(string companyID, WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, string Layout, string xml, string CurrentStateName, List<string> UserID, List<string> PostID, FlowType FlowType, ref DataResult DataResult)
        {
            WorkflowRuntime WfRuntime = null;
            WorkflowInstance Instance = null;
            List<UserInfo> AppUserInfo = null;
            string strNextState = CurrentStateName;
            FlowRole RuleName;
            try
            {
                if (!WfRuntimeClone.IsStarted)
                {
                    WfRuntimeClone.StartRuntime();
                }
                WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false);
                Instance = SMTWorkFlowManage.CloneWorkflowInstance(WfRuntimeClone, instanceClone, WfRuntime);
                bool iscurruser = true;

                while (iscurruser)
                {
                    //   CurrentStateName = strNextState;
                    strNextState = SMTWorkFlowManage.GetFlowNextStepRoles(WfRuntime, Instance, strNextState, xml);
                    //if (FlowType == FlowType.Task && strNextState != "EndFlow")
                    //{
                    //    XmlReader XmlReader;

                    //    StringReader tmpLayout = new StringReader(Layout);
                    //    XmlReader = XmlReader.Create(tmpLayout);
                    //    XElement XElementS = XElement.Load(XmlReader);
                    //    var a = from c in XElementS.Descendants("Activity")
                    //            where c.Attribute("Name").Value == strNextState
                    //            select c.Attribute("RoleName").Value;
                    //    if (a.Count() > 0)
                    //    {
                    //        strNextState = a.First().ToString();
                    //    }
                    //    else
                    //    {
                    //        DataResult.Err = "没有找到对应角色";
                    //        DataResult.FlowResult = FlowResult.FAIL;
                    //        return;
                    //    }

                    //    tmpLayout = null;
                    //    XmlReader = null;
                    //    XElementS = null;
                    //    a = null;
                    //}

                    RuleName = FlowUtility.GetRlueName(Layout, strNextState);

                    if (RuleName == null)
                    {
                        DataResult.Err = "没有找到对应角色";
                        DataResult.FlowResult = FlowResult.FAIL;
                        return;
                    }

                    string tmpPostID = RuleName.UserType == "CREATEUSER" ? PostID[0] : PostID[1];
                    bool isHigher = false;
                    AppUserInfo = TmGetUserByRoleId(RuleName.RoleName, null, tmpPostID, ref isHigher);
                    #region 打印审核人
                    string names = "\r\n=======打印审核人E(RuleName.RoleName=" + RuleName.RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n";
                    foreach (var user in AppUserInfo)
                    {
                        names += "CompanyID:" + user.CompanyID + "\r\n";
                        names += "DepartmentID:" + user.DepartmentID + "\r\n";
                        names += "PostID:" + user.PostID + "\r\n";
                        names += "UserID:" + user.UserID + "\r\n";

                        names += "CompanyName:" + user.CompanyName + "\r\n";
                        names += "DepartmentName:" + user.DepartmentName + "\r\n";
                        names += "PostName:" + user.PostName + "\r\n";
                        names += "UserName:"******"\r\n";
                        names += "----------------------------------------------------\r\n";
                    }
                    if (!isHigher && RuleName.IsOtherCompany != null)
                    {
                        if (RuleName.IsOtherCompany.Value == true)
                        {
                            names += "是否指定公司:" + RuleName.IsOtherCompany.Value.ToString() + "\r\n";
                            names += "公司的ID:" + RuleName.OtherCompanyID + "\r\n";
                            if (string.IsNullOrEmpty(RuleName.OtherCompanyID))
                            {
                                names += "Layout=" + Layout + "\r\n";
                            }
                        }
                        else if (RuleName.IsOtherCompany.Value == false)
                        {
                            names += "实际要查找公司的ID:" + companyID + "\r\n";
                        }
                    }

                    Tracer.Debug(names);
                    #endregion
                    #region beyond
                    if (!isHigher && RuleName.IsOtherCompany != null)
                    {
                        if (RuleName.IsOtherCompany.Value == true)
                        {
                            AppUserInfo = AppUserInfo.Where(user => user.CompanyID == RuleName.OtherCompanyID).ToList();
                        }
                        else if (RuleName.IsOtherCompany.Value == false)
                        {
                            AppUserInfo = AppUserInfo.Where(user => user.CompanyID == companyID).ToList();
                        }
                    }

                    #endregion
                    if (AppUserInfo == null || AppUserInfo.Count == 0)
                    {
                        DataResult.Err = "没有找到审核人";
                        DataResult.FlowResult = FlowResult.FAIL;
                        return;
                    }
                    if (AppUserInfo.Where(c => c.UserID == UserID[1]).Count() == 0)
                        iscurruser = false;
                }

                if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人
                {
                    DataResult.FlowResult = FlowResult.MULTIUSER;
                }

                DataResult.AppState = strNextState;
                DataResult.UserInfo = AppUserInfo;

            }
            catch (Exception ex)
            {
                Tracer.Debug("GetUserByInstance异常信息 :" + ex.ToString());
                throw new Exception("GetUserByInstance:" + ex.Message);
            }
            finally
            {
                strNextState = null;
                AppUserInfo = null;
                RuleName = null;
                Instance = null;
                SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime);

            }
        }
Esempio n. 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="companyID"></param>
        /// <param name="WfRuntimeClone"></param>
        /// <param name="instanceClone"></param>
        /// <param name="Layout">从审核主表记录ACTIVEROLE字段获取</param>
        /// <param name="xml"></param>
        /// <param name="CurrentStateName">当前状态</param>
        /// <param name="UserID"></param>
        /// <param name="PostID"></param>
        /// <param name="FlowType"></param>
        /// <param name="DataResult"></param>
        public void GetUserByInstance2(string companyID, WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, string Layout, string xml, string CurrentStateName, List<string> UserID, List<string> PostID, FlowType FlowType, ref DataResult DataResult,ref FlowUser fUser)
        {
            WorkflowRuntime WfRuntime = null;
            WorkflowInstance Instance = null;
            List<UserInfo> AppUserInfo = null;
            string strNextState = CurrentStateName;
            bool IsCountersign = false;
            string CountersignType = "0";
            //Role_UserType RuleName;
            //List<UserInfo> AppUserInfo = null;
            Dictionary<FlowRole, List<UserInfo>> DictCounterUser = null;
            try
            {
                if (!WfRuntimeClone.IsStarted)
                {
                    WfRuntimeClone.StartRuntime();
                }
                WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false);
                Instance = SMTWorkFlowManage.CloneWorkflowInstance(WfRuntimeClone, instanceClone, WfRuntime);
                bool iscurruser = true;
                int testflag = 0;
                while (iscurruser)
                {
                    testflag++;
                    if (testflag > 10)
                    {
                        throw new Exception("循环处理流程超过10次,请联系系统管理员");
                    }
                    #region

                    strNextState = SMTWorkFlowManage.GetFlowNextStepRoles(WfRuntime, Instance, strNextState, xml);
                    List<FlowRole> listRole = FlowUtility.GetRlueIdFromActivitID(Layout, strNextState, ref IsCountersign, ref CountersignType);
                    if (listRole.Count == 0)
                    {
                        DataResult.Err = "没有找到对应角色";
                        DataResult.FlowResult = FlowResult.FAIL;
                        return;
                    }

                    if (!IsCountersign)
                    {
                        #region
                        string tmpPostID = listRole[0].UserType == "CREATEUSER" ? PostID[0] : PostID[1];
                        bool isHigher = false;
                        AppUserInfo = TmGetUserByRoleId(listRole[0].RoleName, null, tmpPostID, ref isHigher);
                        #region 打印审核人
                        string names = "\r\nFormID=" + fUser.FormID + ";=======打印审核人F(listRole[0].RoleName=" + listRole[0].RoleName + ";审核人数量=" + AppUserInfo.Count + ";isHigher=" + isHigher.ToString() + ")=======\r\n";
                        foreach (var user in AppUserInfo)
                        {
                            names += "CompanyID:" + user.CompanyID + "\r\n";
                            names += "DepartmentID:" + user.DepartmentID + "\r\n";
                            names += "PostID:" + user.PostID + "\r\n";
                            names += "UserID:" + user.UserID + "\r\n";

                            names += "CompanyName:" + user.CompanyName + "\r\n";
                            names += "DepartmentName:" + user.DepartmentName + "\r\n";
                            names += "PostName:" + user.PostName + "\r\n";
                            names += "UserName:"******"\r\n";
                            names += "----------------------------------------------------\r\n";
                        }
                        if (!isHigher && listRole[0].IsOtherCompany != null)
                        {
                            if (listRole[0].IsOtherCompany.Value == true)
                            {
                                names += "是否指定公司:" + listRole[0].IsOtherCompany.Value.ToString() + "\r\n";
                                names += "公司的ID:" + listRole[0].OtherCompanyID + "\r\n";
                                if (string.IsNullOrEmpty(listRole[0].OtherCompanyID))
                                {
                                    names += "Layout=" + Layout + "\r\n";
                                }
                            }
                            else if (listRole[0].IsOtherCompany.Value == false)
                            {
                                names += "实际要查找公司的ID:" + companyID + "\r\n";
                            }
                        }
                        fUser.ErrorMsg += names;
                        Tracer.Debug(names);
                        #endregion
                        #region beyond

                        if (!isHigher && strNextState.ToUpper() != "ENDFLOW")
                        {
                            if (listRole[0].IsOtherCompany != null && listRole[0].IsOtherCompany.Value == true)
                            {
                                AppUserInfo = AppUserInfo.Where(user => user.CompanyID == listRole[0].OtherCompanyID).ToList();
                            }
                            else
                            {
                                AppUserInfo = AppUserInfo.Where(user => user.CompanyID == companyID).ToList();
                            }

                        }

                        #endregion
                        if (AppUserInfo == null || AppUserInfo.Count == 0)
                        {
                            DataResult.Err = "当前角色 " + listRole[0].Remark + " 没有找到审核人" ;
                            DataResult.FlowResult = FlowResult.FAIL;
                            return;
                        }

                        if (AppUserInfo.Where(c => c.UserID == UserID[1]).Count() == 0)
                            iscurruser = false;
                        #endregion
                    }
                    else
                    {
                        #region
                        DictCounterUser = new Dictionary<FlowRole, List<UserInfo>>();
                        if (CountersignType == "0")
                        {
                            #region
                            for (int i = 0; i < listRole.Count; i++)
                            {
                                string tmpPostID = listRole[i].UserType == "CREATEUSER" ? PostID[0] : PostID[1];
                                bool isHigher = false;
                                var listuserinfo = TmGetUserByRoleId(listRole[i].RoleName, null, tmpPostID, ref isHigher);
                                #region 打印审核人
                                string names = "\r\n=======打印审核人G(listRole[i].RoleName=" + listRole[0].RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n";
                                foreach (var user in listuserinfo)
                                {
                                    names += "CompanyID:" + user.CompanyID + "\r\n";
                                    names += "DepartmentID:" + user.DepartmentID + "\r\n";
                                    names += "PostID:" + user.PostID + "\r\n";
                                    names += "UserID:" + user.UserID + "\r\n";

                                    names += "CompanyName:" + user.CompanyName + "\r\n";
                                    names += "DepartmentName:" + user.DepartmentName + "\r\n";
                                    names += "PostName:" + user.PostName + "\r\n";
                                    names += "UserName:"******"\r\n";
                                    names += "----------------------------------------------------\r\n";
                                }
                                if (!isHigher && listRole[0].IsOtherCompany != null)
                                {
                                    if (listRole[0].IsOtherCompany.Value == true)
                                    {
                                        names += "是否指定公司:" + listRole[0].IsOtherCompany.Value.ToString() + "\r\n";
                                        names += "公司的ID:" + listRole[0].OtherCompanyID + "\r\n";
                                        if (string.IsNullOrEmpty(listRole[0].OtherCompanyID))
                                        {
                                            names += "Layout=" + Layout + "\r\n";
                                        }
                                    }
                                    else if (listRole[0].IsOtherCompany.Value == false)
                                    {
                                        names += "实际要查找公司的ID:" + companyID + "\r\n";
                                    }
                                }
                                fUser.ErrorMsg += names;
                                Tracer.Debug(names);
                                #endregion
                                if (!isHigher)
                                {
                                    if (listRole[i].IsOtherCompany != null && listRole[i].IsOtherCompany.Value == true)
                                    {
                                        listuserinfo = listuserinfo.Where(user => user.CompanyID == listRole[i].OtherCompanyID).ToList();
                                    }
                                    else
                                    {
                                        listuserinfo = listuserinfo.Where(user => user.CompanyID == companyID).ToList();
                                    }
                                }

                                if (listuserinfo == null || listuserinfo.Count == 0)
                                {
                                    DataResult.Err = "角色 " + listRole[i].Remark + "没有找到审核人";
                                    DataResult.FlowResult = FlowResult.FAIL;
                                    return;
                                }
                                DictCounterUser.Add(listRole[i], listuserinfo);
                            }
                            iscurruser = false;
                            #endregion
                        }
                        else
                        {
                            #region
                            string roleNames = "";//所有角色名称
                            iscurruser = false;
                            bool bFlag = false;
                            for (int i = 0; i < listRole.Count; i++)
                            {
                                roleNames += listRole[i].Remark + "、";
                                string tmpPostID = listRole[i].UserType == "CREATEUSER" ? PostID[0] : PostID[1];
                                bool isHigher = false;
                                var listuserinfo = TmGetUserByRoleId(listRole[i].RoleName, null, tmpPostID, ref isHigher);
                                #region 打印审核人
                                string names = "\r\n=======打印审核人H(listRole[0].RoleName=" + listRole[i].RoleName + ";UserID=" + UserID + ";PostID=" + tmpPostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n";
                                foreach (var user in listuserinfo)
                                {
                                    names += "CompanyID:" + user.CompanyID + "\r\n";
                                    names += "DepartmentID:" + user.DepartmentID + "\r\n";
                                    names += "PostID:" + user.PostID + "\r\n";
                                    names += "UserID:" + user.UserID + "\r\n";

                                    names += "CompanyName:" + user.CompanyName + "\r\n";
                                    names += "DepartmentName:" + user.DepartmentName + "\r\n";
                                    names += "PostName:" + user.PostName + "\r\n";
                                    names += "UserName:"******"\r\n";
                                    names += "----------------------------------------------------\r\n";
                                }
                                if (!isHigher && listRole[0].IsOtherCompany != null)
                                {
                                    if (listRole[0].IsOtherCompany.Value == true)
                                    {
                                        names += "是否指定公司:" + listRole[0].IsOtherCompany.Value.ToString() + "\r\n";
                                        names += "公司的ID:" + listRole[0].OtherCompanyID + "\r\n";
                                        if (string.IsNullOrEmpty(listRole[0].OtherCompanyID))
                                        {
                                            names += "Layout=" + Layout + "\r\n";
                                        }
                                    }
                                    else if (listRole[0].IsOtherCompany.Value == false)
                                    {
                                        names += "实际要查找公司的ID:" + companyID + "\r\n";
                                    }
                                }
                                fUser.ErrorMsg += names;
                                Tracer.Debug(names);
                                #endregion
                                if (!isHigher)
                                {
                                    if (listRole[i].IsOtherCompany != null && listRole[i].IsOtherCompany.Value == true)
                                    {
                                        listuserinfo = listuserinfo.Where(user => user.CompanyID == listRole[i].OtherCompanyID).ToList();
                                    }
                                    else
                                    {
                                        listuserinfo = listuserinfo.Where(user => user.CompanyID == companyID).ToList();
                                    }
                                }
                                if (listuserinfo != null && listuserinfo.Count > 0)
                                {
                                    bFlag = true;
                                    if (listuserinfo.FirstOrDefault(u => u.UserID == UserID[1]) != null)
                                    {
                                        iscurruser = true;
                                        break;
                                    }
                                    //DataResult.Err = "没有找到审核人";
                                    //DataResult.FlowResult = FlowResult.FAIL;
                                    //return;
                                }
                                DictCounterUser.Add(listRole[i], listuserinfo);
                            }
                            if (!bFlag)
                            {
                                DataResult.Err = "当前的角色 " + roleNames + " 没有找到审核人";
                                DataResult.FlowResult = FlowResult.FAIL;
                                return;
                            }
                            #endregion
                        }
                        #endregion
                    }

                    #endregion
                }
                DataResult.IsCountersign = IsCountersign;
                DataResult.AppState = strNextState;
                DataResult.CountersignType = CountersignType;
                if (!IsCountersign)
                {
                    #region
                    if (AppUserInfo != null && AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人
                    {
                        DataResult.FlowResult = FlowResult.MULTIUSER;
                    }
                    DataResult.UserInfo = AppUserInfo;
                    #endregion
                }
                else
                {
                    #region
                    if (DataResult.DictCounterUser == null)
                    {
                        DataResult.DictCounterUser = new Dictionary<FlowRole, List<UserInfo>>();
                    }
                    DataResult.DictCounterUser = DictCounterUser;

                    List<FlowRole> listkeys = DictCounterUser.Keys.ToList();
                    for (int i = 0; i < listkeys.Count; i++)
                    {
                        FlowRole key = listkeys[i];
                        if (DictCounterUser[key].Count > 1)
                        {
                            DataResult.FlowResult = FlowResult.Countersign;
                            break;
                        }
                    }
                    #endregion

                }

            }
            catch (Exception ex)
            {
                //throw new Exception("GetUserByInstance2:" + ex.Message);//旧的
                Tracer.Debug("FORMID="+fUser.FormID+";通过实体例查找用户Instance=" + Instance.InstanceId.ToString()+" 异常信息:\r\n" + ex.ToString());
                throw new Exception(ex.Message);
            }
            finally
            {
                strNextState = null;
                AppUserInfo = null;
                //RuleName = null;
                Instance = null;
                SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime);

            }
        }
Esempio n. 4
0
        /// <summary>
        /// 通过持久化服务查询下一处理人
        /// </summary>
        /// <param name="WfRuntimeClone">持久化运行时</param>
        /// <param name="instanceClone">持久化实例</param>
        /// <param name="xml">条件XML</param>
        /// <param name="CurrentStateName">当前状态代码</param>
        /// <param name="DataResult">操作结果</param>
        public void GetUserByInstance(WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, string xml, string CurrentStateName, string UserID, string PostID, ref DataResult DataResult)
        {
            if (!WfRuntimeClone.IsStarted)
            {
                WfRuntimeClone.StartRuntime();
            }
            WorkflowRuntime WfRuntime = null;
            WorkflowInstance Instance = null;
            try
            {
                WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false);
                Instance = SMTWorkFlowManage.CloneWorkflowInstance(WfRuntimeClone, instanceClone, WfRuntime);

                string strNextState = SMTWorkFlowManage.GetFlowNextStepRoles(WfRuntime, Instance, CurrentStateName, xml);
                bool isHigher = false;
                List<UserInfo> AppUserInfo = TmGetUserByRoleId(strNextState, UserID, PostID, ref isHigher);
                #region 打印审核人
                string names = "\r\n=======打印审核人D(strNextState" + strNextState + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n";
                foreach (var user in AppUserInfo)
                {
                    names += "CompanyID:" + user.CompanyID + "\r\n";
                    names += "DepartmentID:" + user.DepartmentID + "\r\n";
                    names += "PostID:" + user.PostID + "\r\n";
                    names += "UserID:" + user.UserID + "\r\n";

                    names += "CompanyName:" + user.CompanyName + "\r\n";
                    names += "DepartmentName:" + user.DepartmentName + "\r\n";
                    names += "PostName:" + user.PostName + "\r\n";
                    names += "UserName:"******"\r\n";
                    names += "----------------------------------------------------\r\n";
                }
                #endregion
                if (AppUserInfo == null || AppUserInfo.Count == 0)
                {
                    DataResult.Err = "没有找到审核人";
                    DataResult.FlowResult = FlowResult.FAIL;
                }
                else if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人
                {
                    DataResult.FlowResult = FlowResult.MULTIUSER;
                }
                DataResult.UserInfo = AppUserInfo;

            }
            catch (Exception ex)
            {
                Tracer.Debug("GetUserByInstance异常信息 :" + ex.ToString());
                throw new Exception(ex.Message);
            }
            finally
            {
                Instance = null;
                SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime);

            }
        }