Пример #1
0
        /// <summary>
        /// получаем текущий платеж
        /// </summary>
        /// <param name="berserkMembers"></param>
        public void GetMonthPayment(List <BerserkMembers> berserkMembers)
        {
            Console.WriteLine("Введите имя плательщика:");
            string name = Console.ReadLine();

            using (var db = new BerserkMembersDatabase())
            {
                if (db.BerserkMembers.Any(n => n.BerserksName == name))
                {
                    Console.WriteLine("Введите сумму платежа:");
                    if (int.TryParse(Console.ReadLine(), out int paymentSum) && paymentSum > 0)
                    {
                        MonthPaymentToDatabase(name, paymentSum);
                    }
                    else
                    {
                        Console.WriteLine("Неверный формат введенных данных");
                    }
                }
                else
                {
                    Console.WriteLine("Введено неправильное имя");
                }
            }
        }
        /// <summary>
        /// удаление члена клуба
        /// </summary>
        public void RemoveMember()
        {
            var flag = true;

            while (flag)
            {
                Console.WriteLine("Введите имя члена клуба для удаления:");
                string name = Console.ReadLine();
                if (String.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException("Имя не может быть пустым", nameof(name));
                }

                using (var db = new BerserkMembersDatabase())
                {
                    if (db.BerserkMembers.All(n => n.BerserksName != name))
                    {
                        Console.WriteLine("Такого имени не существует");
                    }
                    else
                    {
                        var memberForRemove = db.BerserkMembers.Where(n => n.BerserksName == name);
                        PaymentsSumOfRemovedMember(name);

                        Console.WriteLine($"{name} удален из членов клуба");
                        db.BerserkMembers.RemoveRange(memberForRemove);
                        db.SaveChanges();

                        flag = false;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// разница между первой и последней операцией члена клуба (в месяцах)
        /// </summary>
        /// <returns>разница между первой и последней операцией члена клуба (в месяцах)</returns>
        public int MonthDifference(DateTime currentData)
        {
            int monthDifference = 0;

            using (var db = new BerserkMembersDatabase())
            {
                monthDifference = (currentData.Month - db.BerserkMembers.Find(1).CurrentDate.Month)
                                  + 12 * (currentData.Year - db.BerserkMembers.Find(1).CurrentDate.Year);
            }
            return(monthDifference);
        }
Пример #4
0
        /// <summary>
        /// сумма всех взносов за месяц
        /// </summary>
        /// <returns>сумма всех взносов за месяц</returns>
        public int MonthPaymentsSum()
        {
            var totalMonthPaymentsSum = 0;

            using (var db = new BerserkMembersDatabase())
            {
                totalMonthPaymentsSum = db.BerserkMembers
                                        .Where(y => y.CurrentDate.Year == DateTime.Now.Year)
                                        .Where(d => d.CurrentDate.Month == DateTime.Now.Month)
                                        .Sum(p => p.CurrentPayment);
            }
            return(totalMonthPaymentsSum);
        }
Пример #5
0
 /// <summary>
 /// запись клубного взноса в казну
 /// </summary>
 /// <param name="name">имя члена клуба</param>
 /// <param name="paymentSum">сумма взноса</param>
 public void MonthPaymentToDatabase(string name, int paymentSum)
 {
     using (var db = new BerserkMembersDatabase())
     {
         var firstRecordCurrentMember = db.BerserkMembers.Where(n => n.BerserksName == name).First();
         var newPaymentOperation      = new BerserkMembers {
             BerserksName = name, CurrentPayment = paymentSum, CurrentDate = DateTime.Now, StartDate = firstRecordCurrentMember.StartDate
         };
         db.BerserkMembers.Add(newPaymentOperation);
         Console.WriteLine($"{name} внес {paymentSum} грн.");
         db.SaveChanges();
     }
 }
 /// <summary>
 /// общий долг члена клуба
 /// </summary>
 public void GetTotalDebt()
 {
     using (var db = new BerserkMembersDatabase())
     {
         var members = db.BerserkMembers;
         foreach (var item in members)
         {
             // разница между теперешним месяцем и месяцем добавление члена клуба в казну
             var monthDifference = (DateTime.Now.Month - item.StartDate.Month)
                                   + 12 * (DateTime.Now.Year - item.StartDate.Year);
             item.TotalDebt = item.StartDebt * (monthDifference + 1);
         }
         db.SaveChanges();
     }
 }
        /// <summary>
        /// сумма взносов удаленного члена клуба(записывается на анонимного члена клуба)
        /// </summary>
        /// <param name="name">удаленный член клуба</param>
        /// <returns>сумма взносов удаленного члена клуба</returns>
        public int PaymentsSumOfRemovedMember(string name)
        {
            var paymentsSumOfRemovedMember = 0;

            using (var db = new BerserkMembersDatabase())
            {
                paymentsSumOfRemovedMember = db.BerserkMembers.Where(n => n.BerserksName == name).Sum(n => n.CurrentPayment);
                if (paymentsSumOfRemovedMember > 0)
                {
                    BerserkMembers noNameMember = new BerserkMembers {
                        BerserksName = "NoName", StartDebt = 0, CurrentPayment = paymentsSumOfRemovedMember, CurrentDate = DateTime.Now, StartDate = DateTime.Now
                    };

                    db.BerserkMembers.Add(noNameMember);
                    db.SaveChanges();
                }
            }
            return(paymentsSumOfRemovedMember);
        }
        /// <summary>
        /// месячный отчет по клубным взносам
        /// </summary>
        /// <param name="berserkMembers">члены клуба</param>
        public void MembersPaymentsMonthReport(List <BerserkMembers> berserkMembers)
        {
            using (var db = new BerserkMembersDatabase())
            {
                Console.WriteLine();
                Console.WriteLine($"Задолженность по людям за {(MonthName)(DateTime.Now.Month)}:");
                Console.WriteLine("№  Член клуба \t   Долг(начало месяца)" +
                                  "\t   Взнос(тек.месяц) \t  Баланс(тек. месяц)");

                GetTotalDebt();

                berserkMembers = db.BerserkMembers.ToList();
                // выборка уникальных имен членов клуба
                var uniqueBerserksMember = berserkMembers.GroupBy(n => n.BerserksName)
                                           .Select(m => m.FirstOrDefault());
                var count = 0;
                foreach (var item in uniqueBerserksMember)
                {
                    var memberMonthPaymentsSum = db.BerserkMembers
                                                 .Where(y => y.CurrentDate.Year == DateTime.Now.Year)
                                                 .Where(d => d.CurrentDate.Month == DateTime.Now.Month)
                                                 .Where(n => n.BerserksName == item.BerserksName)
                                                 .Sum(p => p.CurrentPayment);
                    var memberPreviousMonthsPaymentsSum = db.BerserkMembers
                                                          .Where(y => y.CurrentDate.Year < DateTime.Now.Year)
                                                          .Where(n => n.BerserksName == item.BerserksName)
                                                          .Sum(p => p.CurrentPayment)
                                                          + db.BerserkMembers
                                                          .Where(y => y.CurrentDate.Year == DateTime.Now.Year)
                                                          .Where(d => d.CurrentDate.Month < DateTime.Now.Month)
                                                          .Where(n => n.BerserksName == item.BerserksName)
                                                          .Sum(p => p.CurrentPayment);
                    var currentDebt = item.TotalDebt - memberPreviousMonthsPaymentsSum;
                    item.MoneyBalance = -(currentDebt - memberMonthPaymentsSum);

                    Console.WriteLine($"{++count}. {item.BerserksName}\t\t  {currentDebt} грн." +
                                      $" \t\t  {memberMonthPaymentsSum} грн. \t\t  {item.MoneyBalance} грн.");
                }
            }
        }
        /// <summary>
        /// добавление нового члена клуба
        /// </summary>
        /// <param name="berserkMembers">член клуба</param>
        public void AddNewMember(List <BerserkMembers> berserkMembers)
        {
            var flag = true;

            while (flag)
            {
                Console.WriteLine("Введите имя нового члена клуба:");
                string name = Console.ReadLine();
                if (string.IsNullOrEmpty(name))
                {
                    throw new ArgumentNullException("Имя не может быть пустым", nameof(name));
                }

                using (var db = new BerserkMembersDatabase())
                {
                    if (db.BerserkMembers.Any(n => n.BerserksName == name))
                    {
                        Console.WriteLine("Такое имя уже существует");
                    }
                    else
                    {
                        int monthPaymentSum = CashBoxPaymentsOperation.ParseInt("Введите сумму ежемесячного взноса");

                        BerserkMembers newMember = new BerserkMembers {
                            BerserksName = name, StartDebt = monthPaymentSum, StartDate = DateTime.Now, CurrentDate = DateTime.Now
                        };
                        berserkMembers.Add(newMember);
                        Console.WriteLine($"{name} добавлен в члены клуба");

                        db.BerserkMembers.Add(newMember);
                        db.SaveChanges();

                        flag = false;
                    }
                }
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            var cashBox = new CashBox()
            {
                BaseCashBoxSum = 2500
            };
            var cashBoxReport             = new CashBoxReport();
            var cashBoxPaymentsOperation  = new CashBoxPaymentsOperation();
            var berserkMembersMonthReport = new BerserkMembersMonthReport();
            var berserkMembers            = new List <BerserkMembers>();

            var monthPaymentOperations   = new BerserkMembersMonthPaymentOperations();
            var add_RemoveBerserksMember = new Add_RemoveBerserkMembers();

            #region Инициализация объектами
            berserkMembers.Add(new BerserkMembers {
                BerserksName = "Ragnar", StartDebt = 250, CurrentDate = DateTime.Now, StartDate = DateTime.Now
            });
            berserkMembers.Add(new BerserkMembers {
                BerserksName = "Ottar", StartDebt = 250, CurrentDate = DateTime.Now, StartDate = DateTime.Now
            });
            berserkMembers.Add(new BerserkMembers {
                BerserksName = "Torbiorn", StartDebt = 250, CurrentDate = DateTime.Now, StartDate = DateTime.Now
            });
            berserkMembers.Add(new BerserkMembers {
                BerserksName = "Eivar", StartDebt = 150, CurrentDate = DateTime.Now, StartDate = DateTime.Now
            });
            using (var db = new BerserkMembersDatabase())
            {
                if (db.BerserkMembers.Count() == 0)
                {
                    db.BerserkMembers.AddRange(berserkMembers);
                    db.SaveChanges();
                }
            }
            #endregion

            bool flag = true;
            while (flag)
            {
                ConsoleColor color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("1.Ежемесячный взнос  \t 2. Оплата мастерской  \t 3. Оплата общинного дома");
                Console.WriteLine("4. Другие расходы \t 5. Другие доходы \t 6. Баланс по людям");
                Console.WriteLine("7. Баланс по кассе \t 8. Добавить/удалить члена клуба \t 9. Выйти из программы");
                Console.WriteLine("--------------------------------");
                Console.WriteLine("Введите номер пункта:");
                Console.ForegroundColor = color;
                try
                {
                    int number = Convert.ToInt32(Console.ReadLine());

                    switch (number)
                    {
                    case 1:
                        monthPaymentOperations.GetMonthPayment(berserkMembers);
                        berserkMembersMonthReport.MembersPaymentsMonthReport(berserkMembers);
                        break;

                    case 2:
                        cashBoxPaymentsOperation.WorkshopRentalPayment(cashBox);
                        break;

                    case 3:
                        cashBoxPaymentsOperation.CommunityHouseRentalPayment(cashBox);
                        break;

                    case 4:
                        cashBoxPaymentsOperation.GetOtherExpenses(cashBox);
                        break;

                    case 5:
                        cashBoxPaymentsOperation.GetOtherIncomes(cashBox);
                        break;

                    case 6:
                        berserkMembersMonthReport.MembersPaymentsMonthReport(berserkMembers);
                        break;

                    case 7:
                        cashBoxReport.TotalSumInCashBox(monthPaymentOperations, cashBox, cashBoxPaymentsOperation);
                        break;

                    case 8:
                        add_RemoveBerserksMember.AddAndRemoveMembers(berserkMembers);
                        break;

                    case 9:
                        flag = false;
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    color = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.Message);
                    Console.ForegroundColor = color;
                }
            }
        }