Ejemplo n.º 1
0
        public MainForm(User user) : this()
        {
            currentUser  = user;
            label1.Text += currentUser.Name + "!";
            ParkingManager parkingManager = new ParkingManager();

            foreach (var session in parkingManager.ActiveSessions)
            {
                if (session.CarPlateNumber == currentUser.CarPlateNumber)
                {
                    textActiveSession.Text += session.ToString();
                    textActiveSession.Text += "Remaining cost: " + parkingManager.GetRemainingCost(session.TicketNumber).ToString() + "\r\n";
                    textActiveSession.Text += "=============================================\r\n";
                }
            }
            if (textActiveSession.Text == "")
            {
                textActiveSession.Text = "You don't have any active sessions";
            }
            foreach (var session in parkingManager.PastSessions)
            {
                if (session.CarPlateNumber == currentUser.CarPlateNumber)
                {
                    textCompletedSessions.Text += session.ToString();
                    textCompletedSessions.Text += "=============================================\r\n";
                }
            }
        }
Ejemplo n.º 2
0
        static void TestLeavingParkingSystem(ParkingManager parkingManager, int activeUsersLeft)
        {
            ParkingSession session;

            for (int i = 0; i < activeUsersLeft; i++)
            {
                Console.WriteLine("How many minutes have passed?");
                int passed = GetInt("minutes passed");
                // We skip some time
                IncreaseTime(parkingManager, passed);
                Console.WriteLine($"We skipped {passed} minutes.\n");
                Console.WriteLine($"{users[i].Name} wants to leave with car {users[i].CarPlateNumber}.");

                // We check, if the user should pay for parking
                if (parkingManager.TryLeaveParkingWithTicket((int)users[i].TicketNumber, out session))
                {
                    Console.WriteLine($"Exit for car {users[i].CarPlateNumber} is granted. Related session:");
                    Console.WriteLine(session);
                }
                else
                {
                    Console.WriteLine($"Exit for car {users[i].CarPlateNumber} is denied. Payment needed.");
                    decimal rate = parkingManager.GetRemainingCost((int)users[i].TicketNumber);
                    Console.WriteLine($"{users[i].Name} has to pay {rate} roubles.");
                    Console.WriteLine($"{users[i].Name} pays immidiately.\n");
                    parkingManager.PayForParking((int)users[i].TicketNumber, rate);

                    Console.WriteLine("How many minutes have passed?");
                    passed = GetInt("minutes passed");
                    // We skip some time
                    IncreaseTime(parkingManager, passed);
                    Console.WriteLine($"We skipped {passed} minutes.\n");

                    // We check, if the user should pay extra money for being late to leave
                    if (parkingManager.TryLeaveParkingWithTicket((int)users[i].TicketNumber, out session))
                    {
                        Console.WriteLine($"Exit for car {users[i].CarPlateNumber} is granted. Related session:");
                        Console.WriteLine(session);
                    }
                    else
                    {
                        Console.WriteLine($"Exit for car {users[i].CarPlateNumber} is denied. Payment needed.");
                        rate = parkingManager.GetRemainingCost((int)users[i].TicketNumber);
                        Console.WriteLine($"{users[i].Name} has to extra pay {rate} roubles.");
                        Console.WriteLine($"{users[i].Name} pays.\n");
                        parkingManager.PayForParking((int)users[i].TicketNumber, rate);

                        if (parkingManager.TryLeaveParkingWithTicket((int)users[i].TicketNumber, out session))
                        {
                            Console.WriteLine($"Exit for car {users[i].CarPlateNumber} is granted. Related session:");
                            Console.WriteLine(session);
                        }
                        else
                        {
                            Console.WriteLine("ERROR OF THE SYSTEM");
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var pm = new ParkingManager();

            pm.GetAllData();
            pm.EnterParking("2123");
            Console.WriteLine(pm.GetRemainingCost(0));
        }
Ejemplo n.º 4
0
        private void EmulateUserActivity()
        {
            ParkingManager parkingManager = new ParkingManager();

            for (int i = 0; i < parkingManager.Users.Count; i++)
            {
                parkingManager.EnterParking(parkingManager.Users[i].CarPlateNumber);
                ParkingSession session = new ParkingSession();
                parkingManager.TryLeaveParkingByCarPlateNumber(parkingManager.Users[i].CarPlateNumber, out session);
            }
            for (int i = 0; i < parkingManager.Users.Count / 2; i++)
            {
                parkingManager.EnterParking(parkingManager.Users[i].CarPlateNumber);
                ParkingSession session = new ParkingSession();
            }
        }
Ejemplo n.º 5
0
        static void TestEnterParkingMethod(ParkingManager parkingManager)
        {
            ParkingSession session;

            for (int i = 0; i < users.Length; i++)
            {
                session = parkingManager.EnterParking(users[i].CarPlateNumber);
                if (session == null)
                {
                    Console.WriteLine($"There's no place for {users[i].Name} to park the Car {users[i].CarPlateNumber}.");
                }
                else
                {
                    Console.WriteLine($"{users[i].Name} parked the car {users[i].CarPlateNumber}. Related session:");
                    Console.WriteLine(session);
                    users[i].TicketNumber = session.TicketNumber;
                }
                Console.WriteLine();
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            ParkingSession session;
            var            pm = new ParkingManager();

            pm.GetData();
            pm.PayForParking(3, pm.GetRemainingCost(3));
            var check = pm.TryLeaveParkingByCarPlateNumber("125", out session);

            Console.WriteLine(check + " " + session.TicketNumber + " " + session.CarPlateNumber + " " + session.EntryDt);
            var checkcost = pm.GetRemainingCost(2);

            pm.PayForParking(2, checkcost);
            var checkleaving = pm.TryLeaveParkingWithTicket(2, out session);

            Console.WriteLine(checkleaving + " " + session.TicketNumber + " " + session.CarPlateNumber + " " + session.EntryDt + " " + session.TotalPayment + " " + session.ExitDt);
            var checkuser = pm.GetRemainingCost(1);

            pm.PayForParking(1, checkcost);
            var checkleavinguser = pm.TryLeaveParkingWithTicket(1, out session);

            Console.WriteLine(checkleavinguser + " " + session.TicketNumber + " " + session.CarPlateNumber + " " + session.EntryDt + " " + session.ParkingUser + " " + session.TotalPayment + " " + session.ExitDt);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Smart parking application\n");

            users = new User[numberOfUsers];

            // Create users
            Console.WriteLine($"We create {users.Length} users:");
            for (int i = 0; i < users.Length; i++)
            {
                users[i] = new User(CreateUserName(), CreateUserCarPlateNumber(), CreateUserPhone());
                Console.WriteLine($"User {i + 1}: " + users[i]);
            }
            Console.WriteLine("\n");

            // Create ParkingManager with capacity of 3 cars
            ParkingManager parkingManager = new ParkingManager(parkingManagerCapacity);

            // We test EnterParking method, 1 user won't have place to park his car
            Console.WriteLine("We want to test EnterParking method:");

            TestEnterParkingMethod(parkingManager);

            int activeUsersLeft = Math.Min(numberOfUsers, parkingManagerCapacity);

            // We test paying and leaving parking systems
            Console.WriteLine("Now we are testing paying and leaving parking systems.\n");
            Console.WriteLine(
                "For each user you'll have to input the number of minutes\n" +
                "he was abcent and the number of minutes passed between\n" +
                "paying and trying to leave the parking.\n");

            TestLeavingParkingSystem(parkingManager, activeUsersLeft);

            Console.WriteLine("Press any button to exit . . .");
            Console.ReadKey();
        }
Ejemplo n.º 8
0
 public LoginForm()
 {
     InitializeComponent();
     parkingManager = new ParkingManager();
 }
Ejemplo n.º 9
0
 // Emulates skipping time in ParkingManager. Is needed for testing.
 static void IncreaseTime(ParkingManager parkingManager, double diff)
 {
     parkingManager.CurrentTime = parkingManager.CurrentTime.AddMinutes(diff);
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            ParkingManager Current_session = null;

            if (Files.Is_saved() == true)
            {
                Console.WriteLine(@"Previous session is stored,
                                    do you want to continue?
                                    Enter 'y' if yes");
                string continue_asnwer = Console.ReadLine();

                Current_session = continue_asnwer == "y" ? (ParkingManager)Files.Reload_session() : Current_session;
            }
            Current_session = Current_session == null ? new ParkingManager() : Current_session;

            Current_session = Current_session == null ? new ParkingManager() : Current_session;

            string Main_menu = (@"1 - Choose test scenario
                                  2 - Exit");

            while (true)
            {
                Console.WriteLine(Main_menu);
                string User_input = Console.ReadLine();
                switch (User_input)
                {
                case "1":
                    string   Scenario_menu = (@"Scenarios:
                                                  1 - Scenario 1 from task
                                                  2 - Scenario 2 from task
                                                  3 - Scenario 3 from task
                                                  4 - User leaves parking within 15 minutes
                                                  5 - No free places
                                                  6 - Same Plate Number");
                    string[] Cars =
                    {
                        "car1", "car2", "car3", "car4",  "car5",  "car6",
                        "car7", "car8", "car9", "car10", "car11", "car12"
                    };
                    int[] Add_hours =
                    {
                        -2, 0, -1, 0
                    };
                    int[] Add_mnutes =
                    {
                        0, -10, -30, -5
                    };
                    while (true)
                    {
                        Console.WriteLine(Scenario_menu);
                        string Scenario_choice = Console.ReadLine();
                        switch (Scenario_choice)
                        {
                        case "1":
                            ParkingSession session_1 = Current_session.EnterParking(Cars[0]);
                            session_1.EntryDt = session_1.EntryDt.AddHours(Add_hours[0]);
                            Console.WriteLine("Scenario 1");
                            Console.WriteLine($"Remaining cost : {Current_session.GetRemainingCost(session_1.TicketNumber)}");
                            Current_session.PayForParking(session_1.TicketNumber, Current_session.GetRemainingCost(session_1.TicketNumber));
                            Console.WriteLine($"Exiting: {Current_session.TryLeaveParkingWithTicket(session_1.TicketNumber, out session_1)}");
                            Console.WriteLine("---End of the scenario 1---");
                            break;

                        case "2":
                            ParkingSession session_2 = Current_session.EnterParking(Cars[1]);
                            session_2.EntryDt = session_2.EntryDt.AddMinutes(Add_mnutes[1]);
                            Console.WriteLine("Scenario 2");
                            Console.WriteLine($"Remaining cost: { Current_session.GetRemainingCost(session_2.TicketNumber)}");
                            Console.WriteLine($"Exiting: {Current_session.TryLeaveParkingWithTicket(session_2.TicketNumber, out session_2)}");
                            Console.WriteLine("---End of the scenario 2---");
                            break;

                        case "3":
                            ParkingSession session_3 = Current_session.EnterParking(Cars[2]);
                            session_3.EntryDt = session_3.EntryDt.AddHours(Add_hours[2]);
                            Console.WriteLine("Scenario 3");
                            Console.WriteLine($"Remaining cost: {Current_session.GetRemainingCost(session_3.TicketNumber)}");
                            Current_session.PayForParking(session_3.TicketNumber, Current_session.GetRemainingCost(session_3.TicketNumber));
                            DateTime newPaymentDt = (DateTime)session_3.PaymentDt;
                            session_3.PaymentDt = newPaymentDt.AddMinutes(Add_mnutes[2]);
                            Console.WriteLine($"Exiting: {Current_session.TryLeaveParkingWithTicket(session_3.TicketNumber, out session_3)}");
                            Console.WriteLine($"Remaining cost: {Current_session.GetRemainingCost(session_3.TicketNumber)}");
                            Current_session.PayForParking(session_3.TicketNumber, Current_session.GetRemainingCost(session_3.TicketNumber));
                            Console.WriteLine($"Exiting: {Current_session.TryLeaveParkingWithTicket(session_3.TicketNumber, out session_3)}");
                            Console.WriteLine("---End of the scenario 3---");
                            break;

                        case "4":
                            ParkingSession session_4 = Current_session.EnterParking(Cars[3]);
                            session_4.EntryDt = session_4.EntryDt.AddMinutes(Add_mnutes[3]);
                            Console.WriteLine("Scenario 4");
                            Console.WriteLine($"Exiting: {Current_session.TryLeaveParkingByCarPlateNumber(Cars[5], out session_4)}");
                            Console.WriteLine("---End of the scenario 4---");
                            break;

                        case "5":
                            Console.WriteLine("Scenario 5");
                            ParkingManager newParking = new ParkingManager();
                            for (int i = 0; i < ParkingManager.Capacity; i++)
                            {
                                ParkingSession session = newParking.EnterParking(Cars[4] + i);
                                if (session == null)
                                {
                                    Console.WriteLine($"Parking cannot accommodate {ParkingManager.Capacity} car");
                                }
                            }
                            string result_5 = (newParking.EnterParking(Cars[4]) == null ? "null" : "not null");
                            Console.WriteLine($"{ParkingManager.Capacity + 1} car entering the parking: {result_5}");
                            Console.WriteLine("---End of the scenario 5---");
                            break;

                        case "6":
                            Console.WriteLine("Scenario 6");
                            Current_session.EnterParking(Cars[5]);
                            string result_6 = Current_session.EnterParking(Cars[5]) == null ? "null" : "not null";
                            Console.WriteLine($"Car with the same plate number can't access parking: {result_6}");
                            Console.WriteLine();
                            break;

                        default:
                            Console.WriteLine("There is no such an option, try one more times");
                            break;
                        }
                    }
                    break;

                case "2":
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("There is no such an option, try one more time");
                    break;
                }
            }
        }
Ejemplo n.º 11
0
        private void startButon_Click(object sender, EventArgs e)
        {
            if (textName.Text == "")
            {
                SetErrorMessage("Enter your name, please:");
            }
            else if (textNumber.Text == "")
            {
                SetErrorMessage("Enter your phone number, please:");
            }
            else if (textCar.Text == "")
            {
                SetErrorMessage("Enter car plate number, please:");
            }
            else if (textPass.Text == "")
            {
                SetErrorMessage("Enter password, please:");
            }
            else if (textRepeatPass.Text == "")
            {
                SetErrorMessage("Repeat password, please:");
            }
            else if (textPass.Text != textRepeatPass.Text)
            {
                SetErrorMessage("Passwords you entered must be equal:");
            }
            else if (!Regex.IsMatch(textNumber.Text, @"[0-9+]{11,12}"))
            {
                SetErrorMessage("Incorrect phone number format:");
            }
            else
            {
                ParkingManager parkingManager = new ParkingManager();
                bool           isUnique       = true;
                int            newId          = 0;
                foreach (var user in parkingManager.Users)
                {
                    newId = Math.Max(newId, user.Id);
                    if (user.Phone == textNumber.Text)
                    {
                        isUnique = false;
                    }
                }
                if (!isUnique)
                {
                    SetErrorMessage("User with this phone number's already registered");
                }
                else
                {
                    User user = new User(newId + 1, textName.Text,
                                         textCar.Text, textNumber.Text, textPass.Text);
                    parkingManager.Users.Add(user);
                    parkingManager.SerializeAllUsers();
                    MainForm logForm = new MainForm(user);
                    Visible = false;

                    logForm.ShowDialog();

                    Close();
                }
            }
        }