void showFlowchar(WFNode node) { this.Background = System.Windows.Media.Brushes.Red; Canvas.SetLeft(this, node.ShapeSize.x); Canvas.SetTop(this, node.ShapeSize.y); this.Width = node.ShapeSize.width; this.Height = node.ShapeSize.height; this.displayName.Text = node.DisplayName; }
/// <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 { } } }
/// <summary> /// 获取流程节点信息 /// </summary> /// <param name="nodeId">节点id</param> public static void RetrieveWFNode(int nodeId) { try { CurrentNode = new WFNode(nodeId); } catch (Exception ex) { throw new Exception("获取流程节点时出现错误", ex); } }
/// <summary> /// 登陆 /// </summary> /// <param name="emp"></param> public static void Sigin(Emp emp) { isLogin = true; No = emp.No; Name = emp.Name; FK_Dept = emp.FK_Dept; DoType = ""; CurrentNode = null; //置空 GetFtpInfomation(); WriterIt(); }
public ActionResult deleteNode() { string templateId = Request.Form["templateId"]; string nodeID = Request.Form["nodeID"]; if (Session[templateId] != null) { MyDB mydb = Session[templateId] as MyDB; WFNode node = mydb.WFNodes.Find(nodeID); mydb.WFNodes.Remove(node); return(Json(new { success = true })); } return(Json(new { success = false })); }
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 static FlowcharStruct getFlowcharStruct(string xaml) { char[] sp = { ',' }; char[] sl = { ' ' }; //(1) FlowcharStruct flowcharStruct = new FlowcharStruct(); //(2) DynamicActivity dynamicActivity = tool.activityByXaml(xaml) as DynamicActivity; Activity activity = tool.getImplementation(dynamicActivity); Flowchart flowchar = activity as Flowchart; if (flowchar == null) { return(null); } //(3)===================================== //(3.1)---------------------------------------------------------------------------------- flowcharStruct.beginNode.DisplayName = "开始"; flowcharStruct.beginNode.id = "begin"; //(3.1.1) if (WorkflowViewStateService.GetViewState(flowchar)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowchar)["ShapeLocation"].ToString(); flowcharStruct.beginNode.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); flowcharStruct.beginNode.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.1.2) if (WorkflowViewStateService.GetViewState(flowchar)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowchar)["ShapeSize"].ToString(); flowcharStruct.beginNode.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); flowcharStruct.beginNode.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.1.3) if (WorkflowViewStateService.GetViewState(flowchar)["ConnectorLocation"] != null) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowchar)["ConnectorLocation"].ToString(); string[] points = ConnectorLocation.Split(sl); WFLine oneline = new WFLine(); oneline.beginNodeID = flowchar.Id; oneline.text = flowchar.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); oneline.connectorPoint.Add(new WFPoint() { x = x, y = y }); } flowcharStruct.lineList.Add(oneline); } //(3.2)-------------------------------------------------------------------------------- foreach (FlowNode flowNode in flowchar.Nodes) { FlowStep flowStep = flowNode as FlowStep; if (flowStep != null) { WFNode node = new WFNode(); node.DisplayName = flowStep.Action.DisplayName; node.id = flowStep.Action.Id; //(3.2.1) if (WorkflowViewStateService.GetViewState(flowStep)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowStep)["ShapeLocation"].ToString(); node.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); node.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.2.2) if (WorkflowViewStateService.GetViewState(flowStep)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowStep)["ShapeSize"].ToString(); node.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); node.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.2.3) if (WorkflowViewStateService.GetViewState(flowStep).Count(p => p.Key == "ConnectorLocation") == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowStep)["ConnectorLocation"].ToString(); string[] points = ConnectorLocation.Split(sl); WFLine line = new WFLine(); line.beginNodeID = flowStep.Action.Id; line.text = flowStep.Action.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WFPoint() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } flowcharStruct.nodeList.Add(node); } } //(3.3)------------------------------------------------------------- foreach (FlowNode flowNode in flowchar.Nodes) { FlowSwitch <string> flowSwitch = flowNode as FlowSwitch <string>; if (flowSwitch != null) { WFNode node = new WFNode(); node.DisplayName = flowSwitch.Expression.DisplayName; node.id = flowSwitch.Expression.Id; //(3.3.1) if (WorkflowViewStateService.GetViewState(flowSwitch)["ShapeLocation"] != null) { string ShapeLocation = WorkflowViewStateService.GetViewState(flowSwitch)["ShapeLocation"].ToString(); node.ShapeSize.x = double.Parse(ShapeLocation.Split(sp)[0]); node.ShapeSize.y = double.Parse(ShapeLocation.Split(sp)[1]); } //(3.3.2) if (WorkflowViewStateService.GetViewState(flowSwitch)["ShapeSize"] != null) { string ShapeSize = WorkflowViewStateService.GetViewState(flowSwitch)["ShapeSize"].ToString(); node.ShapeSize.width = double.Parse(ShapeSize.Split(sp)[0]); node.ShapeSize.height = double.Parse(ShapeSize.Split(sp)[1]); } //(3.3.3) if (WorkflowViewStateService.GetViewState(flowSwitch).Count(p => p.Key == "Default") == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowSwitch)["Default"].ToString(); string[] points = ConnectorLocation.Split(sl); WFLine line = new WFLine(); line.beginNodeID = flowSwitch.Expression.Id; line.text = flowSwitch.Expression.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WFPoint() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } //(3.3.4) foreach (var v in flowSwitch.Cases) { FlowNode next = v.Value; Console.WriteLine(v.Key); string caseValue = v.Key + "Connector"; if (WorkflowViewStateService.GetViewState(flowSwitch).Count(p => p.Key == caseValue) == 1) { string ConnectorLocation = WorkflowViewStateService.GetViewState(flowSwitch)[caseValue].ToString(); string[] points = ConnectorLocation.Split(sl); WFLine line = new WFLine(); line.beginNodeID = flowSwitch.Expression.Id; line.text = flowSwitch.Expression.DisplayName; foreach (string item in points) { double x = double.Parse(item.Split(sp)[0]); double y = double.Parse(item.Split(sp)[1]); line.connectorPoint.Add(new WFPoint() { x = x, y = y }); } flowcharStruct.lineList.Add(line); } } flowcharStruct.nodeList.Add(node); } } return(flowcharStruct); }//end
/// <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 { } } }
public NodeControl(WFNode node) { InitializeComponent(); showFlowchar(node); }