private void AddToBasketButton_Click(object sender, RoutedEventArgs e) { try { var quantity = Convert.ToInt32(QuantityTextBox.Text); var index = ComboBox.SelectedIndex + 1;//W sqlu index zaczyna sie od 1 int ClientID = Convert.ToInt32(Passdata.Text); var basket = db.Set <Basket>(); if (quantity > 0) { basket.Add(new Basket { ProductID = index, Quantity = quantity, ClientID = ClientID }); db.SaveChanges(); MessageBox.Show("Dodano produkt"); } } catch (System.FormatException) { MessageBox.Show("Podano nieprawidłowy format wartości ilosci lub nie podano wgle"); } ComboBoxDelete.Items.Clear(); FillDeleteCombobox(); }
private void Button_Click(object sender, RoutedEventArgs e) { try { var FirstName = FirstNameTextBox.Text; var LastName = LastNameTextBox.Text; var BornYear = Int32.Parse(BornYearTextBox.Text); var Telephone = PhoneTextBox.Text; var Email = EmailTextBox.Text; var Pass1 = PasswordTextBox.Password.ToString(); var Pass2 = SecondPasswTextBox.Password.ToString(); if ((bool)CheckBox.IsChecked) { if (Pass1 == Pass2 && Pass1 != "") { var db = new ShopEntities(); var clients = db.Set <Client>(); clients.Add(new Client { FirstName = FirstName, LastName = LastName, BornYear = BornYear, PhoneNb = Telephone, ClientPassword = Pass1, Mail = Email }); db.SaveChanges(); MessageBox.Show("Zarejestrowano!"); } else { MessageBox.Show("Podane hasła nie są takie same!"); } } else { MessageBox.Show("Musisz zaakceptować nasze warunki!"); } } catch (System.Data.Entity.Infrastructure.DbUpdateException) { MessageBox.Show("Baza danych nie chce przyjac danych w takiej postaci !"); } catch (FormatException) { MessageBox.Show("Wpisałeś niepoprawne dane (Rok urodzenia)!"); } }