Exemple #1
0
        public void Remove(ParkedCar removedCar)
        {
            if (removedCar == null)
            {
                return;
            }

            _carsInParking.Remove(removedCar);

            var totalSecondsInParking = (DateTime.Now - removedCar.InitialParkingTime).Value.TotalSeconds;

            var paidCar = new LeavedCar()
            {
                Client = removedCar.Client,
                TotalSecondsInParking = totalSecondsInParking
            };

            if (totalSecondsInParking > AppSettings.FreePeriodInSeconds)
            {
                var amount = AppSettings.PricePerSeconds * (totalSecondsInParking - AppSettings.FreePeriodInSeconds);

                Console.WriteLine($"{removedCar.Client.FirstName}, Вы пробыли на парковке {totalSecondsInParking:f0} секунд. Ваш счёт: {amount:f2}$");

                ParkingManager.Pay(removedCar.Client, amount);
            }
            else
            {
                Console.WriteLine($"Вы успели уехать в бесплатный период. Хорошего дня, {removedCar.Client.FirstName}!");
            }

            ReportDay.LeavedCars.Add(paidCar);
        }
        private static void AddCarToParking(ParkedCar parkedCar, ParkingManager parkingManager)
        {
            if (parkingManager.GetCountFreeCarPlaces() <= 0)
            {
                Console.Clear();
                Console.WriteLine($"К сожалению, все места на парковке заняты, {parkedCar.Client.FirstName} уезжает на своей {parkedCar.Car.Make} на другую парковку");
                return;
            }

            var timerStartTimeSpan = DateTime.Now.AddSeconds(AppSettings.FreePeriodInSeconds) - DateTime.Now;
            var notify             = new TimerCallback(Notify);
            var timer = new Timer(notify, parkedCar.Client, timerStartTimeSpan, Timeout.InfiniteTimeSpan);

            parkingManager.Add(parkedCar);

            Console.Clear();

            Console.WriteLine($"На парковку заехала машина: {parkedCar}");
        }
