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

@@ -55,17 +55,14 @@
</Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding AllowedPrimitives}"
SelectedItem="{Binding SelectedAllowedPrimitive}"
ItemTemplate="{StaticResource ColoredItemTemplate}">
</ListBox>
ItemTemplate="{StaticResource ColoredItemTemplate}"/>
<StackPanel Grid.Column="1">
<Button Content="Add all" Command="{Binding AddAllPrimitivesCommand}"/>
<Button Content="Clear all" Command="{Binding ClearAllPrimitivesCommand}"/>
<Button Content=">>" Command="{Binding AddSelectedPrimitiveCommand}"/>
<Button Content="&lt;&lt;" Command="{Binding RemoveSelectedPrimitiveCommand}"/>
</StackPanel>
<ListBox Grid.Column="2" ItemsSource="{Binding Primitives}" SelectedItem="{Binding SelectedPrimitive}" ItemTemplate="{StaticResource ColoredItemTemplate}">
</ListBox>
<ListBox Grid.Column="2" ItemsSource="{Binding Primitives}" SelectedItem="{Binding SelectedPrimitive}" ItemTemplate="{StaticResource ColoredItemTemplate}"/>
</Grid>
</TabItem>
<TabItem Header="Iterations">

View File

@@ -7,11 +7,11 @@
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Calculations.Calculators"
d:DataContext="{d:DesignInstance vm:ForcesResultsViewModel}"
mc:Ignorable="d"
Title="ForceResultsView" Height="350" Width="650" MinHeight="300" MinWidth="400" WindowStartupLocation="CenterScreen">
Title="Calculation Results" Height="350" Width="850" MinHeight="300" MinWidth="400" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="90"/>
</Grid.ColumnDefinitions>
<DataGrid x:Name="ResultGrid" IsReadOnly="True" AutoGenerateColumns="False" ItemsSource="{Binding ForcesResults.ForcesResultList}" SelectedItem="{Binding SelectedResult}" >
<DataGrid.RowStyle>

View File

@@ -72,6 +72,7 @@
<ListBox.ContextMenu>
<ContextMenu>
<Button Content="Edit" Command="{Binding Edit}"/>
<Button Content="Copy" Command="{Binding Copy}"/>
<Button Content="Delete" Command="{Binding Delete}"/>
</ContextMenu>
</ListBox.ContextMenu>
@@ -122,6 +123,7 @@
<ContextMenu>
<Button Content="Run" Command="{Binding Run}"/>
<Button Content="Edit" Command="{Binding Edit}"/>
<Button Content="Copy" Command="{Binding Copy}"/>
<Button Content="Delete" Command="{Binding Delete}"/>
</ContextMenu>
</ListBox.ContextMenu>

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()
{