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 bool _LinqIsChecked;
|
||||||
|
private Customer mySelectedItem;
|
||||||
|
|
||||||
public bool LinqIsChecked
|
public bool LinqIsChecked
|
||||||
{
|
{
|
||||||
get { return _LinqIsChecked; }
|
get { return _LinqIsChecked; }
|
||||||
@ -67,17 +69,26 @@ namespace LoggingClient.ViewModel
|
|||||||
OnPropertyChanged(nameof(LinqIsChecked));
|
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!;";
|
||||||
|
|
||||||
Customers = new List<Customer>();
|
Customers = new List<Customer>();
|
||||||
|
|
||||||
_dupChecker = new DuplicateChecker();
|
_dupChecker = new DuplicateChecker();
|
||||||
}
|
}
|
||||||
public Customer MySelectedItem { get; set; }
|
public Customer MySelectedItem
|
||||||
|
{
|
||||||
|
get => mySelectedItem;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
mySelectedItem = value;
|
||||||
|
this.OnPropertyChanged("MySelectedItem");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
public string TxtConnectionString
|
public string TxtConnectionString
|
||||||
@ -161,6 +172,8 @@ namespace LoggingClient.ViewModel
|
|||||||
{
|
{
|
||||||
var customerModelRepositoryEF = new CustomerRepositoryEF();
|
var customerModelRepositoryEF = new CustomerRepositoryEF();
|
||||||
Customers = customerModelRepositoryEF.GetAll();
|
Customers = customerModelRepositoryEF.GetAll();
|
||||||
|
|
||||||
|
this.MySelectedItem = new Customer();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -204,20 +217,34 @@ namespace LoggingClient.ViewModel
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
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)
|
if (_LinqIsChecked)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//var customerModelRepositoryLinq = new CustomerRepositoryLinq<Customer>(TxtConnectionString);
|
var customerModelRepositoryLinq = new CustomerRepositoryLinq();
|
||||||
//customerModelRepositoryLinq.Add(NewCustomerEntry);
|
customerModelRepositoryLinq.Add(MySelectedItem);
|
||||||
//Customers = customerModelRepositoryLinq.GetAll();
|
Customers = customerModelRepositoryLinq.GetAll();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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)
|
if (!_EfIsChecked && !_LinqIsChecked)
|
||||||
@ -225,7 +252,7 @@ namespace LoggingClient.ViewModel
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
||||||
customerModelRepository.Add(this.SelectedItem);
|
customerModelRepository.Add(MySelectedItem);
|
||||||
this.Customers = customerModelRepository.GetAll().ToList();
|
this.Customers = customerModelRepository.GetAll().ToList();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -267,7 +294,7 @@ namespace LoggingClient.ViewModel
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
||||||
customerModelRepository.Delete(this.SelectedItem);
|
customerModelRepository.Delete(MySelectedItem);
|
||||||
this.Customers = customerModelRepository.GetAll().ToList();
|
this.Customers = customerModelRepository.GetAll().ToList();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -310,7 +337,7 @@ namespace LoggingClient.ViewModel
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
var customerModelRepository = new CustomerRepository(TxtConnectionString);
|
||||||
customerModelRepository.Update(this.SelectedItem);
|
customerModelRepository.Update(MySelectedItem);
|
||||||
this.Customers = customerModelRepository.GetAll().ToList();
|
this.Customers = customerModelRepository.GetAll().ToList();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<Label Content="Firstname" HorizontalAlignment="Left" Margin="10,290,0,0" VerticalAlignment="Top" Width="95"/>
|
<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 HorizontalAlignment="Left" Height="25" Margin="10,321,0,0" TextWrapping="Wrap" Name="EnterFirstName" VerticalAlignment="Top" Width="95">
|
||||||
<TextBox.Text>
|
<TextBox.Text>
|
||||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.firstname" UpdateSourceTrigger="PropertyChanged">
|
<Binding Path="MySelectedItem.firstname" UpdateSourceTrigger="PropertyChanged">
|
||||||
<Binding.ValidationRules>
|
<Binding.ValidationRules>
|
||||||
<validators:StringRangeValidationRule
|
<validators:StringRangeValidationRule
|
||||||
MinimumLength="1" MaximumLength="45"
|
MinimumLength="1" MaximumLength="45"
|
||||||
@ -48,7 +48,7 @@
|
|||||||
<Label Content="Lastname" HorizontalAlignment="Left" Margin="110,290,0,0" VerticalAlignment="Top" Width="95"/>
|
<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 HorizontalAlignment="Left" Height="25" Margin="110,321,0,0" TextWrapping="Wrap" Name="EnterLastName" VerticalAlignment="Top" Width="95" >
|
||||||
<TextBox.Text>
|
<TextBox.Text>
|
||||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.lastname" UpdateSourceTrigger="PropertyChanged">
|
<Binding Path="MySelectedItem.lastname" UpdateSourceTrigger="PropertyChanged">
|
||||||
<Binding.ValidationRules>
|
<Binding.ValidationRules>
|
||||||
<validators:StringRangeValidationRule
|
<validators:StringRangeValidationRule
|
||||||
MinimumLength="1" MaximumLength="45"
|
MinimumLength="1" MaximumLength="45"
|
||||||
@ -61,7 +61,7 @@
|
|||||||
<Label Content="CustomerNr" HorizontalAlignment="Left" Margin="210,290,0,0" VerticalAlignment="Top" Width="95"/>
|
<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 HorizontalAlignment="Left" Height="25" Margin="210,321,0,0" TextWrapping="Wrap" Name="EnterCustomerNr" VerticalAlignment="Top" Width="95">
|
||||||
<TextBox.Text>
|
<TextBox.Text>
|
||||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.customernumber" UpdateSourceTrigger="PropertyChanged">
|
<Binding Path="MySelectedItem.customernumber" UpdateSourceTrigger="PropertyChanged">
|
||||||
<Binding.ValidationRules>
|
<Binding.ValidationRules>
|
||||||
<validators:CustomerNumberValidationRule
|
<validators:CustomerNumberValidationRule
|
||||||
ErrorMessage="CU12345 - Pattern of a valid CustomerNumber" />
|
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"/>
|
<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">
|
<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>
|
<Binding.ValidationRules>
|
||||||
<validators:UrlValidationRule
|
<validators:UrlValidationRule
|
||||||
ErrorMessage="Invalid URL." />
|
ErrorMessage="Invalid URL." />
|
||||||
@ -83,7 +83,7 @@
|
|||||||
<Label Content="CustAcc ID" HorizontalAlignment="Left" Margin="10,346,0,0" VerticalAlignment="Top" Width="95"/>
|
<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 HorizontalAlignment="Left" Height="25" Margin="10,372,0,0" TextWrapping="Wrap" Name="EnterCustAccFk" VerticalAlignment="Top" Width="95">
|
||||||
<TextBox.Text>
|
<TextBox.Text>
|
||||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.kundenkonto_fk" UpdateSourceTrigger="PropertyChanged">
|
<Binding Path="MySelectedItem.kundenkonto_fk" UpdateSourceTrigger="PropertyChanged">
|
||||||
<Binding.ValidationRules>
|
<Binding.ValidationRules>
|
||||||
<validators:IntRangeValidationRule
|
<validators:IntRangeValidationRule
|
||||||
MinimumLength="1" MaximumLength="8"/>
|
MinimumLength="1" MaximumLength="8"/>
|
||||||
@ -95,7 +95,7 @@
|
|||||||
<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"/>
|
||||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="110,372,0,0" TextWrapping="Wrap" Name="EnterPhoneNumber" VerticalAlignment="Top" Width="95">
|
<TextBox HorizontalAlignment="Left" Height="25" Margin="110,372,0,0" TextWrapping="Wrap" Name="EnterPhoneNumber" VerticalAlignment="Top" Width="95">
|
||||||
<TextBox.Text>
|
<TextBox.Text>
|
||||||
<Binding ElementName="DataGridCustomer" Path="SelectedItem.tel" UpdateSourceTrigger="PropertyChanged">
|
<Binding Path="MySelectedItem.tel" UpdateSourceTrigger="PropertyChanged">
|
||||||
<Binding.ValidationRules>
|
<Binding.ValidationRules>
|
||||||
<validators:StringRangeValidationRule
|
<validators:StringRangeValidationRule
|
||||||
MinimumLength="1" MaximumLength="20"
|
MinimumLength="1" MaximumLength="20"
|
||||||
@ -107,7 +107,7 @@
|
|||||||
|
|
||||||
<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"/>
|
||||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="210,372,0,0" TextWrapping="Wrap" x:Name="EnterEmail" 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>
|
<Binding.ValidationRules>
|
||||||
<validators:EmailValidationRule
|
<validators:EmailValidationRule
|
||||||
ErrorMessage="Invalid Email Address" />
|
ErrorMessage="Invalid Email Address" />
|
||||||
@ -117,7 +117,7 @@
|
|||||||
|
|
||||||
<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"/>
|
||||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="310,372,0,0" TextWrapping="Wrap" x:Name="EnterPassword" 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>
|
<Binding.ValidationRules>
|
||||||
<validators:PasswordValidationRule
|
<validators:PasswordValidationRule
|
||||||
ErrorMessage="1 lower, 1 UPPER-case, 1 number, 1 SpecialCaracter, 8-15 caracters" />
|
ErrorMessage="1 lower, 1 UPPER-case, 1 number, 1 SpecialCaracter, 8-15 caracters" />
|
||||||
|
Loading…
Reference in New Issue
Block a user