Пример #1
0
        /// <summary>
        /// This method reads from the parkinglist on startup - I know, this method is huge...
        /// </summary>
        public static void ReadParkingFile()
        {
            string        parkingPath = @"../../../Textfiles/Parkinglist.txt";
            List <string> lines       = File.ReadAllLines(parkingPath).ToList(); // Thank you Tim Corey!

            string[] places;
            if (lines.Count > 0)
            {
                foreach (string line in lines)
                {
                    places = line.Split("|");
                    int spotNr = int.Parse(places[1]);
                    int spot   = spotNr - 1;
                    ParkingSpots[spot]            = new ParkingSpot();
                    ParkingSpots[spot].SpotNumber = spotNr;
                    ParkingSpots[spot].FreeSpace  = int.Parse(places[2]);

                    if (places[0] == "1") // One vehicle in the spot
                    {
                        if (places[3] == "Car")
                        {
                            AddFirstCar(places, spot);
                        }
                        else
                        {
                            AddFirstMC(places, spot);
                        }
                    }
                    else if (places[0] == "2") // Two vehicles in the spot
                    {
                        if (places[3] == "Car")
                        {
                            AddFirstCar(places, spot);
                        }
                        else
                        {
                            AddFirstMC(places, spot);
                        }

                        if (places[6] == "Car")
                        {
                            AddSecondCar(places, spot);
                        }
                        else
                        {
                            AddSecondMC(places, spot);
                        }
                    }
                    else if (places[0] == "3") // Three vehicles in the spot
                    {
                        if (places[3] == "Car")
                        {
                            AddFirstCar(places, spot);
                        }
                        else
                        {
                            AddFirstMC(places, spot);
                        }

                        if (places[6] == "Car")
                        {
                            AddSecondCar(places, spot);
                        }
                        else
                        {
                            AddSecondMC(places, spot);
                        }

                        if (places[9] == "Car")
                        {
                            AddThirdCar(places, spot);
                        }
                        else
                        {
                            AddThirdMC(places, spot);
                        }
                    }
                    else if (places[0] == "4") // Four vehicles in the spot
                    {
                        if (places[3] == "Car")
                        {
                            AddFirstCar(places, spot);
                        }
                        else
                        {
                            AddFirstMC(places, spot);
                        }

                        if (places[6] == "Car")
                        {
                            AddSecondCar(places, spot);
                        }
                        else
                        {
                            AddSecondMC(places, spot);
                        }

                        if (places[9] == "Car")
                        {
                            AddThirdCar(places, spot);
                        }
                        else
                        {
                            AddThirdMC(places, spot);
                        }

                        if (places[12] == "Car")
                        {
                            AddFourthCar(places, spot);
                        }
                        else
                        {
                            AddFourthMC(places, spot);
                        }
                    }
                }
            }
            else
            { //This loop creates the ParkingSpots in the ParkingHouse if the parkinglistfile is empty.
                for (int i = 0; i < Initilizing.ParkValue; i++)
                {
                    ParkingSpots[i]            = new ParkingSpot();
                    ParkingSpots[i].SpotNumber = i + 1;
                }
            }
        }