diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs | 196 |
1 files changed, 192 insertions, 4 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs index b33ead70a..4802e0af1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs @@ -28,11 +28,19 @@ using Tango.MachineStudio.ThreadExtensions.Views; using Tango.MachineStudio.ThreadExtensions.Models; using Tango.Settings; using System.Reflection; +using Tango.Core.Helpers; +using Tango.Documents; namespace Tango.MachineStudio.ThreadExtensions.ViewModels { public class MainViewVM : StudioViewModel<IMainView> { + public enum MachineTestResultsTabs + { + ColorParameters, + TestResults + } + private INotificationProvider _notification; private IAuthenticationProvider _authentication; private IActionLogManager _actionLogManager; @@ -286,11 +294,27 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels } + private MachineTestResultsTabs PreviosSelectedTab { get; set; } + + private MachineTestResultsTabs _selectedTab; + + public MachineTestResultsTabs SelectedTab + { + get { return _selectedTab; } + set { + PreviosSelectedTab = _selectedTab; + _selectedTab = value; + OnSelectedMachineTestResultsTabChanged(); + RaisePropertyChangedAuto(); + } + } + #endregion #region commands public RelayCommand SaveCommand { get; set; } + public RelayCommand ExportToFileCommand { get; set; } public RelayCommand ManageRmlExtensionCommand { get; set; } @@ -298,8 +322,11 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels private async void BackToThreadExtensionViews(object obj) { - View.NavigateTo(RMLExtensionNavigationView.RMLExtensionsView); - await LoadRmlExtentions(); + if (_notification.ShowQuestion("Are you sure you want to exit the RML without saving changes?")) + { + View.NavigateTo(RMLExtensionNavigationView.RMLExtensionsView); + await LoadRmlExtentions(); + } } public RelayCommand AddManufacturerItemCommand { get; set; } @@ -766,14 +793,15 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels BackToThreadExtensionViewsCommand = new RelayCommand(BackToThreadExtensionViews, () => IsFree); SaveCommand = new RelayCommand(Save, () => IsFree); + ExportToFileCommand = new RelayCommand(ExportRMLToExcel, () => IsFree); ManageRmlExtensionCommand = new RelayCommand(() => LoadActiveRMLExtension(SelectedRMLExtension.Guid), () => SelectedRMLExtension != null); AddManufacturerItemCommand = new RelayCommand(AddManufacturerItem); - EditManufacturerItemCommand = new RelayCommand(EditManufacturerItem, () => ActiveRML.Manufacturer != ""); + EditManufacturerItemCommand = new RelayCommand(EditManufacturerItem, () => ActiveRML !=null && ActiveRML.Manufacturer != ""); AddBrandItemCommand = new RelayCommand(AddBrandItem); - EditBrandItemCommand = new RelayCommand(EditBrandItem, () => ActiveRMLExtension.YarnBrand != null); + EditBrandItemCommand = new RelayCommand(EditBrandItem, () => ActiveRMLExtension != null && ActiveRMLExtension.YarnBrand != null); AddEndUseItemCommand = new RelayCommand(AddEndUseItem); EditEndUseItemCommand = new RelayCommand(EditEndUseItem); @@ -1102,6 +1130,10 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels { ColorParametersVewVM.SelectedMachineGUID = SelectedMachine.Guid; } + if(TestResultsViewVM != null) + { + TestResultsViewVM.SelectedMachineGUID = SelectedMachine.Guid; + } } #endregion @@ -1148,5 +1180,161 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels } #endregion + + #region selections + + private void OnSelectedMachineTestResultsTabChanged() + { + if(SelectedTab == MachineTestResultsTabs.ColorParameters) + { + //if(PreviosSelectedTab == MachineTestResultsTabs.TestResults && TestResultsViewVM != null) + //{ + // TestResultsViewVM.Save(); + //} + //save + //if (_notification.ShowQuestion("Are you sure you want to exit this page without saving changes?")) + + } + else if(SelectedTab == MachineTestResultsTabs.TestResults) + { + //if (PreviosSelectedTab == MachineTestResultsTabs.ColorParameters && ColorParametersVewVM != null) + //{ + // ColorParametersVewVM.Save(); + //} + } + } + + #endregion + + #region Export / Import Excel + + public void ExportRMLToExcel() + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Filter = "Excel Documents|*.xlsx"; + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem("Exporting RML to file...")) + { + Task.Factory.StartNew(() => + { + try + { + IsFree = false; + + Stream stream = null; + bool dispose = false; + String file = AssemblyHelper.GetCurrentAssemblyFolder() + "\\Templates\\ExportRMLTemplate.xlsx"; + + if (File.Exists(file)) + { + stream = File.OpenRead(file); + dispose = true; + } + else + { + stream = EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.ThreadExtensions.Templates.ExportRMLTemplate.xlsx"); + } + + byte[] data = new byte[stream.Length]; + stream.Read(data, 0, data.Length); + File.WriteAllBytes(dlg.FileName, data); + + if (dispose) + { + stream.Dispose(); + } + + ExcelWriter writer = new ExcelWriter(dlg.FileName); + //ActiveRMLExtension = await new RmlExtensionsBuilder(_active_context) + // .Set(guid) + // .WithUser() + // .BuildAsync(); + + //ActiveRML = new RmlBuilder(_active_context) + // .Set(SelectedRMLExtension.RMLGuid) + // .Build(); + + List<ThreadCharacteristicsExcelModel> threadCharacteristicsExelModels = new List<ThreadCharacteristicsExcelModel>(); + ThreadCharacteristicsExcelModel model = new ThreadCharacteristicsExcelModel(); + model.ThreadName = ActiveRML.Name; + model.Manufacturer = ActiveRML.Manufacturer == null? "": ActiveRML.Manufacturer; + model.Brand = ActiveRMLExtension.YarnBrand == null ? "": ActiveRMLExtension.YarnBrand.Name; + model.Country = ActiveRMLExtension.Country == null? "" : ActiveRMLExtension.Country; + model.EndUse = ActiveRML.MediaPurpose == null ? "" : ActiveRML.MediaPurpose.Name; + model.Applications = ActiveRMLExtension.YarnApplication == null ? "" : ActiveRMLExtension.YarnApplication.Name; + model.IndustrySector = ActiveRMLExtension.YarnIndustrysector == null ? "" : ActiveRMLExtension.YarnIndustrysector.Name; + model.Material = ActiveRML.MediaMaterial == null ? "" : ActiveRML.MediaMaterial.Name; + model.Type = ActiveRMLExtension.YarnType == null ? "" : ActiveRMLExtension.YarnType.Name; + model.SubFamily = ActiveRMLExtension.YarnSubFamily == null ? "" : ActiveRMLExtension.YarnSubFamily.Name; + model.Family = ActiveRMLExtension.YarnFamily == null ? "" : ActiveRMLExtension.YarnFamily.Name; + model.Group = ActiveRMLExtension.YarnGroup == null ? "" : ActiveRMLExtension.YarnGroup.Name; + model.Texturing = ActiveRMLExtension.YarnTexturing == null ? "" : ActiveRMLExtension.YarnTexturing.Name; + model.Geometry = ActiveRML.FiberShape == null ? "" : ActiveRML.FiberShape.Name; + model.Color = ActiveRMLExtension.YarnWhiteShade == null ? "" : ActiveRMLExtension.YarnWhiteShade.Name; + model.GlossLevel = ActiveRMLExtension.YarnGlossLevel == null ? "" : ActiveRMLExtension.YarnGlossLevel.Name; + model.LinearDensity = ActiveRML.FiberSize; + model.Unit = ActiveRML.LinearMassDensityUnit == null ? "" : ActiveRML.LinearMassDensityUnit.Name; + model.Plies = (int) ActiveRML.RMLPlies; + model.FilamentCountPerPlie = ActiveRML.PliesPerFiber; + model.LinearDensityCount = ActiveRML.DencityCount; + model.CountDen = ActiveRML.DencityCount; + model.FiberCount = ActiveRML.FiberCount; + model.Twist = ActiveRMLExtension.TwistTpm; + model.TwistDirection = ActiveRMLExtension.YarnTwistDirections.ToDescription(); + threadCharacteristicsExelModels.Add(model); + writer.WriteData(threadCharacteristicsExelModels, "Thread characteristics", 2); + + List<ColorParametrsExcelModel> colorParametrsExcelList = new List<ColorParametrsExcelModel>(); + + List<TestResultsExcelModel> testResultsExcelModelList = new List<TestResultsExcelModel>(); + + foreach(var machine in Machines) + { + if (machine.HasRMLTest) + { + ColorParametrsExcelModel colorParametrsExcelModel = new ColorParametrsExcelModel(); + colorParametrsExcelModel.Thread_name = ActiveRML.Name; + colorParametrsExcelModel.MachineNumber = machine.SerialNumber.ToString(); + colorParametrsExcelModel.White_point_L = ActiveRML.WhitePointL; + colorParametrsExcelModel.White_point_a = ActiveRML.WhitePointA; + colorParametrsExcelModel.White_point_B = ActiveRML.WhitePointB; + ColorParametersVewVM.WritetoExcel(colorParametrsExcelModel, machine.Guid); + + colorParametrsExcelList.Add(colorParametrsExcelModel); + + TestResultsViewVM.LoadTestResultsExcel(testResultsExcelModelList, machine.Guid, machine.SerialNumber); + } + } + + writer.WriteData(colorParametrsExcelList, "Color parameters"); + writer.WriteData(testResultsExcelModelList.OrderBy(x => x.Machine_number), "Machine tests results"); + + writer.Dispose(); + + InvokeUI(() => + { + _notification.ShowInfo("RML extensions exported successfully."); + }); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error exporting RML extensions to {dlg.FileName}"); + + InvokeUI(() => + { + _notification.ShowError($"An error occurred while trying to export the RML extensions. Make sure the selected excel file is closed and data is valid.\n{ex.FlattenMessage()}"); + }); + } + finally + { + IsFree = true; + } + }); + } + } + } + + #endregion } } |
