Umbau angefangen auf ICommand

This commit is contained in:
Husky
2020-07-12 19:32:14 +02:00
parent 9f8e167ce3
commit 3e9a353fc0
33 changed files with 342 additions and 77 deletions

View File

@@ -1,16 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
namespace KanSan.ViewModel
{
public class PropertyChangedClass
public class BaseViewModel
{
public event PropertyChangedEventHandler PropertyChanged;
protected internal void OnPropertyChanged([CallerMemberName] string propertyname = null)
{
Trace.WriteLine("OnPropertyChanged ()" + propertyname);
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
}

View File

@@ -9,7 +9,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class BaustelleEditViewModel : PropertyChangedClass, INotifyPropertyChanged, IBaustelleEditViewModel
public class BaustelleEditViewModel : BaseViewModel, INotifyPropertyChanged, IBaustelleEditViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
private Baustelle baustelle;

View File

@@ -9,7 +9,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class BaustellenListViewModel : IBaustelleListViewModel
public class BaustellenListViewModel :BaseViewModel, IBaustelleListViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
private List<Baustelle> baustellen;

View File

@@ -0,0 +1,32 @@
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
namespace KanSan.ViewModel.Commands
{
public class RelayCommand : ICommand
{
private Action<object> execute;
private Func<object, bool> canExecute;
public event EventHandler CanExecuteChanged;
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
this.execute = execute;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
return this.canExecute == null || this.canExecute(parameter);
}
public void Execute(object parameter)
{
this.execute(parameter);
}
}
}

View File

@@ -9,7 +9,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class KundenEditViewModel : PropertyChangedClass, INotifyPropertyChanged
public class KundenEditViewModel : BaseViewModel, INotifyPropertyChanged
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());

View File

@@ -2,19 +2,23 @@
using KanSan.Base.Interfaces;
using KanSan.Base.Interfaces.UI;
using KanSan.Base.Models;
using KanSan.ViewModel.Commands;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Input;
namespace KanSan.ViewModel
{
public class KundenListViewModel : IKundenListViewModel
public class KundenListViewModel : BaseViewModel, IKundenListViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
private List<Kunde> kunden;
public ICommand AddNewClientCommand { get; set; }
public List<Kunde> Kunden
{
get
@@ -26,6 +30,8 @@ namespace KanSan.ViewModel
public KundenListViewModel()
{
kunden = unitOfWork.KundenRepository.Get().ToList();
AddNewClientCommand = new RelayCommand(parameter => NeueKunde());
}
public Kunde NeueKunde()

View File

@@ -27,7 +27,7 @@ namespace KanSan.ViewModel
public string Tag { get => tag; set => tag = value; }
public bool IsActiveInBaustelle { get => isActiveInBaustelle; set => isActiveInBaustelle = value; }
}
public class LeistungsverzeichnisBaustelleViewModel : PropertyChangedClass, INotifyPropertyChanged, ILeistungsverzeichnisBaustelleViewModel
public class LeistungsverzeichnisBaustelleViewModel : BaseViewModel, INotifyPropertyChanged, ILeistungsverzeichnisBaustelleViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());

View File

@@ -10,7 +10,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class LeistungsverzeichnisPositionenListViewModel :PropertyChangedClass, INotifyPropertyChanged, ILeistungsverzeichnisPositionListViewModel
public class LeistungsverzeichnisPositionenListViewModel :BaseViewModel, INotifyPropertyChanged, ILeistungsverzeichnisPositionListViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
List<LeistungsverzeichnisPosition> lvPositionen;

View File

@@ -9,7 +9,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class LeistungsverzeichnisPositionViewModel : PropertyChangedClass, INotifyPropertyChanged, ILeistungsverzeichnisPositionViewModel
public class LeistungsverzeichnisPositionViewModel : BaseViewModel, INotifyPropertyChanged, ILeistungsverzeichnisPositionViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());

View File

