private void PFDone_Click(object sender, RoutedEventArgs e) { double price; double.TryParse(PFPriceHT.Text, out price); int qte; int.TryParse(PFQentity.Text, out qte); if (PFTitle.Text == String.Empty) { MessageBox.Show(Application.Current.Resources["mpfTitleNull"] as String); } else if (PFTitle.Text.Length < 2) { MessageBox.Show(Application.Current.Resources["mpfTitleMin"] as String); } else if (PFTitle.Text.Length > 100) { MessageBox.Show(Application.Current.Resources["mpfTitleMax"] as String); } else if (PFPriceHT.Text == String.Empty || price == 0) { MessageBox.Show(Application.Current.Resources["mpfPriceNull"] as String); } else if (PFRef.Text == String.Empty) { MessageBox.Show(Application.Current.Resources["mpfRefnull"] as String); } else if (PFRef.Text.Length < 6) { MessageBox.Show(Application.Current.Resources["mpfRefMin"] as String); } else if (PFRef.Text.Length > 100) { MessageBox.Show(Application.Current.Resources["mpfRefMax"] as String); } else if (PFDes.Text.Length > 1000) { MessageBox.Show(Application.Current.Resources["mpfDesMax"] as String); } else { Product product = dgProducts.SelectedIndex == -1? new Product() : dgProducts.SelectedItem as Product; product.Title = PFTitle.Text; product.PriceHT = price; product.Quantity = qte; product.Reference = PFRef.Text; product.Category = PFCat.SelectedItem as Category; product.Description = PFDes.Text; if (dgProducts.SelectedIndex == -1) { Data.Products.Add(product); product.Id = DbProduct.CreateProduct(product); resetProductForm(); } else { DbProduct.UpdateProduct(product); } dgProducts.Items.Refresh(); } }