From 778b4a9a64b758dd34c58f6209715bf2d1f91b95 Mon Sep 17 00:00:00 2001 From: Damian Wessels Date: Sun, 6 Aug 2023 19:19:44 +0200 Subject: [PATCH] Letzte Projekt wird beigehalten --- StammGenerator/MainWindow.xaml | 2 +- .../ViewModel/Haltung/HaltungEditViewModel.cs | 2 +- .../ViewModel/MainWindowViewModel.cs | 3 ++- StammGenerator/ViewModel/State/ActualState.cs | 23 +++++++++++++++++-- .../ViewModel/State/IActualState.cs | 2 ++ StammGenerator/Views/HomeView.xaml | 2 +- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/StammGenerator/MainWindow.xaml b/StammGenerator/MainWindow.xaml index 8882e69..4bbe344 100644 --- a/StammGenerator/MainWindow.xaml +++ b/StammGenerator/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:StammGenerator" mc:Ignorable="d" - + WindowState="Maximized" xmlns:view="clr-namespace:StammGenerator.Views" xmlns:viewmodel="clr-namespace:StammGenerator.ViewModel" diff --git a/StammGenerator/ViewModel/Haltung/HaltungEditViewModel.cs b/StammGenerator/ViewModel/Haltung/HaltungEditViewModel.cs index dc3e932..73d6eb4 100644 --- a/StammGenerator/ViewModel/Haltung/HaltungEditViewModel.cs +++ b/StammGenerator/ViewModel/Haltung/HaltungEditViewModel.cs @@ -15,7 +15,7 @@ namespace StammGenerator.ViewModel private readonly IActualState _actualState; private readonly IHaltungDataService _haltungDataService; private readonly ISchachtDataService _schachtDataService; - private List avaibleSchaechte; + private List avaibleSchaechte = new List(); private int _selectedObenIndex; private int _selectedUntenIndex; private Kanal _model; diff --git a/StammGenerator/ViewModel/MainWindowViewModel.cs b/StammGenerator/ViewModel/MainWindowViewModel.cs index 2006621..4701da8 100644 --- a/StammGenerator/ViewModel/MainWindowViewModel.cs +++ b/StammGenerator/ViewModel/MainWindowViewModel.cs @@ -42,9 +42,10 @@ namespace StammGenerator.ViewModel UpdateCurrentViewModelCommand.Execute(EMainWindowViewType.Home); _actualState = actualState; + _actualState.ProjektChanged += ActualState_ProjektChanged; - + _actualState.LoadLastProjekt(); Navigator.StateChanged += Navigator_StateChanged; } diff --git a/StammGenerator/ViewModel/State/ActualState.cs b/StammGenerator/ViewModel/State/ActualState.cs index 50cbb2e..59ea59c 100644 --- a/StammGenerator/ViewModel/State/ActualState.cs +++ b/StammGenerator/ViewModel/State/ActualState.cs @@ -1,4 +1,5 @@ -using SewerStammGen.Shared.Domain; +using Microsoft.Win32; +using SewerStammGen.Shared.Domain; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +10,10 @@ namespace StammGenerator.ViewModel { internal class ActualState : IActualState { + const string userroot = "HKEY_CURRENT_USER\\Software"; + const string firmkey = "WWTech"; + const string subkey = "StammGenerator"; + // TODO: set auf private set setzen public int ProjektID { get; set; } @@ -25,6 +30,9 @@ namespace StammGenerator.ViewModel { OnProjektChanged(); } + + string keyName = userroot + "\\" + firmkey + "\\" + subkey; + Registry.SetValue(keyName, "LastProjekt", ProjektID); } public void SetSchacht(Schacht schacht, bool notification = true) { @@ -61,6 +69,17 @@ namespace StammGenerator.ViewModel { HaltungChanged?.Invoke(this, new EventArgs()); } - + + public void LoadLastProjekt() + { + string keyName = userroot + "\\" + firmkey + "\\" + subkey; + if(Registry.GetValue(keyName,"LastProjekt","")!= null) + { + ProjektID = Convert.ToInt32(Registry.GetValue(keyName, "LastProjekt", "")); + OnProjektChanged(); + } + } + + } } diff --git a/StammGenerator/ViewModel/State/IActualState.cs b/StammGenerator/ViewModel/State/IActualState.cs index 6dfbb57..5de1825 100644 --- a/StammGenerator/ViewModel/State/IActualState.cs +++ b/StammGenerator/ViewModel/State/IActualState.cs @@ -20,5 +20,7 @@ namespace StammGenerator.ViewModel void SetProjekt(Projekt projekt, bool notification = true); void SetSchacht(Schacht schacht, bool notification = true); void SetHaltung(Kanal haltung, bool notification = true); + + void LoadLastProjekt(); } } diff --git a/StammGenerator/Views/HomeView.xaml b/StammGenerator/Views/HomeView.xaml index f6eeabe..57ab3ff 100644 --- a/StammGenerator/Views/HomeView.xaml +++ b/StammGenerator/Views/HomeView.xaml @@ -7,6 +7,6 @@ mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> - +