Exemple #3
0
        static void Main(string[] args)
        {
            ParkingManager manager = new ParkingManager();

            while (true)
            {
                Console.WriteLine("1.Add vehicle");
                Console.WriteLine("2.Remove vehicle");
                Console.WriteLine("3.Total Income");
                Console.WriteLine("4.Quit");
                Console.Write("Choose:");
                int choose = int.Parse(Console.ReadLine());
                if (choose == 1)
                {
                    char?add = null;
                    while (add != 'N')
                    {
                        Console.WriteLine("1.Car");
                        Console.WriteLine("2.Bike");
                        Console.Write("Choose (Enter 0 To Back):");
                        int addchoose = int.Parse(Console.ReadLine());
                        if (addchoose == 0)
                        {
                            add = 'N';
                            continue;
                        }
                        if (addchoose == 1)
                        {
                            Console.Write("Enter Time:");
                            int Enter = int.Parse(Console.ReadLine());
                            if (Enter < 1 || Enter > 24)
                            {
                                Console.WriteLine("Must Enter Number Between 1 & 24");
                                continue;
                            }
                            Car car = new Car()
                            {
                                EntryHour = Enter,
                                Type      = Vehicle.VehicleType.Car
                            };
                            manager.AddVehicle(car);
                        }
                        else if (addchoose == 2)
                        {
                            Console.Write("Enter Time:");
                            int Enter = int.Parse(Console.ReadLine());
                            if (Enter < 1 || Enter > 24)
                            {
                                Console.WriteLine("Must Enter Number Between 1 & 24");
                                continue;
                            }
                            Bike bike = new Bike()
                            {
                                EntryHour = Enter,
                                Type      = Vehicle.VehicleType.Bike
                            };
                            manager.AddVehicle(bike);
                        }
                        Console.Write("Do yo Want Continue? Y/N : ");
                        add = char.Parse(Console.ReadLine().ToUpper());
                    }
                }
                else if (choose == 2)
                {
                    char?remove = null;
                    while (remove != 'N')
                    {
                        Console.Write("Enter Id To Delete (Enter 0 To Cancel): ");
                        string id = Console.ReadLine();
                        if (id == "0")
                        {
                            continue;
                        }
                        Console.Write("Enter Exit Time To Delete (Enter 0 To Cancel): ");
                        int exit = int.Parse(Console.ReadLine());
                        if (exit == 0)
                        {
                            continue;
                        }

                        manager.RemoveVehicle(id, exit);
                        if (manager.result == 0)
                        {
                            Console.WriteLine("Your ID Not Found :(");
                        }
                        manager.result = 0;
                        Console.Write("Do yo Want Continue? Y/N : ");
                        remove = char.Parse(Console.ReadLine().ToUpper());
                    }
                }
                else if (choose == 3)
                {
                    manager.GetTotal();
                    manager.res = 0;
                }
                else if (choose == 4)
                {
                    Environment.Exit(0);
                }
                else
                {
                }
            }



            #region
            //Console.WriteLine(Guid.NewGuid().ToString());
            //Car car = new Car()
            //{
            //    Type = Vehicle.VehicleType.Car,
            //    EntryHour = 12
            //};


            //ParkingManager parking = new ParkingManager();

            //parking.AddVehicle(car);
            #endregion
            Console.ReadKey();
        }
        public static void Main(string[] args)
        {
            AppSettings.Initialize();

            var random         = new Random();
            var parking        = GetParkingPlace();
            var parkingManager = new ParkingManager(parking);

            var parkedCarsDB = new List <ParkedCar>();

            using (StreamReader sr = new StreamReader(AppSettings.ParkedCarsPath))
            {
                parkedCarsDB = JsonConvert.DeserializeObject <List <ParkedCar> >(sr.ReadToEnd());
            }

            var periodTimeSpanDailyReport     = DateTime.Now.AddSeconds(AppSettings.DailyReportPeriodInSeconds) - DateTime.Now;
            var printDailyReportTimerCallback = new TimerCallback(ReportDay.PrintDailyReport);
            var timerDailyReport = new Timer(printDailyReportTimerCallback, parking.CarsInParking, periodTimeSpanDailyReport, Timeout.InfiniteTimeSpan);

            bool notLeaveProgram = true;

            do
            {
                Console.WriteLine($"\n{DateTime.Now:T}");
                Console.WriteLine("Введите одну из 4-х команд");
                Console.WriteLine("1. add - добавить машину на парковку");
                Console.WriteLine("2. remove - убрать машину с парковки");
                Console.WriteLine("3. getall - получить все машины на парковке на текущий момент");
                Console.WriteLine("4. q - выйти из программы");

                var command = SanitizeString(Console.ReadLine());

                switch (command)
                {
                case "add":
                    var parkedCar = parkedCarsDB[random.Next(0, parkedCarsDB.Count)];

                    AddCarToParking(parkedCar, parkingManager);
                    break;

                case "remove":
                    Console.Clear();
                    Console.WriteLine("Введите id машины, которую хотите удалить: ");

                    getAll(parking.CarsInParking);

                    var removedCar = parkingManager.GetCarByID(Console.ReadLine());

                    parkingManager.Remove(removedCar);
                    break;

                case "getall":
                    Console.Clear();

                    getAll(parking.CarsInParking);
                    break;

                case "q":
                    parkingManager.SerializeCarsInParking();

                    notLeaveProgram = false;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Ну ты даёшь, введи нормально!");
                    break;
                }
            } while (notLeaveProgram);
        }
Exemple #5
0
        static void Main(string[] args)
        {
            char MainMenuKey;

            while (true)
            {
                //Main menu texts
                ScreenMessages.PrintMainMenuTexts();
                MainMenuKey = Console.ReadKey().KeyChar;
                switch (MainMenuKey)
                {
                case '1':
                    //Add new vehice menu texts
                    ScreenMessages.PrintAddMenuTexts();
                    char AddMenuKey = Console.ReadKey().KeyChar;
                    switch (AddMenuKey)
                    {
                    case '1':
                        ScreenMessages.PrintAddVehicleMenuText("Car");
                        ParkingManager.AddVehicle(Vehicle.VehicleType.Car);
                        break;

                    case '2':
                        ScreenMessages.PrintAddVehicleMenuText("Bike");
                        ParkingManager.AddVehicle(Vehicle.VehicleType.Bike);
                        break;

                    default:
                        ScreenMessages.PrintErrorMessage();
                        break;
                    }
                    break;

                case '2':
                    //Remove vehicle menu texts
                    ScreenMessages.PrintRemoveMenuTexts();
                    ParkingManager.RemoveVehicle();
                    break;

                case '3':
                    //Feature vehicle menu texts
                    ScreenMessages.PrintFeaturesMenuTexts();
                    char FeatureKey = Console.ReadKey().KeyChar;
                    switch (FeatureKey)
                    {
                    case '1':
                        ParkingManager.PrintTotalIncome();
                        break;

                    case '2':
                        ParkingManager.PrintTotalVehicles();
                        break;

                    default:
                        ScreenMessages.PrintErrorMessage();
                        break;
                    }
                    break;

                case 'q':
                    Environment.Exit(0);
                    break;

                default:
                    ScreenMessages.PrintErrorMessage();
                    break;
                }
            }
        }