diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2021-11-18 11:27:19 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2021-11-18 11:27:19 +0200 |
| commit | b88f12398df6b1d3126369a4016eceecdfa4dbc8 (patch) | |
| tree | 1b6ef829d9891c6083be02bf6de5ac8980e4c9c5 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/MainViewVM.cs | |
| parent | 854f883509443230cc0360ea45c7d8085dd52882 (diff) | |
| download | Tango-b88f12398df6b1d3126369a4016eceecdfa4dbc8.tar.gz Tango-b88f12398df6b1d3126369a4016eceecdfa4dbc8.zip | |
5818 RML EXTANSION- EXPORT EXCEL FILE
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 | 120 |
1 files changed, 120 insertions, 0 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 12ae1aa89..954500b60 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,6 +28,8 @@ 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 { @@ -312,6 +314,7 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels #region commands public RelayCommand SaveCommand { get; set; } + public RelayCommand ExportToFileCommand { get; set; } public RelayCommand ManageRmlExtensionCommand { get; set; } @@ -790,6 +793,7 @@ 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); @@ -1201,5 +1205,121 @@ namespace Tango.MachineStudio.ThreadExtensions.ViewModels } #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<ThreadCharacteristicsExelModel> threadCharacteristicsExelModels = new List<ThreadCharacteristicsExelModel>(); + ThreadCharacteristicsExelModel model = new ThreadCharacteristicsExelModel(); + 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"); + //List<ColorGroup> groups = ActiveCatalog.ColorCatalogsGroups.Select(x => new ColorGroup() + //{ + // GroupColor = x.Color, + // GroupName = x.Name, + // GroupIndex = x.GroupIndex, + //}).ToList(); + + //writer.WriteData(groups, "Groups"); + + //ActiveRMLExtension. + + 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 } } |
