Export to CSV was added

This commit is contained in:
Evgeny Redikultsev
2022-12-22 21:08:28 +05:00
parent b3952767c8
commit 913d31e04f
16 changed files with 190 additions and 18 deletions

View File

@@ -7,12 +7,16 @@ using StructureHelper.Services.Reports;
using StructureHelper.Services.Reports.CalculationReports;
using StructureHelper.Services.ResultViewers;
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperLogics.NdmCalculations.Analyses;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperLogics.Services.NdmCalculations;
using StructureHelperLogics.Services.NdmPrimitives;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -59,12 +63,48 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
return exportToCSVCommand ??
(exportToCSVCommand = new RelayCommand(o =>
{
ExportToCSV();
}
));
}
}
private void ExportToCSV()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "csv |*.csv";
saveFileDialog.Title = "Save an Image File";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var filename = saveFileDialog.FileName;
// If the file name is not an empty string open it for saving.
if (filename != "")
{
if (File.Exists(filename))
{
try
{
File.Delete(filename);
}
catch (Exception ex)
{
throw new StructureHelperException(ErrorStrings.FileCantBeDeleted + ex + filename);
}
}
try
{
var logic = new ExportToCSVLogic(saveFileDialog.FileName);
logic.Export(forcesResults);
}
catch (Exception ex)
{
throw new StructureHelperException(ErrorStrings.FileCantBeSaved + ex + filename);
}
}
}
}
public RelayCommand InterpolateCommand
{
get
@@ -91,7 +131,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
{
var vm = new ForcesResultsViewModel(calculator);
var wnd = new ForceResultsView(vm);
wnd.Show();
wnd.ShowDialog();
}
}

View File

@@ -50,8 +50,12 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
(
editCalculatorCommand = new RelayCommand(o =>
{
var tmpSelected = SelectedItem;
EditCalculator();
Items.Clear();
AddItems(repository.CalculatorsList);
OnPropertyChanged(nameof(Items));
SelectedItem = tmpSelected;
}, o => SelectedItem != null));
}
}
@@ -68,6 +72,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
}
private RelayCommand deleteCalculatorCommand;
private RelayCommand runCommand;
private RelayCommand copyCalculatorCommand;
public RelayCommand Delete
{
get
@@ -100,13 +106,27 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
var calculator = SelectedItem as IForceCalculator;
var vm = new ForcesResultsViewModel(calculator);
var wnd = new ForceResultsView(vm);
wnd.Show();
wnd.ShowDialog();
}
}, o => SelectedItem != null));
}
}
public RelayCommand Copy => throw new NotImplementedException();
public RelayCommand Copy
{
get
{
return copyCalculatorCommand ??
(
copyCalculatorCommand = new RelayCommand(o =>
{
var item = SelectedItem.Clone() as INdmCalculator;
repository.CalculatorsList.Add(item);
Items.Add(item);
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void DeleteCalculator()
{

View File

@@ -3,6 +3,7 @@ using StructureHelper.Windows.Forces;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.Calculations.CalculationProperties;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Analyses;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -65,6 +66,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
}
}
private RelayCommand editForceCombinationCommand;
private RelayCommand copyCommand;
public RelayCommand Edit
{
get
@@ -74,12 +77,28 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
editForceCombinationCommand = new RelayCommand(o =>
{
EditForceCombination();
Items.Clear();
AddItems(repository.ForceCombinationLists);
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
public RelayCommand Copy => throw new NotImplementedException();
public RelayCommand Copy
{
get
{
return copyCommand ??
(
copyCommand = new RelayCommand(o =>
{
var item = SelectedItem.Clone() as IForceCombinationList;
repository.ForceCombinationLists.Add(item);
Items.Add(item);
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void EditForceCombination()
{