Exemplo n.º 1
0
        /// <summary>
        /// Изменить тарифный план
        /// </summary>
        /// <param name="abonents"></param>
        private static void ChangeTariff(Abonent[] abonents)
        {
            Console.WriteLine("Номер договора");
            int number = Convert.ToInt32(Console.ReadLine());

            Abonent currentAbonent = abonents[number];

            Console.WriteLine($"Ваш текущий тариф:{currentAbonent.Dogovor.Tariff.Name}" + Environment.NewLine);
            Console.WriteLine("Доступные тарифные планы: " + Environment.NewLine);

            //не заморачивался тут с рефлексией для полного списка тарифных планов
            Type baseType = typeof(Tariff);

            Tariff[] tariffs = new Tariff[3];
            tariffs[0] = new EasyTariff();
            tariffs[1] = new MediumTariff();
            tariffs[2] = new FullTariff();

            Console.WriteLine("Выберите номер нового тарифного плана: ");

            for (int i = 0; i < tariffs.Length; i++)
            {
                Console.WriteLine($"{i} {tariffs[i].Name}");
            }

            int current = Convert.ToInt32(Console.ReadLine());

            currentAbonent.Dogovor.ChangeTariff(tariffs[current]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Пополнить баланс
        /// </summary>
        /// <param name="ats"></param>
        /// <param name="abonents"></param>
        private static void AddMoney(Station ats, Abonent[] abonents)
        {
            Console.WriteLine("Номер договора");
            int number = Convert.ToInt32(Console.ReadLine());

            Abonent currentAbonent = abonents[number];

            Console.WriteLine("Введите сумму:");
            decimal amount = Convert.ToDecimal(Console.ReadLine());

            //урезаем до сотых (копеек)
            amount = Math.Truncate(100 * amount) / 100;
            ats.AddMoney(currentAbonent.Dogovor, amount);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Совершить звонок
        /// </summary>
        /// <param name="abonents"></param>
        private static void MakeDial(Abonent[] abonents)
        {
            Console.WriteLine("Номер договора");
            int number = Convert.ToInt32(Console.ReadLine());

            Abonent abonent = abonents[number];

            Console.WriteLine("Введите номер для звонка:");
            int dialNumber = Convert.ToInt32(Console.ReadLine());

            abonent.Terminal.Dial(dialNumber);
            Console.ReadKey();
            abonent.Terminal.FinishDial();
            Console.ReadKey();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Подключение или отключение терминала к порту
        /// </summary>
        /// <param name="abonents"></param>
        /// <param name="isConnect">True - подключить, False - отключить</param>
        private static void SetTerminalToPorts(Abonent[] abonents, bool isConnect)
        {
            Console.WriteLine("Номер договора");

            int number = Convert.ToInt32(Console.ReadLine());

            Abonent currentAbonent = abonents[number];

            if (isConnect)
            {
                currentAbonent.Terminal.ConnectPort(currentAbonent.Port);
            }

            else
            {
                currentAbonent.Terminal.DisconnectPort();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Создает указанное количество абонентов
        /// </summary>
        /// <param name="ats"></param>
        /// <param name="count">Количество абонентов</param>
        private static Abonent[] CreateDogovors(Station ats, int count)
        {
            Abonent[] abonents = new Abonent[count];

            for (int i = 0; i < count; i++)
            {
                Dogovor  dogovor = ats.CreateDogovor();
                Port     port    = ats.GetPort(dogovor);
                Terminal phone   = ats.GetPhone();
                phone.Ringing += Phone_Ringing;
                abonents[i]    = new Abonent(dogovor, port, phone);
                Console.WriteLine($"{i} - Договор №{dogovor.DogovorNumber} Номер: {port.AbonentNumber} Тариф: {dogovor.Tariff.Name} Терминал: {phone.Name}");
            }

            Console.WriteLine();
            //сразу подключаем всех к портам
            ConnectTerminalsToPorts(abonents);

            return(abonents);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Получить историю звоноков абонента
        /// </summary>
        /// <param name="ats"></param>
        /// <param name="abonents"></param>
        private static void GetHistory(Station ats, Abonent[] abonents)
        {
            Console.WriteLine("Номер договора");
            int     number         = Convert.ToInt32(Console.ReadLine());
            Abonent currentAbonent = abonents[number];

            List <Call> history = ats.GetHistory(currentAbonent.Port.AbonentNumber);

            if (history == null)
            {
                Console.WriteLine($"{currentAbonent.Port.AbonentNumber} - нет истории вызовов");
                return;
            }

            Console.WriteLine("    Дата вызова   \t --\t \t Длительность  \t Стоимость");

            foreach (var s in history)
            {
                Console.WriteLine($"{s.StartDate} \t {s.AbonentFrom}=>{s.AbonentTo} \t {s.Duration.ToString(@"hh\:mm\:ss")} \t {s.Amount} BYN");
            }

            bool isAlive = true;

            while (isAlive)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Фильтровать по:");
                Console.WriteLine($"1. Дате \t 3. Номеру \t 5.Выход");
                Console.WriteLine($"2. Сумме \t 4. Сброс фильтра");
                try
                {
                    int command = Convert.ToInt32(Console.ReadLine());

                    switch (command)
                    {
                    case 1:
                        ApplyFilter(history, Filter.FilterByDate);
                        break;

                    case 2:
                        ApplyFilter(history, Filter.FilterByAmount);
                        break;

                    case 3:
                        ApplyFilter(history, Filter.FilterByAbonent);
                        break;

                    case 4:
                        ApplyFilter(history, Filter.FilterReset);
                        break;

                    case 5:
                        isAlive = false;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }