예제 #1
0
 private void PrintModel(CreditViewModel model)
 {
     if (model == null)
     {
         MessageBoxWPF.Show("Выберите кредит!", "Сообщение.", MessageBoxButton.OK, MessageBoxImage.Information);
         return;
     }
     PrintReport.PrintCredit(model, repository);
 }
예제 #2
0
        private void UpdateModel(CreditViewModel model)
        {
            if (model == null)
            {
                MessageBoxWPF.Show("Выберите кредит!", "Сообщение.", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            Payment modelPay = repository.SearchPayment(model.Id);

            if (modelPay == null)
            {
                MessageBoxWPF.Show("Кредит уже выплачен!", "Сообщение.", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            AddPaymentView view = new AddPaymentView(modelPay, repository)
            {
                ShowInTaskbar = false
            };

            view.ShowDialog();
            if (view.DialogResult != true)
            {
                return;
            }

            bool flag = repository.UpdatePayment(modelPay);

            if (!flag)
            {
                MessageBoxWPF.Show(StringProject.ErrorUpdRecort, StringProject.ErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            List <Payment> list = repository.GetPaymentsByIdCredit(model.Id).ToList();

            if (list.All(x => x.Repay != false))
            {
                ConditionCredit modelConditionCredit = new ConditionCredit
                {
                    Data        = DateTime.Now,
                    IdCredit    = model.Id,
                    IdCondition = 2 // выплачен
                };
                //Сохранение состояния кредита в БД
                repository.AddConditionCredit(modelConditionCredit);
            }
            model.RefreshModel();
        }
예제 #3
0
        public void ShowPaymentModel(CreditViewModel model)
        {
            if (model == null)
            {
                MessageBoxWPF.Show("Выберите кредит!", "Сообщение.", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            List <Payment>   list = repository.GetPaymentsByIdCredit(model.Id).ToList();
            ShowPaymentsView view = new ShowPaymentsView(list)
            {
                ShowInTaskbar = false
            };

            view.ShowDialog();
            if (view.DialogResult != true)
            {
                return;
            }
        }
예제 #4
0
        private void DeleteModel(CreditViewModel model)
        {
            if (model == null)
            {
                MessageBoxWPF.Show("Выберите кредит!", "Сообщение.", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (MessageBoxWPF.Show("Вы действительно хотите удалить кредит ?", StringProject.MessageCaption, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
            {
                return;
            }

            bool flag = repository.DeleteCredit(model.GetModel);

            if (!flag)
            {
                MessageBoxWPF.Show(StringProject.ErrorDelRecort, StringProject.ErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            AllModel.Remove(model);
        }
예제 #5
0
        private void AddModel(CreditViewModel model)
        {
            Credit           modelCredit = new Credit();
            User             modelUser   = new User();
            List <Payment>   listPayment = new List <Payment>();
            CreateCreditView view;

            if (model == null)
            {
                view = new CreateCreditView(true, repository, modelUser, modelCredit)
                {
                    ShowInTaskbar = false
                };
            }
            else
            {
                modelUser = repository.FirstUser(model.IdUser);
                view      = new CreateCreditView(false, repository, modelUser, modelCredit)
                {
                    ShowInTaskbar = false
                };
            }

            view.ShowDialog();

            if (view.DialogResult != true)
            {
                return;
            }

            if (model == null)
            {
                //Сохранение пользователя в БД
                modelUser.Id = repository.AddUser(modelUser);
                if (modelUser.Id == 0)
                {
                    MessageBoxWPF.Show(StringProject.ErrorAddRecort, StringProject.ErrorCaption, MessageBoxButton.OK,
                                       MessageBoxImage.Error);
                    return;
                }
            }

            modelCredit.IdUser  = modelUser.Id;
            modelCredit.UserObj = repository.FirstUser(modelUser.Id);
            //Сохранение кредита в БД
            modelCredit.Id = repository.AddCredit(modelCredit);

            if (modelCredit.Id == 0)
            {
                MessageBoxWPF.Show(StringProject.ErrorAddRecort, StringProject.ErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            listPayment = repository.CalculationPayment(modelCredit.SummaFull, modelCredit.SummaMonth,
                                                        modelCredit.Stavka, modelCredit.TermMonth, modelCredit.DataStart).ToList();

            foreach (Payment item in listPayment)
            {
                item.IdCredit = modelCredit.Id;
                //Сохранение графика платежей в БД
                repository.AddPayment(item);
            }

            ConditionCredit modelConditionCredit = new ConditionCredit
            {
                Data        = DateTime.Now,
                IdCredit    = modelCredit.Id,
                IdCondition = 1 // оформлен
            };

            //Сохранение состояния кредита в БД
            repository.AddConditionCredit(modelConditionCredit);

            AllModel.Add(new CreditViewModel(modelCredit, repository));
        }