Files
GroundOrganizer/VM/StructuresVM.cs
2026-01-06 02:07:18 +03:00

97 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GroundOrganizer
{
public partial class ViewModel : INotifyPropertyChanged
{
int numStructure = 1;
string nameStructure;
private string structureNote;
Structure selectedStructure;
ObservableCollection<Structure> listStructure = new ObservableCollection<Structure>();
public ObservableCollection<Structure> ListStructure { get => listStructure; set { listStructure = value; OnPropertyChanged(); } }
private IEnumerable<TypeFlexStructure> listShemas;
public IEnumerable<TypeFlexStructure> ListShemas { get => listShemas; set { listShemas = value; OnPropertyChanged(); } }
public string StructureNote { get => structureNote; set { structureNote = value; OnPropertyChanged(); } }
private RelayCommand addStructure;
public RelayCommand AddStructure
{
get { return addStructure ?? (addStructure = new RelayCommand(obj => { AddStructureToList(); })); }
}
private RelayCommand updateStructure;
public RelayCommand UpdateStructures
{
get { return updateStructure ?? (updateStructure = new RelayCommand(obj => { UpdateStructureInList(); })); }
}
private RelayCommand renumStructure;
public RelayCommand RenumStructures
{
get { return renumStructure ?? (renumStructure = new RelayCommand(obj => { RenumberingStructureInList(); })); }
}
public Structure SelectedStructure { get => selectedStructure; set { selectedStructure = value; OnPropertyChanged(); ChangeSelectedStructure(); } }
public string NameStructure { get => nameStructure; set { nameStructure = value; OnPropertyChanged(); } }
void AddStructureToList()
{
ListStructure.Add(new Structure() { Number = numStructure }); numStructure++;
//NameStructure = listStructure[0].Name;
}
void RenumberingStructureInList()
{
int j = 1;
foreach (Structure item in ListStructure)
{
item.Number = j;
j++;
}
numStructure = j;
ListStructure = new ObservableCollection<Structure>(ListStructure);
}
void UpdateStructureInList()
{
ListStructure = new ObservableCollection<Structure>(ListStructure);
SaveDB();
}
void ChangeSelectedStructure()
{
if (listStructure.Count == 0 || selectedStructure == null) return;
NameStructure = selectedStructure.Name;
ListFoundation = selectedStructure.Foundations;
RedPlanning = selectedStructure.RedPlanning;
BlackPlanning = selectedStructure.BlackPlanning;
if (redPlanning == null) RedPlanning = new ObservableCollection<PlanningVertex>();
if (blackPlanning == null) BlackPlanning = new ObservableCollection<PlanningVertex>();
}
void CreateListShemas()
{
if (listStructure == null || listPlayGround == null) return;
ListShemas = new List<TypeFlexStructure>() { TypeFlexStructure.Гибкая, TypeFlexStructure.Жесткая };
try
{
StructuresPage structuresPage = (StructuresPage)MW.StructuresFrame.Content;
structuresPage.flexListCbxCol.ItemsSource = listShemas;
}
catch
{
return;
}
}
}
}