266 lines
8.2 KiB
C#
266 lines
8.2 KiB
C#
using KanSan.Base;
|
|
using KanSan.Base.Interfaces;
|
|
using KanSan.Base.Models;
|
|
using KanSan.ViewModel.Commands;
|
|
using Microsoft.Win32;
|
|
using Syncfusion.XlsIO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Windows.Input;
|
|
|
|
namespace KanSan.ViewModel
|
|
{
|
|
public class MainWindowViewModel : BaseViewModel, INotifyPropertyChanged
|
|
{
|
|
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
|
|
|
|
BaseViewModel actualViewModel;
|
|
|
|
|
|
RegistryKey registry;
|
|
const string REGISTRYKEY = "HKEY_CURRENT_USER\\Software\\Cosysda\\KanSan";
|
|
|
|
private Kunde _selectedKunde;
|
|
private Projekt _selectedProjekt;
|
|
private Baustelle _selectedBaustelle;
|
|
private Sewer _selectedObjekt;
|
|
|
|
public static Baustelle Baustelle;
|
|
public static List<LeistungsverzeichnisPosition> LVPositionen = null;
|
|
|
|
|
|
|
|
public ICommand ListClientsCommand { get; set; }
|
|
public ICommand ListProjectsCommand { get; set; }
|
|
public ICommand ListBaustellenCommand { get; set; }
|
|
public ICommand ListObjectsCommand { get; set; }
|
|
public ICommand ShowLeistungsverzeichnisCommand { get; set; }
|
|
public ICommand SelectLeistungsverzeichnisBaustelleCommand { get; set; }
|
|
|
|
|
|
public BaseViewModel ActualViewModel
|
|
{
|
|
get
|
|
{
|
|
Trace.WriteLine(actualViewModel);
|
|
return actualViewModel;
|
|
}
|
|
set
|
|
{
|
|
if (actualViewModel == value) return;
|
|
Trace.WriteLine("Setze viewModel auf " + value);
|
|
actualViewModel = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
|
|
public string ApplicationTitle
|
|
{
|
|
get
|
|
{
|
|
string gitVersion;
|
|
|
|
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("KanSan.ViewModel.version.txt"))
|
|
using (StreamReader reader = new StreamReader(stream))
|
|
{
|
|
gitVersion = reader.ReadToEnd();
|
|
}
|
|
|
|
return string.Format("KanalSanierungsverwaltung : {0}",gitVersion);
|
|
}
|
|
}
|
|
|
|
void LoadBaustellenLeistungsverzeichnis()
|
|
{
|
|
if (LVPositionen == null)
|
|
LVPositionen = new List<LeistungsverzeichnisPosition>();
|
|
if (LVPositionen.Count > 0)
|
|
LVPositionen.Clear();
|
|
IEnumerable<BaustelleLeistungsverzeichnisReferenz> baustelleLeistungsverzeichnis = unitOfWork.LeistungsverzeichnisReferenz.Get(x => x.Baustelle.Equals(Baustelle), includeProperties: "LVPosition");
|
|
foreach(BaustelleLeistungsverzeichnisReferenz referenz in baustelleLeistungsverzeichnis)
|
|
{
|
|
LVPositionen.Add(referenz.LVPosition);
|
|
}
|
|
}
|
|
|
|
public Kunde SelectedKunde
|
|
{
|
|
get
|
|
{
|
|
return _selectedKunde;
|
|
}
|
|
set
|
|
{
|
|
if (_selectedKunde != null)
|
|
{
|
|
if (_selectedKunde.GuidNr.Equals(value.GuidNr)) return;
|
|
}
|
|
_selectedKunde = value;
|
|
_selectedProjekt = null;
|
|
_selectedBaustelle = null;
|
|
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;
|
|
MainWindowViewModel.Baustelle = value;
|
|
SaveInRegistry("LastBaustelle", value.GuidNr.ToString());
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
|
|
public Sewer SelectedObjekt
|
|
{
|
|
get
|
|
{
|
|
return _selectedObjekt;
|
|
}
|
|
set
|
|
{
|
|
if(_selectedObjekt != null)
|
|
{
|
|
if (_selectedObjekt.GuidNr.Equals(value.GuidNr)) return;
|
|
}
|
|
_selectedObjekt = value;
|
|
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();
|
|
MainWindowViewModel.Baustelle = _selectedBaustelle;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void InitRegistry()
|
|
{
|
|
Registry.CurrentUser.CreateSubKey("Software\\Cosysda\\KanSan");
|
|
LadeRegistry();
|
|
}
|
|
|
|
public void init()
|
|
{
|
|
|
|
}
|
|
public MainWindowViewModel()
|
|
{
|
|
|
|
LadeRegistry();
|
|
LoadBaustellenLeistungsverzeichnis();
|
|
|
|
ListClients();
|
|
|
|
|
|
ListClientsCommand = new RelayCommand(parmater => ListClients());
|
|
ListProjectsCommand = new RelayCommand(parameter => ListProjekte());
|
|
ListBaustellenCommand = new RelayCommand(paramter => ListBaustellen());
|
|
ListObjectsCommand = new RelayCommand(parameter => ListObjekte());
|
|
|
|
}
|
|
|
|
private void ListClients()
|
|
{
|
|
ActualViewModel = new KundenListViewModel();
|
|
}
|
|
|
|
private void ListProjekte()
|
|
{
|
|
ActualViewModel = new ProjektListViewModel(SelectedKunde);
|
|
}
|
|
|
|
private void ListBaustellen()
|
|
{
|
|
ActualViewModel = new BaustellenListViewModel(SelectedProjekt);
|
|
}
|
|
|
|
private void ListObjekte()
|
|
{
|
|
ActualViewModel = new ObjekteListViewModel(SelectedBaustelle);
|
|
}
|
|
|
|
public void GenerateExcelFile()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|