Exemplo n.º 1
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();
 }
Exemplo n.º 2
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("Клиент не может быть удалён, так как у него не погашен кредит!");
                }
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
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();
            }
        }
Exemplo 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();
            }
        }
Exemplo n.º 6
0
 private void IncrimentDaysCount(ClientsEntities db, List <Account> list)
 {
     foreach (var acc in list)
     {
         acc.DaysCount++;
         db.GetAccountById(acc.PercentAccountID.Value).DaysCount++;
     }
     db.SaveChanges();
 }
Exemplo n.º 7
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();
 }
Exemplo n.º 8
0
 private void AddClient()
 {
     using (ClientsEntities db = new ClientsEntities())
     {
         var client = new Client();
         InitializeClientForDb(client, db);
         db.Client.Add(client);
         db.SaveChanges();
     }
 }
Exemplo n.º 9
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();
     }
 }
Exemplo n.º 10
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();
        }
Exemplo n.º 11
0
 private void CreateButton_Click(object sender, RoutedEventArgs e)
 {
     if (IsDataCorrect())
     {
         using (var db = new ClientsEntities())
         {
             var mainAccount    = new Account();
             var percentAccount = new Account();
             mainAccount.ClientID         = _accountModel.ClientId;
             percentAccount.ClientID      = _accountModel.ClientId;
             mainAccount.DepositTypeID    = db.GetDepositTypeByName(_accountModel.DepositType).DepositTypeID;
             percentAccount.DepositTypeID = mainAccount.DepositTypeID;
             mainAccount.AccountNumber    = _accountModel.AccountNumber;
             var part1 = _accountModel.AccountNumber.Substring(0, 9);
             var part2 = GetCorrectAccountCountPart(Convert.ToInt32(_accountModel.AccountNumber.Substring(9, 3)) + 1);
             var part3 = new Random().Next(0, 9);
             percentAccount.AccountNumber = part1 + part2 + part3;
             mainAccount.MoneyAmount      = Convert.ToDouble(_accountModel.MoneyAmount);
             if (mainAccount.DepositTypeID == 3 || mainAccount.DepositTypeID == 4)
             {
                 percentAccount.MoneyAmount = Math.Round(mainAccount.MoneyAmount * Convert.ToDouble(_accountModel.Percents) / 100, 2);
             }
             else
             {
                 percentAccount.MoneyAmount = 0;
             }
             mainAccount.StartDate     = _accountModel.StartDate;
             percentAccount.StartDate  = _accountModel.StartDate;
             mainAccount.EndDate       = _accountModel.EndDate;
             percentAccount.EndDate    = _accountModel.EndDate;
             mainAccount.DaysCount     = 0;
             percentAccount.DaysCount  = 0;
             mainAccount.CurrencyID    = db.GetCurrencyByName(_accountModel.Currency).CurrencyID;
             percentAccount.CurrencyID = mainAccount.CurrencyID;
             mainAccount.IsClosed      = false;
             percentAccount.IsClosed   = false;
             db.Account.Add(percentAccount);
             db.SaveChanges();
             mainAccount.PercentAccountID = db.GetAccountByAccountNumber(percentAccount.AccountNumber).AccountID;
             db.Account.Add(mainAccount);
             var bankResources = db.BankResourse.ToList();
             if (mainAccount.DepositTypeID == 3 || mainAccount.DepositTypeID == 4)
             {
                 bankResources[0].PhysicalMoney -= ConvertCurrencyToByn(mainAccount.CurrencyID) * mainAccount.MoneyAmount;
             }
             else
             {
                 bankResources[0].PhysicalMoney += ConvertCurrencyToByn(mainAccount.CurrencyID) * mainAccount.MoneyAmount;
             }
             db.SaveChanges();
             if (mainAccount.DepositTypeID == 3 || mainAccount.DepositTypeID == 4)
             {
                 var additionalAcc = new Account();
                 part1 = _accountModel.AccountNumber.Substring(0, 9);
                 part2 = GetCorrectAccountCountPart(Convert.ToInt32(_accountModel.AccountNumber.Substring(9, 3)) + 1);
                 part3 = new Random().Next(0, 9);
                 additionalAcc.AccountNumber = part1 + part2 + part3;
                 additionalAcc.ClientID      = mainAccount.ClientID;
                 additionalAcc.CurrencyID    = mainAccount.CurrencyID;
                 additionalAcc.DaysCount     = 0;
                 additionalAcc.DepositTypeID = 1;
                 additionalAcc.IsClosed      = true;
                 additionalAcc.StartDate     = mainAccount.StartDate;
                 additionalAcc.EndDate       = mainAccount.EndDate;
                 additionalAcc.MoneyAmount   = mainAccount.MoneyAmount;
                 db.Account.Add(additionalAcc);
                 db.SaveChanges();
                 var card = new Card();
                 card.AccountID = db.GetAccountByAccountNumber(additionalAcc.AccountNumber).AccountID;
                 card.Number    = mainAccount.AccountNumber + new Random().Next(100, 999);
                 card.PIN       = new Random().Next(1000, 9999);
                 db.Card.Add(card);
             }
             db.SaveChanges();
             this.Close();
         }
     }
 }