222 lines
7.0 KiB
C#
222 lines
7.0 KiB
C#
using KanSan.Base;
|
|
using KanSan.Base.Interfaces;
|
|
using KanSan.Base.Models;
|
|
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;
|
|
|
|
namespace KanSan.ViewModel
|
|
{
|
|
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 Projekt _selectedProjekt;
|
|
private Baustelle _selectedBaustelle;
|
|
private Sewer _selectedObjekt;
|
|
|
|
public static Baustelle Baustelle;
|
|
public static List<LeistungsverzeichnisPosition> LVPositionen = null;
|
|
|
|
|
|
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 MainWindowViewModel()
|
|
{
|
|
//InitDB();
|
|
LadeRegistry();
|
|
LoadBaustellenLeistungsverzeichnis();
|
|
}
|
|
|
|
public void GenerateExcelFile()
|
|
{
|
|
|
|
}
|
|
|
|
void InitDB()
|
|
{
|
|
Projekt projekt = new Projekt();
|
|
|
|
Kunde kunde = new Kunde();
|
|
kunde.Vorname = "Damian";
|
|
kunde.Nachname = "Bodde";
|
|
|
|
kunde.GuidNr = Guid.NewGuid();
|
|
projekt.Kunde = kunde;
|
|
projekt.GuidNr = Guid.NewGuid();
|
|
|
|
Baustelle baustelle = new Baustelle();
|
|
baustelle.Projekt = projekt;
|
|
baustelle.GuidNr = Guid.NewGuid();
|
|
|
|
|
|
|
|
unitOfWork.ProjekteRepository.Insert(projekt);
|
|
unitOfWork.Commit();
|
|
}
|
|
}
|
|
}
|