From af01e537cfec1858afd939223f4b681e67041f8e Mon Sep 17 00:00:00 2001 From: HuskyTeufel Date: Wed, 5 May 2021 13:06:56 +0200 Subject: [PATCH] committed --- .vscode/launch.json | 17 +++++ ConsoleApplication/Program.cs | 8 +- DataStoring.EfCore/DPContext.cs | 2 +- DataStoring.EfCore/Repository.cs | 2 +- GuiWPF/App.xaml.cs | 1 + GuiWPF/DelegateCommand.cs | 75 +++++++++++++++++++ GuiWPF/HomePage.cs | 5 ++ GuiWPF/HomePageView.xaml | 12 +++ GuiWPF/HomePageViewModel.cs | 27 +++++++ GuiWPF/MainViewModel.cs | 45 +++++++++++ GuiWPF/MainWindow.xaml | 26 ++++--- GuiWPF/MainWindow.xaml.cs | 7 +- .../NotificationObject.cs | 4 +- GuiWPF/SettingsPageView.xaml | 11 +++ GuiWPF/SettingsPageViewModel.cs | 11 +++ {GuiWPF_ViewModel => GuiWPF}/ViewModelBase.cs | 2 +- GuiWPF_ViewModel/MainViewModel.cs | 17 ----- 17 files changed, 234 insertions(+), 38 deletions(-) create mode 100644 GuiWPF/DelegateCommand.cs create mode 100644 GuiWPF/HomePage.cs create mode 100644 GuiWPF/HomePageView.xaml create mode 100644 GuiWPF/HomePageViewModel.cs create mode 100644 GuiWPF/MainViewModel.cs rename {GuiWPF_ViewModel => GuiWPF}/NotificationObject.cs (79%) create mode 100644 GuiWPF/SettingsPageView.xaml create mode 100644 GuiWPF/SettingsPageViewModel.cs rename {GuiWPF_ViewModel => GuiWPF}/ViewModelBase.cs (96%) delete mode 100644 GuiWPF_ViewModel/MainViewModel.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 731f333..48edeef 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,6 +1,7 @@ { "version": "0.2.0", "configurations": [ + { // Use IntelliSense to find out which attributes exist for C# debugging // Use hover for the description of the existing attributes @@ -17,6 +18,22 @@ "console": "internalConsole", "stopAtEntry": false }, + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (WPF)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/GuiWPF/bin/Debug/net5.0-windows/GuiWPF.exe", + "args": [], + "cwd": "${workspaceFolder}/ConsoleApplication", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, { "name": ".NET Core Attach", "type": "coreclr", diff --git a/ConsoleApplication/Program.cs b/ConsoleApplication/Program.cs index 8146e16..084f9c1 100644 --- a/ConsoleApplication/Program.cs +++ b/ConsoleApplication/Program.cs @@ -16,13 +16,14 @@ namespace ConsoleApplication { static void Main(string[] args) { + Console.WriteLine("Hallo"); var kernel = new StandardKernel(); new KernelInitializer().Initialize(kernel); var manager = kernel.Get(); var baustellen = kernel.Get(); - - /*Auftraggeber auftraggeber = new Auftraggeber(); + /* + Auftraggeber auftraggeber = new Auftraggeber(); auftraggeber.Baustellen = new List(); auftraggeber.Baustellen.Add(new Bauvorhaben() { @@ -36,10 +37,11 @@ namespace ConsoleApplication auftraggeber.Strasse = "Schlachthofstraße 42"; manager.Add(auftraggeber); - */ + var auftragger = manager.GetAllAuftraggeber(); var bau = baustellen.GetAllBauvorhaben(); + */ Debugger.Break(); /* diff --git a/DataStoring.EfCore/DPContext.cs b/DataStoring.EfCore/DPContext.cs index 2aca501..07b3aa2 100644 --- a/DataStoring.EfCore/DPContext.cs +++ b/DataStoring.EfCore/DPContext.cs @@ -24,7 +24,7 @@ namespace DataStoring.EfCore protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); - optionsBuilder.UseNpgsql("Host = localhost; Database = DP; Username = DP; Password = DP"); + optionsBuilder.UseNpgsql("Host = 192.168.1.195; Database = DP; Username = DP; Password = DP"); } } } diff --git a/DataStoring.EfCore/Repository.cs b/DataStoring.EfCore/Repository.cs index c8c8c2e..0987007 100644 --- a/DataStoring.EfCore/Repository.cs +++ b/DataStoring.EfCore/Repository.cs @@ -30,7 +30,7 @@ namespace DataStoring.EfCore } catch(Exception e) { - throw new Exception("Cant delete entity with id " + id); + throw new Exception(string.Format("Cant delete entity with id {0} # {1} " ,id,e.Message)); } } diff --git a/GuiWPF/App.xaml.cs b/GuiWPF/App.xaml.cs index 5d2caa7..d8f7545 100644 --- a/GuiWPF/App.xaml.cs +++ b/GuiWPF/App.xaml.cs @@ -13,5 +13,6 @@ namespace GuiWPF /// public partial class App : Application { + } } diff --git a/GuiWPF/DelegateCommand.cs b/GuiWPF/DelegateCommand.cs new file mode 100644 index 0000000..563c40e --- /dev/null +++ b/GuiWPF/DelegateCommand.cs @@ -0,0 +1,75 @@ +using System; +using System.Windows.Input; + +namespace GuiWPF { + public class DelegateCommand : ICommand { + /// + /// Action to be performed when this command is executed + /// + private Action executionAction; + + /// + /// Predicate to determine if the command is valid for execution + /// + private Predicate canExecutePredicate; + + /// + /// Initializes a new instance of the DelegateCommand class. + /// The command will always be valid for execution. + /// + /// The delegate to call on execution + public DelegateCommand(Action execute) + : this(execute, null) + { + } + + /// + /// Initializes a new instance of the DelegateCommand class. + /// + /// The delegate to call on execution + /// The predicate to determine if command is valid for execution + public DelegateCommand(Action execute, Predicate canExecute) + { + if (execute == null) + { + throw new ArgumentNullException("execute"); + } + + this.executionAction = execute; + this.canExecutePredicate = canExecute; + } + + /// + /// Raised when CanExecute is changed + /// + public event EventHandler CanExecuteChanged + { + add { CommandManager.RequerySuggested += value; } + remove { CommandManager.RequerySuggested -= value; } + } + + /// + /// Executes the delegate backing this DelegateCommand + /// + /// parameter to pass to predicate + /// True if command is valid for execution + public bool CanExecute(object parameter) + { + return this.canExecutePredicate == null ? true : this.canExecutePredicate(parameter); + } + + /// + /// Executes the delegate backing this DelegateCommand + /// + /// parameter to pass to delegate + /// Thrown if CanExecute returns false + public void Execute(object parameter) + { + if (!this.CanExecute(parameter)) + { + throw new InvalidOperationException("The command is not valid for execution, check the CanExecute method before attempting to execute."); + } + this.executionAction(parameter); + } + } +} \ No newline at end of file diff --git a/GuiWPF/HomePage.cs b/GuiWPF/HomePage.cs new file mode 100644 index 0000000..29d1360 --- /dev/null +++ b/GuiWPF/HomePage.cs @@ -0,0 +1,5 @@ +namespace GuiWPF { + public class HomePage { + public string PageTitle {get;set;} + } +} \ No newline at end of file diff --git a/GuiWPF/HomePageView.xaml b/GuiWPF/HomePageView.xaml new file mode 100644 index 0000000..b523fba --- /dev/null +++ b/GuiWPF/HomePageView.xaml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/GuiWPF/HomePageViewModel.cs b/GuiWPF/HomePageViewModel.cs new file mode 100644 index 0000000..3e4073f --- /dev/null +++ b/GuiWPF/HomePageViewModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; + +namespace GuiWPF +{ + public class HomePageViewModel : ViewModelBase { + //public string PageTitle = "HomePage"; + public HomePage Model {get; private set;} + public HomePageViewModel(HomePage model) { + this.Model = model; + + } + + public string PageTitle { + get { + return Model.PageTitle; + } + set { + Model.PageTitle = value; + OnPropertyChanged(); + } + } + } + +} \ No newline at end of file diff --git a/GuiWPF/MainViewModel.cs b/GuiWPF/MainViewModel.cs new file mode 100644 index 0000000..da5c659 --- /dev/null +++ b/GuiWPF/MainViewModel.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using System.Windows.Input; + +namespace GuiWPF +{ + public class MainViewModel : ViewModelBase + { + public string PageTitle { get; set; } + public ICommand LoadHomePageCommand {get; private set;} + public ICommand LoadSettingsPageCommand {get; private set;} + + private ViewModelBase _currentViewModel; + public ViewModelBase CurrentViewModel { + get { + Trace.WriteLine("CurrentAbgefragt"); + return _currentViewModel; + } + set { + Trace.WriteLine("CurrentView ist geändert worden"); + _currentViewModel = value; + OnPropertyChanged(); + } + } + + public MainViewModel() + { + PageTitle = "Dichtheitsprüfung by Damian"; + LoadHomePage(); + LoadHomePageCommand = new DelegateCommand(o => this.LoadHomePage()); + LoadSettingsPageCommand = new DelegateCommand(o => this.LoadSettingsPage()); + + //Initialisieren(); + } + + private void LoadHomePage() { + CurrentViewModel = new HomePageViewModel(new HomePage() { PageTitle = "Home"}); + } + private void LoadSettingsPage() { + CurrentViewModel = new SettingsPageViewModel(); + } + } +} diff --git a/GuiWPF/MainWindow.xaml b/GuiWPF/MainWindow.xaml index 30c3f9c..856eefe 100644 --- a/GuiWPF/MainWindow.xaml +++ b/GuiWPF/MainWindow.xaml @@ -5,14 +5,20 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:GuiWPF" mc:Ignorable="d" - Title="{Binding Titel, StringFormat={} DP - {0}}" Height="450" Width="800"> - - - - - - + Title="{Binding PageTitle, StringFormat={} DP - {0}}" Height="450" Width="800"> + + + + + + + + + + +