コード例 #1
0
ファイル: ClientsWindow.xaml.cs プロジェクト: Aynur11/BankV2
        private void AddNewPhysicalPersonClientButton_OnClick(object sender, RoutedEventArgs e)
        {
            var addingClientWindow = new AddingPhysicalPersonClientWindow();

            if (addingClientWindow.ShowDialog() == true)
            {
                using (var repo = new PhysicalPersonClientRepository())
                {
                    if (!DateTime.TryParse(addingClientWindow.BirthdayTextBox.Text, out var birthday))
                    {
                        MessageBox.Show("Ошибка ввода дня рождения");
                        return;
                    }

                    ClientType clientType = Convert.ToBoolean(addingClientWindow.IsVipCheckBox.IsChecked)
                        ? ClientType.Vip
                        : ClientType.Usual;

                    var client = new PhysicalPersonClient(addingClientWindow.FirstNameTextBox.Text,
                                                          addingClientWindow.LastNameTextBox.Text,
                                                          addingClientWindow.LastNameTextBox.Text,
                                                          birthday,
                                                          clientType);
                    PhysicalPersonClients.Add(client);
                    repo.AddClient(client);
                    repo.Save();
                }
            }
        }
コード例 #2
0
ファイル: ClientsWindow.xaml.cs プロジェクト: Aynur11/BankV2
 private void PhysicalPersonsDataGrid_OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
 {
     if (SelectedPhysicalPersonClient != null)
     {
         using (var repo = new PhysicalPersonClientRepository())
         {
             repo.Update(SelectedPhysicalPersonClient);
             repo.Save();
         }
     }
 }
コード例 #3
0
ファイル: ClientsWindow.xaml.cs プロジェクト: Aynur11/BankV2
        private void RemovePhysicalPersonClientButton_OnClick(object sender, RoutedEventArgs e)
        {
            using (var repo = new PhysicalPersonClientRepository())
            {
                repo.RemoveClient(SelectedPhysicalPersonClient);
                repo.Save();
                repo.Update(SelectedPhysicalPersonClient);
            }

            PhysicalPersonClients.Remove(SelectedPhysicalPersonClient);
        }
コード例 #4
0
ファイル: ClientsWindow.xaml.cs プロジェクト: Aynur11/BankV2
        private void TransferPhysicalPersonMoneyButton_OnClick(object sender, RoutedEventArgs e)
        {
            MoneyTransferWindow moneyTransferWindow = new MoneyTransferWindow();

            using (var physicalPersonClientRepo = new PhysicalPersonClientRepository())
                using (var legalPersonClientRepo = new LegalPersonClientRepository())
                {
                    PhysicalPersonClient client = (PhysicalPersonClient)PhysicalPersonsDataGrid.SelectedItem;
                    moneyTransferWindow.SenderAccountIdComboBox.ItemsSource       = physicalPersonClientRepo.GetAllClientAccounts(client.Id);
                    moneyTransferWindow.SenderAccountIdComboBox.DisplayMemberPath = "Id";

                    var allClients = new List <IClient>();
                    allClients.AddRange(physicalPersonClientRepo.GetClients());
                    allClients.AddRange(legalPersonClientRepo.GetClients());

                    moneyTransferWindow.RecipientClientNamesComboBox.ItemsSource       = allClients;
                    moneyTransferWindow.RecipientClientNamesComboBox.DisplayMemberPath = "DisplayName";

                    if (moneyTransferWindow.ShowDialog() == true)
                    {
                        IAccount accountFrom = (IAccount)moneyTransferWindow.SenderAccountIdComboBox.SelectedValue;
                        IAccount accountTo   = (IAccount)moneyTransferWindow.RecipientAccountsIdComboBox.SelectedValue;
                        try
                        {
                            AccountManager accountManager = new AccountManager();
                            accountManager.TransferMoney(accountFrom, accountTo, moneyTransferWindow.Amount);
                            physicalPersonClientRepo.Save();
                            legalPersonClientRepo.Save();
                        }
                        catch (HimselfTransferException exception)
                        {
                            MessageBox.Show($"Произошла ошибка: {exception.Message}\n" +
                                            $"Перевод с клиента {accountFrom.ClientId} со счета {accountFrom.Id} клиенту {accountTo.ClientId} на счет {accountTo.Id}");
                        }
                        catch (InsufficientAmountsException exception)
                        {
                            MessageBox.Show($"Произошла ошибка: {exception.Message}\nСуммма денег на счету: {exception.Amount}");
                        }
                        catch (CurrencyMismatchException exception)
                        {
                            MessageBox.Show($"Произошла ошибка: {exception.Message}\n" +
                                            $"Валюта счета отправителя: {exception.Sender}, валюта счета получателя: {exception.Recipient}");
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show($"Произошла ошибка: {exception.Message} Выполняем завершение программы.");
                            throw;
                        }
                    }
                }
        }
