UpdateStrategy for Actions was added

This commit is contained in:
Evgeny Redikultsev
2023-07-09 19:46:36 +05:00
parent 03b882f54d
commit 3e0e51d0c9
30 changed files with 402 additions and 138 deletions

View File

@@ -1,5 +1,6 @@
using StructureHelper.Models.Materials;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Repositories;
using StructureHelperLogics.Models.Materials;
using System;
@@ -13,6 +14,8 @@ namespace StructureHelper.Services.Settings
internal static class GlobalRepository
{
private static IDataRepository<IHeadMaterial> materials;
private static IDataRepository<IAction> actions;
public static IDataRepository<IHeadMaterial> Materials
{
get
@@ -21,5 +24,13 @@ namespace StructureHelper.Services.Settings
return materials;
}
}
public static IDataRepository<IAction> Actions
{
get
{
actions ??= new ListRepository<IAction>(new ActionUpdateStrategy());
return actions;
}
}
}
}

View File

@@ -7,11 +7,12 @@
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Forces"
d:DataContext="{d:DesignInstance vm:ForceCombinationByFactorVM}"
mc:Ignorable="d"
Title="Force Combination By Factor" Height="250" Width="350" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
Title="Force Combination By Factor" Height="290" Width="350" MinHeight="290" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="95"/>
<RowDefinition/>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<!--ForceTemplates.xaml-->
<ContentControl ContentTemplate="{StaticResource ResourceKey=ForceActionTemplate}" Content="{Binding}"/>
@@ -49,5 +50,6 @@
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding ULSFactor, Converter={StaticResource PlainDouble}, ValidatesOnExceptions=True}"/>
</Grid>
</StackPanel>
<ContentControl Grid.Row="2" ContentTemplate="{StaticResource OkCancelButtons}" Content="{Binding}"/>
</Grid>
</Window>

View File

@@ -27,6 +27,7 @@ namespace StructureHelper.Windows.Forces
InitializeComponent();
viewModel = new ForceCombinationByFactorVM(forceCombination);
DataContext = viewModel;
viewModel.ParentWindow = this;
}
}
}

View File

@@ -7,16 +7,18 @@
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Forces"
d:DataContext="{d:DesignInstance vm:ForceCombinationViewModel}"
mc:Ignorable="d"
Title="Force Combination" Height="250" Width="550" MinHeight="300" MinWidth="450" MaxWidth="500" WindowStartupLocation="CenterScreen">
Title="Force Combination" Height="350" Width="550" MinHeight="300" MinWidth="450" MaxWidth="500" WindowStartupLocation="CenterScreen">
<Window.Resources>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="95"/>
<RowDefinition/>
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<!--ForceTemplates.xaml-->
<ContentControl ContentTemplate="{StaticResource ResourceKey=ForceActionTemplate}" Content="{Binding}"/>
<ContentControl Grid.Row="1" ContentTemplate="{StaticResource ResourceKey=CombinationListTemplate}" Content="{Binding}"/>
<ContentControl Grid.Row="2" ContentTemplate="{StaticResource OkCancelButtons}" Content="{Binding}"/>
</Grid>
</Window>

View File

@@ -27,13 +27,11 @@ namespace StructureHelper.Windows.Forces
viewModel = _viewModel;
DataContext = viewModel;
InitializeComponent();
viewModel.ParentWindow = this;
}
public ForceCombinationView(IForceCombinationList combinationList)
public ForceCombinationView(IForceCombinationList combinationList) : this(new ForceCombinationViewModel(combinationList))
{
viewModel = new ForceCombinationViewModel(combinationList);
DataContext = viewModel;
InitializeComponent();
}
}
}

View File

@@ -407,6 +407,10 @@ namespace StructureHelper.Windows.MainWindow
{
GlobalRepository.Materials.Create(item);
}
foreach (var item in newRepository.ForceActions)
{
GlobalRepository.Actions.Create(item);
}
return primitives;
}
return new List<PrimitiveBase>();

View File

