merged AllContactsView into ShellView due to notification problems

pull/1/head
Sascha Woitschetzki 2021-07-15 11:30:40 +07:00
parent ed8dfd1eb8
commit 432560c7b4
9 changed files with 97 additions and 98 deletions

@ -115,7 +115,7 @@ namespace Gremlin.MVVM
private void BtnShowContactList_Click(object sender, RoutedEventArgs e) private void BtnShowContactList_Click(object sender, RoutedEventArgs e)
{ {
ObservableCollection<ContactViewModel> contacts = new(AllContactsViewModel.GetAllContactsVM()); ObservableCollection<ContactViewModel> contacts = new(_AllContactsViewModel.GetAllContactsVM());
dg_Test.ItemsSource = contacts; dg_Test.ItemsSource = contacts;
} }
} }

@ -25,7 +25,7 @@ namespace Gremlin.MVVM
private void LoadContacts() private void LoadContacts()
{ {
listCollectionContacts = new(AllContactsViewModel.GetAllContactsVM()); listCollectionContacts = new(_AllContactsViewModel.GetAllContactsVM());
listCollectionContacts.Filter = ContactViewModel.SearchContact(listCollectionContacts, tbContactSearch.Text); listCollectionContacts.Filter = ContactViewModel.SearchContact(listCollectionContacts, tbContactSearch.Text);
dgFoundContacts.ItemsSource = listCollectionContacts; dgFoundContacts.ItemsSource = listCollectionContacts;
UpdateUI(); UpdateUI();

@ -1,55 +0,0 @@
using Caliburn.Micro;
using Gremlin.GremlinData.DBClasses;
using Gremlin.GremlinData.EntityClasses;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
namespace Gremlin.MVVM
{
public class AllContactsViewModel : PropertyChangedBase
{
private ContactViewModel _selectedContact;
private ObservableCollection<ContactViewModel> _listOfContactsVM;
public ContactViewModel SelectedContact { get => _selectedContact; set { _selectedContact = value; NotifyOfPropertyChange(() => SelectedContact); } }
public ObservableCollection<ContactViewModel> ListOfContactsVM
{
get => _listOfContactsVM;
set { _listOfContactsVM = value; NotifyOfPropertyChange(() => ListOfContactsVM); }
}
public AllContactsViewModel() => ListOfContactsVM = GetAllContactsVM();
internal static ObservableCollection<ContactViewModel> GetAllContactsVM()
{
try
{
using (GremlinContext gremlinContext = new())
{
List<Contact> contacts = gremlinContext.Contacts.Include(contact => contact.Account).ToList();
ObservableCollection<ContactViewModel> contactsVM = new();
foreach (Contact contact in contacts)
{
contactsVM.Add(ContactViewModel.ConvertContactToVM(contact));
}
Debug.WriteLine($"Es wurden {contactsVM.Count} Kontakte geladen.");
return contactsVM;
}
}
catch (Exception ex)
{
ErrorHandler.ShowErrorInMessageBox(ex);
return null;
throw;
}
}
}
}

@ -17,7 +17,7 @@ namespace Gremlin.MVVM
private string _eMail = "email@email.de"; private string _eMail = "email@email.de";
private string _accountName = "accountName"; private string _accountName = "accountName";
private string _accountStreet = "accountStreet"; private string _accountStreet = "accountStreet";
private uint _accountZIP = 0; private uint _accountZIP;
private string _accountCity = "accountCity"; private string _accountCity = "accountCity";
public byte Gender { get => _gender; set { _gender = value; NotifyOfPropertyChange(() => Gender); } } public byte Gender { get => _gender; set { _gender = value; NotifyOfPropertyChange(() => Gender); } }

@ -1,19 +1,90 @@
using Caliburn.Micro; using Caliburn.Micro;
using Gremlin.GremlinData.DBClasses;
using Gremlin.GremlinData.EntityClasses;
using Gremlin.Operations; using Gremlin.Operations;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
namespace Gremlin.MVVM namespace Gremlin.MVVM
{ {
public class ShellViewModel : PropertyChangedBase public class ShellViewModel : PropertyChangedBase
{ {
public AllContactsViewModel AllContactsVM { get; set; } //public AllContactsViewModel AllContactsVM { get; set; }
public QuoteViewModel QuoteVM { get; set; }
private ContactViewModel _selectedContact;
private ObservableCollection<ContactViewModel> _contacts;
private QuoteViewModel _quoteVM;
public QuoteViewModel QuoteVM
{
get => _quoteVM;
set
{
_quoteVM = value;
NotifyOfPropertyChange(() => QuoteVM);
}
}
public ContactViewModel SelectedContact
{
get => _selectedContact;
set
{
_selectedContact = value;
NotifyOfPropertyChange(() => SelectedContact);
QuoteVM.Recipient = value;
NotifyOfPropertyChange(() => QuoteVM.Recipient);
}
}
public ObservableCollection<ContactViewModel> Contacts
{
get => _contacts;
set
{
_contacts = value;
NotifyOfPropertyChange(() => Contacts);
}
}
public ShellViewModel() public ShellViewModel()
{ {
AllContactsVM = new(); //AllContactsVM = new();
QuoteVM = new(); QuoteVM = new();
Contacts = GetAllContactsVM();
}
internal static ObservableCollection<ContactViewModel> GetAllContactsVM()
{
try
{
using (GremlinContext gremlinContext = new())
{
List<Contact> contacts = gremlinContext.Contacts.Include(contact => contact.Account).ToList();
ObservableCollection<ContactViewModel> contactsVM = new();
foreach (Contact contact in contacts)
{
contactsVM.Add(ContactViewModel.ConvertContactToVM(contact));
}
Debug.WriteLine($"Es wurden {contactsVM.Count} Kontakte geladen.");
return contactsVM;
}
}
catch (Exception ex)
{
ErrorHandler.ShowErrorInMessageBox(ex);
return null;
throw;
}
} }
public void CreateTex() public void CreateTex()
{ {
TexHandler.CreateTexAndOpen(QuoteVM); TexHandler.CreateTexAndOpen(QuoteVM);

@ -1,15 +0,0 @@
<UserControl x:Class="Gremlin.MVVM.AllContactsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="1" Grid.Column="0" Height="Auto">
<DataGrid x:Name="ListOfContactsVM" AutoGenerateColumns="True" AlternatingRowBackground="LightBlue" Height="300" Width ="1280" Margin="10,5,10,5" SelectionChanged="ListOfContactsVM_SelectionChanged" />
</Grid>
</Grid>
</UserControl>

@ -1,19 +0,0 @@
using System.Diagnostics;
using System.Windows.Controls;
namespace Gremlin.MVVM
{
public partial class AllContactsView : UserControl
{
public AllContactsView()
{
InitializeComponent();
}
private void ListOfContactsVM_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ContactViewModel selectedContact = (sender as DataGrid).SelectedItem as ContactViewModel;
Debug.WriteLine("Es wurde folgender Kontakt ausgewählt: " + selectedContact.LastName);
}
}
}

@ -17,7 +17,7 @@
<!--Recepient--> <!--Recepient-->
<Grid Grid.Row="0" Grid.Column="0" Height="Auto"> <Grid Grid.Row="0" Grid.Column="0" Height="Auto">
<TextBlock x:Name="Recipient" Margin="10,5,10,5" /> <DataGrid x:Name="Recipient" Margin="10,5,10,5" />
</Grid> </Grid>
<!--QuoteDetails--> <!--QuoteDetails-->
@ -64,7 +64,15 @@
<!--LineItems--> <!--LineItems-->
<Grid Grid.Row="2" Grid.ColumnSpan="4" Height="Auto"> <Grid Grid.Row="2" Grid.ColumnSpan="4" Height="Auto">
<DataGrid x:Name="LineItemsViewModel" AutoGenerateColumns="True" Height="300" Width ="1280" Margin="10,5,10,5" /> <DataGrid
x:Name="LineItemsViewModel"
AutoGenerateColumns="True"
CanUserAddRows="False"
Height="300"
Width ="1280"
Margin="10,5,10,5"
AlternatingRowBackground="LightGray"
/>
</Grid> </Grid>
</Grid> </Grid>
</UserControl> </UserControl>

@ -4,7 +4,16 @@
xmlns:cal="http://www.caliburnproject.org" xmlns:cal="http://www.caliburnproject.org"
xmlns:local="clr-namespace:Gremlin.MVVM"> xmlns:local="clr-namespace:Gremlin.MVVM">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<local:AllContactsView cal:Bind.Model="{Binding AllContactsVM}" /> <DataGrid
x:Name="Contacts"
AutoGenerateColumns="True"
SelectionMode="Single"
SelectedItem="SelectedContact"
AlternatingRowBackground="LightGray"
Height="300"
Width ="1280"
Margin="10,5,10,5"
/>
<local:QuoteView cal:Bind.Model="{Binding QuoteVM}" /> <local:QuoteView cal:Bind.Model="{Binding QuoteVM}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Button x:Name="CreateTex" Content="TexFile erzeugen" Margin="10,5,10,5"/> <Button x:Name="CreateTex" Content="TexFile erzeugen" Margin="10,5,10,5"/>