public async Task <ActionResult> Save(RouteViewModel model) { using (RouteServiceClient client = new RouteServiceClient()) { Route obj = new Route() { Key = model.Name, Status = model.Status, RouteType = model.RouteType, Description = model.Description, Editor = User.Identity.Name, EditTime = DateTime.Now, CreateTime = DateTime.Now, Creator = User.Identity.Name }; MethodReturnResult rst = await client.AddAsync(obj); if (rst.Code == 0) { rst.Message = string.Format(FMMResources.StringResource.Route_Save_Success , model.Name); } return(Json(rst)); } }
public async Task <ActionResult> SaveCopy(RouteViewModel model) { Route obj = new Route() { Key = model.Name, RouteType = model.RouteType, Status = model.Status, Description = model.Description, Creator = User.Identity.Name, CreateTime = DateTime.Now, Editor = User.Identity.Name, EditTime = DateTime.Now }; MethodReturnResult result = new MethodReturnResult(); using (RouteServiceClient client = new RouteServiceClient()) { result = await client.AddAsync(obj); if (result.Code == 0) { result.Message = "复制工艺流程主体成功"; StringBuilder where = new StringBuilder(); using (RouteStepServiceClient routeStepServiceClient = new RouteStepServiceClient()) { where.AppendFormat(" Key.RouteName ='{0}'", model.ParentName); PagingConfig cfg = new PagingConfig() { IsPaging = false, OrderBy = "SortSeq", Where = where.ToString() }; MethodReturnResult <IList <RouteStep> > routeStep = routeStepServiceClient.Get(ref cfg); if (routeStep.Code == 0) { List <RouteStep> listOfRouteStep = routeStep.Data.ToList <RouteStep>(); foreach (RouteStep itemOfRouteStep in listOfRouteStep) { #region 制工步信息 RouteStep objRouteStep = new RouteStep() { Key = new RouteStepKey() { RouteName = model.Name, RouteStepName = itemOfRouteStep.Key.RouteStepName }, DefectReasonCodeCategoryName = itemOfRouteStep.DefectReasonCodeCategoryName, Duration = itemOfRouteStep.Duration, ScrapReasonCodeCategoryName = itemOfRouteStep.ScrapReasonCodeCategoryName, SortSeq = itemOfRouteStep.SortSeq, RouteOperationName = itemOfRouteStep.RouteOperationName, Description = itemOfRouteStep.Description, Editor = User.Identity.Name, EditTime = DateTime.Now, CreateTime = DateTime.Now, Creator = User.Identity.Name }; MethodReturnResult rstOfRouteStep = await routeStepServiceClient.AddAsync(objRouteStep); if (rstOfRouteStep.Code != 0) { result.Code = 1001; result.Message = "复制工步信息失败" + rstOfRouteStep.Message; return(Json(result)); } #endregion #region 制工步参数 using (RouteStepParameterServiceClient routeStepParameterServiceClient = new RouteStepParameterServiceClient()) { #region 除新增工艺流程工步带过来的工步参数 cfg = new PagingConfig() { Where = string.Format(" Key.RouteName='{0}' AND Key.RouteStepName = '{1}'" , model.Name , itemOfRouteStep.Key.RouteStepName), OrderBy = "ParamIndex" }; MethodReturnResult <IList <RouteStepParameter> > routeStepParameterNewAdd = routeStepParameterServiceClient.Get(ref cfg); if (routeStepParameterNewAdd.Code == 0) { List <RouteStepParameter> listOfRouteStepParameterNewAdd = routeStepParameterNewAdd.Data.ToList <RouteStepParameter>(); foreach (RouteStepParameter itemOfRouteStepParameterNewAdd in listOfRouteStepParameterNewAdd) { MethodReturnResult rstOfRouteStepParameterNewAdd = routeStepParameterServiceClient.Delete(itemOfRouteStepParameterNewAdd.Key); if (rstOfRouteStepParameterNewAdd.Code != 0) { result.Code = 1001; result.Message = "删除初始工步参数信息失败" + rstOfRouteStepParameterNewAdd.Message; return(Json(result)); } } } #endregion #region 制工步参数 cfg = new PagingConfig() { Where = string.Format(" Key.RouteName='{0}' AND Key.RouteStepName = '{1}'" , model.ParentName , itemOfRouteStep.Key.RouteStepName), OrderBy = "ParamIndex" }; MethodReturnResult <IList <RouteStepParameter> > routeStepParameter = routeStepParameterServiceClient.Get(ref cfg); if (routeStepParameter.Code == 0) { List <RouteStepParameter> listOfRouteStepParameter = routeStepParameter.Data.ToList <RouteStepParameter>(); foreach (RouteStepParameter itemOfRouteStepParameter in listOfRouteStepParameter) { RouteStepParameter objRouteStepParameter = new RouteStepParameter() { Key = new RouteStepParameterKey() { RouteName = model.Name, RouteStepName = itemOfRouteStepParameter.Key.RouteStepName, ParameterName = itemOfRouteStepParameter.Key.ParameterName }, MaterialType = itemOfRouteStepParameter.MaterialType, DataFrom = itemOfRouteStepParameter.DataFrom, DataType = itemOfRouteStepParameter.DataType, DCType = itemOfRouteStepParameter.DCType, IsDeleted = itemOfRouteStepParameter.IsDeleted, IsMustInput = itemOfRouteStepParameter.IsMustInput, IsReadOnly = itemOfRouteStepParameter.IsReadOnly, IsUsePreValue = itemOfRouteStepParameter.IsUsePreValue, ParamIndex = itemOfRouteStepParameter.ParamIndex, ValidateFailedMessage = itemOfRouteStepParameter.ValidateFailedMessage, ValidateFailedRule = itemOfRouteStepParameter.ValidateFailedRule, ValidateRule = itemOfRouteStepParameter.ValidateRule, Editor = User.Identity.Name, EditTime = DateTime.Now, }; MethodReturnResult rstOfRouteStepParameter = await routeStepParameterServiceClient.AddAsync(objRouteStepParameter); if (rstOfRouteStepParameter.Code != 0) { result.Code = 1001; result.Message = "复制工步参数信息失败" + rstOfRouteStepParameter.Message; return(Json(result)); } } } #endregion } #endregion #region 制工步属性 using (RouteStepAttributeServiceClient routeStepAttributeServiceClient = new RouteStepAttributeServiceClient()) { #region 除新增工艺流程工步带过来的工步属性 cfg = new PagingConfig() { Where = string.Format(" Key.RouteName='{0}' AND Key.RouteStepName = '{1}'" , model.Name , itemOfRouteStep.Key.RouteStepName), OrderBy = "Key.AttributeName" }; MethodReturnResult <IList <RouteStepAttribute> > routeStepAttributeNewAdd = routeStepAttributeServiceClient.Get(ref cfg); if (routeStepAttributeNewAdd.Code == 0) { List <RouteStepAttribute> listOfRouteStepAttributeNewAdd = routeStepAttributeNewAdd.Data.ToList <RouteStepAttribute>(); foreach (RouteStepAttribute itemOfRouteStepAttributeNewAdd in listOfRouteStepAttributeNewAdd) { MethodReturnResult rstOfRouteStepAttributeNewAdd = routeStepAttributeServiceClient.Delete(itemOfRouteStepAttributeNewAdd.Key); if (rstOfRouteStepAttributeNewAdd.Code != 0) { result.Code = 1001; result.Message = "删除初始工步属性信息失败" + rstOfRouteStepAttributeNewAdd.Message; return(Json(result)); } } } #endregion #region 制工步属性 cfg = new PagingConfig() { Where = string.Format(" Key.RouteName='{0}' AND Key.RouteStepName = '{1}'" , model.ParentName , itemOfRouteStep.Key.RouteStepName), OrderBy = "Key.AttributeName" }; MethodReturnResult <IList <RouteStepAttribute> > routeStepAttribute = routeStepAttributeServiceClient.Get(ref cfg); if (routeStepAttribute.Code == 0) { List <RouteStepAttribute> listOfRouteStepAttribute = routeStepAttribute.Data.ToList <RouteStepAttribute>(); foreach (RouteStepAttribute itemOfRouteStepAttribute in listOfRouteStepAttribute) { RouteStepAttribute objRouteStepAttribute = new RouteStepAttribute() { Key = new RouteStepAttributeKey() { RouteName = model.Name, RouteStepName = itemOfRouteStepAttribute.Key.RouteStepName, AttributeName = itemOfRouteStepAttribute.Key.AttributeName }, Value = itemOfRouteStepAttribute.Value, Editor = User.Identity.Name, EditTime = DateTime.Now, }; MethodReturnResult rstOfRouteStepAttribute = await routeStepAttributeServiceClient.AddAsync(objRouteStepAttribute); if (rstOfRouteStepAttribute.Code != 0) { result.Code = 1001; result.Message = "复制工步属性信息失败" + rstOfRouteStepAttribute.Message; return(Json(result)); } } } #endregion } #endregion } result.Message += " \r\n 复制工艺流程工步参数及工步属性成功"; } } } } return(Json(result)); }