Projekte integration angefangen

This commit is contained in:
HuskyTeufel
2021-08-31 13:31:52 +02:00
parent c66751ddc5
commit ade84e30e3
9 changed files with 59 additions and 87 deletions

View File

@@ -27,6 +27,7 @@ namespace KanSan.ViewModel
}
public ICommand AddNewClientCommand { get; set; }
public ICommand EditClientCommand { get; set; }
public ICommand SelectClientCommand { get; set; }
public List<Kunde> Kunden
{
@@ -42,6 +43,13 @@ namespace KanSan.ViewModel
AddNewClientCommand = new RelayCommand(parameter => NewClient());
EditClientCommand = new RelayCommand(parameter => EditClient());
SelectClientCommand = new RelayCommand(parameter => SelectClient());
}
private void SelectClient()
{
if (selectedKunde == null) return;
Mediator.Notify("ClientSelected", selectedKunde);
}
private void NewClient()

View File

@@ -243,7 +243,23 @@ namespace KanSan.ViewModel
Mediator.Subscribe("GoToListClientScreen", OnGoToListClientScreen);
Mediator.Subscribe("GoToEditClientScreen", OnGoToEditClientScreen);
Mediator.Subscribe("ClientSelected", OnSelectedClient);
Mediator.Subscribe("GoToEditProjektScreen", OnGoToEditProjektScreen);
}
private void OnGoToEditProjektScreen(object obj)
{
if (!(obj is Projekt)) return;
ActualViewModel = new ProjektEditViewModel((obj as Projekt));
}
private void OnSelectedClient(object obj)
{
if (!(obj is Kunde)) return;
SelectedKunde = (obj as Kunde);
ListProjekte();
}
private void OnGoToEditClientScreen(object obj)
@@ -278,6 +294,9 @@ namespace KanSan.ViewModel
private void ListProjekte()
{
if (SelectedKunde == null)
ActualViewModel = new KundenListViewModel();
else
ActualViewModel = new ProjektListViewModel(SelectedKunde);
}

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
{
@@ -22,26 +25,38 @@ namespace KanSan.ViewModel
}
private Kunde selectedKunde;
public ICommand NewProjekt { get; set; }
public ICommand EditProjekt { get; set; }
public ICommand SelectProjekt { get; set; }
public Projekt SelectedProjekt { get; set; }
public ProjektListViewModel(Kunde client)
{
this.selectedKunde = client;
projektevonKunde = unitOfWork.ProjekteRepository.Get(x => x.Kunde.Equals(client)).ToList();
EditProjekt = new RelayCommand(parameter => EditSelectedProjekt());
NewProjekt = new RelayCommand(parameter => AddNewProjekt());
}
public void SelectProjekt()
private void AddNewProjekt()
{
Projekt newProj = NeueProjekt();
Mediator.Notify("GoToEditProjektScreen", newProj);
}
private void EditSelectedProjekt()
{
Mediator.Notify("GoToEditProjektScreen", SelectedProjekt);
}
public Projekt NeueProjekt()
{
Guid guid = Guid.NewGuid();
Projekt newProjekt = new Projekt()
{
GuidNr = guid,
GuidNr = Guid.NewGuid(),
Kunde = selectedKunde
};
@@ -49,9 +64,7 @@ namespace KanSan.ViewModel
//unitOfWork.ProjekteRepository.Insert(newProjekt);
unitOfWork.Commit();
List<Projekt> res = unitOfWork.ProjekteRepository.Get(x => x.GuidNr.Equals(guid)).ToList();
if (res.Count < 1) throw new Exception("Der zuvor eingefügte Projekt konnte nicht in der Datenbank gefunden werden");
return res.First();
return newProjekt;
}
}
}

View File

@@ -24,7 +24,7 @@
<DataGridTextColumn Header="Ort" Binding="{Binding Ort}" />
</DataGrid.Columns>
</DataGrid>
<Button Grid.Row="1" Name="SelectKunde" Content="Kunde Auswählen" />
<Button Grid.Row="1" Name="SelectKunde" Content="Kunde Auswählen" Command="{Binding SelectClientCommand}" />
<Button Grid.Row="2" Name="EditKunde" Content="Kunde Editieren" Command="{Binding EditClientCommand}" />
<Button Grid.Row="3" Name="NeueKunde" Content="Neue Kunde anlegen" Command="{Binding AddNewClientCommand}" />

View File

@@ -23,7 +23,7 @@
<Label Background="Beige" Grid.Column="0" Grid.Row="0" Content="Projektnummer" />
<Label Background="Beige" Grid.Column="0" Grid.Row="1" Content="Ort" />
<Button Grid.Row="2" Grid.ColumnSpan="2" Name="Speichern" Content="Speichern" Click="Speichern_Click" />
<Button Grid.Row="2" Grid.ColumnSpan="2" Name="Speichern" Content="Speichern" />
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Projektnummer}" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Ort}" />

