Ejemplo n.º 1
0
        private void MoneyForMobileEntered(object sender, RoutedEventArgs e)
        {
            Button1.Click -= MoneyForMobileEntered;
            double sum;

            if (double.TryParse(InputTextBox.Text, out sum))
            {
                if (_account.MoneyAmount * ConvertCurrencyToByn(_account.CurrencyID) > sum)
                {
                    using (var db = new ClientsEntities())
                    {
                        var acc = db.GetAccountById(_account.AccountID);
                        acc.MoneyAmount -= sum / ConvertCurrencyToByn(_account.CurrencyID);
                        db.SaveChanges();
                        cash = sum;
                        MessageBox.Show("Оплата мобильной связи. Номер телефона: " + phoneNumber + "; Дата: " + DateTime.Now + "; Номер карты: " + _card.Number
                                        + "; Сумма на счёте: " + acc.MoneyAmount + "; Денег снято: " + cash + "BYN.");
                        MenuState();
                    }
                }
                else
                {
                    MessageBox.Show("На вашем счёте недостаточно средств.");
                    MenuState();
                }
            }
            else
            {
                MessageBox.Show("Введите корректную сумму.");
                EnteringMoneyForMobileState();
            }
        }
Ejemplo n.º 2
0
        private void UpdateClientInfo()
        {
            using (var db = new ClientsEntities())
            {
                var client = db.GetClientById(Client.Id);

                client.Surname              = Client.Surname;
                client.Name                 = Client.Name;
                client.Patronimic           = Client.Patronimic;
                client.BirthDate            = Client.BirthDate;
                client.PassportSeries       = Client.PassportSeries;
                client.PassportNumber       = Client.PassportNumber;
                client.Authority            = Client.Authority;
                client.DateOfIssue          = Client.IssueDate;
                client.PlaceOfBirth         = Client.PlaceOfBirth;
                client.IdentificationNumber = Client.IdentificationNumber;
                client.Location             = db.GetCityIDByValue(Client.Location);
                client.Address              = Client.Address;
                client.MobileNumber         = Client.MobileNumber;
                client.PhoneNumber          = Client.PhoneNumber?.Replace("_", "");
                client.Email                = Client.Email;
                client.MaritalStatus        = db.GetMaritualStatusIDByValue(Client.MaritualStatus);
                client.Disability           = db.GetDisabilityIDByValue(Client.Disability);
                client.Nationality          = db.GetNationalityIDByValue(Client.Nationality);
                client.Pensioner            = Client.Pensioner;
                client.RegistrationCity     = db.GetCityIDByValue(Client.RegistrationCity);
                client.Gender               = (Client.MaleGender) ? true : false;
                client.MonthlyIncome        = ConvertStringToMoneyValue(Client.MonthlyIncome);

                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        private void CheckCardNumber(object sender, RoutedEventArgs e)
        {
            string text = InputTextBox.Text;

            if (IsDigitsOnly(text) && text.Length == 16)
            {
                using (var db = new ClientsEntities())
                {
                    _card = db.GetCardByNumber(text);
                    if (_card != null)
                    {
                        _account = db.GetAccountById(_card.AccountID);
                        WaitingForPINState();
                        Button1.Click -= CheckCardNumber;
                    }
                    else
                    {
                        InfoTextBox.Text = "Карта с таким номером не найдена.";
                    }
                }
            }
            else
            {
                InfoTextBox.Text = "Введите корректный номер карты.";
            }
        }
Ejemplo n.º 4
0
 public AccountViewModel(Account account)
 {
     using (var db = new ClientsEntities())
     {
         var client = db.GetClientById(account.ClientID);
         _surname    = client?.Surname;
         _name       = client?.Name;
         _patronimic = client?.Patronimic;
         var depositType = db.GetDepositTypeById(account.DepositTypeID);
         _depositType   = depositType.Name;
         _accountNumber = account.AccountNumber;
         _moneyAmount   = account.MoneyAmount.ToString();
         _startDate     = account.StartDate;
         _endDate       = account.EndDate;
         _daysCount     = account.DaysCount.ToString();
         _percents      = depositType.Percents.ToString();
         _currency      = db.GetCurrencyById(account.CurrencyID);
         _isPercentage  = (account.PercentAccountID == null) ? "Да" : "Нет";
         if (account.PercentAccountID != null)
         {
             var percentAcc = db.GetAccountById(account.PercentAccountID.Value);
             _percentMoney = percentAcc.MoneyAmount.ToString();
         }
         _isClosed = account.IsClosed ? "Закрыт" : "Открыт";
     }
 }
Ejemplo n.º 5
0
        private void CashAmountEntered(object sender, RoutedEventArgs e)
        {
            Button1.Click -= CashAmountEntered;
            double sum;

            if (double.TryParse(InputTextBox.Text, out sum))
            {
                if (_account.MoneyAmount * ConvertCurrencyToByn(_account.CurrencyID) > sum)
                {
                    using (var db = new ClientsEntities())
                    {
                        var acc = db.GetAccountById(_account.AccountID);
                        acc.MoneyAmount -= sum / ConvertCurrencyToByn(_account.CurrencyID);
                        db.SaveChanges();
                        cash = sum;
                        ShowMoneyAmountState();
                    }
                }
                else
                {
                    MessageBox.Show("На вашем счёте недостаточно средств.");
                    MenuState();
                }
            }
            else
            {
                MessageBox.Show("Введите корректную сумму.");
                GetCashState();
            }
        }
Ejemplo n.º 6
0
 private void EndOfTermPayments(ClientsEntities db, List <Account> list)
 {
     foreach (var acc in list)
     {
         if ((acc.EndDate - acc.StartDate).Days + 1 == acc.DaysCount)
         {
             var percentAccount = db.GetAccountById(acc.PercentAccountID.Value);
             percentAccount.IsClosed = true;
             acc.IsClosed            = true;
             if (acc.DepositTypeID == 1 || acc.DepositTypeID == 2)
             {
                 acc.MoneyAmount += percentAccount.MoneyAmount;
                 var bankResources = db.BankResourse.ToList();
                 bankResources[0].RealMoney -= ConvertCurrencyToByn(acc.CurrencyID) * percentAccount.MoneyAmount;
             }
             if (acc.DepositTypeID == 3 || acc.DepositTypeID == 4)
             {
                 var bankResources = db.BankResourse.ToList();
                 bankResources[0].RealMoney += ConvertCurrencyToByn(acc.CurrencyID) * (percentAccount.MoneyAmount + acc.MoneyAmount);
                 acc.MoneyAmount             = 0;
             }
             percentAccount.MoneyAmount = 0;
         }
     }
     db.SaveChanges();
 }
Ejemplo n.º 7
0
 private void DepositTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     using (var db = new ClientsEntities())
     {
         _accountModel.Percents = db.GetDepositTypeByName(_accountModel.DepositType).Percents.ToString();
     }
 }
Ejemplo n.º 8
0
 private void InitializeClientForDb(Client client, ClientsEntities db)
 {
     client.Surname              = Client.Surname;
     client.Name                 = Client.Name;
     client.Patronimic           = Client.Patronimic;
     client.BirthDate            = Client.BirthDate;
     client.PassportSeries       = Client.PassportSeries;
     client.PassportNumber       = Client.PassportNumber;
     client.Authority            = Client.Authority;
     client.DateOfIssue          = Client.IssueDate;
     client.PlaceOfBirth         = Client.PlaceOfBirth;
     client.IdentificationNumber = Client.IdentificationNumber;
     client.Location             = db.GetCityIDByValue(Client.Location);
     client.Address              = Client.Address;
     client.MobileNumber         = Client.MobileNumber;
     client.PhoneNumber          = Client.PhoneNumber?.Replace("_", "");
     client.Email                = Client.Email;
     client.MaritalStatus        = db.GetMaritualStatusIDByValue(Client.MaritualStatus);
     client.Disability           = db.GetDisabilityIDByValue(Client.Disability);
     client.Nationality          = db.GetNationalityIDByValue(Client.Nationality);
     client.Pensioner            = Client.Pensioner;
     client.RegistrationCity     = db.GetCityIDByValue(Client.RegistrationCity);
     client.Gender               = (Client.MaleGender) ? true : false;
     client.MonthlyIncome        = ConvertStringToMoneyValue(Client.MonthlyIncome);
 }
Ejemplo n.º 9
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            if (Client.Id == 0)
            {
                MessageBox.Show("Выберете клиента!");
                return;
            }

            using (var db = new ClientsEntities())
            {
                var credits = db.Account.Where(a => (a.DepositTypeID == 3 || a.DepositTypeID == 4) && a.ClientID == Client.Id && !a.IsClosed).ToList();
                if (credits.Count == 0)
                {
                    var client = db.GetClientById(Client.Id);
                    db.Client.Remove(client);
                    db.SaveChanges();
                    MessageBox.Show("Информация о клиенте успешно удалена!");
                    ClearFields();
                }
                else
                {
                    MessageBox.Show("Клиент не может быть удалён, так как у него не погашен кредит!");
                }
            }
        }
