MainviewModel erstellt
This commit is contained in:
@@ -14,6 +14,10 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\KanSan.Base\KanSan.Base.csproj" />
|
<ProjectReference Include="..\KanSan.Base\KanSan.Base.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
using KanSan.Base.Models;
|
using KanSan.Base;
|
||||||
|
using KanSan.Base.Interfaces;
|
||||||
|
using KanSan.Base.Models;
|
||||||
|
using Microsoft.Win32;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace KanSan.ViewModel
|
namespace KanSan.ViewModel
|
||||||
{
|
{
|
||||||
public class MainWindowViewModel
|
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 Kunde _selectedKunde;
|
||||||
private string applicationTitle;
|
private Projekt _selectedProjekt;
|
||||||
|
private Baustelle _selectedBaustelle;
|
||||||
|
|
||||||
|
|
||||||
public string ApplicationTitle
|
public string ApplicationTitle
|
||||||
{
|
{
|
||||||
@@ -34,11 +46,110 @@ namespace KanSan.ViewModel
|
|||||||
{
|
{
|
||||||
return _selectedKunde;
|
return _selectedKunde;
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_selectedKunde != null)
|
||||||
|
{
|
||||||
|
if (_selectedKunde.GuidNr.Equals(value.GuidNr)) return;
|
||||||
|
}
|
||||||
|
_selectedKunde = value;
|
||||||
|
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;
|
||||||
|
SaveInRegistry("LastBaustelle", value.GuidNr.ToString());
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitRegistry()
|
||||||
|
{
|
||||||
|
Registry.CurrentUser.CreateSubKey("Software\\Cosysda\\KanSan");
|
||||||
|
LadeRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MainWindowViewModel()
|
public MainWindowViewModel()
|
||||||
{
|
{
|
||||||
|
LadeRegistry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,6 @@
|
|||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="version.txt" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<EmbeddedResource Include="version.txt">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</EmbeddedResource>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ilmerge" Version="3.0.29" />
|
<PackageReference Include="ilmerge" Version="3.0.29" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
<ContentControl Grid.Column="1" Name="ContentController" Content="KanSan"/>
|
<ContentControl Grid.Column="1" Name="ContentController" Content="KanSan"/>
|
||||||
<StatusBar Grid.ColumnSpan="2" Margin="0,1,0,0" Grid.Row="1">
|
<StatusBar Grid.ColumnSpan="2" Margin="0,1,0,0" Grid.Row="1">
|
||||||
<StatusBarItem Content="Kunde" />
|
<StatusBarItem Content="{Binding SelectedKunde.Vorname}" />
|
||||||
<StatusBarItem Content="Projekt" />
|
<StatusBarItem Content="Projekt" />
|
||||||
<StatusBarItem Content="Baustelle" />
|
<StatusBarItem Content="Baustelle" />
|
||||||
</StatusBar>
|
</StatusBar>
|
||||||
|
|||||||
@@ -25,24 +25,33 @@ namespace KanSan
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
|
UI.UCKundeEdit UCKundeEdit;
|
||||||
|
UI.UCKundeList UCKundeList;
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.DataContext = new MainWindowViewModel();
|
this.DataContext = new MainWindowViewModel();
|
||||||
//this.Title = ProgrammHashVersion.GIT_HASH;
|
|
||||||
|
UCKundeList = new UI.UCKundeList();
|
||||||
|
UCKundeList.KundeAdded += UCKundeList_KundeAdded;
|
||||||
|
UCKundeList.KundeSelect += UCKundeList_KundeSelect;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UCKundeList_KundeSelect(object sender, UI.KundeAddedKlickEventArgs e)
|
||||||
|
{
|
||||||
|
(DataContext as MainWindowViewModel).SelectedKunde = e.kunde;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UCKundeList_KundeAdded(object sender, UI.KundeAddedKlickEventArgs e)
|
private void UCKundeList_KundeAdded(object sender, UI.KundeAddedKlickEventArgs e)
|
||||||
{
|
{
|
||||||
UI.UCKundeEdit uCKundeEdit = new UI.UCKundeEdit(e.kunde);
|
UCKundeEdit = new UI.UCKundeEdit(e.kunde);
|
||||||
ContentController.Content = uCKundeEdit;
|
ContentController.Content = UCKundeEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnKunden_Click(object sender, RoutedEventArgs e)
|
private void btnKunden_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
UI.UCKundeList uCKundeList = new UI.UCKundeList();
|
ContentController.Content = UCKundeList;
|
||||||
uCKundeList.KundeAdded += UCKundeList_KundeAdded;
|
|
||||||
ContentController.Content = uCKundeList;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace KanSan
|
|
||||||
{
|
|
||||||
public static class ProgrammHashVersion
|
|
||||||
{
|
|
||||||
public static string GIT_HASH
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
string gitVersion;
|
|
||||||
|
|
||||||
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("KanSan.version.txt"))
|
|
||||||
using (StreamReader reader = new StreamReader(stream))
|
|
||||||
{
|
|
||||||
gitVersion = reader.ReadToEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
return gitVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
<RowDefinition Height="50" />
|
<RowDefinition Height="50" />
|
||||||
<RowDefinition Height="50"/>
|
<RowDefinition Height="50"/>
|
||||||
|
<RowDefinition Height="50" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<DataGrid AutoGenerateColumns="False" SelectionMode="Single" ItemsSource="{Binding Kunden}" Name="dgKundenList">
|
<DataGrid AutoGenerateColumns="False" SelectionMode="Single" ItemsSource="{Binding Kunden}" Name="dgKundenList">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
@@ -19,8 +20,9 @@
|
|||||||
<DataGridTextColumn Header="Ort" Binding="{Binding Ort}" />
|
<DataGridTextColumn Header="Ort" Binding="{Binding Ort}" />
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
<Button Grid.Row="1" Name="EditKunde" Content="Kunde Editieren" Click="EditKunde_Click" />
|
<Button Grid.Row="1" Name="SelectKunde" Content="Kunde Auswählen" Click="SelectKunde_Click" />
|
||||||
<Button Grid.Row="2" Name="NeueKunde" Content="Neue Kunde anlegen" Click="NeueKunde_Click" />
|
<Button Grid.Row="2" Name="EditKunde" Content="Kunde Editieren" Click="EditKunde_Click" />
|
||||||
|
<Button Grid.Row="3" Name="NeueKunde" Content="Neue Kunde anlegen" Click="NeueKunde_Click" />
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ namespace KanSan.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class UCKundeList : UserControl
|
public partial class UCKundeList : UserControl
|
||||||
{
|
{
|
||||||
|
public event EventHandler<KundeAddedKlickEventArgs> KundeAdded;
|
||||||
|
public event EventHandler<KundeAddedKlickEventArgs> KundeSelect;
|
||||||
public UCKundeList()
|
public UCKundeList()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -32,23 +33,37 @@ namespace KanSan.UI
|
|||||||
{
|
{
|
||||||
KundeAddedKlickEventArgs args = new KundeAddedKlickEventArgs();
|
KundeAddedKlickEventArgs args = new KundeAddedKlickEventArgs();
|
||||||
args.kunde = (DataContext as KundenListViewModel).NeueKunde();
|
args.kunde = (DataContext as KundenListViewModel).NeueKunde();
|
||||||
OnKlickedKunde(args);
|
OnClickKundeAdded(args);
|
||||||
|
|
||||||
}
|
}
|
||||||
protected virtual void OnKlickedKunde(KundeAddedKlickEventArgs e)
|
protected virtual void OnClickKundeAdded(KundeAddedKlickEventArgs e)
|
||||||
{
|
{
|
||||||
EventHandler<KundeAddedKlickEventArgs> handler = KundeAdded;
|
EventHandler<KundeAddedKlickEventArgs> handler = KundeAdded;
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
handler(this, e);
|
handler(this, e);
|
||||||
}
|
}
|
||||||
public event EventHandler<KundeAddedKlickEventArgs> KundeAdded;
|
|
||||||
|
protected virtual void OnClickSelectedKunde(KundeAddedKlickEventArgs e)
|
||||||
|
{
|
||||||
|
EventHandler<KundeAddedKlickEventArgs> handler = KundeSelect;
|
||||||
|
if (handler != null)
|
||||||
|
handler(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void EditKunde_Click(object sender, RoutedEventArgs e)
|
private void EditKunde_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Kunde selectedKunde = (dgKundenList.SelectedItem as Kunde);
|
Kunde selectedKunde = (dgKundenList.SelectedItem as Kunde);
|
||||||
if (selectedKunde == null) return;
|
if (selectedKunde == null) return;
|
||||||
|
|
||||||
OnKlickedKunde(new KundeAddedKlickEventArgs() { kunde = selectedKunde });
|
OnClickKundeAdded(new KundeAddedKlickEventArgs() { kunde = selectedKunde });
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectKunde_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Kunde selectedKunde = (dgKundenList.SelectedItem as Kunde);
|
||||||
|
if (selectedKunde == null) return;
|
||||||
|
OnClickSelectedKunde(new KundeAddedKlickEventArgs() { kunde = selectedKunde });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user