コード例 #1
0
ファイル: IncomesUI.cs プロジェクト: tsybulsky/training
        private void InputFromConsole()
        {
            Console.Clear();
            bool     working = true;
            DateTime?date;
            decimal? value;
            string   incomeFrom = "";
            string   notes;

            while (working)
            {
                date = CustomActionUI.InputDate("Введите дату получения дохода (пустая строка - завершить): ", true);
                if (date == null)
                {
                    return;
                }
                if (date < ledger.MinWorkingDate)
                {
                    Console.WriteLine($"Минимальная допустимая дата {ledger.MinWorkingDate.ToString("dd.MM.yyyy")}");
                    continue;
                }
                value = CustomActionUI.InputDecimal($"Укажите сумму дохода: ", false);
                string[] articles =
                {
                    "Заработная плата",
                    "по договору подряда",
                    "кредит в банке",
                    "проценты по депозиту",
                    "выигрыш в казино",
                    "прочие"
                };
                int choice = CustomActionUI.ShowMenu("Выберите источник дохода", articles, false);
                if (choice < articles.Length - 1)
                {
                    incomeFrom = articles[choice - 1];
                }
                else if (choice == articles.Length)
                {
                    Console.Write("Укажите иной источник дохода: ");
                    incomeFrom = Console.ReadLine();
                }
                double taxRate = (CustomActionUI.ShowYesNo("Облагается налогом?")) ? 13 : 0;
                Console.Write("\r\nПримечание: ");
                notes = Console.ReadLine();
                try
                {
                    ledger.AddIncome((DateTime)date, (decimal)value, incomeFrom, taxRate, notes);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }