/// <summary> /// Открывает вклад. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenDepositButtonBase_OnClick(object sender, RoutedEventArgs e) { if (PhysicalTabItem.IsSelected && PhysicalPersonsDataGrid.CurrentItem != null) { row = (DataRowView)PhysicalPersonsDataGrid.SelectedItem; } else if (LegalTabItem.IsSelected && LegalPersonsDataGrid.CurrentItem != null) { row = (DataRowView)LegalPersonsDataGrid.SelectedItem; } else { MessageBox.Show("Выберите нужного клиента!"); return; } OpenDepositOrCreditWindow openDepositOrCreditWindow = new OpenDepositOrCreditWindow(); if (openDepositOrCreditWindow.ShowDialog() == true) { try { if (Int32.Parse(row["Sum"].ToString()) < openDepositOrCreditWindow.Sum) { throw new ClientInsufficientFundsException(openDepositOrCreditWindow.Sum, "Недостаточно средств для открытия депозита."); } } catch (ClientInsufficientFundsException ex) { MessageBox.Show(ex.Message); return; } // Костыль для инициализации таблицы. bankManager.GetDepositsTable(); DataRow dataRow = bankManager.DepositsDataTable.NewRow(); dataRow["ClientId"] = Int32.Parse(row["Id"].ToString()); dataRow["Sum"] = openDepositOrCreditWindow.Sum; dataRow["Rate"] = bool.Parse(row["Vip"].ToString()) ? 0.3 : 0.2; dataRow["Period"] = openDepositOrCreditWindow.Period; dataRow["Capitalization"] = openDepositOrCreditWindow.CapitalizationCheckBox.IsEnabled; bankManager.DepositsDataTable.Rows.Add(dataRow); try { bankManager.DepositsSqlDataAdapter.SafelyUpdate(bankManager.DepositsDataTable); } catch (Exception ex) { MessageBox.Show($"Не удалось обновить таблицу депозитов. {ex.Message}"); Close(); } row["Sum"] = Int32.Parse(row["Sum"].ToString()) - openDepositOrCreditWindow.Sum; try { bankManager.ClientsSqlDataAdapter.SafelyUpdate(bankManager.PhysDataTable); } catch (Exception ex) { MessageBox.Show($"Не удалось обновить таблицу депозитов. {ex.Message}"); Close(); } } }