@@ -1,6 +1,7 @@
using KanSan.Base;
using KanSan.Base.Interfaces;
using KanSan.Base.Models;
using KanSan.ViewModel.Commands;
using Microsoft.Win32;
using Syncfusion.XlsIO;
using System;
@@ -11,12 +12,17 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Input;
namespace KanSan.ViewModel
{
public class MainWindowViewModel : PropertyChangedClass, INotifyPropertyChanged
public class MainWindowViewModel : BaseViewModel, INotifyPropertyChanged
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
BaseViewModel actualViewModel;
RegistryKey registry;
const string REGISTRYKEY = "HKEY_CURRENT_USER\\Software\\Cosysda\\KanSan";
@@ -27,6 +33,32 @@ namespace KanSan.ViewModel
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
@@ -184,10 +216,45 @@ namespace KanSan.ViewModel
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()

View File

@@ -9,7 +9,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class ObjekteEditViewModel : PropertyChangedClass,IObjekteEditViewModel, INotifyPropertyChanged
public class ObjekteEditViewModel : BaseViewModel,IObjekteEditViewModel, INotifyPropertyChanged
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
string strassename;

View File

@@ -2,10 +2,13 @@
using KanSan.Base.Interfaces;
using KanSan.Base.Interfaces.UI;
using KanSan.Base.Models;
using KanSan.ViewModel.Commands;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Input;
namespace KanSan.ViewModel
{
@@ -14,8 +17,10 @@ namespace KanSan.ViewModel
public string Strassename { get; set; }
public IEnumerable<Sewer> Objekte { get; set; }
}
public class ObjekteListViewModel
public class ObjekteListViewModel : BaseViewModel
{
public ICommand ObjektSelected { get; set; }
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
List<ObjekteTransfer> kanalObjekte = new List<ObjekteTransfer>();
@@ -37,9 +42,22 @@ namespace KanSan.ViewModel
}).ToList();
kanalObjekte = x;
ObjektSelected = new RelayCommand(SelectObjekt);
//kanalObjekte = unitOfWork.KanaeleRepository.Get(x => x.Baustelle.Equals(selectedBaustelle)).ToList();
}
private void SelectObjekt(object obj)
{
if (!(obj is Sewer)) return;
Sewer sewer = (Sewer)obj;
if (sewer == null) return;
SewerMainWindowViewModel t = new SewerMainWindowViewModel(sewer);
Debugger.Break();
//throw new NotImplementedException();
}
public Sewer NeueObjektHinzufügen()
{
Guid guid = Guid.NewGuid();

View File

@@ -9,7 +9,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class ProjektEditViewModel : PropertyChangedClass,INotifyPropertyChanged, IProjektEditViewModel
public class ProjektEditViewModel : BaseViewModel,INotifyPropertyChanged, IProjektEditViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
private Projekt projekt;

View File

@@ -9,7 +9,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class ProjektListViewModel : IProjektListViewModel
public class ProjektListViewModel : BaseViewModel, IProjektListViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
private List<Projekt> projektevonKunde;

View File

@@ -10,7 +10,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class ProjektViewModel : PropertyChangedClass,INotifyPropertyChanged
public class ProjektViewModel : BaseViewModel,INotifyPropertyChanged
{
private Projekt _baustelle;
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());

View File

@@ -11,7 +11,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class SchaedenEditViewModel : PropertyChangedClass, INotifyPropertyChanged, ISchaedenEditViewModel
public class SchaedenEditViewModel : BaseViewModel, INotifyPropertyChanged, ISchaedenEditViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
decimal entfernung;

View File

@@ -7,7 +7,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class SewerMainMenuViewModel : PropertyChangedClass,INotifyPropertyChanged
public class SewerMainWindowViewModel : BaseViewModel,INotifyPropertyChanged
{
private Sewer model;
private SchaedenViewModel schadenViewModel;
@@ -58,7 +58,7 @@ namespace KanSan.ViewModel
public SewerMainMenuViewModel(Sewer model)
public SewerMainWindowViewModel(Sewer model)
{
if (model == null) throw new ArgumentNullException();
this.model = model;

View File

@@ -10,7 +10,7 @@ using System.Text;
namespace KanSan.ViewModel
{
public class TaetigkeitEditViewModel : PropertyChangedClass, INotifyPropertyChanged, ITaetigkeitEditViewModel
public class TaetigkeitEditViewModel : BaseViewModel, INotifyPropertyChanged, ITaetigkeitEditViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
Fahrzeug fahrzeug;