Ejemplo n.º 1
0
        /// <summary>
        /// URL: /workflow/Instance/handle
        /// id: 流程实例节点ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult handle()
        {
            string UserID = this.User.Identity.Name;

            string TemplateID = Request.Form["TemplateID"];
            string instNodeID = Request.Form["instNodeID"];
            string nodeID = Request.Form["nodeID"];
            string actionID = Request.Form["actionID"];

            using (MyDB mydb = new MyDB())
            {
                WFInstNode instNode = mydb.WFInstNodes.FirstOrDefault(n => n.ID.Equals(instNodeID));
                WFTemplate template = mydb.WFTemplates.Find(TemplateID);

                Type t = getType(template);

                if (instNode == null)
                {
                    EntityObjectLib.WFInst inst = Activator.CreateInstance(t) as EntityObjectLib.WFInst;
                    //Object inst = Activator.CreateInstance(t);
                    foreach (string key in Request.Form.Keys)
                    {
                        PropertyInfo pi = t.GetProperty(key);
                        if (pi != null)
                        {
                            pi.SetValue(
                                inst,
                                //Request.Form[key],
                                Convert.ChangeType(Request.Form[key], pi.PropertyType.UnderlyingSystemType),
                                null);
                        }
                    }

                    inst.WFTemplate = template;
                    inst.State = "处理中";
                    inst.Creator = mydb.Users.Find(UserID);
                    inst.CreateTime = DateTime.Now;

                    instNode = new WFInstNode
                    {
                        ID = instNodeID,
                        WFNode = mydb.WFNodes.Find(nodeID),
                        State = "处理中",
                        EntryTime = DateTime.Now,
                        WFInst = inst,
                        WFInstNodeHandlers = new List<WFInstNodeHandler>()
                            {
                                new WFInstNodeHandler
                                {
                                    Handler = mydb.Users.Find(UserID),
                                    State = "待处理" //如果是"处理中",即表明一个人已经接收,准备处理,其他人不能处理
                                }
                            }
                    };

                    mydb.WFInstNodes.Add(instNode);
                    mydb.SaveChanges();
                }
            }

            this.process(instNodeID, this.HttpContext);

            return View("handleSuccess");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 已完成当前节点工作,将流程实例推入下一个节点
        /// 1,判断下一个节点的类型
        /// 2.如果是处理节点,则创建实例节点,分配处理人
        /// 3.如果是分支节点,则创建实例节点,调用处理该节点
        /// 4.如果是结束节点,创建结束节点,调用处理该节点
        /// </summary>
        /// <param name="instID">流程实例ID</param>
        /// <param name="nextNodeID">下一个节点ID</param>
        /// <param name="ctx">HTTP上下文</param>
        private void entry(string instID, string nextNodeID, HttpContextBase ctx)
        {
            using (MyDB mydb = new MyDB())
            {
                WFNode next = mydb.WFNodes.Find(nextNodeID);
                WFInst inst = mydb.WFInsts.Find(instID);

                if (next is WFNodeHandle)
                {
                    WFInstNode inode = new WFInstNode
                    {
                        EntryTime = DateTime.Now,
                        State = "处理中",
                        WFNode = next,
                        WFInst = inst,
                        WFInstNodeHandlers = ((WFNodeHandle)next).Subjects.OfType<User>().Select(a => new WFInstNodeHandler { Handler = a }).ToArray()
                    };
                    mydb.WFInstNodes.Add(inode);
                    mydb.SaveChanges();
                }
                else if (next is WFNodeXORSplit)
                {
                    //WFNodeXORSplit Split = next as WFNodeXORSplit;
                    WFInstNode inode = new WFInstNode
                    {
                        EntryTime = DateTime.Now,
                        State = "处理中",
                        WFNode = next,
                        WFInst = inst
                    };
                    mydb.WFInstNodes.Add(inode);
                    mydb.SaveChanges();
                    this.process(inode.ID, this.HttpContext);
                }
                else if (next is WFNodeFinish)
                {
                    //WFNodeXORSplit Split = next as WFNodeXORSplit;
                    WFInstNode inode = new WFInstNode
                    {
                        EntryTime = DateTime.Now,
                        State = "处理中",
                        WFNode = next,
                        WFInst = inst
                    };
                    mydb.WFInstNodes.Add(inode);
                    mydb.SaveChanges();
                    this.process(inode.ID, this.HttpContext);
                }
                else
                {
                }
            }
        }