Ejemplo n.º 10
0
 private BankResourse GetBankAccount()
 {
     using (var db = new ClientsEntities())
     {
         var resources = db.BankResourse.ToList();
         return(resources[0]);
     }
 }
Ejemplo n.º 11
0
 private void IncrimentDaysCount(ClientsEntities db, List <Account> list)
 {
     foreach (var acc in list)
     {
         acc.DaysCount++;
         db.GetAccountById(acc.PercentAccountID.Value).DaysCount++;
     }
     db.SaveChanges();
 }
Ejemplo n.º 12
0
 private void PrintCheque()
 {
     using (var db = new ClientsEntities())
     {
         var currency = db.GetCurrencyById(_account.CurrencyID);
         var acc      = db.GetAccountById(_account.AccountID);
         MessageBox.Show("Дата: " + DateTime.Now + "; Номер карты: " + _card.Number + "; Сумма на счёте: " + acc.MoneyAmount + "; Денег снято: " + cash + currency + ".");
     }
 }
Ejemplo n.º 13
0
 private void CalculatePercents(ClientsEntities db, List <Account> list)
 {
     foreach (var acc in list)
     {
         var percents = (db.GetDepositTypeById(acc.DepositTypeID).Percents *acc.MoneyAmount) / (100 * 365);
         db.GetAccountById(acc.PercentAccountID.Value).MoneyAmount += Math.Round(percents, 4);
     }
     db.SaveChanges();
 }
