Leitungen können nun bearbeitet werden
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using DaSaSo.Domain.Enums;
|
||||
using DaSaSo.Domain.Model;
|
||||
using DaSaSo.Domain.Services;
|
||||
using DaSaSo.EntityFramework;
|
||||
using DaSaSo.EntityFramework.Services;
|
||||
using DaSaSo.ViewModel.Commands;
|
||||
@@ -7,10 +8,12 @@ using DaSaSo.ViewModel.Enums;
|
||||
using DaSaSo.ViewModel.Interface;
|
||||
using DaSaSo.ViewModel.State.Navigation;
|
||||
using Microsoft.Toolkit.Mvvm.Input;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
@@ -21,9 +24,15 @@ namespace DaSaSo.ViewModel
|
||||
{
|
||||
private readonly IViewModelAbstractFactory viewModelFactory;
|
||||
private readonly IActualProject _actualProject;
|
||||
private readonly IDataService<Client> _clientDataService;
|
||||
private readonly IDataService<Project> _projectDataService;
|
||||
private readonly IDataService<Buildingsite> _buildingsiteDataService;
|
||||
|
||||
private string _clientname = "";
|
||||
private string _projektname = "";
|
||||
private string _buildingsitename = "";
|
||||
RegistryKey registry;
|
||||
const string REGISTRYKEY = "HKEY_CURRENT_USER\\Software\\Cosysda\\DaSaSo";
|
||||
public bool CanSelectProject { get => _actualProject.AktuellClient != null; }
|
||||
public bool CanSelectBuildingSite { get => _actualProject.AktuellProjekt != null; }
|
||||
public bool CanSelectSewerObjects { get => _actualProject.AktuellBaustelle != null; }
|
||||
@@ -69,11 +78,32 @@ namespace DaSaSo.ViewModel
|
||||
}
|
||||
}
|
||||
}
|
||||
public string ApplicationTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
string gitVersion;
|
||||
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DaSaSo.ViewModel.version.txt"))
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
gitVersion = reader.ReadToEnd();
|
||||
}
|
||||
return string.Format("Cosysda Sanierung Software : {0}",gitVersion);
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindowViewModel(IMainWindowNavigator navigator,IViewModelAbstractFactory viewModelFactory, IActualProject actualProject)
|
||||
public MainWindowViewModel(IMainWindowNavigator navigator,IViewModelAbstractFactory viewModelFactory,
|
||||
IActualProject actualProject,
|
||||
IDataService<Client> clientDataService,
|
||||
IDataService<Project> projectDataService,
|
||||
IDataService<Buildingsite> buildingsiteDataService
|
||||
)
|
||||
{
|
||||
this._navigator = navigator;
|
||||
this.viewModelFactory = viewModelFactory;
|
||||
_clientDataService = clientDataService;
|
||||
_projectDataService = projectDataService;
|
||||
_buildingsiteDataService = buildingsiteDataService;
|
||||
|
||||
_navigator.StateChanged += _navigator_StateChanged;
|
||||
|
||||
@@ -84,6 +114,59 @@ namespace DaSaSo.ViewModel
|
||||
_actualProject.ProjectChanged += _actualProject_ProjectChanged;
|
||||
_actualProject.BuildingSiteChanged += _actualProject_BuildingSiteChanged;
|
||||
_actualProject.SewerObjectChanged += _actualProject_SewerObjectChanged;
|
||||
|
||||
ladeRegistry();
|
||||
}
|
||||
|
||||
private async void ladeRegistry()
|
||||
{
|
||||
|
||||
registry = Registry.CurrentUser.OpenSubKey("Software\\Cosysda\\DaSaSo");
|
||||
if (registry == null) initRegistry();
|
||||
int clientid = Convert.ToInt32((string)registry.GetValue("lastclient", "-1"));
|
||||
if (clientid == -1)
|
||||
return;
|
||||
Client lastClient = await _clientDataService.Get(clientid);
|
||||
if (lastClient == null)
|
||||
{
|
||||
saveInRegistry("lastclient", "-1");
|
||||
return;
|
||||
}
|
||||
_actualProject.SetClient(lastClient);
|
||||
|
||||
int projectid = Convert.ToInt32((string)registry.GetValue("lastproject", "-1"));
|
||||
if (projectid == -1)
|
||||
return;
|
||||
Project lastProject = await _projectDataService.Get(projectid);
|
||||
if(lastProject == null)
|
||||
{
|
||||
saveInRegistry("lastproject","-1");
|
||||
return;
|
||||
}
|
||||
_actualProject.SetProject(lastProject);
|
||||
|
||||
int buildingsiteid = Convert.ToInt32((string)registry.GetValue("lastbuildingsite", "-1"));
|
||||
if (buildingsiteid == -1)
|
||||
return;
|
||||
Buildingsite lastBuildingiste = await _buildingsiteDataService.Get(buildingsiteid);
|
||||
if(lastBuildingiste == null)
|
||||
{
|
||||
saveInRegistry("lastbuildingsite","-1");
|
||||
return;
|
||||
}
|
||||
_actualProject.SetBuildingSite(lastBuildingiste);
|
||||
|
||||
}
|
||||
|
||||
private void saveInRegistry(string key, string value)
|
||||
{
|
||||
Registry.SetValue(REGISTRYKEY, key, value);
|
||||
}
|
||||
|
||||
private void initRegistry()
|
||||
{
|
||||
Registry.CurrentUser.CreateSubKey("Software\\Cosysda\\DaSaSo");
|
||||
ladeRegistry();
|
||||
}
|
||||
|
||||
private void _actualProject_SewerObjectChanged(object? sender, EventArgs e)
|
||||
@@ -98,6 +181,7 @@ namespace DaSaSo.ViewModel
|
||||
|
||||
private void _actualProject_BuildingSiteChanged(object? sender, EventArgs e)
|
||||
{
|
||||
saveInRegistry("lastbuildingsite", _actualProject.AktuellBaustelle.Id.ToString());
|
||||
Buildingsitename = _actualProject.AktuellBaustelle.BuildingSiteNumber;
|
||||
OnPropertyChanged(nameof(CanSelectSewerObjects));
|
||||
UpdateCurrentViewModelCommand.Execute(EMainWindowViewType.SewerObjects);
|
||||
@@ -105,6 +189,7 @@ namespace DaSaSo.ViewModel
|
||||
|
||||
private void _actualProject_ProjectChanged(object? sender, EventArgs e)
|
||||
{
|
||||
saveInRegistry("lastproject", _actualProject.AktuellProjekt.Id.ToString());
|
||||
Projektname = _actualProject.AktuellProjekt.Name;
|
||||
OnPropertyChanged(nameof(CanSelectBuildingSite));
|
||||
UpdateCurrentViewModelCommand.Execute(EMainWindowViewType.Buildingsites);
|
||||
@@ -112,6 +197,7 @@ namespace DaSaSo.ViewModel
|
||||
|
||||
private void _actualProject_ClientChanged(object? sender, EventArgs e)
|
||||
{
|
||||
saveInRegistry("lastclient", _actualProject.AktuellClient.Id.ToString());
|
||||
ClientName = _actualProject.AktuellClient.Firstname;
|
||||
OnPropertyChanged(nameof(CanSelectProject));
|
||||
UpdateCurrentViewModelCommand.Execute(EMainWindowViewType.Projects);
|
||||
|
||||
Reference in New Issue
Block a user