Ejemplo n.º 1
0
        public string GetWfName(int bid)
        {
            ItServiceItem isi = bdb.ItServiceItems.Where(i => i.ID == bid).Single();

            //ItServiceItem isi = bdb.ItServiceItems.Where(i => i.ID == bid).FirstOrDefault();
            return(isi.Title);
        }
Ejemplo n.º 2
0
        public ActionResult ViewLib(Guid id)           //用户查看自己可访问的专病库
        {
            var wf  = bdb.WorkFlowItems.Where(i => i.WfInstanceId == id).FirstOrDefault();
            var bid = wf.WfBusinessId;

            ViewBag.WfWriteField = wf.WfWriteField;
            ViewBag.WfFlowChart  = wf.WfFlowChart;
            ViewBag.instanceId   = wf.WfInstanceId;
            ItServiceItem isi = bdb.ItServiceItems.Where(i => i.ID == bid).FirstOrDefault();

            return(View(isi));
        }
Ejemplo n.º 3
0
        public JObject GetPossiblePath(Guid id, string libID)                     //审批用户获取下一步可能的路径
        {
            WorkFlowItem        cwfi  = bdb.WorkFlowItems.Where(i => i.WfInstanceId == id).FirstOrDefault();
            ItServiceItem       cisi  = bdb.ItServiceItems.Where(i => i.ID == cwfi.WfBusinessId).FirstOrDefault();
            WorkflowApplication wfApp = new WorkflowApplication(new ItService())
            {
                InstanceStore   = CreateInstanceStore(),
                PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
                {
                    //var ex = e.GetInstanceExtensions<CustomTrackingParticipant>();
                    // Outputs = ex.First().Outputs.ToString();
                    return(PersistableIdleAction.Unload);
                },
                Completed = delegate(WorkflowApplicationCompletedEventArgs e)
                {
                },
                Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
                {
                },
                Unloaded = delegate(WorkflowApplicationEventArgs e)
                {
                },
                OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
                {
                    return(UnhandledExceptionAction.Terminate);
                },
                Idle = delegate(WorkflowApplicationIdleEventArgs e)
                {
                }
            };
            var trackerInstance = StateMachineStateTracker.LoadInstance(id, wfApp.WorkflowDefinition, ConfigurationManager.ConnectionStrings["ApacheConnection"].ConnectionString);

            //var Pt = trackerInstance.PossibleTransitions;
            var Pt = GetPossibleTransitions(libID, false, cisi.Status);

            //BookmarkResumptionResult result = wfApp.ResumeBookmark("Hello123", "ddd");
            string[] strs = Pt.Split(',');
            JObject  json = new JObject(
                new JProperty("rows",
                              new JArray(
                                  from r in strs
                                  select new JObject(
                                      new JProperty("ID", r.ToString()),
                                      new JProperty("Name", r.ToString())))));

            return(json);
        }
Ejemplo n.º 4
0
        public ActionResult OpenWorkFlow(Guid id)         //用户处理流程
        {
            #region 判断是不是当前处理人
            WorkFlowItem    cwfi          = bdb.WorkFlowItems.Where(i => i.WfInstanceId == id).FirstOrDefault();
            string          currentUserId = User.Identity.GetUserId();
            ApplicationUser user          = db.Users.Include(i => i.Roles).FirstOrDefault(i => i.Id == currentUserId);
            if (cwfi.WfCurrentUser.ToString().Trim() != user.UserName.ToString().Trim())
            {
                var json = new
                {
                    errorMsg = "你不是当前处理人"
                };

                return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
            }
            #endregion
            var wf  = bdb.WorkFlowItems.Where(i => i.WfInstanceId == id).FirstOrDefault();
            var bid = wf.WfBusinessId;
            ViewBag.WfWriteField = wf.WfWriteField;
            ViewBag.WfFlowChart  = wf.WfFlowChart;
            ViewBag.instanceId   = wf.WfInstanceId;
            ItServiceItem isi = bdb.ItServiceItems.Where(i => i.ID == bid).FirstOrDefault();
            return(View(isi));
        }
