Searching for Contact.LastName now possible

pull/1/head
Sascha Woitschetzki 2021-07-16 13:30:41 +07:00
parent c206b84b73
commit 478965261d
5 changed files with 34 additions and 21 deletions

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

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

@ -2,6 +2,7 @@
using Gremlin.GremlinData.EntityClasses;
using System.Diagnostics;
using System.Linq;
using System.Windows;
namespace Gremlin.MVVM
{
@ -21,8 +22,7 @@ namespace Gremlin.MVVM
{
tempOptionNumber = lineItemVM.OptionNumber == "" ? null : lineItemVM.OptionNumber;
CustomDescriptionViewModel customDescriptionVM = new();
CustomDescription customDescription = gremlinContext.CustomDescriptions.Where(cD => cD.ProductNumber == lineItemVM.ProductNumber && cD.OptionNumber == tempOptionNumber)
.FirstOrDefault();
CustomDescription customDescription = gremlinContext.CustomDescriptions.Where(cD => cD.ProductNumber == lineItemVM.ProductNumber && cD.OptionNumber == tempOptionNumber).FirstOrDefault();
if (customDescription != null)
{
@ -35,7 +35,7 @@ namespace Gremlin.MVVM
}
else
{
Debug.WriteLine($"CustomDescription für {lineItemVM.ProductNumber}#{lineItemVM.OptionNumber} nicht vorhanden! Verwende (vorläufig) Standardbeschreibung {lineItemVM.SapShortDescription}!");
MessageBox.Show($"CustomDescription für \"{lineItemVM.ProductNumber}#{lineItemVM.OptionNumber}\" nicht vorhanden! Verwende (vorläufig) Standardbeschreibung \"{lineItemVM.SapShortDescription}\"!");
customDescriptionVM.DescriptionText = TexReplace(lineItemVM.SapShortDescription);
customDescriptionVM.Heading = TexReplace(lineItemVM.SapShortDescription);
}

@ -13,11 +13,21 @@ namespace Gremlin.MVVM
{
public class ShellViewModel : PropertyChangedBase
{
//public AllContactsViewModel AllContactsVM { get; set; }
private ContactViewModel _selectedContact;
private ObservableCollection<ContactViewModel> _contacts;
private QuoteViewModel _quoteVM;
private string _searchContact;
public string SearchContact
{
get => _searchContact;
set
{
_searchContact = value;
NotifyOfPropertyChange(() => SearchContact);
Contacts = GetContactsVM(_searchContact);
}
}
public QuoteViewModel QuoteVM
{
@ -55,16 +65,19 @@ namespace Gremlin.MVVM
{
//AllContactsVM = new();
QuoteVM = new();
Contacts = GetAllContactsVM();
Contacts = GetContactsVM("");
}
internal static ObservableCollection<ContactViewModel> GetAllContactsVM()
internal static ObservableCollection<ContactViewModel> GetContactsVM(string searchContact)
{
try
{
using (GremlinContext gremlinContext = new())
{
List<Contact> contacts = gremlinContext.Contacts.Include(contact => contact.Account).ToList();
List<Contact> contacts = searchContact is "" or null
? gremlinContext.Contacts.Include(contact => contact.Account).ToList()
: gremlinContext.Contacts.Where(contact => contact.LastName.Contains(searchContact)).Include(contact => contact.Account).ToList();
ObservableCollection<ContactViewModel> contactsVM = new();
foreach (Contact contact in contacts)

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