public CPFlow GetFlowByFlowVerId(int flowVerId, bool isLoadFlowPhaseInfo, bool isLoadPhaseLinkInfo) { int nCount = 0; if (isLoadFlowPhaseInfo) { nCount++; } if (isLoadPhaseLinkInfo) { nCount++; } Expression <Func <CPFlow, dynamic> >[] eagerLoadingProperties = new Expression <Func <CPFlow, dynamic> > [nCount]; int nIndex = 0; if (isLoadFlowPhaseInfo) { eagerLoadingProperties[nIndex] = t => t.PhaseCol; nIndex++; } if (isLoadPhaseLinkInfo) { eagerLoadingProperties[nIndex] = t => t.PhaseLinkCol; nIndex++; } //ISpecification<CPFlow> specification; //specification = new ExpressionSpecification<CPFlow>(t => t.TreeCode.Equals(treeCode)); CPFlow flow = this._BaseCPFlowRep.Get(flowVerId, eagerLoadingProperties); return(flow); }
/// <summary> /// 根据配置信息获取流程首节点 /// </summary> /// <param name="flowVerId">流程版本ID</param> /// <returns>返回首节点,未找到返回空</returns> public CPFlowPhase GetFirstPhase(int flowVerId) { CPFlow flow = this.GetFlowByFlowVerId(flowVerId, true, true); if (flow.PhaseCol == null || flow.PhaseLinkCol.Count <= 0) { return(null); } CPFlowPhase phase = null; flow.PhaseCol.ForEach(t => { if (flow.PhaseLinkColSubmit.Where(c => c.EndPhaseId.Equals(t.PhaseId)).Count() <= 0) { phase = t; return; } }); return(phase); }
public bool UpdateFlow(CPFlow flow) { this._BaseCPFlowRep.Update(flow); return(true); }
public bool UpdateFlowByDesigner(CPFlowDesigner flowDesign, int flowVerId, string flowName, ref string errorMsg) { bool b = true; #region 先修改流程基本信息配置和节点和路径 CPFlow flow = this.GetFlowByFlowVerId(flowVerId, true, true); if (flow == null) { b = false; errorMsg = "根据FlowVerId[" + flowVerId + "]获取流程配置时,未取到配置信息"; return(b); } flow.FlowName = flowName; flow.CreateTime = DateTime.Now; #region 步阶段信息 List <CPFlowPhase> phaseColAdd = new List <CPFlowPhase>(); List <CPFlowPhase> phaseColUpdate = new List <CPFlowPhase>(); List <CPFlowPhase> phaseColDel = new List <CPFlowPhase>(); flow.PhaseCol.ForEach(t => { bool bIsDelete = true; CPFlowDesignerPhase dPhaseTmp = null; foreach (string key in flowDesign.states.Keys) { CPFlowDesignerPhase dPhase = flowDesign.states[key]; if (dPhase.props.temp1 != null && dPhase.props.temp1.value != null && string.IsNullOrEmpty(dPhase.props.temp1.value) == false && int.Parse(dPhase.props.temp1.value).Equals(t.PhaseId)) { dPhaseTmp = dPhase; bIsDelete = false; break; } } //看看是不是删除了 if (bIsDelete) { phaseColDel.Add(t); } else { //修改 t.PhaseType = dPhaseTmp.ConvertTypeToPhaseType(); t.PhaseName = dPhaseTmp.text.text; t.PositionX = Convert.ToDouble(dPhaseTmp.attr.x); t.PositionY = Convert.ToDouble(dPhaseTmp.attr.y); t.Width = Convert.ToDouble(dPhaseTmp.attr.width); t.Height = Convert.ToDouble(dPhaseTmp.attr.height); phaseColUpdate.Add(t); } }); //找出新增加的 foreach (string key in flowDesign.states.Keys) { // string phaseIdTmp = flowDesign.states[key].props.temp1.value;// key.Replace(designerPhasePre, ""); // if(flow.PhaseCol.Where(t=>t.PhaseId.Equals(int.Parse(phaseIdTmp))).Count()<=0) if (flowDesign.states[key].props.temp1 == null || string.IsNullOrEmpty(flowDesign.states[key].props.temp1.value)) { CPFlowDesignerPhase dPhase = flowDesign.states[key]; CPFlowPhase newPhase = new CPFlowPhase(); newPhase.FlowVerId = flow.FlowVerId; newPhase.PhaseType = dPhase.ConvertTypeToPhaseType(); newPhase.PhaseName = dPhase.text.text; newPhase.PositionX = Convert.ToDouble(dPhase.attr.x); newPhase.PositionY = Convert.ToDouble(dPhase.attr.y); newPhase.Width = Convert.ToDouble(dPhase.attr.width); newPhase.Height = Convert.ToDouble(dPhase.attr.height); phaseColAdd.Add(newPhase); } } phaseColDel.ForEach(t => { flow.PhaseCol.Remove(t); }); phaseColAdd.ForEach(t => { flow.PhaseCol.Add(t); }); try { //先删除下阶段相关信息 List <int> phaseIdCol = new List <int>(); phaseColDel.ForEach(t => { phaseIdCol.Add(t.PhaseId); }); this._BaseCPFlowRep.DeletePhase(phaseIdCol); flow.CreateTime = DateTime.Now;//为确保每次都调用保存数据库 this._BaseCPFlowRep.Update(flow); }catch (Exception ex) { b = false; errorMsg = "保存阶段信息时出错,详细信息为:" + ex.Message; return(b); } #endregion #region 步路径信息 List <CPFlowPhaseLink> linkColAdd = new List <CPFlowPhaseLink>(); List <CPFlowPhaseLink> linkColUpdate = new List <CPFlowPhaseLink>(); List <CPFlowPhaseLink> linkColDel = new List <CPFlowPhaseLink>(); //修改或删除 flow.PhaseLinkCol.ForEach(t => { bool bExists = false; CPFlowDesignerPhaseLink dLink = null; foreach (string key in flowDesign.paths.Keys) { CPFlowDesignerPhaseLink dLinkTmp = flowDesign.paths[key]; //if(dLink.from.Equals(designerPhasePre + t.StartPhaseId.ToString(),StringComparison.CurrentCultureIgnoreCase) //&& dLink.to.Equals(designerPhasePre + t.EndPhaseId.ToString(), StringComparison.CurrentCultureIgnoreCase) //) if (dLinkTmp.props.temp1 != null && dLinkTmp.props.temp1.value != null && string.IsNullOrEmpty(dLinkTmp.props.temp1.value) == false && int.Parse(dLinkTmp.props.temp1.value).Equals(t.LinkId) ) { bExists = true; dLink = dLinkTmp; break; } } if (bExists == false) { linkColDel.Add(t); } else { t.TipX = Convert.ToDouble(dLink.text.textPos.x); t.TipY = Convert.ToDouble(dLink.text.textPos.y); t.LinkDots = ""; dLink.dots.ForEach(dot => { if (string.IsNullOrEmpty(t.LinkDots)) { t.LinkDots = dot.x + "," + dot.y; } else { t.LinkDots += ";" + dot.x + "," + dot.y; } }); } }); //新加的 foreach (string key in flowDesign.paths.Keys) { CPFlowDesignerPhaseLink dLink = flowDesign.paths[key]; CPFlowDesignerPhase startPhaseDesigner = flowDesign.states[dLink.from]; CPFlowDesignerPhase endPhaseDesigner = flowDesign.states[dLink.to]; int startPhaseIdDesigner = 0; int endPhaseIdDesigner = 0; //看下这个节点是不是新加的 if (startPhaseDesigner.props.temp1 != null && startPhaseDesigner.props.temp1.value != null && string.IsNullOrEmpty(startPhaseDesigner.props.temp1.value) == false ) { startPhaseIdDesigner = int.Parse(startPhaseDesigner.props.temp1.value); } else { //新加的节点 List <CPFlowPhase> tColTmp = flow.PhaseCol.Where(t => t.PositionX.Equals(Convert.ToDouble(startPhaseDesigner.attr.x)) && t.PositionY.Equals(Convert.ToDouble(startPhaseDesigner.attr.y))).ToList(); startPhaseIdDesigner = tColTmp[0].PhaseId; } if (endPhaseDesigner.props.temp1 != null && endPhaseDesigner.props.temp1.value != null && string.IsNullOrEmpty(endPhaseDesigner.props.temp1.value) == false ) { endPhaseIdDesigner = int.Parse(endPhaseDesigner.props.temp1.value); } else { //说明开始节点是新加的,那就要根据定制器中新节点的X和Y去找对应数据库中的ID List <CPFlowPhase> tColTmp = flow.PhaseCol.Where(t => t.PositionX.Equals(Convert.ToDouble(endPhaseDesigner.attr.x)) && t.PositionY.Equals(Convert.ToDouble(endPhaseDesigner.attr.y))).ToList(); endPhaseIdDesigner = tColTmp[0].PhaseId; } if (flow.PhaseLinkCol.Where(t => t.StartPhaseId.Equals(startPhaseIdDesigner) && t.EndPhaseId.Equals(endPhaseIdDesigner)).Count() <= 0) { CPFlowPhaseLink linkNew = new CPFlowPhaseLink(); linkNew.FlowVerId = flow.FlowVerId; linkNew.StartPhaseId = startPhaseIdDesigner; linkNew.EndPhaseId = endPhaseIdDesigner; linkNew.TipX = Convert.ToDouble(dLink.text.textPos.x); linkNew.TipY = Convert.ToDouble(dLink.text.textPos.y); linkNew.LinkDots = ""; dLink.dots.ForEach(dot => { if (string.IsNullOrEmpty(linkNew.LinkDots)) { linkNew.LinkDots = dot.x + "," + dot.y; } else { linkNew.LinkDots += ";" + dot.x + "," + dot.y; } }); if (dLink.props == null || dLink.props.PathType == null || string.IsNullOrEmpty(dLink.props.PathType.value)) { linkNew.LinkType = CPFlowEnum.LinkTypeEnum.Submit; } else { if (dLink.props.PathType.value.Trim().Equals("1")) { linkNew.LinkType = CPFlowEnum.LinkTypeEnum.Submit; } else if (dLink.props.PathType.value.Trim().Equals("2")) { linkNew.LinkType = CPFlowEnum.LinkTypeEnum.Fallback; } else { linkNew.LinkType = CPFlowEnum.LinkTypeEnum.Submit; } } linkColAdd.Add(linkNew); } } linkColDel.ForEach(t => { flow.PhaseLinkCol.Remove(t); }); linkColAdd.ForEach(t => { flow.PhaseLinkCol.Add(t); }); try { flow.CreateTime = DateTime.Now;//为确保每次都调用保存数据库 this._BaseCPFlowRep.Update(flow); } catch (Exception ex) { b = false; errorMsg = "保存阶段路径信息时出错,详细信息为:" + ex.Message; return(b); } #endregion #endregion return(b); }