@@ -15,13 +15,12 @@
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="280"/>
</Grid.ColumnDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}" SelectionChanged="ListBox_SelectionChanged">
<ListBox ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding SelectedMaterial}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
@@ -42,19 +41,7 @@
</ListBox>
</Grid>
<StackPanel Grid.Column="1">
<Button Content="New Concrete" Command="{Binding AddNewConcreteMaterialCommand}"/>
<Button Content="New Reinforcement" Command="{Binding AddNewReinforcementMaterialCommand}"/>
<Button Content="New Elastic Material" Command="{Binding AddElasticMaterialCommand}"/>
<Button Content="Show diagram" Command="{Binding ShowMaterialDiagram}"/>
<Button Content="Edit color" Command="{Binding EditColorCommand}"/>
<Button Content="Edit" Command="{Binding EditCommand}"/>
<Button Content="Copy" Command="{Binding CopyHeadMaterialCommand}"/>
<Button Content="Delete" Command="{Binding DeleteMaterialCommand}"/>
</StackPanel>
<StackPanel x:Name="MatProps" Grid.Column="2">
<TextBlock Text="Name"/>
<TextBox Text="{Binding SelectedMaterial.Name}"/>
<StackPanel x:Name="StpMaterialProperties"/>
</StackPanel>
</Grid>
</Window>

View File

@@ -33,37 +33,5 @@ namespace StructureHelper.Windows.MainWindow.Materials
this.DataContext = viewModel;
InitializeComponent();
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
StpMaterialProperties.Children.Clear();
var selectedMaterial = viewModel.SelectedMaterial;
if (selectedMaterial == null) { return; }
var helperMaterial = selectedMaterial.HelperMaterial;
string dataTemplateName = string.Empty;
Binding binding = new Binding();
if (helperMaterial is IConcreteLibMaterial)
{
dataTemplateName = "ConcreteLibMaterial";
binding.Source = viewModel;
}
else if (helperMaterial is IReinforcementLibMaterial)
{
dataTemplateName = "ReinforcementLibMaterial";
binding.Source = viewModel;
}
else if (helperMaterial is IElasticMaterial)
{
dataTemplateName = "ElasticMaterial";
binding.Source = viewModel.SelectedMaterial.HelperMaterial;
}
if (dataTemplateName != string.Empty)
{
ContentControl contentControl = new ContentControl();
contentControl.SetResourceReference(ContentTemplateProperty, dataTemplateName);
contentControl.SetBinding(ContentProperty, binding);
StpMaterialProperties.Children.Add(contentControl);
}
}
}
}

View File

@@ -1,8 +1,12 @@
using StructureHelper.Infrastructure.Enums;
using StructureHelper.Models.Materials;
using StructureHelper.Services.Settings;
using StructureHelper.Windows.Forces;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
@@ -15,6 +19,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
{
public class ActionsViewModel : SelectedItemViewModel<IForceAction>
{
readonly IUpdateStrategy<IAction> updateStrategy = new ActionUpdateStrategy();
ICrossSectionRepository repository;
public override void AddMethod(object parameter)
@@ -30,7 +35,8 @@ namespace StructureHelper.Windows.ViewModels.Forces
{
NewItem = new ForceCombinationByFactor() { Name = "New Factored Combination" };
}
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $": Actual type: {nameof(paramType)}");
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $": Actual type: {nameof(paramType)}");
GlobalRepository.Actions.Create(NewItem);
base.AddMethod(parameter);
}
}
@@ -41,6 +47,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
if (dialogResult == DialogResult.Yes)
{
if (DeleteAction() != true) return;
GlobalRepository.Materials.Delete(SelectedItem.Id);
base.DeleteMethod(parameter);
}
}
@@ -49,6 +56,7 @@ namespace StructureHelper.Windows.ViewModels.Forces
public override void EditMethod(object parameter)
{
var copyObject = GlobalRepository.Actions.GetById(SelectedItem.Id).Clone() as IAction;
System.Windows.Window wnd;
if (SelectedItem is IForceCombinationList)
{
@@ -62,6 +70,14 @@ namespace StructureHelper.Windows.ViewModels.Forces
}
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + $"actual object type: {nameof(SelectedItem)}");
wnd.ShowDialog();
if (wnd.DialogResult == true)
{
GlobalRepository.Actions.Update(SelectedItem);
}
else
{
updateStrategy.Update(SelectedItem, copyObject);
}
base.EditMethod(parameter);
}

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.Forces
{
public abstract class ForceActionVMBase : ViewModelBase
public abstract class ForceActionVMBase : OkCancelViewModelBase
{
IForceAction forceAction;