Baustellen können nun angelegt und ausgewählt werden

This commit is contained in:
Husky
2020-03-11 19:21:10 +01:00
parent 7a4068439c
commit 47beb8b598
19 changed files with 405 additions and 13 deletions

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace KanSan.Base.Interfaces.UI
{
public interface IBaustelleEditViewModel
{
string BaustelleNummer { get; set; }
string OrtTeil { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using KanSan.Base.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace KanSan.Base.Interfaces.UI
{
public interface IBaustelleListViewModel
{
List<Baustelle> Baustellen { get; }
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace KanSan.Base.Interfaces.UI
{
public interface IObjekteEditViewModel
{
string StrasseName { get; set; }
string Objektnummer { get; set; }
string PunktOben { get; set; }
string PunktUnten { get; set; }
int Durchmesser { get; set; }
string Material { get; set; }
}
}

View File

@@ -5,7 +5,7 @@ using System.Text;
namespace KanSan.Base.Interfaces.UI namespace KanSan.Base.Interfaces.UI
{ {
public interface IProjekteListViewModel public interface IProjektListViewModel
{ {
List<Projekt> ProjekteVomKunde { get; } List<Projekt> ProjekteVomKunde { get; }
} }

View File

@@ -0,0 +1,55 @@
using KanSan.Base;
using KanSan.Base.Interfaces;
using KanSan.Base.Interfaces.UI;
using KanSan.Base.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace KanSan.ViewModel
{
public class BaustelleEditViewModel : PropertyChangedClass, INotifyPropertyChanged, IBaustelleEditViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
private Baustelle baustelle;
string ortTeil;
string baustelleNummer;
public string OrtTeil
{
get => ortTeil;
set
{
if (ortTeil != null && ortTeil == value) return;
ortTeil = value;
OnPropertyChanged();
}
}
public string BaustelleNummer
{
get => baustelleNummer;
set
{
if (baustelleNummer != null && baustelleNummer == value) return;
baustelleNummer = value;
OnPropertyChanged();
}
}
public BaustelleEditViewModel(Baustelle baustelle)
{
this.baustelle = baustelle;
baustelleNummer = baustelle.BaustelleNummer;
ortTeil = baustelle.OrtTeil;
}
public void Speichern()
{
baustelle.OrtTeil = OrtTeil;
baustelle.BaustelleNummer = BaustelleNummer;
unitOfWork.BaustelleRepository.Update(baustelle);
unitOfWork.Commit();
}
}
}

View File

@@ -0,0 +1,48 @@
using KanSan.Base;
using KanSan.Base.Interfaces;
using KanSan.Base.Interfaces.UI;
using KanSan.Base.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace KanSan.ViewModel
{
public class BaustellenListViewModel : IBaustelleListViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
private List<Baustelle> baustellen;
private Projekt selectedProjekt;
public List<Baustelle> Baustellen
{
get
{
return baustellen;
}
}
public BaustellenListViewModel(Projekt projekt)
{
selectedProjekt = projekt;
baustellen = unitOfWork.BaustelleRepository.Get(x => x.Projekt.Equals(projekt)).ToList();
}
public Baustelle NeueBaustelle()
{
Guid guid = Guid.NewGuid();
Baustelle newBaustelle = new Baustelle()
{
GuidNr = guid,
Projekt = selectedProjekt
};
unitOfWork.BaustelleRepository.Update(newBaustelle);
unitOfWork.Commit();
List<Baustelle> res = unitOfWork.BaustelleRepository.Get(x => x.GuidNr.Equals(guid)).ToList();
if (res.Count < 1) throw new Exception("Der zuvor eingefügte Baustelle konnte nicht gefunden werden");
return res.First();
}
}
}

View File

@@ -0,0 +1,51 @@
using KanSan.Base;
using KanSan.Base.Interfaces;
using KanSan.Base.Interfaces.UI;
using KanSan.Base.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace KanSan.ViewModel
{
public class ObjekteEditViewModel : IObjekteEditViewModel
{
IUnitOfWork unitOfWork = new UnitOfWork(new KanSanContext());
string strassename;
string objektnummer;
string punktOben;
string punktUnten;
int durchmesser;
string material;
private Sewer objekt;
public string StrasseName { get => strassename; set => throw new NotImplementedException(); }
public string Objektnummer { get => objektnummer; set => throw new NotImplementedException(); }
public string PunktOben { get => punktOben; set => throw new NotImplementedException(); }
public string PunktUnten { get => punktUnten; set => throw new NotImplementedException(); }
public int Durchmesser { get => durchmesser; set => throw new NotImplementedException(); }
public string Material { get => material; set => throw new NotImplementedException(); }
public ObjekteEditViewModel(Sewer sewer)
{
objekt = sewer;
strassename = objekt.StrasseName;
punktOben = objekt.PunktOben.Objektnummer;
punktUnten = objekt.PunktUnten.Objektnummer;
objektnummer = objekt.ObjektNummer;
durchmesser = objekt.DN;
material = objekt.Material.ToString();
}
public void Speichern()
{
objekt.StrasseName = strassename;
objekt.DN = durchmesser;
unitOfWork.KanaeleRepository.Update(objekt);
unitOfWork.Commit();
}
}
}

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace KanSan.ViewModel namespace KanSan.ViewModel
{ {
class BaustellenListViewModel class ObjekteListViewModel
{ {
} }
} }

View File

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

View File

@@ -22,6 +22,12 @@
<Compile Update="UI\Projekt\UCProjektList.xaml.cs"> <Compile Update="UI\Projekt\UCProjektList.xaml.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Update="UI\Baustelle\UCBaustelleEdit.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="UI\Baustelle\UCBaustelleList.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Update="MainWindow.xaml"> <Page Update="MainWindow.xaml">
@@ -42,5 +48,11 @@
<Page Update="UI\Projekt\UCProjektList.xaml"> <Page Update="UI\Projekt\UCProjektList.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Update="UI\Baustelle\UCBaustelleEdit.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="UI\Baustelle\UCBaustelleList.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -19,14 +19,14 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<Button Content="Kunden" Name="btnKunden" Click="btnKunden_Click" /> <Button Content="Kunden" Name="btnKunden" Click="btnKunden_Click" />
<Button Content="Projekte" Name="btnProjekte" Click="btnProjekte_Click" /> <Button Content="Projekte" Name="btnProjekte" Click="btnProjekte_Click" />
<Button Content="Baustellen" Name="btnBaustellen" /> <Button Content="Baustellen" Name="btnBaustellen" Click="btnBaustellen_Click" />
<Button Content="Objekte" Name="btnObjekte" /> <Button Content="Objekte" Name="btnObjekte" />
</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="{Binding SelectedKunde.Vorname}" /> <StatusBarItem Content="{Binding SelectedKunde.Vorname}" />
<StatusBarItem Content="{Binding SelectedProjekt.Projektnummer}" /> <StatusBarItem Content="{Binding SelectedProjekt.Projektnummer}" />
<StatusBarItem Content="Baustelle" /> <StatusBarItem Content="{Binding SelectedBaustelle.OrtTeil}" />
</StatusBar> </StatusBar>
</Grid> </Grid>
</Window> </Window>

View File

@@ -28,6 +28,7 @@ namespace KanSan
UI.UCKundeEdit UCKundeEdit; UI.UCKundeEdit UCKundeEdit;
UI.UCKundeList UCKundeList; UI.UCKundeList UCKundeList;
UI.UCProjektList UCProjektList; UI.UCProjektList UCProjektList;
UI.UCBaustelleList UCBaustelleList;
public MainWindow() public MainWindow()
{ {
@@ -92,6 +93,39 @@ namespace KanSan
{ {
ContentController.Content = "MainView"; ContentController.Content = "MainView";
} }
private void btnBaustellen_Click(object sender, RoutedEventArgs e)
{
Projekt projekt = (DataContext as MainWindowViewModel).SelectedProjekt;
if (projekt == null) return;
UCBaustelleList = new UI.UCBaustelleList(projekt);
UCBaustelleList.BaustelleAdded += UCBaustelleList_BaustelleAdded;
UCBaustelleList.BaustelleEdited += UCBaustelleList_BaustelleEdited;
UCBaustelleList.BaustelleSelected += UCBaustelleList_BaustelleSelected;
ContentController.Content = UCBaustelleList;
}
private void UCBaustelleList_BaustelleSelected(object sender, UI.SelectBaustelleEventArgs e)
{
(DataContext as MainWindowViewModel).SelectedBaustelle = e.baustelle;
}
private void UCBaustelleList_BaustelleEdited(object sender, UI.SelectBaustelleEventArgs e)
{
if (e.baustelle == null) return;
UI.UCBaustelleEdit uCBaustelleEdit = new UI.UCBaustelleEdit(e.baustelle);
uCBaustelleEdit.SpeichernClicked += Edit_SpeichernClicked;
ContentController.Content = uCBaustelleEdit;
}
private void UCBaustelleList_BaustelleAdded(object sender, UI.SelectBaustelleEventArgs e)
{
/*if (e.baustelle == null) return;
UI.UCBaustelleEdit uBaustelleEdit = new UI.UCBaustelleEdit(e.baustelle);
*/
}
} }
} }

View File

@@ -0,0 +1,21 @@
using KanSan.Base.Interfaces.UI;
using System;
using System.Collections.Generic;
using System.Text;
namespace KanSan.SampleData
{
class BaustelleEditViewModelSampleData : IBaustelleEditViewModel
{
string baustelleNummer;
string ortTeil;
public string BaustelleNummer { get => baustelleNummer; set => baustelleNummer = value; }
public string OrtTeil { get => ortTeil; set => ortTeil = value; }
public BaustelleEditViewModelSampleData()
{
baustelleNummer = "20-850-005";
ortTeil = "Bramsche";
}
}
}

View File

@@ -0,0 +1,26 @@
using KanSan.Base.Interfaces.UI;
using KanSan.Base.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace KanSan.SampleData
{
class BaustelleListViewModelSampleData : IBaustelleListViewModel
{
List<Baustelle> baustellen = new List<Baustelle>();
public List<Baustelle> Baustellen => baustellen;
public BaustelleListViewModelSampleData()
{
for (int i = 0; i < 10; i++)
{
baustellen.Add(new Baustelle()
{
BaustelleNummer = "00" + i,
OrtTeil = "Huntlosen "+i
});
}
}
}
}

View File

@@ -6,7 +6,7 @@ using System.Text;
namespace KanSan.SampleData namespace KanSan.SampleData
{ {
class ProjektListViewModelSampleData : IProjekteListViewModel class ProjektListViewModelSampleData : IProjektListViewModel
{ {
private List<Projekt> _projekteVomKunde = new List<Projekt>(); private List<Projekt> _projekteVomKunde = new List<Projekt>();
public List<Projekt> ProjekteVomKunde => _projekteVomKunde; public List<Projekt> ProjekteVomKunde => _projekteVomKunde;

View File

@@ -5,8 +5,27 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:KanSan.UI" xmlns:local="clr-namespace:KanSan.UI"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:sd ="clr-namespace:KanSan.SampleData"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<d:UserControl.DataContext>
<sd:BaustelleEditViewModelSampleData/>
</d:UserControl.DataContext>
<Grid> <Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Background="Beige" Content="OrtTeil" />
<Label Grid.Row="1" Grid.Column="0" Background="Beige" Content="Projektnummer" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding OrtTeil}" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding BaustelleNummer}"/>
<Button Grid.ColumnSpan="2" Grid.Row="2" Content="Speichern" Name="Speichern" Click="Speichern_Click" />
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -1,4 +1,6 @@
using System; using KanSan.Base.Models;
using KanSan.ViewModel;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
@@ -18,9 +20,23 @@ namespace KanSan.UI
/// </summary> /// </summary>
public partial class UCBaustelleEdit : UserControl public partial class UCBaustelleEdit : UserControl
{ {
public UCBaustelleEdit() public event EventHandler SpeichernClicked;
public UCBaustelleEdit(Baustelle baustelle)
{ {
InitializeComponent(); InitializeComponent();
this.DataContext = new BaustelleEditViewModel(baustelle);
}
protected virtual void OnSpeichernKlicked(EventArgs e)
{
EventHandler handler = SpeichernClicked;
if (handler != null)
handler(this, e);
}
private void Speichern_Click(object sender, RoutedEventArgs e)
{
(DataContext as BaustelleEditViewModel).Speichern();
OnSpeichernKlicked(EventArgs.Empty);
} }
} }
} }

View File

@@ -4,9 +4,27 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:KanSan.UI" xmlns:local="clr-namespace:KanSan.UI"
xmlns:sd ="clr-namespace:KanSan.SampleData"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="1024">
<d:UserControl.DataContext>
<sd:BaustelleListViewModelSampleData />
</d:UserControl.DataContext>
<Grid> <Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<DataGrid Name="dgBaustelle" ItemsSource="{Binding Baustellen}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="OrtTeil" Binding="{Binding OrtTeil}" />
<DataGridTextColumn Header="BaustelleNummer" Binding="{Binding BaustelleNummer}"/>
</DataGrid.Columns>
</DataGrid>
<Button Grid.Row="1" Name="BaustelleSelect" Content="Baustelle Auswählen" Click="BaustelleSelect_Click" />
<Button Grid.Row="2" Name="BaustelleEdit" Content="Baustelle Editieren" Click="BaustelleEdit_Click" />
<Button Grid.Row="3" Name="BaustelleNew" Content="Neue Baustelle Hinzufügen" Click="BaustelleNew_Click" />
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -1,4 +1,6 @@
using System; using KanSan.Base.Models;
using KanSan.ViewModel;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
@@ -18,9 +20,59 @@ namespace KanSan.UI
/// </summary> /// </summary>
public partial class UCBaustelleList : UserControl public partial class UCBaustelleList : UserControl
{ {
public UCBaustelleList() public event EventHandler<SelectBaustelleEventArgs> BaustelleSelected;
public event EventHandler<SelectBaustelleEventArgs> BaustelleAdded;
public event EventHandler<SelectBaustelleEventArgs> BaustelleEdited;
public UCBaustelleList(Projekt projekt)
{ {
InitializeComponent(); InitializeComponent();
this.DataContext = new BaustellenListViewModel(projekt);
}
private void BaustelleSelect_Click(object sender, RoutedEventArgs e)
{
Baustelle selectedBaustelle = (dgBaustelle.SelectedItem as Baustelle);
if (selectedBaustelle == null) return;
OnClickBaustelleSelect(new SelectBaustelleEventArgs() { baustelle = selectedBaustelle });
}
private void BaustelleEdit_Click(object sender, RoutedEventArgs e)
{
Baustelle selectedBaustelle = (dgBaustelle.SelectedItem as Baustelle);
if (selectedBaustelle == null) return;
OnClickBaustelleEdit(new SelectBaustelleEventArgs() { baustelle = selectedBaustelle });
}
private void BaustelleNew_Click(object sender, RoutedEventArgs e)
{
OnClickBaustelleAdd(
new SelectBaustelleEventArgs()
{
baustelle = (DataContext as BaustellenListViewModel).NeueBaustelle()
});
}
protected virtual void OnClickBaustelleSelect(SelectBaustelleEventArgs e)
{
EventHandler<SelectBaustelleEventArgs> handler = BaustelleSelected;
if (handler != null)
handler(this, e);
}
protected virtual void OnClickBaustelleAdd(SelectBaustelleEventArgs e)
{
EventHandler<SelectBaustelleEventArgs> handler = BaustelleAdded;
if (handler != null)
handler(this, e);
}
protected virtual void OnClickBaustelleEdit(SelectBaustelleEventArgs e)
{
EventHandler<SelectBaustelleEventArgs> handler = BaustelleEdited;
if (handler != null)
handler(this, e);
} }
} }
public class SelectBaustelleEventArgs : EventArgs
{
public Baustelle baustelle { get; set; }
}
} }