Mvvm Pattern erweitert
This commit is contained in:
@@ -6,8 +6,13 @@
|
|||||||
xmlns:local="clr-namespace:KanSan"
|
xmlns:local="clr-namespace:KanSan"
|
||||||
xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Class="KanSan.MainWindow"
|
xmlns:syncfusion="http://schemas.syncfusion.com/wpf" x:Class="KanSan.MainWindow"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="MainWindow" Height="450" Width="800">
|
Title="MainWindow" Height="450" Width="800" WindowStartupLocation="CenterScreen" WindowState="Maximized">
|
||||||
<Grid>
|
<Grid>
|
||||||
<ContentControl Name="ContentController" Content="ContentControl" HorizontalAlignment="Left" Height="402" Margin="226,22,0,0" VerticalAlignment="Top" Width="564"/>
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition />
|
||||||
|
<ColumnDefinition />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<ContentControl Grid.Column="1" Name="ContentController" Content="ContentControl" HorizontalAlignment="Left" Height="402" Margin="226,22,0,0" VerticalAlignment="Top" Width="564"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -28,11 +28,9 @@ namespace KanSan
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Title = ProgrammHashVersion.GIT_HASH;
|
this.Title = ProgrammHashVersion.GIT_HASH;
|
||||||
|
|
||||||
UnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
|
|
||||||
var d = unitOfWork.KundenRepository.Get().First();
|
|
||||||
|
|
||||||
UI.UCKundeEdit uCKundeEdit = new UI.UCKundeEdit(d);
|
|
||||||
|
UI.UCKundeEdit uCKundeEdit = new UI.UCKundeEdit();
|
||||||
ContentController.Content = uCKundeEdit;
|
ContentController.Content = uCKundeEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,40 +23,15 @@ namespace KanSan.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class WindowBaustelleEdit : Window
|
public partial class WindowBaustelleEdit : Window
|
||||||
{
|
{
|
||||||
private UnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
|
|
||||||
private Baustelle bs = null;
|
|
||||||
|
|
||||||
|
|
||||||
public WindowBaustelleEdit(Baustelle baustelle)
|
public WindowBaustelleEdit()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
if (baustelle == null) throw new ArgumentNullException("baustelle");
|
this.DataContext = new BaustelleViewModel();
|
||||||
|
|
||||||
bs = baustelle;
|
|
||||||
|
|
||||||
BaustelleViewModel model = new BaustelleViewModel(bs);
|
|
||||||
|
|
||||||
|
|
||||||
model.PropertyChanged += Model_PropertyChanged;
|
|
||||||
|
|
||||||
this.DataContext = model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
||||||
{
|
|
||||||
BaustelleViewModel baustelleViewModel = (BaustelleViewModel)sender;
|
|
||||||
bs.Ort = baustelleViewModel.Ort;
|
|
||||||
bs.Projektnummer = baustelleViewModel.Projektnummer;
|
|
||||||
bs.Strasse = baustelleViewModel.Strasse;
|
|
||||||
|
|
||||||
unitOfWork.BaustellenRepository.Update(bs);
|
|
||||||
//Debugger.Break();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Window_Closed(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
unitOfWork.Commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<RowDefinition />
|
<RowDefinition />
|
||||||
<RowDefinition />
|
<RowDefinition />
|
||||||
<RowDefinition />
|
<RowDefinition />
|
||||||
|
<RowDefinition />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition />
|
<ColumnDefinition />
|
||||||
@@ -25,6 +26,8 @@
|
|||||||
<Label Grid.Column="0" Grid.Row="3">Plz</Label>
|
<Label Grid.Column="0" Grid.Row="3">Plz</Label>
|
||||||
<Label Grid.Column="0" Grid.Row="4">Ort</Label>
|
<Label Grid.Column="0" Grid.Row="4">Ort</Label>
|
||||||
|
|
||||||
|
<Button Name="Speichern" Content="Speichern" Grid.Row="5" Grid.ColumnSpan="2" Click="Speichern_Click" />
|
||||||
|
|
||||||
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Vorname}" />
|
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Vorname}" />
|
||||||
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Nachname}" />
|
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Nachname}" />
|
||||||
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Strasse}" />
|
<TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Strasse}" />
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using KanSan.Base.Models;
|
|||||||
using KanSan.ViewModel;
|
using KanSan.ViewModel;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
@@ -21,24 +22,20 @@ namespace KanSan.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class UCKundeEdit : UserControl
|
public partial class UCKundeEdit : UserControl
|
||||||
{
|
{
|
||||||
private Kunde kunde = null;
|
//private Kunde kunde = null;
|
||||||
private UnitOfWork unitOfWork = null;
|
//private UnitOfWork unitOfWork = null;
|
||||||
public UCKundeEdit(Kunde kunde)
|
public UCKundeEdit()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
this.kunde = kunde;
|
|
||||||
|
|
||||||
unitOfWork = new UnitOfWork(new KanSanContext());
|
this.DataContext = new KundeViewModel();
|
||||||
|
|
||||||
KundeViewModel kundeViewModel = new KundeViewModel(kunde);
|
|
||||||
kundeViewModel.PropertyChanged += KundeViewModel_PropertyChanged;
|
|
||||||
this.DataContext = kundeViewModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void KundeViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
private void Speichern_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
((KundeViewModel)DataContext).Speichern();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
using KanSan.Base.Models;
|
using KanSan.Base;
|
||||||
|
using KanSan.Base.Interfaces;
|
||||||
|
using KanSan.Base.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -10,7 +13,7 @@ namespace KanSan.ViewModel
|
|||||||
class BaustelleViewModel : PropertyChangedClass,INotifyPropertyChanged
|
class BaustelleViewModel : PropertyChangedClass,INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
private Baustelle _baustelle;
|
private Baustelle _baustelle;
|
||||||
|
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
|
||||||
|
|
||||||
private string ort;
|
private string ort;
|
||||||
private string strasse;
|
private string strasse;
|
||||||
@@ -57,9 +60,9 @@ namespace KanSan.ViewModel
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public BaustelleViewModel(Baustelle baustelle)
|
public BaustelleViewModel()
|
||||||
{
|
{
|
||||||
_baustelle = baustelle;
|
_baustelle = unitOfWork.BaustellenRepository.Get().First();
|
||||||
ort = _baustelle.Ort;
|
ort = _baustelle.Ort;
|
||||||
strasse = _baustelle.Strasse;
|
strasse = _baustelle.Strasse;
|
||||||
projektnummer = _baustelle.Projektnummer;
|
projektnummer = _baustelle.Projektnummer;
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
using KanSan.Base.Models;
|
using KanSan.Base;
|
||||||
|
using KanSan.Base.Interfaces;
|
||||||
|
using KanSan.Base.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace KanSan.ViewModel
|
namespace KanSan.ViewModel
|
||||||
{
|
{
|
||||||
class KundeViewModel : PropertyChangedClass, INotifyPropertyChanged
|
class KundeViewModel : PropertyChangedClass, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
|
||||||
|
|
||||||
private Kunde _kunde;
|
private Kunde _kunde;
|
||||||
private string vorname;
|
private string vorname;
|
||||||
private string nachname;
|
private string nachname;
|
||||||
@@ -83,14 +88,27 @@ namespace KanSan.ViewModel
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public KundeViewModel(Kunde kunde)
|
public KundeViewModel()
|
||||||
{
|
{
|
||||||
_kunde = kunde;
|
_kunde = unitOfWork.KundenRepository.Get().First();
|
||||||
|
|
||||||
vorname = _kunde.Vorname;
|
vorname = _kunde.Vorname;
|
||||||
nachname = _kunde.Nachname;
|
nachname = _kunde.Nachname;
|
||||||
strasse = _kunde.Strasse;
|
strasse = _kunde.Strasse;
|
||||||
plz = _kunde.PLZ;
|
plz = _kunde.PLZ;
|
||||||
ort = _kunde.Ort;
|
ort = _kunde.Ort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Speichern()
|
||||||
|
{
|
||||||
|
_kunde.Vorname = Vorname;
|
||||||
|
_kunde.Nachname = Nachname;
|
||||||
|
_kunde.Strasse = Strasse;
|
||||||
|
_kunde.Ort = Ort;
|
||||||
|
_kunde.PLZ = PLZ;
|
||||||
|
|
||||||
|
unitOfWork.KundenRepository.Update(_kunde);
|
||||||
|
unitOfWork.Commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user