SourceToTargetViewModel was added

This commit is contained in:
Evgeny Redikultsev
2022-12-15 21:46:15 +05:00
parent f562cf2bce
commit d240968f29
21 changed files with 632 additions and 200 deletions

View File

@@ -0,0 +1,120 @@
using StructureHelper.Infrastructure;
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews;
using StructureHelper.Windows.ViewModels.Calculations.Calculators;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Analyses;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Input;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public class CalculatorsViewModelLogic : ViewModelBase, ICalculatorsViewModelLogic
{
private readonly ICrossSectionRepository repository;
public INdmCalculator SelectedItem { get; set; }
public ObservableCollection<INdmCalculator> Items
{
get
{
var collection = new ObservableCollection<INdmCalculator>();
foreach (var item in repository.CalculatorsList)
{
collection.Add(item);
}
return collection;
}
}
private RelayCommand addCalculatorCommand;
public RelayCommand Add
{
get
{
return addCalculatorCommand ??
(
addCalculatorCommand = new RelayCommand(o =>
{
AddCalculator();
OnPropertyChanged(nameof(Items));
}));
}
}
private void AddCalculator()
{
var item = new ForceCalculator() { Name = "New force calculator" };
repository.CalculatorsList.Add(item);
}
private RelayCommand editCalculatorCommand;
public RelayCommand Edit
{
get
{
return editCalculatorCommand ??
(
editCalculatorCommand = new RelayCommand(o =>
{
EditCalculator();
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void EditCalculator()
{
if (SelectedItem is ForceCalculator)
{
var calculator = SelectedItem as ForceCalculator;
var vm = new ForceCalculatorViewModel(repository.Primitives, repository.ForceCombinationLists, calculator);
var wnd = new ForceCalculatorView(vm);
wnd.ShowDialog();
}
}
private RelayCommand deleteCalculatorCommand;
private RelayCommand runCommand;
public RelayCommand Delete
{
get
{
return deleteCalculatorCommand ??
(
deleteCalculatorCommand = new RelayCommand(o =>
{
DeleteCalculator();
}, o => SelectedItem != null));
}
}
public RelayCommand Run
{
get
{
return runCommand ??
(
runCommand = new RelayCommand(o =>
{
(SelectedItem as INdmCalculator).Run();
}, o => SelectedItem != null));
}
}
private void DeleteCalculator()
{
var dialogResult = MessageBox.Show("Delete calculator?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
repository.CalculatorsList.Remove(SelectedItem as INdmCalculator);
OnPropertyChanged(nameof(Items));
}
}
public CalculatorsViewModelLogic(ICrossSectionRepository repository)
{
this.repository = repository;
}
}
}

View File

@@ -0,0 +1,102 @@
using StructureHelper.Infrastructure;
using StructureHelper.Windows.Forces;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.Calculations.CalculationProperties;
using StructureHelperLogics.Models.CrossSections;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public class ForceCombinationViewModelLogic : ViewModelBase, IForceCombinationViewModelLogic
{
private readonly ICrossSectionRepository repository;
public IForceCombinationList SelectedItem { get; set; }
public ObservableCollection<IForceCombinationList> Items
{
get
{
var collection = new ObservableCollection<IForceCombinationList>();
foreach (var item in repository.ForceCombinationLists)
{
collection.Add(item);
}
return collection;
}
}
private RelayCommand addForceCombinationCommand;
public RelayCommand Add
{
get
{
return addForceCombinationCommand ??
(
addForceCombinationCommand = new RelayCommand(o =>
{
AddCombination();
OnPropertyChanged(nameof(Items));
}));
}
}
private void AddCombination()
{
var item = new ForceCombinationList() { Name = "New Force Combination" };
repository.ForceCombinationLists.Add(item);
}
private RelayCommand deleteForceCombinationCommand;
public RelayCommand Delete
{
get
{
return deleteForceCombinationCommand ??
(
deleteForceCombinationCommand = new RelayCommand(o =>
{
DeleteForceCombination();
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void DeleteForceCombination()
{
var dialogResult = MessageBox.Show("Delete action?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
repository.ForceCombinationLists.Remove(SelectedItem);
}
}
private RelayCommand editForceCombinationCommand;
public RelayCommand Edit
{
get
{
return editForceCombinationCommand ??
(
editForceCombinationCommand = new RelayCommand(o =>
{
EditForceCombination();
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void EditForceCombination()
{
var wnd = new ForceCombinationView(SelectedItem);
wnd.ShowDialog();
}
public ForceCombinationViewModelLogic(ICrossSectionRepository repository)
{
this.repository = repository;
}
}
}

View File

@@ -0,0 +1,13 @@
using StructureHelper.Infrastructure;
using StructureHelperLogics.NdmCalculations.Analyses;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public interface ICalculatorsViewModelLogic : ICRUDViewModel<INdmCalculator>
{
RelayCommand Run { get; }
}
}

View File

@@ -0,0 +1,14 @@
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.Calculations.CalculationProperties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public interface IForceCombinationViewModelLogic : ICRUDViewModel<IForceCombinationList>
{
}
}