View File

@@ -20,25 +20,9 @@ namespace KanSan.UI
/// </summary>
public partial class UCProjektEdit : UserControl
{
public event EventHandler SpeichernClicked;
protected virtual void OnSpeichernKlicked(EventArgs e)
{
EventHandler handler = SpeichernClicked;
if (handler != null)
handler(this, e);
}
public UCProjektEdit(Projekt projekt)
public UCProjektEdit()
{
InitializeComponent();
this.DataContext = new ProjektEditViewModel(projekt);
}
private void Speichern_Click(object sender, RoutedEventArgs e)
{
(DataContext as ProjektEditViewModel).Speichern();
OnSpeichernKlicked(EventArgs.Empty);
}
}
}

View File

@@ -17,14 +17,14 @@
<RowDefinition Height="50" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<DataGrid ItemsSource="{Binding ProjekteVomKunde}" Name="dgProjekte" AutoGenerateColumns="False">
<DataGrid IsReadOnly="True" ItemsSource="{Binding ProjekteVomKunde}" SelectedItem="{Binding SelectedProjekt}" Name="dgProjekte" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Projektnummer" Binding="{Binding Projektnummer}" />
<DataGridTextColumn Header="Ort" Binding="{Binding Ort}" />
</DataGrid.Columns>
</DataGrid>
<Button Grid.Row="1" x:Name="ProjektSelect" Content="Projekt Auswählen" Click="ProjektSelect_Click" />
<Button Grid.Row="2" Name="ProjektEdit" Content="Projekt Editieren" Click="ProjektEdit_Click" />
<Button Grid.Row="3" Name="ProjektNew" Content="Neue Projekt Hinzufügen" Click="ProjektNew_Click" />
<Button Grid.Row="1" x:Name="ProjektSelect" Content="Projekt Auswählen" Command="{Binding SelectProjekt}"/>
<Button Grid.Row="2" Name="ProjektEdit" Content="Projekt Editieren" Command="{Binding EditProjekt}"/>
<Button Grid.Row="3" Name="ProjektNew" Content="Neue Projekt Hinzufügen" Command="{Binding NewProjekt}" />
</Grid>
</UserControl>

View File

@@ -20,65 +20,10 @@ namespace KanSan.UI
/// </summary>
public partial class UCProjektList : UserControl
{
public event EventHandler<SelectProjektEventArgs> ProjektAdded;
public event EventHandler<SelectProjektEventArgs> ProjektEdited;
public event EventHandler<SelectProjektEventArgs> ProjektSelected;
public UCProjektList()
{
InitializeComponent();
}
public UCProjektList(Kunde selectedKunde)
{
InitializeComponent();
this.DataContext = new ProjektListViewModel(selectedKunde);
}
private void ProjektSelect_Click(object sender, RoutedEventArgs e)
{
Projekt selectedProjekt = (dgProjekte.SelectedItem as Projekt);
if (selectedProjekt == null) return;
OnClickProjektSelect(new SelectProjektEventArgs() { projekt = selectedProjekt });
}
private void ProjektEdit_Click(object sender, RoutedEventArgs e)
{
Projekt selectedProjekt = (dgProjekte.SelectedItem as Projekt);
if (selectedProjekt == null) return;
OnClickProjektEdit(new SelectProjektEventArgs() { projekt = selectedProjekt });
}
private void ProjektNew_Click(object sender, RoutedEventArgs e)
{
OnClickProjektAdd(
new SelectProjektEventArgs()
{
projekt = (DataContext as ProjektListViewModel).NeueProjekt()
});
}
protected virtual void OnClickProjektSelect(SelectProjektEventArgs e)
{
EventHandler<SelectProjektEventArgs> handler = ProjektSelected;
if (handler != null)
handler(this, e);
}
protected virtual void OnClickProjektEdit(SelectProjektEventArgs e)
{
EventHandler<SelectProjektEventArgs> handler = ProjektEdited;
if (handler != null)
handler(this, e);
}
protected virtual void OnClickProjektAdd(SelectProjektEventArgs e)
{
EventHandler<SelectProjektEventArgs> handler = ProjektAdded;
if (handler != null)
handler(this, e);
}
}
public class SelectProjektEventArgs : EventArgs
{
public Projekt projekt { get; set; }
}
}

View File

@@ -6,6 +6,9 @@
<DataTemplate x:Key="SanierungViewModelDataTemplate" DataType="{x:Type l:UCHarzSanierung }">
<l:UCHarzSanierung />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:ProjektEditViewModel}">
<l:UCProjektEdit />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:KundenListViewModel}">
<l:UCKundeList/>
</DataTemplate>