Ejemplo n.º 14
0
 private void SelectButton_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new ClientsEntities())
     {
         var selectedAccount   = AccountListDataGrid.SelectedItem as AccountViewModel;
         var acc               = db.GetAccountByAccountNumber(selectedAccount.AccountNumber);
         var accountInfoWindow = new AccountInfoWindow(new AccountViewModel(acc));
         accountInfoWindow.Show();
     }
 }
Ejemplo n.º 15
0
 private void Load()
 {
     using (ClientsEntities db = new ClientsEntities())
     {
         Client.Nationalities    = db.Nationality.ToList <Nationality>();
         Client.Cities           = db.City.ToList <City>();
         Client.Disabilities     = db.Disability.ToList <Disability>();
         Client.MaritualStatuses = db.MaritualStatus.ToList <MaritualStatus>();
     }
 }
Ejemplo n.º 16
0
 private void AddClient()
 {
     using (ClientsEntities db = new ClientsEntities())
     {
         var client = new Client();
         InitializeClientForDb(client, db);
         db.Client.Add(client);
         db.SaveChanges();
     }
 }
Ejemplo n.º 17
0
 private void Load()
 {
     using (ClientsEntities db = new ClientsEntities())
     {
         ClientListDataGrid.ItemsSource = db.Client
                                          .ToList <Client>()
                                          .Where(c => c.Surname != null)
                                          .OrderBy(s => s.Surname)
                                          .ThenBy(s => s.Name)
                                          .ThenBy(s => s.Patronimic);
     }
 }