コード例 #5
0
ファイル: ClientsWindow.xaml.cs プロジェクト: Aynur11/BankV2
        private void ShowAllPhysicalPersonAccountsMenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            if (SelectedPhysicalPersonClient == null)
            {
                MessageBox.Show("Выберите клиента корректным образом!");
                return;
            }
            var accountsWindow = new AccountsWindow();

            accountsWindow.Title = $"Все счета клиента: {SelectedPhysicalPersonClient.DisplayName}";
            using (var repo = new PhysicalPersonClientRepository())
            {
                accountsWindow.AccountsDataGrid.DataContext = repo.GetAllClientAccounts(SelectedPhysicalPersonClient.Id);
                accountsWindow.ShowDialog();
            }
        }
コード例 #6
0
ファイル: ClientsWindow.xaml.cs プロジェクト: Aynur11/BankV2
        public ClientsWindow()
        {
            InitializeComponent();
            //TestData testData = new TestData();
            //testData.FillAllTables();
            using (var repo = new PhysicalPersonClientRepository())
            {
                PhysicalPersonClients = new ObservableCollection <PhysicalPersonClient>(repo.GetClients());
                PhysicalPersonsDataGrid.DataContext = this;
            }

            using (var repo = new LegalPersonClientRepository())
            {
                LegalPersonClients = new ObservableCollection <LegalPersonClient>(repo.GetClients());
                LegalPersonsDataGrid.DataContext = this;
            }
            rate = new Rate();
        }
コード例 #7
0
ファイル: ClientsWindow.xaml.cs プロジェクト: Aynur11/BankV2
        private void OpenPhysicalPersonDepositButton_OnClick(object sender, RoutedEventArgs e)
        {
            AddingAnyAccountWindow accountWindow = new AddingAnyAccountWindow();

            if (PhysicalPersonsDataGrid.CurrentItem != null)
            {
                PhysicalPersonClient client = (PhysicalPersonClient)PhysicalPersonsDataGrid.SelectedItem;
                if (accountWindow.ShowDialog() == true)
                {
                    using (var repo = new PhysicalPersonClientRepository())
                    {
                        repo.AddDeposit(client.Id, accountWindow.Currency, accountWindow.Amount, accountWindow.Period,
                                        accountWindow.WithCapitalization, rate.CalcPhysicalPersonDepositRate(client.Type));
                    }
                }
            }
            else
            {
                MessageBox.Show("Выберите нужного клиента!");
            }
        }
コード例 #8
0
        private void ShowAccountHistoryMenuItem_OnClick(object sender, RoutedEventArgs e)
        {
            var historyWindow = new AccountHistoryWindow();
            var account       = (IAccount)AccountsDataGrid.SelectedValue;

            if (account is PhysicalPersonAccount)
            {
                using (var repo = new PhysicalPersonClientRepository())
                {
                    historyWindow.HistoryDataGrid.ItemsSource = repo.GetAccountHistory(account.Id);
                }
            }
            else
            {
                using (var repo = new LegalPersonClientRepository())
                {
                    historyWindow.HistoryDataGrid.ItemsSource = repo.GetAccountHistory(account.Id);
                }
            }
            historyWindow.ShowDialog();
        }
コード例 #9
0
ファイル: ClientsWindow.xaml.cs プロジェクト: Aynur11/BankV2
        private void OpenPhysicalPersonAccountButton_OnClick(object sender, RoutedEventArgs e)
        {
            AddingAnyAccountWindow accountWindow = new AddingAnyAccountWindow();

            accountWindow.CapitalizationCheckBox.IsEnabled = false;
            accountWindow.PeriodTextBox.IsEnabled          = false;
            if (PhysicalPersonsDataGrid.CurrentItem != null)
            {
                PhysicalPersonClient client = (PhysicalPersonClient)PhysicalPersonsDataGrid.SelectedItem;
                if (accountWindow.ShowDialog() == true)
                {
                    using (var repo = new PhysicalPersonClientRepository())
                    {
                        repo.AddAccount(client.Id, accountWindow.Currency, accountWindow.Amount);
                    }
                }
            }
            else
            {
                MessageBox.Show("Выберите нужного клиента!");
            }
        }