/// <summary> /// URL: /workflow/Instance/create/id /// id: 模板ID /// 发起流程 /// </summary> /// <returns></returns> public ActionResult create(string id) { using (MyDB mydb = new MyDB()) { WFTemplate template = mydb.WFTemplates.Find(id); WFNodeStart start = template.Nodes.OfType <WFNodeStart>().First(); WFNodeHandle next = start.Next as WFNodeHandle; if (next is WFNodeHandle) { ((WFNodeHandle)next).Actions.Select(a => a); } Type t = getType(template); EntityObjectLib.WFInst inst = Activator.CreateInstance(t) as EntityObjectLib.WFInst; inst.WFTemplate = template; inst.State = "处理中"; inst.WFInstNodes = new WFInstNode[] { new WFInstNode { WFNode = next, State = "处理中", EntryTime = DateTime.Now, WFInst = inst } }; // 这里有一个设计约束:开始节点后一定是个处理节点 return(View("toHandle", inst.CurrentNode)); } }
/// <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")); }