Example #1
0
        /// <summary>
        /// 根据登录用户、表单ID、申请单标题创建所需要的流程数据。
        /// 创建流程前,业务表的数据必须先保存,在执行该流程创建操作,因为逻辑需要调用AppForm的GetApplyCount函数,根据条件过滤不需要的流程。
        /// </summary>
        /// <param name="userInfo">用户、部门、公司对象</param>
        /// <param name="applyId">申请单的ID标识,请使用一个不重复的ID值,如:System.Guid.NewGuid().ToString(),并且和业务表单的Apply_ID保持一致。</param>
        /// <param name="formId">表单ID</param>
        /// <param name="applyTitle">申请单标题</param>
        /// <param name="selprocuser">第一步的流程处理人</param>
        /// <param name="remark">备注说明</param>
        /// <returns></returns>
        public bool CreateApply(LoginUserInfo userInfo, string applyId, string formId, string applyTitle, string selprocuser, string remark)
        {
            ArgumentCheck.Begin().NotNullOrEmpty(userInfo.DeptId, "部门ID").NotNullOrEmpty(userInfo.CompanyId, "公司ID");

            bool insertFlag = false;

            try
            {
                string   message  = "";
                FormInfo formInfo = BLLFactory <Form> .Instance.FindByID(formId);

                ArgumentCheck.Begin().NotNull(formInfo, "表单对象formInfo");

                #region 创建申请单记录
                ApplyInfo applyInfo = new ApplyInfo(formInfo, userInfo);
                applyInfo.ID     = applyId;     //申请单ID
                applyInfo.Title  = applyTitle;  //申请标题
                applyInfo.Remark = remark;      //备注说明

                insertFlag = BLLFactory <Apply> .Instance.Insert(applyInfo);

                #endregion

                if (insertFlag)
                {
                    #region 保存流程信息

                    List <FormFlowInfo> flowList = GetRelatedFlows(userInfo, applyInfo.FormId, applyId);
                    int orderNum = 0;
                    foreach (FormFlowInfo flowInfo in flowList)
                    {
                        orderNum++;

                        //申请单流程数据
                        ApplyFlowInfo appFlowInfo = new ApplyFlowInfo(flowInfo);
                        appFlowInfo.ApplyId = applyId;//外部指定
                        appFlowInfo.OrderNo = orderNum;

                        //如果是第一个流程,那么采用传过来的流程处理人(具体的人员名字)
                        if (orderNum == 1 && !string.IsNullOrEmpty(selprocuser))
                        {
                            appFlowInfo.ProcUser = selprocuser;
                        }

                        BLLFactory <ApplyFlow> .Instance.Insert(appFlowInfo);
                    }
                    #endregion

                    //保存申请单日志
                    var content = string.Format("创建了该申请单的处理流程,共有{0}个流程环节。", flowList.Count);
                    BLLFactory <ApplyLog> .Instance.AddApplyLog(applyId, userInfo.ID.ToInt32(), content);

                    message  = "您已经提交了该申请单。";
                    message += CreateCurrentFlow(userInfo, applyId);
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.Error(ex);
                throw;
            }

            return(insertFlag);
        }