MainWindow Viewmodel erstellt

This commit is contained in:
Husky
2020-02-22 19:54:08 +01:00
parent 169cfb9830
commit ba431a8fba
10 changed files with 128 additions and 20 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@
/KanSan/version.txt /KanSan/version.txt
/KanSan.ViewModel/bin/* /KanSan.ViewModel/bin/*
/KanSan.ViewModel/obj/* /KanSan.ViewModel/obj/*
*/version.txt

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace KanSan.ViewModel
{
class BaustellenListViewModel
{
}
}

View File

@@ -4,8 +4,22 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="version.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="version.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\KanSan.Base\KanSan.Base.csproj" /> <ProjectReference Include="..\KanSan.Base\KanSan.Base.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="git rev-parse HEAD &gt;&quot;$(ProjectDir)\version.txt" />
</Target>
</Project> </Project>

View File

@@ -0,0 +1,44 @@
using KanSan.Base.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
namespace KanSan.ViewModel
{
public class MainWindowViewModel
{
private Kunde _selectedKunde;
private string applicationTitle;
public string ApplicationTitle
{
get
{
string gitVersion;
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("KanSan.ViewModel.version.txt"))
using (StreamReader reader = new StreamReader(stream))
{
gitVersion = reader.ReadToEnd();
}
return gitVersion;
}
}
public Kunde SelectedKunde
{
get
{
return _selectedKunde;
}
}
public MainWindowViewModel()
{
}
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace KanSan.ViewModel
{
public class ProjektListViewModel
{
}
}

View File

@@ -36,8 +36,4 @@
<ProjectReference Include="..\KanSan.ViewModel\KanSan.ViewModel.csproj" /> <ProjectReference Include="..\KanSan.ViewModel\KanSan.ViewModel.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="git rev-parse HEAD &gt;&quot;$(ProjectDir)\version.txt" />
</Target>
</Project> </Project>

View File

@@ -6,13 +6,27 @@
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" WindowStartupLocation="CenterScreen" WindowState="Maximized"> Title="{Binding ApplicationTitle}" Height="450" Width="800" WindowStartupLocation="CenterScreen" WindowState="Maximized">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition Width="29*" />
<ColumnDefinition /> <ColumnDefinition Width="171*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<ContentControl Grid.Column="1" Name="ContentController" Content="ContentControl" HorizontalAlignment="Left" Height="402" Margin="226,22,0,0" VerticalAlignment="Top" Width="564"/> <RowDefinition Height="206*" />
<RowDefinition Height="11*" />
</Grid.RowDefinitions>
<StackPanel Grid.Column="0">
<Button Content="Kunden" Name="btnKunden" Click="btnKunden_Click" />
<Button Content="Projekte" Name="btnProjekte" />
<Button Content="Baustellen" Name="btnBaustellen" />
<Button Content="Objekte" Name="btnObjekte" />
</StackPanel>
<ContentControl Grid.Column="1" Name="ContentController" Content="KanSan"/>
<StatusBar Grid.ColumnSpan="2" Margin="0,1,0,0" Grid.Row="1">
<StatusBarItem Content="Kunde" />
<StatusBarItem Content="Projekt" />
<StatusBarItem Content="Baustelle" />
</StatusBar>
</Grid> </Grid>
</Window> </Window>

View File

@@ -15,6 +15,7 @@ using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using KanSan.Base; using KanSan.Base;
using KanSan.Base.Models; using KanSan.Base.Models;
using KanSan.ViewModel;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace KanSan namespace KanSan
@@ -27,15 +28,8 @@ namespace KanSan
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
this.Title = ProgrammHashVersion.GIT_HASH; this.DataContext = new MainWindowViewModel();
//this.Title = ProgrammHashVersion.GIT_HASH;
/*UI.UCKundeEdit uCKundeEdit = new UI.UCKundeEdit();
ContentController.Content = uCKundeEdit;*/
UI.UCKundeList uCKundeList = new UI.UCKundeList();
uCKundeList.KundeAdded += UCKundeList_KundeAdded;
ContentController.Content = uCKundeList;
} }
private void UCKundeList_KundeAdded(object sender, UI.KundeAddedKlickEventArgs e) private void UCKundeList_KundeAdded(object sender, UI.KundeAddedKlickEventArgs e)
@@ -43,6 +37,13 @@ namespace KanSan
UI.UCKundeEdit uCKundeEdit = new UI.UCKundeEdit(e.kunde); UI.UCKundeEdit uCKundeEdit = new UI.UCKundeEdit(e.kunde);
ContentController.Content = uCKundeEdit; ContentController.Content = uCKundeEdit;
} }
private void btnKunden_Click(object sender, RoutedEventArgs e)
{
UI.UCKundeList uCKundeList = new UI.UCKundeList();
uCKundeList.KundeAdded += UCKundeList_KundeAdded;
ContentController.Content = uCKundeList;
}
} }
} }

View File

@@ -10,8 +10,17 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="50"/> <RowDefinition Height="50"/>
<RowDefinition Height="50" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<DataGrid ItemsSource="{Binding Kunden}" /> <DataGrid AutoGenerateColumns="False" SelectionMode="Single" ItemsSource="{Binding Kunden}" Name="dgKundenList">
<Button Grid.Row="1" Name="NeueKunde" Content="Neue Kunde anlegen" Click="NeueKunde_Click" /> <DataGrid.Columns>
<DataGridTextColumn Header="Vorname" Binding="{Binding Vorname}" />
<DataGridTextColumn Header="Nachname" Binding="{Binding Nachname}" />
<DataGridTextColumn Header="Ort" Binding="{Binding Ort}" />
</DataGrid.Columns>
</DataGrid>
<Button Grid.Row="1" Name="EditKunde" Content="Kunde Editieren" Click="EditKunde_Click" />
<Button Grid.Row="2" Name="NeueKunde" Content="Neue Kunde anlegen" Click="NeueKunde_Click" />
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -2,6 +2,7 @@
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;
@@ -41,6 +42,14 @@ namespace KanSan.UI
handler(this, e); handler(this, e);
} }
public event EventHandler<KundeAddedKlickEventArgs> KundeAdded; public event EventHandler<KundeAddedKlickEventArgs> KundeAdded;
private void EditKunde_Click(object sender, RoutedEventArgs e)
{
Kunde selectedKunde = (dgKundenList.SelectedItem as Kunde);
if (selectedKunde == null) return;
OnKlickedKunde(new KundeAddedKlickEventArgs() { kunde = selectedKunde });
}
} }
public class KundeAddedKlickEventArgs : EventArgs public class KundeAddedKlickEventArgs : EventArgs