MainviewModel erstellt
This commit is contained in:
@@ -1,16 +1,28 @@
|
||||
using KanSan.Base.Models;
|
||||
using KanSan.Base;
|
||||
using KanSan.Base.Interfaces;
|
||||
using KanSan.Base.Models;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace KanSan.ViewModel
|
||||
{
|
||||
public class MainWindowViewModel
|
||||
public class MainWindowViewModel : PropertyChangedClass, INotifyPropertyChanged
|
||||
{
|
||||
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
|
||||
RegistryKey registry;
|
||||
const string REGISTRYKEY = "HKEY_CURRENT_USER\\Software\\Cosysda\\KanSan";
|
||||
|
||||
private Kunde _selectedKunde;
|
||||
private string applicationTitle;
|
||||
private Projekt _selectedProjekt;
|
||||
private Baustelle _selectedBaustelle;
|
||||
|
||||
|
||||
public string ApplicationTitle
|
||||
{
|
||||
@@ -34,11 +46,110 @@ namespace KanSan.ViewModel
|
||||
{
|
||||
return _selectedKunde;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_selectedKunde != null)
|
||||
{
|
||||
if (_selectedKunde.GuidNr.Equals(value.GuidNr)) return;
|
||||
}
|
||||
_selectedKunde = value;
|
||||
SaveInRegistry("LastKunde", value.GuidNr.ToString());
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public Projekt SelectedProjekt
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedProjekt;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(_selectedProjekt != null)
|
||||
{
|
||||
if (_selectedProjekt.GuidNr.Equals(value.GuidNr)) return;
|
||||
}
|
||||
_selectedProjekt = value;
|
||||
SaveInRegistry("LastProjekt", value.GuidNr.ToString());
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public Baustelle SelectedBaustelle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedBaustelle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(_selectedBaustelle != null)
|
||||
{
|
||||
if (_selectedBaustelle.GuidNr.Equals(value.GuidNr)) return;
|
||||
}
|
||||
_selectedBaustelle = value;
|
||||
SaveInRegistry("LastBaustelle", value.GuidNr.ToString());
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SaveInRegistry(string key, string value)
|
||||
{
|
||||
Registry.SetValue(REGISTRYKEY, key, value);
|
||||
|
||||
}
|
||||
|
||||
private void LadeRegistry()
|
||||
{
|
||||
registry = Registry.CurrentUser.OpenSubKey("Software\\Cosysda\\KanSan");
|
||||
if (registry == null) InitRegistry();
|
||||
|
||||
string clientGuidStr = (string)registry.GetValue("LastKunde");
|
||||
if (clientGuidStr != null)
|
||||
{
|
||||
Guid clientGuid = Guid.Parse(clientGuidStr);
|
||||
|
||||
if (clientGuid != null)
|
||||
{
|
||||
IEnumerable<Kunde> loadedKunden = unitOfWork.KundenRepository.Get(x => x.GuidNr.Equals(clientGuid));
|
||||
if (loadedKunden.Count() == 1) _selectedKunde = loadedKunden.First();
|
||||
}
|
||||
}
|
||||
|
||||
string projekteGuidStr = (string)registry.GetValue("LastProjekt");
|
||||
if (projekteGuidStr != null)
|
||||
{
|
||||
Guid projekteGuid = Guid.Parse(projekteGuidStr);
|
||||
|
||||
if (projekteGuid != null)
|
||||
{
|
||||
IEnumerable<Projekt> loadedProjekte = unitOfWork.ProjekteRepository.Get(x => x.GuidNr.Equals(projekteGuid));
|
||||
if (loadedProjekte.Count() == 1) _selectedProjekt = loadedProjekte.First();
|
||||
}
|
||||
}
|
||||
|
||||
string baustellenGuidStr = (string)registry.GetValue("LastBaustelle");
|
||||
if (baustellenGuidStr != null)
|
||||
{
|
||||
Guid baustellenGuid = Guid.Parse(baustellenGuidStr);
|
||||
|
||||
if (baustellenGuid != null)
|
||||
{
|
||||
IEnumerable<Baustelle> loadedBaustelle = unitOfWork.BaustelleRepository.Get(x => x.GuidNr.Equals(baustellenGuid));
|
||||
if (loadedBaustelle.Count() == 1) _selectedBaustelle = loadedBaustelle.First();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitRegistry()
|
||||
{
|
||||
Registry.CurrentUser.CreateSubKey("Software\\Cosysda\\KanSan");
|
||||
LadeRegistry();
|
||||
}
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
|
||||
LadeRegistry();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user