Beispiel #1
0
        /// <summary>
        /// 从数据库创建Process类。
        /// </summary>
        /// <param name="processID">流程ID。</param>
        /// <returns>流程类。</returns>
        public static Process CreateProcess(GUIDEx processID)
        {
            lock (ModuleUtils.SynchronizedObject)
            {
                Process process = null;
                if (processID.IsValid)
                {
                    #region 流程信息。
                    FlowProcessEntity flowProcessEntity = new FlowProcessEntity();
                    FlowStepEntity flowStepEntity = new FlowStepEntity();
                    FlowTransitionEntity flowTransitionEntity = new FlowTransitionEntity();

                    FlowProcess p = new FlowProcess();
                    p.ProcessID = processID;
                    if (flowProcessEntity.LoadRecord(ref p))
                    {
                        process = new Process();
                        process.ProcessID = p.ProcessID;
                        process.ProcessName = p.ProcessName;
                        process.ProcessSign = p.ProcessSign;
                        process.BeginDate = p.BeginDate;
                        process.EndDate = p.EndDate;
                        process.ProcessDescription = p.ProcessDescription;

                        #region 步骤信息。
                        process.Steps = flowStepEntity.LoadStepCollection(process.ProcessID);
                        #endregion

                        #region 变迁规则。
                        process.Transitions = flowTransitionEntity.LoadTransitionCollection(process.ProcessID);
                        #endregion
                    }
                    #endregion
                }
                return process;
            }
        }
        /// <summary>
        /// 对指定的步骤进行授权。
        /// </summary>
        /// <param name="processSign">流程标识。</param>
        /// <param name="employeeID">进行授权的用户ID。</param>
        /// <param name="employeeName">进行授权的用户名称。</param>
        /// <param name="stepSigns">进行授权的步骤标识列表。</param>
        /// <param name="toEmployeeID">授权的目标用户ID。</param>
        /// <param name="fromDate">授权开始时间,为2010-01-11 15:00:00格式。</param>
        /// <param name="toDate">授权结束时间,为2010-01-11 15:00:00格式。</param>
        /// <param name="msgError">调用失败时的错误消息。</param>
        /// <returns>如果授权成功则返回true,否则返回false。</returns>
        public bool AuthorizeFlow(string processSign, GUIDEx employeeID, string employeeName, string[] stepSigns, GUIDEx toEmployeeID, DateTime fromDate, DateTime toDate, out string msgError)
        {
            lock (this)
            {
                msgError = null;
                bool result = false;
                try
                {
                    #region 验证参数。
                    if (string.IsNullOrEmpty(processSign))
                    {
                        msgError = "流程标识为空。";
                        return result;
                    }
                    if (!employeeID.IsValid)
                    {
                        msgError = "进行授权的用户ID为空。";
                        return result;
                    }
                    if (string.IsNullOrEmpty(employeeName))
                    {
                        msgError = "进行授权的用户名称为空。";
                        return result;
                    }
                    if (stepSigns == null || stepSigns.Length == 0)
                    {
                        msgError = "进行授权的步骤标识列表不存在或为空。";
                        return result;
                    }
                    if (!toEmployeeID.IsValid)
                    {
                        msgError = "授权的目标用户ID为空。";
                        return result;
                    }
                    #endregion

                    #region 获取流程定义。
                    GUIDEx processID = this.flowProcessEntity.FindProcessID(processSign);
                    if (!processID.IsValid)
                    {
                        msgError = "流程标识不正确。";
                        return result;
                    }
                    #endregion

                    #region 流程步骤定义。
                    FlowStepEntity flowStepEntity = new FlowStepEntity();
                    List<FlowStep> flowStepList = flowStepEntity.FindFlowStep(processID, stepSigns);
                    if (flowStepList == null || flowStepList.Count == 0)
                    {
                        msgError = "进行授权的步骤标识列表不存在或为空。";
                        return result;
                    }
                    #endregion

                    #region 流程步骤的授权。
                    FlowStepAuthorize flowStepAuthorize = new FlowStepAuthorize();
                    FlowStepAuthorizeEntity flowStepAuthorizeEntity = new FlowStepAuthorizeEntity();
                    foreach (FlowStep fs in flowStepList)
                    {
                        flowStepAuthorize.AuthorizeID = GUIDEx.New;
                        flowStepAuthorize.BeginDate = fromDate;
                        flowStepAuthorize.EndDate = toDate;
                        flowStepAuthorize.EmployeeID = employeeID;
                        flowStepAuthorize.StepID = fs.StepID;
                        flowStepAuthorize.TargetEmployeeID = toEmployeeID;

                        result = flowStepAuthorizeEntity.UpdateRecord(flowStepAuthorize);
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    msgError = e.Message;
                }
                return result;
            }
        }
        /// <summary>
        /// 收回流程的授权。
        /// </summary>
        /// <param name="processSign">流程标识。</param>
        /// <param name="employeeID">进行回收的用户ID,只能回收自己的授权。</param>
        /// <param name="employeeName">进行回收的用户名称。</param>
        /// <param name="authorizeID">要回收的流程授权的步骤标识列表。</param>
        /// <param name="msgError">调用失败时的错误消息。</param>
        /// <returns>回收成功则返回true,否则返回false。</returns>
        public bool WithdrawFlow(string processSign, GUIDEx employeeID, string employeeName, string[] stepSigns, out string msgError)
        {
            lock (this)
            {
                msgError = null;
                bool result = false;
                try
                {
                    #region 验证参数。
                    if (string.IsNullOrEmpty(processSign))
                    {
                        msgError = "流程标识为空。";
                        return result;
                    }
                    if (!employeeID.IsValid)
                    {
                        msgError = "用户ID为空。";
                        return result;
                    }
                    if (stepSigns == null || stepSigns.Length == 0)
                    {
                        msgError = "要回收的流程授权的步骤标识列表为空。";
                        return result;
                    }
                    #endregion

                    #region 获取流程定义。
                    GUIDEx processID = this.flowProcessEntity.FindProcessID(processSign);
                    if (!processID.IsValid)
                    {
                        msgError = "流程标识不正确。";
                        return result;
                    }
                    #endregion

                    #region 流程步骤定义。
                    FlowStepEntity flowStepEntity = new FlowStepEntity();
                    List<FlowStep> flowStepList = flowStepEntity.FindFlowStep(processID, stepSigns);
                    if (flowStepList == null || flowStepList.Count == 0)
                    {
                        msgError = "进行授权的步骤标识列表不存在或为空。";
                        return result;
                    }
                    #endregion

                    #region 流程步骤授权取消。
                    FlowStepAuthorizeEntity flowStepAuthorizeEntity = new FlowStepAuthorizeEntity();
                    foreach (FlowStep fs in flowStepList)
                    {
                        result = flowStepAuthorizeEntity.DeleteFlowStepAuthorize(employeeID, fs.StepID);
                    }
                    #endregion
                }
                catch (Exception e)
                {
                    msgError = e.Message;
                }
                return result;
            }
        }