private void UpdateButton_Click(object sender, RoutedEventArgs e) { if (clientGrid.Visibility == Visibility.Visible) { ClientWindow window = new ClientWindow(); if (window.ShowDialog() == true) { Client client = new Client(); client.FirstName = window.getFirstName; client.MiddleName = window.getMiddleName; client.LastName = window.getLastName; client.Firma = window.getFirma; client.Town = window.getTown; client.Phone = window.getPhone; db.Client.Add(client); } db.SaveChanges(); } if (TovarGrid.Visibility == Visibility.Visible) { TovarWindow window = new TovarWindow(); if (window.ShowDialog() == true) { Tovar tovar = new Tovar(); tovar.nameTovar = window.getName; tovar.type = window.getType; tovar.sort = window.getSort; tovar.price = decimal.Parse(window.getPrice); tovar.ostatok = int.Parse(window.getOstatok); tovar.town = window.getTown; db.Tovar.Add(tovar); } db.SaveChanges(); } }
private void DeleteButton_Click(object sender, RoutedEventArgs e) { if (clientGrid.Visibility == Visibility.Visible) { try { if (clientGrid.SelectedItems.Count > 0) { for (int i = 0; i < clientGrid.SelectedItems.Count; i++) { Client phone = clientGrid.SelectedItems[i] as Client; if (phone != null) { db.Client.Remove(phone); } } } db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (TovarGrid.Visibility == Visibility.Visible) { try { if (TovarGrid.SelectedItems.Count > 0) { for (int i = 0; i < TovarGrid.SelectedItems.Count; i++) { Tovar tovar = TovarGrid.SelectedItems[i] as Tovar; if (tovar != null) { db.Tovar.Remove(tovar); } } } db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }