Add Radiobutton in CustomerView for Query-Selection-Method

This commit is contained in:
Francesco 2020-07-30 14:00:50 +02:00
parent 3c0e23284f
commit 13d3654303
4 changed files with 148 additions and 13 deletions

View File

@ -84,6 +84,7 @@
<Compile Include="Model\Node.cs" /> <Compile Include="Model\Node.cs" />
<Compile Include="Model\SeverityComboBoxItem.cs" /> <Compile Include="Model\SeverityComboBoxItem.cs" />
<Compile Include="Repository\CustomerRepository.cs" /> <Compile Include="Repository\CustomerRepository.cs" />
<Compile Include="Repository\CustomerRepositoryEF.cs" />
<Compile Include="Repository\IRepositoryBase.cs" /> <Compile Include="Repository\IRepositoryBase.cs" />
<Compile Include="Repository\LocationRepository.cs" /> <Compile Include="Repository\LocationRepository.cs" />
<Compile Include="Repository\LoggingRepository.cs" /> <Compile Include="Repository\LoggingRepository.cs" />

View File

@ -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<Customer>
{
public CustomerRepositoryEF(string connectionString) : base(connectionString)
{
Customers = new List<Customer>();
}
public List<Customer> 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<Customer> GetAll(string whereCondition, Dictionary<string, object> parameterValues)
{
throw new NotImplementedException();
}
public override List<Customer> GetAll()
{
throw new NotImplementedException();
}
public override Customer GetSingle<P>(P pkValue)
{
throw new NotImplementedException();
}
public override void Update(Customer entity)
{
throw new NotImplementedException();
}
}
}

View File

@ -34,6 +34,29 @@ namespace LoggingClient.ViewModel
private List<Customer> _customers; private List<Customer> _customers;
public Customer NewCustomerEntry { get; set; } 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() public CustomerViewModel()
{ {
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;"; TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;";
@ -120,28 +143,76 @@ namespace LoggingClient.ViewModel
} }
private void LoadData() private void LoadData()
{ {
try if (_EfIsChecked)
{ {
var customerModelRepository = new CustomerRepository(TxtConnectionString);
this.Customers = customerModelRepository.GetAll().ToList(); try
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LocationTree")); {
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() private void AddData()
{ {
try if (_EfIsChecked)
{ {
var customerModelRepository = new CustomerRepository(TxtConnectionString); try
customerModelRepository.Add(this.NewCustomerEntry); {
this.Customers = customerModelRepository.GetAll().ToList(); 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() private void DeleteData()

View File

@ -150,6 +150,9 @@
<Label Content="Phone" HorizontalAlignment="Left" Margin="110,346,0,0" VerticalAlignment="Top" Width="95"/> <Label Content="Phone" HorizontalAlignment="Left" Margin="110,346,0,0" VerticalAlignment="Top" Width="95"/>
<Label Content="Email" HorizontalAlignment="Left" Margin="210,346,0,0" VerticalAlignment="Top" Width="95"/> <Label Content="Email" HorizontalAlignment="Left" Margin="210,346,0,0" VerticalAlignment="Top" Width="95"/>
<Label Content="Password" HorizontalAlignment="Left" Margin="310,347,0,0" VerticalAlignment="Top" Width="95"/> <Label Content="Password" HorizontalAlignment="Left" Margin="310,347,0,0" VerticalAlignment="Top" Width="95"/>
<Label Content="Select Strategy for SQL" HorizontalAlignment="Left" Margin="508,290,0,0" VerticalAlignment="Top" Width="175"/>
<RadioButton Content="EF" IsChecked="{Binding EfIsChecked}" HorizontalAlignment="Left" Margin="508,341,0,0" VerticalAlignment="Top"/>
<RadioButton Content="LINQ" IsChecked="{Binding LinqIsChecked}" HorizontalAlignment="Left" Margin="508,321,0,0" VerticalAlignment="Top"/>
</Grid> </Grid>
</Grid> </Grid>
</UserControl> </UserControl>