public Result PostSet([FromBody] MonitoringKanBanSet set) { if (set.UI <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetSecondError)); } if (set.Second <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetSecondError)); } if (set.Type == KanBanEnum.设备状态看板) { if (set.Row <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetRowError)); } if (set.Col <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetColError)); } if (set.Length <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetLengthError)); } if (set.VariableList.Count == 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetVariableError)); } if (set.VariableList.Any()) { if (set.VariableList.GroupBy(x => new { x.Order, x.SubOrder }).Any(x => x.Count() > 1)) { return(Result.GenError <Result>(Error.MonitoringKanBanSetVariableOrderDuplicate)); } var nVariableList = new List <DataNameDictionaryOrder>(); var orderGroup = set.VariableList.GroupBy(x => x.Order).Select(x => x.Key).OrderBy(x => x); for (int i = 0; i < orderGroup.Count(); i++) { var order = orderGroup.ElementAt(i); var oVariableList = set.VariableList.Where(x => x.Order == order).OrderBy(x => x.SubOrder); for (int j = 0; j < oVariableList.Count(); j++) { var variable = oVariableList.ElementAt(j); //variable.Order = i + 1; variable.SubOrder = j + 1; variable.Delimiter = variable.Delimiter ?? ""; nVariableList.Add(variable); } } set.Variables = nVariableList.Select(x => new { x.ScriptId, x.VariableTypeId, x.VariableName, x.PointerAddress, x.Order, x.SubOrder, x.Delimiter, }).ToJSON(); } } var sames = new List <string> { set.Name }; if (MonitoringKanBanSetHelper.GetHaveSame((int)set.Type, sames)) { return(Result.GenError <Result>(Error.MonitoringKanBanSetIsExist)); } set.CreateUserId = Request.GetIdentityInformation(); set.MarkedDateTime = DateTime.Now; MonitoringKanBanSetHelper.Instance.Add(set); return(Result.GenError <Result>(Error.Success)); }
public Result PutSet([FromBody] MonitoringKanBanSet set) { if (set.Type == 0) { return(Result.GenError <Result>(Error.ParamError)); } var sames = new List <string> { set.Name }; var ids = new List <int> { set.Id }; //if (MonitoringKanBanSetHelper.GetHaveSame((int)set.Type, sames, ids)) //{ // return Result.GenError<Result>(Error.MonitoringKanBanSetIsExist); //} var cnt = MonitoringKanBanSetHelper.Instance.GetCountById(set.Id); if (cnt != 1) { return(Result.GenError <Result>(Error.MonitoringKanBanSetNotExist)); } if (set.UI <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetSecondError)); } if (set.Second <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetSecondError)); } if (set.Type == KanBanEnum.设备状态看板) { if (set.Row <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetRowError)); } if (set.Col <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetColError)); } if (set.Length <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetLengthError)); } if (set.VariableList.Count == 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetVariableError)); } if (set.VariableList.Any()) { if (set.VariableList.GroupBy(x => new { x.Order, x.SubOrder }).Any(x => x.Count() > 1)) { return(Result.GenError <Result>(Error.MonitoringKanBanSetVariableOrderDuplicate)); } var nVariableList = new List <DataNameDictionaryOrder>(); var orderGroup = set.VariableList.GroupBy(x => x.Order).Select(x => x.Key).OrderBy(x => x); for (int i = 0; i < orderGroup.Count(); i++) { var order = orderGroup.ElementAt(i); var oVariableList = set.VariableList.Where(x => x.Order == order).OrderBy(x => x.SubOrder); for (int j = 0; j < oVariableList.Count(); j++) { var variable = oVariableList.ElementAt(j); //variable.Order = i + 1; variable.SubOrder = j + 1; variable.Delimiter = variable.Delimiter ?? ""; nVariableList.Add(variable); } } set.Variables = nVariableList.Select(x => new { x.ScriptId, x.VariableTypeId, x.VariableName, x.PointerAddress, x.Order, x.SubOrder, x.Delimiter, }).ToJSON(); } } else if (set.Type == KanBanEnum.生产相关看板) { if (set.Col <= 0) { return(Result.GenError <Result>(Error.MonitoringKanBanSetColError)); } if (set.ItemList.Count == 0) { return(Result.GenError <Result>(Error.MonitoringKanBanNoItem)); } if (set.ItemList.GroupBy(x => new { x.Col, x.Order }).Any(x => x.Count() > 1)) { return(Result.GenError <Result>(Error.MonitoringKanBanItemOrderDuplicate)); } } set.MarkedDateTime = DateTime.Now; MonitoringKanBanSetHelper.Instance.Update(set); return(Result.GenError <Result>(Error.Success)); }