Fix Binding for Add and Update functionality
This commit is contained in:
parent
9b233de6a8
commit
f7fb73a66c
@ -58,6 +58,8 @@ namespace LoggingClient.ViewModel
|
||||
}
|
||||
|
||||
private bool _LinqIsChecked;
|
||||
private Customer mySelectedItem;
|
||||
|
||||
public bool LinqIsChecked
|
||||
{
|
||||
get { return _LinqIsChecked; }
|
||||
@ -67,17 +69,26 @@ namespace LoggingClient.ViewModel
|
||||
OnPropertyChanged(nameof(LinqIsChecked));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public CustomerViewModel()
|
||||
{
|
||||
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;";
|
||||
|
||||
Customers = new List<Customer>();
|
||||
|
||||
|
||||
_dupChecker = new DuplicateChecker();
|
||||
}
|
||||
public Customer MySelectedItem { get; set; }
|
||||
public Customer MySelectedItem
|
||||
{
|
||||
get => mySelectedItem;
|
||||
set
|
||||
{
|
||||
mySelectedItem = value;
|
||||
this.OnPropertyChanged("MySelectedItem");
|
||||
|
||||
}
|
||||
}
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public string TxtConnectionString
|
||||
@ -161,6 +172,8 @@ namespace LoggingClient.ViewModel
|
||||
{
|
||||
var customerModelRepositoryEF = new CustomerRepositoryEF();
|
||||
Customers = customerModelRepositoryEF.GetAll();
|
||||
|
||||
this.MySelectedItem = new Customer();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -204,20 +217,34 @@ namespace LoggingClient.ViewModel
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
if (MySelectedItem.kundenkonto_fk == 0)
|
||||
{
|
||||
MessageBox.Show("Error occurred: CustAcck ID darf nicht 0 sein");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_LinqIsChecked)
|
||||
{
|
||||
try
|
||||
{
|
||||
//var customerModelRepositoryLinq = new CustomerRepositoryLinq<Customer>(TxtConnectionString);
|
||||
//customerModelRepositoryLinq.Add(NewCustomerEntry);
|
||||
//Customers = customerModelRepositoryLinq.GetAll();
|
||||
var customerModelRepositoryLinq = new CustomerRepositoryLinq();
|
||||
customerModelRepositoryLinq.Add(MySelectedItem);
|
||||
Customers = customerModelRepositoryLinq.GetAll();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
if (MySelectedItem.kundenkonto_fk == 0)
|
||||
{
|
||||
MessageBox.Show("Error occurred: CustAcck ID darf nicht 0 sein");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!_EfIsChecked && !_LinqIsChecked)
|
||||
@ -225,7 +252,7 @@ namespace LoggingClient.ViewModel
|
||||
try
|
||||
{
|
||||
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
||||
customerModelRepository.Add(this.SelectedItem);
|
||||
customerModelRepository.Add(MySelectedItem);
|
||||
this.Customers = customerModelRepository.GetAll().ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -267,7 +294,7 @@ namespace LoggingClient.ViewModel
|
||||
try
|
||||
{
|
||||
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
||||
customerModelRepository.Delete(this.SelectedItem);
|
||||
customerModelRepository.Delete(MySelectedItem);
|
||||
this.Customers = customerModelRepository.GetAll().ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -310,7 +337,7 @@ namespace LoggingClient.ViewModel
|
||||
try
|
||||
{
|
||||
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
||||
customerModelRepository.Update(this.SelectedItem);
|
||||
customerModelRepository.Update(MySelectedItem);
|
||||
this.Customers = customerModelRepository.GetAll().ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -35,7 +35,7 @@
|
||||
<Label Content="Firstname" HorizontalAlignment="Left" Margin="10,290,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="10,321,0,0" TextWrapping="Wrap" Name="EnterFirstName" VerticalAlignment="Top" Width="95">
|
||||
<TextBox.Text>
|
||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.firstname" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="MySelectedItem.firstname" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:StringRangeValidationRule
|
||||
MinimumLength="1" MaximumLength="45"
|
||||
@ -48,7 +48,7 @@
|
||||
<Label Content="Lastname" HorizontalAlignment="Left" Margin="110,290,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="110,321,0,0" TextWrapping="Wrap" Name="EnterLastName" VerticalAlignment="Top" Width="95" >
|
||||
<TextBox.Text>
|
||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.lastname" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="MySelectedItem.lastname" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:StringRangeValidationRule
|
||||
MinimumLength="1" MaximumLength="45"
|
||||
@ -61,7 +61,7 @@
|
||||
<Label Content="CustomerNr" HorizontalAlignment="Left" Margin="210,290,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="210,321,0,0" TextWrapping="Wrap" Name="EnterCustomerNr" VerticalAlignment="Top" Width="95">
|
||||
<TextBox.Text>
|
||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.customernumber" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="MySelectedItem.customernumber" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:CustomerNumberValidationRule
|
||||
ErrorMessage="CU12345 - Pattern of a valid CustomerNumber" />
|
||||
@ -72,7 +72,7 @@
|
||||
|
||||
<Label Content="Url" HorizontalAlignment="Left" Margin="310,291,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="310,321,0,0" TextWrapping="Wrap" x:Name="EnterUrl" VerticalAlignment="Top" Width="95">
|
||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.url" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="MySelectedItem.url" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:UrlValidationRule
|
||||
ErrorMessage="Invalid URL." />
|
||||
@ -83,7 +83,7 @@
|
||||
<Label Content="CustAcc ID" HorizontalAlignment="Left" Margin="10,346,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="10,372,0,0" TextWrapping="Wrap" Name="EnterCustAccFk" VerticalAlignment="Top" Width="95">
|
||||
<TextBox.Text>
|
||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.kundenkonto_fk" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="MySelectedItem.kundenkonto_fk" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:IntRangeValidationRule
|
||||
MinimumLength="1" MaximumLength="8"/>
|
||||
@ -95,7 +95,7 @@
|
||||
<Label Content="Phone" HorizontalAlignment="Left" Margin="110,346,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="110,372,0,0" TextWrapping="Wrap" Name="EnterPhoneNumber" VerticalAlignment="Top" Width="95">
|
||||
<TextBox.Text>
|
||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.tel" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="MySelectedItem.tel" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:StringRangeValidationRule
|
||||
MinimumLength="1" MaximumLength="20"
|
||||
@ -107,7 +107,7 @@
|
||||
|
||||
<Label Content="Email" HorizontalAlignment="Left" Margin="210,346,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="210,372,0,0" TextWrapping="Wrap" x:Name="EnterEmail" VerticalAlignment="Top" Width="95">
|
||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.email" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="MySelectedItem.email" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:EmailValidationRule
|
||||
ErrorMessage="Invalid Email Address" />
|
||||
@ -117,7 +117,7 @@
|
||||
|
||||
<Label Content="Password" HorizontalAlignment="Left" Margin="310,347,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="310,372,0,0" TextWrapping="Wrap" x:Name="EnterPassword" VerticalAlignment="Top" Width="95">
|
||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.password" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="MySelectedItem.password" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:PasswordValidationRule
|
||||
ErrorMessage="1 lower, 1 UPPER-case, 1 number, 1 SpecialCaracter, 8-15 caracters" />
|
||||
|
Loading…
Reference in New Issue
Block a user