From 13d365430368dd42e3016b1cee7a365b6b01cc9f Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 30 Jul 2020 14:00:50 +0200 Subject: [PATCH] Add Radiobutton in CustomerView for Query-Selection-Method --- .../LoggingClient/LoggingClient.csproj | 1 + .../Repository/CustomerRepositoryEF.cs | 60 ++++++++++++ .../ViewModel/CustomerViewModel.cs | 95 ++++++++++++++++--- .../LoggingClient/Views/CustomerView.xaml | 5 +- 4 files changed, 148 insertions(+), 13 deletions(-) create mode 100755 LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs diff --git a/LoggingClient/LoggingClient/LoggingClient.csproj b/LoggingClient/LoggingClient/LoggingClient.csproj index 9ca6f56..1469bdf 100644 --- a/LoggingClient/LoggingClient/LoggingClient.csproj +++ b/LoggingClient/LoggingClient/LoggingClient.csproj @@ -84,6 +84,7 @@ + diff --git a/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs b/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs new file mode 100755 index 0000000..aac45a2 --- /dev/null +++ b/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs @@ -0,0 +1,60 @@ +using LoggingClient.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LoggingClient.Repository +{ + public class CustomerRepositoryEF : RepositoryBase + { + public CustomerRepositoryEF(string connectionString) : base(connectionString) + { + Customers = new List(); + } + public List Customers { get; set; } + public override string TableName => throw new NotImplementedException(); + + public override string ColumnsForSelect => throw new NotImplementedException(); + + public override string ColumnsForAdd => throw new NotImplementedException(); + + public override string PrimaryKeyFromTable => throw new NotImplementedException(); + + public override void Add(Customer entity) + { + throw new NotImplementedException(); + } + + public override void CallStoredProcedure(Customer entity) + { + throw new NotImplementedException(); + } + + public override void Delete(Customer entity) + { + throw new NotImplementedException(); + } + + public override List GetAll(string whereCondition, Dictionary parameterValues) + { + throw new NotImplementedException(); + } + + public override List GetAll() + { + throw new NotImplementedException(); + } + + public override Customer GetSingle

(P pkValue) + { + throw new NotImplementedException(); + } + + public override void Update(Customer entity) + { + throw new NotImplementedException(); + } + } +} diff --git a/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs b/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs index 3c4c93d..d56b17e 100755 --- a/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs +++ b/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs @@ -34,6 +34,29 @@ namespace LoggingClient.ViewModel private List _customers; public Customer NewCustomerEntry { get; set; } + private bool _EfIsChecked; + private bool _LinqIsChecked; + + public bool EfIsChecked + { + get { return _EfIsChecked; } + set + { + _EfIsChecked = value; + OnPropertyChanged(nameof(EfIsChecked)); + } + } + + public bool LinqIsChecked + { + get { return _LinqIsChecked; } + set + { + _LinqIsChecked = value; + OnPropertyChanged(nameof(LinqIsChecked)); + } + } + public CustomerViewModel() { TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;"; @@ -120,28 +143,76 @@ namespace LoggingClient.ViewModel } private void LoadData() { - try + if (_EfIsChecked) { - var customerModelRepository = new CustomerRepository(TxtConnectionString); - this.Customers = customerModelRepository.GetAll().ToList(); - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LocationTree")); + + try + { + var customerModelRepository = new CustomerRepositoryEF(TxtConnectionString); + this.Customers = customerModelRepository.GetAll().ToList(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } - catch (Exception ex) + if (_LinqIsChecked) { - MessageBox.Show("Error occurred: " + ex.Message); + //TODO + } + else + { + try + { + var customerModelRepository = new CustomerRepository(TxtConnectionString); + this.Customers = customerModelRepository.GetAll().ToList(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } } private void AddData() { - try + if (_EfIsChecked) { - var customerModelRepository = new CustomerRepository(TxtConnectionString); - customerModelRepository.Add(this.NewCustomerEntry); - this.Customers = customerModelRepository.GetAll().ToList(); + try + { + var customerModelRepository = new CustomerRepositoryEF(TxtConnectionString); + customerModelRepository.Add(this.NewCustomerEntry); + this.Customers = customerModelRepository.GetAll().ToList(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } - catch (Exception ex) + if (_LinqIsChecked) { - MessageBox.Show("Error occurred: " + ex.Message); + try + { + var customerModelRepository = new CustomerRepository(TxtConnectionString); + customerModelRepository.Add(this.NewCustomerEntry); + this.Customers = customerModelRepository.GetAll().ToList(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } + } + else + { + try + { + var customerModelRepository = new CustomerRepository(TxtConnectionString); + customerModelRepository.Add(this.NewCustomerEntry); + this.Customers = customerModelRepository.GetAll().ToList(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } } private void DeleteData() diff --git a/LoggingClient/LoggingClient/Views/CustomerView.xaml b/LoggingClient/LoggingClient/Views/CustomerView.xaml index 2d71fc1..1ae7aec 100755 --- a/LoggingClient/LoggingClient/Views/CustomerView.xaml +++ b/LoggingClient/LoggingClient/Views/CustomerView.xaml @@ -149,7 +149,10 @@