public ActionResult addNodeXOR() { string templateId = Request.Form["templateId"]; string id = Request.Form["id"]; string Name = Request.Form["Name"]; int x = int.Parse(Request.Form["x"]); int y = int.Parse(Request.Form["y"]); if (Session[templateId] != null) { MyDB mydb = Session[templateId] as MyDB; WFTemplate template = mydb.WFTemplates.Find(templateId); WFNodeXORSplit node = new WFNodeXORSplit { ID = Guid.NewGuid().ToString(), PositionX = x, PositionY = y, Name = Name, WFTemplate = template }; mydb.WFNodeXORSplits.Add(node); return(Json(new { success = true, data = node.ID })); } return(Json(new { success = false })); }
/// <summary> /// 处理当前流程实例节点 /// 1.判断节点类型 /// 2.如果是处理节点,则取活动CODE,找到下一个节点,调用推入 /// 3.如果是分支节点,则计算表达式,找到下一个节点,调用推入 /// 4.如果是结束节点,完成结束必须的工作 /// </summary> /// <param name="instNodeID">当前流程实例节点ID</param> /// <param name="ctx">HTTP上下文</param> private void process(string instNodeID, HttpContextBase ctx) { using (MyDB mydb = new MyDB()) { WFInstNode current = mydb.WFInstNodes.Find(instNodeID); WFInst inst = current.WFInst; if (current.WFNode is WFNodeHandle) { string actionID = Request.Form["actionID"]; string UserID = ctx.User.Identity.Name; WFNodeAction action = mydb.WFNodeActions.Find(actionID); WFNode next = action.NextNode; if (next != null) { Type t = getType(inst.WFTemplate); PropertyInfo[] PropertyInfos = t.GetProperties().ToArray(); foreach (string key in Request.Form.Keys) { PropertyInfo pi = t.GetProperty(key); if (pi != null) { DisplayAttribute[] attrs = pi.GetCustomAttributes(typeof(DisplayAttribute), true) as DisplayAttribute[]; if (attrs.Length > 0) { pi.SetValue( inst, //Request.Form[key], Convert.ChangeType(Request.Form[key], pi.PropertyType.UnderlyingSystemType), null); } } } // 当前节点处理完成,准备转入下一节点 current.State = "已处理"; current.LeaveTime = DateTime.Now; current.Summary = string.Format("节点名称:{0},处理人:{1},动作:{2}", current.WFNode.Name, mydb.Subjects.Find(UserID).Name, action.Name); // 节点处理人 WFInstNodeHandler handler = current.WFInstNodeHandlers.First(h => h.Handler.ID.Equals(UserID)); handler.HandleTime = DateTime.Now; handler.Opinion = action.Name; handler.State = "已处理"; // 其他的处理人置为失效 foreach (WFInstNodeHandler other in current.WFInstNodeHandlers.Where(h => !h.Handler.ID.Equals(UserID))) { handler.State = "已失效"; } mydb.SaveChanges(); this.entry(inst.ID, next.ID, ctx); return; } } else if (current.WFNode is WFNodeXORSplit) { WFNodeXORSplit Split = current.WFNode as WFNodeXORSplit; Type t = getType(inst.WFTemplate); PropertyInfo[] PropertyInfos = t.GetProperties().ToArray(); IEnumerable <WFNodeExpression> exps = Split.WFNodeExpressions.OrderBy(exp => exp.OrderNO).Select(exp => exp); foreach (WFNodeExpression exp in exps) { string expString = exp.Expression; foreach (PropertyInfo pi in PropertyInfos) { DisplayAttribute[] attrs = pi.GetCustomAttributes(typeof(DisplayAttribute), true) as DisplayAttribute[]; if (attrs.Length > 0) { string Name = attrs[0].Name; expString = expString.Replace( string.Format("{{{0}}}", Name), pi.Name ); } } expString = string.Format("select count(*) as v from {2}s where ID=\"{0}\" and {1}", current.WFInst.ID, expString, inst.WFTemplate.BuizCode); //int count = mydb.WFInsts.Where(expString).Count(); int count = mydb.Database.SqlQuery <int>(expString, new object[] { }).ToArray()[0]; if (count > 0)// 条件满足,短路,找下一节点 { current.Summary = string.Format("节点名称:{0},满足条件:{1}", current.WFNode.Name, exp.Expression); current.LeaveTime = DateTime.Now; current.State = "已处理"; mydb.SaveChanges(); this.entry(inst.ID, exp.Next.ID, ctx); return; } } } else if (current.WFNode is WFNodeFinish) { current.Summary = "流程结束"; current.LeaveTime = DateTime.Now; current.State = "已处理"; inst.State = "已处理"; mydb.SaveChanges(); return; } else { } } }