private void ButtonAddAccount_Click(object sender, RoutedEventArgs e) { EditAccountWindow window = new EditAccountWindow(); window.Owner = this; window.ExistingAccounts = Settings.Accounts.Select(acc => acc.AccountName).ToList(); if (window.ShowDialog() == true) { Settings.AddAccount(window.AccountName); Settings.SetActiveAccount(window.AccountName); UpdateAccountsComboBox(); } }
private void EditAccount_Clicked(object sender, RoutedEventArgs e) { if (AccountsGrid.SelectedIndex > -1) { EditAccountWindow newEditAccountWindow = new EditAccountWindow(); Account editAccount = AccountsGrid.SelectedItem as Account; newEditAccountWindow.tbOwner.Text = editAccount.Owner; newEditAccountWindow.tbApartmentNumber.Text = editAccount.ApartmentNumber.ToString(); newEditAccountWindow.tbLivingSpace.Text = editAccount.LivingSpace.ToString(); var result = newEditAccountWindow.ShowDialog(); if (result == false) { newEditAccountWindow.Close(); } else { try { using (var dbContext = new CalculationSystemDbContext()) { Account account = dbContext.Accounts.Single(x => x.Id == editAccount.Id); account.Owner = newEditAccountWindow.tbOwner.Text; account.ApartmentNumber = int.Parse(newEditAccountWindow.tbApartmentNumber.Text); account.LivingSpace = double.Parse(newEditAccountWindow.tbLivingSpace.Text); dbContext.SaveChanges(); UpdateAccountsTable(); MessageBox.Show("Account edited"); } } catch (Exception ex) { MessageBox.Show($"Impossible! Reason: -{ex.Message}"); } } } else { MessageBox.Show("Select account before"); } }