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 })); }
public ActionResult addNodeExpression() { string templateId = Request.Form["templateId"]; string from = Request.Form["from"]; string to = Request.Form["to"]; string Expression = Request.Form["Expression"]; string Description = Request.Form["Description"]; int OrderNO = int.Parse(Request.Form["OrderNO"]); if (Session[templateId] != null) { MyDB mydb = Session[templateId] as MyDB; WFTemplate template = mydb.WFTemplates.Find(templateId); WFNodeExpression expression = new WFNodeExpression { ID = Guid.NewGuid().ToString(), Expression = string.IsNullOrEmpty(Expression) ? "1==1" : Expression, Description = Description, OrderNO = OrderNO, WFNode = mydb.WFNodeXORSplits.Find(from), Next = mydb.WFNodes.Find(to) }; mydb.WFNodeExpressions.Add(expression); return(Json(new { success = true, data = expression.ID })); } return(Json(new { success = false })); }
// public ActionResult addNodeAction() { string templateId = Request.Form["templateId"]; string from = Request.Form["from"]; string to = Request.Form["to"]; string Name = Request.Form["Name"]; string Code = Request.Form["Code"]; if (Session[templateId] != null) { MyDB mydb = Session[templateId] as MyDB; WFTemplate template = mydb.WFTemplates.Find(templateId); WFNodeAction action = new WFNodeAction { ID = Guid.NewGuid().ToString(), Code = Code, Name = Name, WFNode = mydb.WFNodeHandles.Find(from), NextNode = mydb.WFNodes.Find(to) }; mydb.WFNodeActions.Add(action); return(Json(new { success = true, data = action.ID })); } return(Json(new { success = false })); }
/// <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)); } }
public ActionResult addNodeHandle() { string templateId = Request.Form["templateId"]; string id = Request.Form["id"]; string Name = Request.Form["Name"]; string ViewCode = Request.Form["ViewCode"]; bool IsCountersign = Request.Form["IsCountersign"] != null; string[] Handlers = Request.Form["Handlers"].Split(",".ToCharArray()); 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); WFNodeHandle node = new WFNodeHandle { ID = Guid.NewGuid().ToString(), PositionX = x, PositionY = y, Name = Name, ViewCode = ViewCode, IsCountersign = IsCountersign, WFTemplate = template, Subjects = mydb.Subjects.Where(s => Handlers.Contains(s.ID)).ToArray() }; mydb.WFNodeHandles.Add(node); return(Json(new { success = true, data = node.ID })); } return(Json(new { success = false })); }
public ActionResult saveWFTemplate() { string id = Request.Form["id"]; string Name = Request.Form["Name"]; string BuizCode = Request.Form["BuizCode"]; string BuizName = Request.Form["BuizName"]; using (MyDB mydb = new MyDB()) { WFNodeFinish finish = new WFNodeFinish { ID = Guid.NewGuid().ToString(), Name = "结束节点", PositionX = 200, PositionY = 40 }; WFTemplate wft = new WFTemplate { ID = Guid.NewGuid().ToString(), Name = Name, BuizCode = BuizCode, BuizName = BuizName, Creator = mydb.Users.Find(this.User.Identity.Name), CreateTime = DateTime.Now, Nodes = new WFNode[] { new WFNodeStart { ID = Guid.NewGuid().ToString(), PositionX = 100, PositionY = 40, Name = "开始节点", Next = finish }, finish } }; mydb.WFTemplates.Add(wft); mydb.SaveChanges(); return(Json(new { success = true })); } }
/// <summary> /// 取模板,准备编辑,上下文在于session中 /// </summary> /// <returns></returns> public ActionResult getTemplate() { string id = Request.Params["templateId"]; //if (Session[id] == null) Session[id] = new MyDB(); MyDB mydb = Session[id] as MyDB; WFTemplate template = mydb.WFTemplates.Find(id); return(Json( new { success = true, data = new { template.ID, template.Name, template.BuizCode, template.BuizName, template.OffsetX, template.OffsetY, nodes = template.Nodes.Select(n => new { n.ID, name = n.Name, type = n.ExtType, position = new { x = n.PositionX, y = n.PositionY } }).ToArray(), lines = template.Nodes.SelectMany(n => n.FromActions) .Where(a => a.NextNode != null) .Select(a => new { a.ID, name = a.Name, from = a.WFNode.ID, to = a.NextNode.ID, middlePoint = a.PositionX != null && a.PositionY != null ? new { x = a.PositionX, y = a.PositionY } : null }) .Union( template.Nodes.SelectMany(n => n.FromExpressions) .Select(e => new { e.ID, name = string.Format("[{0}]{1}", e.OrderNO, e.Expression), from = e.WFNode.ID, to = e.Next.ID, middlePoint = e.PositionX != null && e.PositionY != null ? new { x = e.PositionX, y = e.PositionY } : null }) ) .Union( template.Nodes.OfType <WFNodeStart>() .Select(s => new { s.ID, name = "", from = s.ID, to = s.Next.ID, middlePoint = false ? new { x = null as int?, y = null as int? } : null //注意int?与int不是同一种类型,上面的是int?,这里必须也是int? }) ) .ToArray() } }, JsonRequestBehavior.AllowGet )); }
public ActionResult modifyTemplate() { string id = Request.Params["templateId"]; string mode = Request.Params["mode"]; if (Session[id] == null) { Session[id] = new MyDB(); } MyDB mydb = Session[id] as MyDB; switch (mode) { case "select": { if (Request.Params["nodeID"] != null) { string nodeID = Request.Params["nodeID"]; int x = int.Parse(Request.Params["x"]); int y = int.Parse(Request.Params["y"]); WFNode node = mydb.WFNodes.Find(nodeID); node.PositionX = x; node.PositionY = y; } else if (Request.Params["lineID"] != null) { string LineID = Request.Params["lineID"]; if (string.IsNullOrEmpty(Request.Params["x"]) || string.IsNullOrEmpty(Request.Params["y"])) { WFNodeAction action = mydb.WFNodeActions.Find(LineID); if (action != null) { action.PositionX = null; action.PositionY = null; } WFNodeExpression expression = mydb.WFNodeExpressions.Find(LineID); if (expression != null) { expression.PositionX = null; expression.PositionY = null; } } else { int x = int.Parse(Request.Params["x"]); int y = int.Parse(Request.Params["y"]); WFNodeAction action = mydb.WFNodeActions.Find(LineID); if (action != null) { action.PositionX = x; action.PositionY = y; } WFNodeExpression expression = mydb.WFNodeExpressions.Find(LineID); if (expression != null) { expression.PositionX = x; expression.PositionY = y; } } } } break; case "move": { int x = int.Parse(Request.Params["x"]); int y = int.Parse(Request.Params["y"]); WFTemplate t = mydb.WFTemplates.Find(id); t.OffsetX = x; t.OffsetY = y; } break; default: break; } return(Json(new { success = true })); }
public void InitData() { clear(); using (MyDB mydb = new MyDB()) { WFTemplate wft = new WFTemplate { ID = Guid.NewGuid().ToString(), Name = "费用申请流程", BuizCode = "ApplyExpense", BuizName = "费用申请", Creator = mydb.Users.First(u => u.Code.Equals("chw")), CreateTime = DateTime.Now, Nodes = new WFNode[] { new WFNodeStart { Name = "开始", Next = null }, new WFNodeHandle { Name = "创建申请", ViewCode = "createForm", ViewName = "创建表单", Actions = new [] { new WFNodeAction { Code = "save", Name = "保存", NextNode = null //为空表示仍在停留在此节点中 }, new WFNodeAction { Code = "submit", Name = "提交", NextNode = null //这个不应该为NULL,但所需的节点还未创建 }, }, Subjects = new [] { mydb.Users.First(u => u.Code.Equals("chw")), mydb.Users.First(u => u.Code.Equals("lilin")) } }, new WFNodeHandle { Name = "部门确认", ViewCode = "auditForm", ViewName = "审核表单", Actions = new [] { new WFNodeAction { Code = "pass", Name = "确认", NextNode = null //为空表示仍在停留在此节点中 }, new WFNodeAction { Code = "deny", Name = "否决", NextNode = null //这个不应该为NULL,但所需的节点还未创建 }, }, Subjects = new [] { mydb.Users.First(u => u.Code.Equals("chw")) } }, new WFNodeHandle { Name = "副总审核", ViewCode = "auditForm", ViewName = "审核表单", Actions = new [] { new WFNodeAction { Code = "pass", Name = "确认", NextNode = null //为空表示仍在停留在此节点中 }, new WFNodeAction { Code = "deny", Name = "否决", NextNode = null //这个不应该为NULL,但所需的节点还未创建 }, }, Subjects = new [] { mydb.Users.First(u => u.Code.Equals("chw")) } }, new WFNodeXORSplit { Name = "费用金额分支", //Next = null, //缺省节点 WFNodeExpressions = new [] { new WFNodeExpression { Expression = "{费用金额}>10000", Description = "费用金额大于10000元时,需要总经理审核", Next = null, OrderNO = 1 }, new WFNodeExpression { Expression = "{费用金额}>5000", Description = "费用金额大于5000元时,需要通知监察科", Next = null, OrderNO = 3 } } }, new WFNodeHandle { Name = "总经理审核", ViewCode = "auditForm", ViewName = "审核表单", Actions = new [] { new WFNodeAction { Code = "pass", Name = "同意", NextNode = null //为空表示仍在停留在此节点中 }, new WFNodeAction { Code = "deny", Name = "不同意", NextNode = null //这个不应该为NULL,但所需的节点还未创建 }, }, Subjects = new [] { mydb.Users.First(u => u.Code.Equals("lxx")) } }, new WFNodeFinish { ID = Guid.NewGuid().ToString(), Name = "结束" } } }; mydb.WFTemplates.Add(wft); wft.Nodes.OfType <WFNodeStart>().First().Next = wft.Nodes.First(n => n.Name.Equals("创建申请")); wft.Nodes.OfType <WFNodeHandle>().First(n => n.Name.Equals("创建申请")).Actions.First(a => a.Code.Equals("submit")).NextNode = wft.Nodes.First(n => n.Name.Equals("部门确认")); wft.Nodes.OfType <WFNodeHandle>().First(n => n.Name.Equals("部门确认")).Actions.First(a => a.Code.Equals("pass")).NextNode = wft.Nodes.First(n => n.Name.Equals("副总审核")); wft.Nodes.OfType <WFNodeHandle>().First(n => n.Name.Equals("部门确认")).Actions.First(a => a.Code.Equals("deny")).NextNode = wft.Nodes.OfType <WFNodeFinish>().First(); wft.Nodes.OfType <WFNodeHandle>().First(n => n.Name.Equals("副总审核")).Actions.First(a => a.Code.Equals("pass")).NextNode = wft.Nodes.First(n => n.Name.Equals("费用金额分支")); wft.Nodes.OfType <WFNodeHandle>().First(n => n.Name.Equals("副总审核")).Actions.First(a => a.Code.Equals("deny")).NextNode = wft.Nodes.OfType <WFNodeFinish>().First(); //wft.Nodes.OfType<WFNodeXORSplit>().First(n => n.Name.Equals("费用金额分支")).Next = wft.Nodes.OfType<WFNodeFinish>().First(); wft.Nodes.OfType <WFNodeXORSplit>().First(n => n.Name.Equals("费用金额分支")).WFNodeExpressions.First(exp => exp.Expression.Equals("{费用金额}>10000")).Next = wft.Nodes.First(n => n.Name.Equals("总经理审核")); wft.Nodes.OfType <WFNodeXORSplit>().First(n => n.Name.Equals("费用金额分支")).WFNodeExpressions.First(exp => exp.Expression.Equals("{费用金额}>5000")).Next = wft.Nodes.First(n => n.Name.Equals("总经理审核")); wft.Nodes.OfType <WFNodeHandle>().First(n => n.Name.Equals("总经理审核")).Actions.First(a => a.Code.Equals("pass")).NextNode = wft.Nodes.OfType <WFNodeFinish>().First(); wft.Nodes.OfType <WFNodeHandle>().First(n => n.Name.Equals("总经理审核")).Actions.First(a => a.Code.Equals("deny")).NextNode = wft.Nodes.OfType <WFNodeFinish>().First(); try { mydb.SaveChanges(); } catch (Exception e) { } } }
/// <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")); }
// // GET: /workflow/Instance/ public Type getType(WFTemplate template) { //System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFrom(Server.MapPath("~/bin/EntityObjectLib.dll")); System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFrom(Server.MapPath("~/bin/RTBuizModel.dll")); return(ass.GetType("EntityObjectLib." + template.BuizCode)); }
public void Append() { using (MyDB mydb = new MyDB()) { WFTemplate template = new WFTemplate { ID = Guid.NewGuid().ToString(), BuizCode = "GenericBuiz", BuizName = "通用业务", Name = "通用业务模板一", Creator = mydb.Users.First(u => u.Code == "chw"), CreateTime = DateTime.Now }; mydb.WFTemplates.Add(template); GenericModel model = new GenericModel { Name = "test1", Model = @"[ {code:'ID',name:'ID',type:'string'}, {code:'amount',name:'申请金额(元)',type:'numeric'}, {code:'description',name:'申请说明',type:'string'}, {code:'applyTime',name:'申请时间',type:'date'}, {code:'detail',name:'明细',type:'array',ctype:[ {code:'ID',name:'ID',type:'string'}, {code:'item',name:'项目',type:'string'}, {code:'item',name:'费用(元)',type:'numeric'}, ] } ]", Views = new[] { new GenericView { Name = "view1", Content = @"<script type='text/javascript'> var data={}; </script> <input type='hidden' name='ID' id='ID' value=''/> <table border='1'> <tr> <td><span>申请金额(元)</span></td><td><input type='text' name='amount' id='amount' value=''/></td></tr> <tr> <td><span>申请说明</span></td><td><input type='text' name='description' id='description' value=''/></td></tr> <tr> <td><span>申请时间</span></td><td><input type='text' name='applyTime' id='applyTime' value=''/></td> </tr> </table> <!--以下是明细-->" }, new GenericView { Name = "view2", Content = "" } }, Buizs = new[] { new GenericBuiz { Name = "业务实例1", Data = "", Creator = mydb.Users.First(u => u.Code == "chw"), WFTemplate = template }, new GenericBuiz { Name = "业务实例2", Data = "", Creator = mydb.Users.First(u => u.Code == "chw"), WFTemplate = template } } }; mydb.GenericModels.Add(model); mydb.SaveChanges(); } }