Ejemplo n.º 18
0
 public AccountInfoWindow(AccountViewModel account)
 {
     _account         = account;
     this.DataContext = account;
     InitializeComponent();
     using (var db = new ClientsEntities())
     {
         var depositTypeID = db.GetDepositTypeByName(_account.DepositType).DepositTypeID;
         if ((depositTypeID == 3 || depositTypeID == 4) && _account.IsPercentage == "Нет")
         {
             PaymentsButton.IsEnabled = true;
         }
     }
 }
Ejemplo n.º 19
0
        private List <DepositType> GetDepositTypes()
        {
            List <DepositType> list = new List <DepositType>();

            using (var db = new ClientsEntities())
            {
                foreach (var type in db.DepositType)
                {
                    list.Add(type);
                }
            }

            return(list);
        }
Ejemplo n.º 20
0
        private List <Currency> GetCurrencies()
        {
            List <Currency> list = new List <Currency>();

            using (var db = new ClientsEntities())
            {
                foreach (var cur in db.Currency)
                {
                    list.Add(cur);
                }
            }

            return(list);
        }
Ejemplo n.º 21
0
 private void ShowMoneyAmountState()
 {
     InputTextBox.Text = string.Empty;
     using (var db = new ClientsEntities())
     {
         var acc = db.GetAccountById(_account.AccountID);
         InfoTextBox.Text = "Сумма средств: " + acc.MoneyAmount + ". Печатать чек?";
     }
     Button1.Content = "Да";
     Button1.Click  += PrintCheque;
     Button2.Content = "Нет";
     Button2.Click  += DontPrintCheque;
     Button3.Content = string.Empty;
 }
Ejemplo n.º 22
0
        public void Load(AccountViewModel account)
        {
            var    list            = new List <AmountByDay>();
            var    daysCount       = (account.EndDate - account.StartDate).Days + 1;
            var    mainAmount      = Convert.ToDouble(account.MoneyAmount);
            var    percents        = mainAmount * Convert.ToDouble(account.Percents) / 100;
            var    percentsByDay   = Math.Round(percents / daysCount, 2);
            var    mainAmountByDay = Math.Round(mainAmount / daysCount, 2);
            double sum             = 0;

            using (var db = new ClientsEntities())
            {
                if (db.GetDepositTypeByName(account.DepositType).DepositTypeID == 3)
                {
                    foreach (DateTime day in EachThirtyDays(account.StartDate, account.EndDate))
                    {
                        sum += (percentsByDay + mainAmountByDay) * 30;
                        list.Add(new AmountByDay()
                        {
                            Amount = ((percentsByDay + mainAmountByDay) * 30).ToString(), Date = day
                        });
                    }
                    if (sum < mainAmount + percents)
                    {
                        list.Add(new AmountByDay()
                        {
                            Amount = Math.Round(mainAmount + percents - sum, 2).ToString(), Date = account.EndDate
                        });
                    }
                }
                else
                {
                    foreach (DateTime day in EachThirtyDays(account.StartDate, account.EndDate.AddDays(-1)))
                    {
                        sum += percentsByDay * 30;
                        list.Add(new AmountByDay()
                        {
                            Amount = (percentsByDay * 30).ToString(), Date = day
                        });
                    }
                    list.Add(new AmountByDay()
                    {
                        Date = account.EndDate, Amount = Math.Round(mainAmount + percents - sum, 2).ToString()
                    });
                }
            }
            CreditPaymentsDataGrid.ItemsSource = list;
        }