Ejemplo n.º 5
0
        public string GetWfApplicantName(int bid)
        {
            ItServiceItem isi = bdb.ItServiceItems.Where(i => i.ID == bid).Single();

            return(isi.applicant);
        }
Ejemplo n.º 6
0
        public ActionResult DelWorkFlow(Guid id)          //删除流程及业务数据
        {
            if (id != null)
            {
                WorkFlowItem  wf  = bdb.WorkFlowItems.Where(i => i.WfInstanceId == id).FirstOrDefault();
                var           bid = wf.WfBusinessId;
                ItServiceItem isi = bdb.ItServiceItems.Where(i => i.ID == bid).FirstOrDefault();

                if (wf != null && isi != null)
                {
                    if (wf.Wfstatus != "已结束")
                    {
                        bdb.WorkFlowItems.Remove(wf);
                        bdb.ItServiceItems.Remove(isi);
                        try
                        {
                            bdb.SaveChanges();
                            var json = new
                            {
                                okMsg = "删除成功"
                            };

                            return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
                        }
                        catch
                        {
                            var json = new
                            {
                                errorMsg = "由于数据库或系统原因,删除流程失败"
                            };

                            return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        var json = new
                        {
                            okMsg = "已结束流程不能删除"
                        };

                        return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    var json = new
                    {
                        okMsg = "未找到相关流程和业务数据"
                    };

                    return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                var json = new
                {
                    okMsg = "数据输入有误"
                };

                return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 7
0
        public ActionResult ToNextState(ItServiceItem isi, Guid instanceId, string NextLink, string libid, string Opinion)  //审批者到下一环节,思路:保存当前流程的数据,恢复bookmark到下一环节,并保存下一环节流程信息
        {
            #region 判断是不是当前处理人
            WorkFlowItem    cwfi          = bdb.WorkFlowItems.Where(i => i.WfInstanceId == instanceId).FirstOrDefault();
            string          currentUserId = User.Identity.GetUserId();
            ApplicationUser user          = db.Users.Include(i => i.Roles).FirstOrDefault(i => i.Id == currentUserId);
            if (cwfi.WfCurrentUser.ToString().Trim() != user.UserName.ToString().Trim())
            {
                var json = new
                {
                    errorMsg = "你不是当前处理人"
                };

                return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
            }
            #endregion
            string[]            strs       = NextLink.Trim().Split('(');
            AutoResetEvent      syncEvent  = new AutoResetEvent(false);
            int                 isComplete = 0;
            WorkflowApplication wfApp      = new WorkflowApplication(new ItService())
            {
                InstanceStore   = CreateInstanceStore(),
                PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
                {
                    //var ex = e.GetInstanceExtensions<CustomTrackingParticipant>();
                    // Outputs = ex.First().Outputs.ToString();
                    return(PersistableIdleAction.Unload);
                },
                Completed = delegate(WorkflowApplicationCompletedEventArgs e)
                {
                    isComplete = 1;
                    syncEvent.Set();
                },
                Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
                {
                },
                Unloaded = delegate(WorkflowApplicationEventArgs e)
                {
                    syncEvent.Set();
                },
                OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
                {
                    return(UnhandledExceptionAction.Terminate);
                },
                Idle = delegate(WorkflowApplicationIdleEventArgs e)
                {
                }
            };
            var StateTracker = new StateMachineStateTracker(wfApp.WorkflowDefinition); //当前状态追踪
            wfApp.Extensions.Add(StateTracker);
            wfApp.Extensions.Add(new StateTrackerPersistenceProvider(StateTracker));
            var cu = new CustomTrackingParticipant();         //获取Activity内部变量
            wfApp.Extensions.Add(cu);                         //获取Activity内部变量需要的追踪器
            //Guid instanceId = wfApp.Id;
            var trackerInstance = StateMachineStateTracker.LoadInstance(instanceId, wfApp.WorkflowDefinition, ConfigurationManager.ConnectionStrings["ApacheConnection"].ConnectionString);
            wfApp.Load(instanceId);
            BookmarkResumptionResult result = wfApp.ResumeBookmark(trackerInstance.CurrentState, strs[0]);
            //BookmarkResumptionResult result = wfApp.ResumeBookmark(trackerInstance.CurrentState, NextLink.Trim());   //恢复当前状态,并进入下一个bookmark,注意使用Trim,开始没使用,NextLInk无法取到,调试了大半夜
            syncEvent.WaitOne();

            string CurrentUser;
            string OpinionField = "";
            string CurrentState;
            string completeStr = "";

            if (isComplete == 0)
            {
                if (strs.Count() == 1)
                {
                    CurrentUser = cu.Outputs["CurrentUser"].ToString();
                }
                else
                {
                    CurrentUser = db.LibraryApprovers.ToList().First(p => (p.LibID == libid) && (p.ApproverName == strs[1].Replace(")", ""))).Approver;
                }
                OpinionField = cu.Outputs["OpinionField"].ToString();
                CurrentState = StateTracker.CurrentState;
            }
            else
            {
                CurrentUser  = "******";
                CurrentState = "已结束";
                completeStr  = "->结束";
            }
            //string currentUserId = User.Identity.GetUserId();
            //ApplicationUser user = db.Users.Include(i => i.Roles).FirstOrDefault(i => i.Id == currentUserId);    //获取当前用户TrueName,为增加流转信息提供数据
            WorkFlowItem  wfi  = bdb.WorkFlowItems.Where(i => i.WfInstanceId == instanceId).FirstOrDefault();   //获取当前流程信息
            ItServiceItem cisi = bdb.ItServiceItems.Where(i => i.ID == isi.ID).FirstOrDefault();                //获取当前业务数据的信息

            //业务数据更新开始
            cisi.Title          = isi.Title;
            cisi.applicant      = isi.applicant;
            cisi.applicant_dept = isi.applicant_dept;
            //cisi.description = isi.description;
            cisi.isitype     = isi.isitype;
            cisi.sub_isitype = isi.sub_isitype;
            cisi.end_isitype = isi.end_isitype;
            cisi.Object      = isi.Object;
            cisi.Topic       = isi.Topic;
            cisi.Purpose     = isi.Purpose;
            cisi.Status      = 1;
            if (NextLink == "驳回")
            {
                cisi.Status = 3;
            }
            if (isComplete == 1)
            {
                cisi.isiCompleteDate = DateTime.Now;
                if (NextLink == "撤销")
                {
                    cisi.Status = 4;
                }
                else
                {
                    cisi.Status = 2;
                }
            }

            #region 审批意见更新开始
            if (Opinion != null)
            {
                if (Convert.ToString(Opinion) != "")
                {
                    if (wfi.WfWriteField.Trim() == "FirstExamine")
                    {
                        cisi.FirstExamine = cisi.FirstExamine + "<br>" + Opinion + "     (意见填写人:" + user.TrueName + "    时间:" + DateTime.Now + ")";
                    }
                    if (wfi.WfWriteField.Trim() == "SecondExamine")
                    {
                        cisi.SecondExamine = cisi.SecondExamine + "<br>" + Opinion + "     (意见填写人:" + user.TrueName + "    时间:" + DateTime.Now + ")";
                    }
                    if (wfi.WfWriteField.Trim() == "LastExamine")
                    {
                        cisi.LastExamine = cisi.LastExamine + "<br>" + Opinion + "     (意见填写人:" + user.TrueName + "    时间:" + DateTime.Now + ")";
                    }
                }
            }
            #endregion


            if (wfi != null)
            {
                wfi.WfCurrentUser = CurrentUser;
                wfi.Wfstatus      = CurrentState;
                wfi.WfWriteField  = OpinionField;
                if (isComplete == 1)
                {
                    wfi.WfCompleteDate = DateTime.Now;
                }
                wfi.WfFlowChart = wfi.WfFlowChart + "->" + trackerInstance.CurrentState + "(" + user.TrueName + ")" + completeStr;          //增加流转信息
                try
                {
                    bdb.SaveChanges();
                    var json = new
                    {
                        okMsg = "提交成功"
                    };

                    return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    var json = new
                    {
                        errorMsg = "提交失败"
                    };

                    return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                var json = new
                {
                    errorMsg = "流程不存在"
                };

                return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 8
0
        public ActionResult DrafterToNextState(ItServiceItem isi, Guid instanceId, string NextLink, string libid)  //起草者到下一环节
        {
            string[] strs = NextLink.Trim().Split('(');

            AutoResetEvent syncEvent = new AutoResetEvent(false);

            WorkflowApplication wfApp = new WorkflowApplication(new ItService())
            {
                InstanceStore   = CreateInstanceStore(),
                PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
                {
                    //var ex = e.GetInstanceExtensions<CustomTrackingParticipant>();
                    // Outputs = ex.First().Outputs.ToString();`
                    return(PersistableIdleAction.Unload);
                },
                Completed = delegate(WorkflowApplicationCompletedEventArgs e)
                {
                },
                Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
                {
                },
                Unloaded = delegate(WorkflowApplicationEventArgs e)
                {
                    syncEvent.Set();
                },
                OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
                {
                    return(UnhandledExceptionAction.Terminate);
                },
                Idle = delegate(WorkflowApplicationIdleEventArgs e)
                {
                }
            };
            var StateTracker = new StateMachineStateTracker(wfApp.WorkflowDefinition); //当前状态追踪

            wfApp.Extensions.Add(StateTracker);
            wfApp.Extensions.Add(new StateTrackerPersistenceProvider(StateTracker));
            var cu = new CustomTrackingParticipant();         //获取Activity内部变量

            wfApp.Extensions.Add(cu);                         //获取Activity内部变量需要的追踪器
            //Guid instanceId = wfApp.Id;
            var trackerInstance = StateMachineStateTracker.LoadInstance(instanceId, wfApp.WorkflowDefinition, ConfigurationManager.ConnectionStrings["ApacheConnection"].ConnectionString);

            wfApp.Load(instanceId);
            //BookmarkResumptionResult result = wfApp.ResumeBookmark(trackerInstance.CurrentState, NextLink.Trim());
            BookmarkResumptionResult result = wfApp.ResumeBookmark(trackerInstance.CurrentState, strs[0]);

            syncEvent.WaitOne();
            //string CurrentUser = cu.Outputs["CurrentUser"].ToString();
            string CurrentUser = db.LibraryApprovers.ToList().First(p => (p.LibID == libid) && (p.ApproverName == strs[1].Replace(")", ""))).Approver;
            //string CurrentRole = cu.Outputs["CurrentRole"].ToString();
            string OpinionField = cu.Outputs["OpinionField"].ToString();
            string Drafter      = cu.Outputs["Drafter"].ToString();
            var    CurrentState = StateTracker.CurrentState;
            //var Pt = StateTracker.PossibleTransitions;
            ApplicationUser user = db.Users.Include(i => i.Roles).FirstOrDefault(i => i.UserName == Drafter);    //获取当前用户username

            isi.drafter       = Drafter;
            isi.isiCreateDate = DateTime.Now;
            isi.Status        = 1;
            bdb.ItServiceItems.Add(isi);      //添加业务数据
            try
            {
                bdb.SaveChanges();
            }
            catch
            {
                var json = new
                {
                    errorMsg = "添加业务数据出错"
                };

                return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
            }
            WorkFlowItem wf = new WorkFlowItem();

            wf.WfInstanceId   = instanceId;
            wf.WfType         = "专病库IT服务申请";
            wf.WfCurrentUser  = CurrentUser;
            wf.WfDrafter      = Drafter;
            wf.WfWriteField   = OpinionField;
            wf.Wfstatus       = CurrentState;
            wf.WfBussinessUrl = "/ItService/OpenWorkFlow?id=" + instanceId;
            wf.WfCreateDate   = DateTime.Now;
            wf.WfBusinessId   = isi.ID; //添加业务数据关联
            wf.WfFlowChart    = trackerInstance.CurrentState + "(" + user.TrueName + ")";
            bdb.WorkFlowItems.Add(wf);
            bdb.SaveChanges();
            try
            {
                bdb.SaveChanges();
                var json = new
                {
                    okMsg = "流程保存成功"
                };

                return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
            }
            catch
            {
                var json = new
                {
                    errorMsg = "流程保存出错"
                };

                return(Json(json, "text/html", JsonRequestBehavior.AllowGet));
            }
        }