diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs index cc1bba0e7..2dd444f0f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultsViewVM.cs @@ -275,7 +275,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels ResultTabs.Clear(); if(WashingTestMaterials == null) - WashingTestMaterials = _active_context.WashingTestMaterials.ToList(); + WashingTestMaterials = _active_context.WashingTestMaterials.OrderBy(x=> x.Name).ToList(); LogManager.Log("Loading selected test results..."); @@ -336,25 +336,54 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels CreateWashingResult(newtab); + return newtab; } private void CreateWashingResult(TestResultViewVM testresultViewVM) { - if(testresultViewVM.TestResult.RmlExtensionTestWashingResults != null) - return; - - var whashingresults = new SynchronizedObservableCollection<RmlExtensionTestWashingResult>(); - foreach (var material in WashingTestMaterials) + if(testresultViewVM.TestResult.RmlExtensionTestWashingResults != null && testresultViewVM.TestResult.RmlExtensionTestWashingResults.Count > 0 ) { - foreach (WashingResultColor color in Enum.GetValues(typeof(WashingResultColor))) + var collection = new ObservableCollection<WashingMaterialColorModel>(); + Dictionary<int, WashingMaterialColorModel> colorDictionary = new Dictionary<int, WashingMaterialColorModel>(); + List< RmlExtensionTestWashingResult > washingResultsOrdersByColor = testresultViewVM.TestResult.RmlExtensionTestWashingResults.OrderBy(x=>x.IndexRow).ThenBy(c => c.WashingTestMaterials != null ? c.WashingTestMaterials.Name : c.WashingTestMaterialsGuid).ToList(); + foreach (var res in washingResultsOrdersByColor) { - whashingresults.Add(new RmlExtensionTestWashingResult() { RmlExtensionTestResultsGuid = testresultViewVM.TestResult.Guid, WashingTestMaterialsGuid = material.Guid, Color = (int)color }); + WashingMaterialColorModel wmodel = null; + if(false == colorDictionary.TryGetValue(res.IndexRow, out wmodel)) + { + wmodel = new WashingMaterialColorModel() { Color = res.Color }; + colorDictionary.Add(res.IndexRow, wmodel); + collection.Add(wmodel); + } + wmodel.AddMaterial(res.Guid, res.GetMaterialName, res.WashingValue); } + testresultViewVM.ColorsToMaterialCollection = collection; } - testresultViewVM.TestResult.RmlExtensionTestWashingResults = whashingresults; + else + { + var whashingresults = new SynchronizedObservableCollection<RmlExtensionTestWashingResult>(); + var collecction = new ObservableCollection<WashingMaterialColorModel>(); + for (int index_row = 0; index_row < 6; index_row++) + { + var model = new WashingMaterialColorModel() { Color = -1 }; + + foreach (var material in WashingTestMaterials) + { + var rmlExtensionTestWashingResult = new RmlExtensionTestWashingResult() { RmlExtensionTestResultsGuid = testresultViewVM.TestResult.Guid, WashingTestMaterialsGuid = material.Guid, Color = -1, IndexRow = index_row }; + model.AddMaterial(rmlExtensionTestWashingResult.Guid, material.Name, null); + rmlExtensionTestWashingResult.WashingTestMaterials = material; + whashingresults.Add(rmlExtensionTestWashingResult); + + } + collecction.Add( model); + } + testresultViewVM.ColorsToMaterialCollection = collecction; + testresultViewVM.TestResult.RmlExtensionTestWashingResults = whashingresults; + } } + #endregion #region Save @@ -398,6 +427,22 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels } } + public void ApplyToWashingResults(TestResultViewVM testresultViewVM) + { + foreach ( var model in testresultViewVM.ColorsToMaterialCollection) + { + foreach( var colormodel in model.ColorValues) + { + var result = testresultViewVM.TestResult.RmlExtensionTestWashingResults.FirstOrDefault(x=> x.Guid == colormodel.RmlExtensionTestWashingResultGUID); + if( result != null) + { + result.Color = model.Color; + result.WashingValue = colormodel.ColorValue; + } + } + } + } + public async void Save() { if (String.IsNullOrEmpty(SelectedMachineGUID)) @@ -412,6 +457,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { foreach (var tab in ResultTabs) { + ApplyToWashingResults(tab); tab.TestResult.LastUpdated = DateTime.UtcNow; } _active_context.SaveChanges(); |