Ejemplo n.º 23
0
 private void CloseButton_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new ClientsEntities())
     {
         var mainAcc = db.GetAccountByAccountNumber(_account.AccountNumber);
         mainAcc.IsClosed = true;
         if (mainAcc.PercentAccountID.HasValue)
         {
             var percentAcc = db.GetAccountById(mainAcc.PercentAccountID.Value);
             percentAcc.MoneyAmount = 0;
             percentAcc.IsClosed    = true;
         }
         db.SaveChanges();
         this.Close();
     }
 }
Ejemplo n.º 24
0
        private bool IdentificationNumberExists()
        {
            using (ClientsEntities db = new ClientsEntities())
            {
                var clients = db.Client.ToList <Client>();
                foreach (var client in clients)
                {
                    if (client.IdentificationNumber == Client.IdentificationNumber)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 25
0
        private void GenerateAccountNumber(ListWindow wnd)
        {
            while (wnd.Dispatcher.Invoke(() => { return(wnd.IsLoaded); }))
            {
            }
            Random rand        = new Random();
            var    randomDigit = rand.Next(0, 9).ToString();
            var    code        = "3014";
            var    clientPart  = GetCorrectClientPart(_accountModel.ClientId);

            using (ClientsEntities db = new ClientsEntities())
            {
                var accountCountPart = db.GetUserAccountsCountById(_accountModel.ClientId) + 1;
                _accountModel.AccountNumber = code + clientPart + GetCorrectAccountCountPart(accountCountPart) + randomDigit;
            }
        }
Ejemplo n.º 26
0
 private void CloseButton_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new ClientsEntities())
     {
         var mainAccounts = db.Account.Where(a => !a.IsClosed && a.PercentAccountID != null && (a.DepositTypeID == 1 || a.DepositTypeID == 2)).ToList();
         IncrimentDaysCount(db, mainAccounts);
         CalculatePercents(db, mainAccounts);
         EndOfMonthPayments(db, mainAccounts.Where(a => a.DepositTypeID == 1).ToList());
         EndOfTermPayments(db, mainAccounts);
         mainAccounts = db.Account.Where(a => !a.IsClosed && a.PercentAccountID != null && (a.DepositTypeID == 3 || a.DepositTypeID == 4)).ToList();
         IncrimentDaysCount(db, mainAccounts);
         EndOfMonthPayments(db, mainAccounts);
         EndOfTermPayments(db, mainAccounts);
     }
     Load();
 }
Ejemplo n.º 27
0
        private void SelectButton_Click(object sender, RoutedEventArgs e)
        {
            var    selectedClientID = (ClientListDataGrid.SelectedItem as Client).ClientID;
            Client selectedClient;

            using (ClientsEntities db = new ClientsEntities())
            {
                selectedClient = db.GetClientById(selectedClientID);

                if (selectedClient != null)
                {
                    InitializeClient(selectedClient, db);
                }
            }

            this.Close();
        }
Ejemplo n.º 28
0
        private void Load()
        {
            using (ClientsEntities db = new ClientsEntities())
            {
                var accounts      = db.Account.ToList <Account>();
                var accountsModel = new List <AccountViewModel>();
                foreach (var account in accounts)
                {
                    accountsModel.Add(new AccountViewModel(account));
                }

                this.Dispatcher.Invoke(() =>
                {
                    AccountListDataGrid.ItemsSource = accountsModel.OrderBy(acc => acc.Surname)
                                                      .ThenBy(acc => acc.Name)
                                                      .ThenBy(acc => acc.Patronimic);
                });
            }
        }
Ejemplo n.º 29
0
        private void EndOfMonthPayments(ClientsEntities db, List <Account> list)
        {
            foreach (var acc in list)
            {
                if (acc.DaysCount % 30 == 0)
                {
                    var percentAccount = db.GetAccountById(acc.PercentAccountID.Value);
                    if (acc.DepositTypeID == 1)
                    {
                        acc.MoneyAmount += percentAccount.MoneyAmount;
                        var bankResources = db.BankResourse.ToList();
                        bankResources[0].RealMoney -= ConvertCurrencyToByn(acc.CurrencyID) * percentAccount.MoneyAmount;
                        percentAccount.MoneyAmount  = 0;
                    }

                    if (acc.DepositTypeID == 3)
                    {
                        var daysCount       = (acc.EndDate - acc.StartDate).Days + 1;
                        var mainAmount      = Convert.ToDouble(acc.MoneyAmount);
                        var percents        = mainAmount * db.GetDepositTypeById(acc.DepositTypeID).Percents / 100;
                        var percentsByDay   = Math.Round(percents / daysCount, 2);
                        var mainAmountByDay = Math.Round(mainAmount / daysCount, 2);
                        acc.MoneyAmount            -= mainAmountByDay * 30;
                        percentAccount.MoneyAmount -= percentsByDay * 30;
                        var bankResources = db.BankResourse.ToList();
                        bankResources[0].RealMoney += ConvertCurrencyToByn(acc.CurrencyID) * (percentsByDay + mainAmountByDay) * 30;
                    }

                    if (acc.DepositTypeID == 4)
                    {
                        var daysCount     = (acc.EndDate - acc.StartDate).Days + 1;
                        var mainAmount    = Convert.ToDouble(acc.MoneyAmount);
                        var percents      = mainAmount * db.GetDepositTypeById(acc.DepositTypeID).Percents / 100;
                        var percentsByDay = Math.Round(percents / daysCount, 2);
                        percentAccount.MoneyAmount -= percentsByDay * 30;
                        var bankResources = db.BankResourse.ToList();
                        bankResources[0].RealMoney += ConvertCurrencyToByn(acc.CurrencyID) * percentsByDay * 30;
                    }
                }
            }
            db.SaveChanges();
        }
Ejemplo n.º 30
0
        private void InitializeClient(Client selectedClient, ClientsEntities db)
        {
            if (_client != null)
            {
                _client.Id                   = selectedClient.ClientID;
                _client.Surname              = selectedClient.Surname;
                _client.Name                 = selectedClient.Name;
                _client.Patronimic           = selectedClient.Patronimic;
                _client.BirthDate            = selectedClient.BirthDate;
                _client.PassportSeries       = selectedClient.PassportSeries;
                _client.PassportNumber       = selectedClient.PassportNumber;
                _client.Authority            = selectedClient.Authority;
                _client.IssueDate            = selectedClient.DateOfIssue;
                _client.PlaceOfBirth         = selectedClient.PlaceOfBirth;
                _client.IdentificationNumber = selectedClient.IdentificationNumber;
                _client.Location             = db.GetCityById(selectedClient.Location);
                _client.Address              = selectedClient.Address;
                _client.MobileNumber         = selectedClient.MobileNumber;
                _client.PhoneNumber          = selectedClient.PhoneNumber == null ? null : FormatePhoneNumber(selectedClient.PhoneNumber);
                _client.Email                = selectedClient.Email;
                _client.MaritualStatus       = db.GetMaritualStatusById(selectedClient.MaritalStatus);
                _client.Disability           = db.GetDisabilityById(selectedClient.Disability);
                _client.Nationality          = db.GetNationalityById(selectedClient.Nationality);
                _client.Pensioner            = selectedClient.Pensioner;
                _client.RegistrationCity     = db.GetCityById(selectedClient.RegistrationCity);
                _client.MaleGender           = (selectedClient.Gender) ? true : false;
                _client.FemaleGender         = (selectedClient.Gender) ? false : true;
                _client.MonthlyIncome        = selectedClient.MonthlyIncome == null ? null : FormateMonthlyIncome(selectedClient.MonthlyIncome.ToString());
            }

            if (_accountModel != null)
            {
                _accountModel.Surname    = selectedClient.Surname;
                _accountModel.Name       = selectedClient.Name;
                _accountModel.Patronimic = selectedClient.Patronimic;
                _accountModel.ClientId   = selectedClient.ClientID;
            }
        }