using Microsoft.Win32; using SewerStammGen.Shared.Domain; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 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; } public int SchachtID { get; private set; } public int HaltungID { get; private set; } public Schacht SelectedSchacht { get; private set; } public Kanal SelectedHaltung {get; private set; } public void SetProjekt(Projekt projekt, bool notification = true) { ProjektID = projekt.Id; if(notification) { OnProjektChanged(); } string keyName = userroot + "\\" + firmkey + "\\" + subkey; Registry.SetValue(keyName, "LastProjekt", ProjektID); } public void SetSchacht(Schacht schacht, bool notification = true) { SelectedSchacht = schacht; SchachtID = schacht.Id; if(notification) { OnSchachtChanged(); } } public void SetHaltung(Kanal haltung, bool notification = true) { SelectedHaltung = haltung; HaltungID = haltung.Id; if(notification) { OnHaltungChanged(); } } public event EventHandler? ProjektChanged; public event EventHandler? SchachtChanged; public event EventHandler? HaltungChanged; private void OnProjektChanged() { ProjektChanged?.Invoke(this, new EventArgs()); } private void OnSchachtChanged() { SchachtChanged?.Invoke(this, new EventArgs()); } private void OnHaltungChanged() { 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(); } } } }