Beispiel #1
0
        /// <summary>
        /// 判断任务是否是关卡最后未完成任务
        /// </summary>
        /// <param name="workItemInstId"></param>
        /// <returns></returns>
        public bool CheckIsFinalTask(int workItemInstId)
        {
            WorkItemInstance item = new WorkItemInstance(workItemInstId);

            ActivityInstance instActivity = item.ActivityInstance;

            //只要任意一个人完成
            if (instActivity.Activity.CompleteType == ActivityCompleteType.ONE)
            {
                return(true);
            }
            else//需要全部人完成
            {
                int count = instActivity.WorkItemInstances.
                            Count(t => t.ID != workItemInstId && t.State == WorkItemState.Waiting);

                //无其他人或其他人已完成
                if (count == 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 分配工作(关卡参与人)
        /// </summary>
        /// <param name="listWorker"></param>
        /// <returns></returns>
        public void AssignWork()
        {
            //解析参与人
            IList <int> listWorkerId = this.Activity.ParseParticipant(this.FlowInstance.FlowDefine.ID,
                                                                      this.FlowInstance.FlowNo);

            if (listWorkerId.Count > 0)
            {
                //分配工作
                foreach (int workerId in listWorkerId)
                {
                    WorkItemInstance item = new WorkItemInstance();
                    item.Create(m_ActivityInstanceId, workerId);
                    m_ListWorkItemInstance.Add(item);
                }

                //发送提醒短信
                if (this.Activity.IsSms == "Y")
                {
                    List <string> listMobile = new List <string>();

                    foreach (int workerId in listWorkerId)
                    {
                        IWorker worker = ctx["Worker"] as IWorker;

                        string mobile = worker.GetWorkerById(workerId).Mobile;

                        if (!string.IsNullOrEmpty(mobile))
                        {
                            listMobile.Add(mobile);
                        }
                    }

                    if (listMobile.Count > 0)
                    {
                        ISMS sms = ctx["SMS"] as ISMS;

                        string content = string.Format("您有一笔{0}需要审核", FlowInstance.FlowDefine.Name);

                        Log4Net.LogInfo(content);

                        sms.SendSMG(listMobile, content, "99999");
                    }
                }
            }
            else
            {
                throw new Exception(string.Format("关卡({0})无签核人", this.Activity.Name));
            }
        }
Beispiel #3
0
        /// <summary>
        /// 撤回
        /// </summary>
        /// <param name="flowInstId"></param>
        public void Recall(string remark)
        {
            //删除未完成的工作
            DAL.WorkFlow.WorkItemInstance.DeleteNoCompleteTask(this.ID);

            //更新流程实例状态
            UpdateState(FlowInstanceState.Recall);

            //创建撤回任务
            WorkItemInstance item = new WorkItemInstance();

            int activityInstId = this.ActivityInstances.Single(t => t.Activity.Type == ActivityType.START).ID;

            item.CreateRecall(activityInstId, m_ApplerId, remark);
        }
Beispiel #4
0
        /// <summary>
        /// 申请工作流内部表单
        /// </summary>
        /// <param name="flowId">流程id</param>
        /// <param name="applyerId">申请人id</param>
        /// <returns>流程实例id,开始关卡实例id,流程号</returns>
        public void ApplyInnerFlow(int flowId, ref int flowNo, int applyerId, string formDigest, out Dictionary <string, string> param)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                param = new Dictionary <string, string>();

                if (flowNo == 0)
                {
                    flowNo = CreateFlowNo(flowId);
                }

                //创建流程实例
                FlowInstance     flowInst     = new FlowInstance();
                ActivityInstance activityInst = new ActivityInstance();

                if (FlowInstance.Exists(flowId, flowNo))
                {
                    flowInst = new FlowInstance(flowId, flowNo);
                    flowInst.UpdateDigest(formDigest);
                    Activity startActvity = flowInst.FlowDefine.GetStartActivity();
                    activityInst = flowInst.FindActivityInstance(ActivityType.START);

                    WorkItemInstance item = new WorkItemInstance();
                    item.CreateResend(activityInst.ID, flowInst.ApplerID, "");
                }
                else
                {
                    flowInst.Create(flowId, flowNo, applyerId, formDigest);
                    activityInst.Create(flowInst.ID, flowInst.FlowDefine.GetStartActivity().ID);
                    activityInst.Active();
                }

                //返回流程实例id,开始关卡实例id,流程号
                param.Add("FlowInstId", flowInst.ID.ToString());
                param.Add("ActivityInstId", activityInst.ID.ToString());
                param.Add("SplitType", flowInst.FlowDefine.GetStartActivity().SplitType);

                scope.Complete();
            }
        }
Beispiel #5
0
        /// <summary>
        /// 签核
        /// </summary>
        /// <param name="workItemId">任务ID</param>
        /// <param name="approveValue">签核值:Y同意;N:否决</param>
        /// <param name="approveRemark">签核意见</param>
        /// <param name="transferNext">是否判断转到哪个下一关卡</param>
        /// <returns>成功与否</returns>
        public bool Approve(int workItemId, int approverId, string approveValue,
                            string approveRemark, string nextActivityId)
        {
            //防止重复点击
            //if (Convert.ToString(HttpContext.Current.Session[approverId.ToString()]) == string.Format("WorkItemId:{0}", workItemId))
            //{
            //    return false;
            //}
            //else
            //{
            //    HttpContext.Current.Session[approverId.ToString()] = string.Format("WorkItemId:{0}", workItemId);
            //}


            lock (lockObj)
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = IsolationLevel.ReadCommitted
                }))
                {
                    try
                    {
                        WorkItemInstance instWorkItem = new WorkItemInstance(workItemId);
                        FlowInstance     instFlow     = instWorkItem.ActivityInstance.FlowInstance;
                        ActivityInstance instActivity = instWorkItem.ActivityInstance;

                        //验证数字摘要
                        if (!instFlow.VerifyDigest())
                        {
                            Log4Net.LogError("Workflow_Engine", string.Format("WorkItemID:{0},Message:表单数据变化,无法签核", workItemId));

                            return(false);
                        }

                        //数字签名
                        if (instActivity.Activity.IsSign.ToUpper() == "Y")
                        {
                            instWorkItem.Sign();
                        }

                        //更新工作实例状态
                        instWorkItem.Actorid   = approverId;
                        instWorkItem.AppValue  = approveValue;
                        instWorkItem.AppRemark = approveRemark;
                        instWorkItem.Approve();

                        //否决关闭所有对象
                        if (approveValue == WorkItemAppValue.Reject)
                        {
                            instFlow.ApproveReject += new FlowInstance.ApproveEventHandler(Mail.SendMail);
                            instFlow.ApproveReject += new FlowInstance.ApproveEventHandler(CallBack.Update);

                            Activity endActivity = instFlow.FlowDefine.Activitys.SingleOrDefault(t => t.Type == "end");

                            if (endActivity != null && endActivity.IsSms.ToUpper() == "Y")
                            {
                                instFlow.ApproveReject += new FlowInstance.ApproveEventHandler(Sms.SendSms);
                            }

                            instActivity.Close();
                            instFlow.Reject();

                            //关闭平行关卡
                            List <ActivityInstance> listParallelActivity =
                                instFlow.ActivityInstances.Where(
                                    t => t.State == ActivityInstanceStatus.Active).ToList();

                            foreach (ActivityInstance p in listParallelActivity)
                            {
                                p.Close();
                            }
                        }
                        else if (approveValue == WorkItemAppValue.Return)
                        {
                            //关闭当间关卡实例
                            instActivity.Close();

                            //创建退回关卡实例
                            ActivityInstance instReturnActivity = new ActivityInstance();

                            instReturnActivity.Create(instFlow.ID, int.Parse(nextActivityId));

                            instReturnActivity.Active();

                            instReturnActivity.AssignWork();
                        }
                        else if (approveValue == WorkItemAppValue.Agree)
                        {
                            if (!string.IsNullOrEmpty(nextActivityId))
                            {
                                string[] arrActivityId = nextActivityId.TrimEnd(',').Split(',');

                                List <int> listActivityId = new List <int>();

                                foreach (string id in arrActivityId)
                                {
                                    listActivityId.Add(int.Parse(id));
                                }

                                if (!TransferBack(instWorkItem.ActivityInstance.ID, listActivityId))
                                {
                                    return(false);
                                }
                            }
                        }
                        else if (approveValue == WorkItemAppValue.Reserve)
                        {
                            WorkItemInstance item = new WorkItemInstance();
                            item.Create(instActivity.ID, approverId);
                        }

                        scope.Complete();

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Log4Net.LogError("Workflow_Engine", string.Format("WorkItemID:{0},Message:{1}", workItemId, ex.ToString()));

                        return(false);
                    }
                }
            }
        }