예제 #1
0
        // Reading file from storage
        public List <Cars> ReadCarStats()
        {
            var CarStats = new List <Cars>();

            using (var reader = new StreamReader(FileName)) // open and read file
            {
                string line = "";
                reader.ReadLine();
                while ((line = reader.ReadLine()) != null) //load line into string
                {
                    string[] values = line.Split(',');     // separate the values by their comma
                    int      parseInt;
                    int.TryParse(values[0], out parseInt);
                    var row = new Cars(parseInt);
                    row.Year  = values[1];
                    row.Make  = values[2];
                    row.Model = values[3];
                    row.Color = values[4];

                    CarStats.Add(row);  // adding title Row into a save file
                }
            }
            return(CarStats);
        }
예제 #2
0
 public static void AddCarInfo(Cars carToSave, List <Cars> fileContents, CarData carRespo)
 {
     fileContents.Add(carToSave);
     carRespo.SaveCSV(fileContents);
 }
예제 #3
0
        /// <summary>
        /// Add Car Information, such as CardId, Year of the car, Make, name of the Model, and a Color
        /// </summary>

        public static List <Cars> AddCar(List <Cars> fileContents, CarData carRespo)
        {
            Cars car = new Cars();

            try
            {
                Console.Clear();
                Console.WriteLine("");
                Console.WriteLine("  \t ____________________________________");
                Console.WriteLine("  \t|                                    |");
                Console.WriteLine("  \t|   Welcome To Add Car Application   |");
                Console.WriteLine("  \t|____________________________________|\n");
                Console.WriteLine("");
                Console.WriteLine("\n\tEnter the following Information To Add New Car\n");
                Console.WriteLine("________________________________________________________\n");
                Console.Write("\tEnter Car ID: ");
                car.ID = Convert.ToInt32(Console.ReadLine());
                Console.Write("\tEnter the Year: ");
                car.Year = Console.ReadLine();
                Console.Write("\tEnter the Make (e.g. Honda, BMW) : ");
                car.Make = Console.ReadLine();
                Console.Write("\tEnter the Model Name (e.g Accord, X3) : ");
                car.Model = Console.ReadLine();
                Console.Write("\tEnter the Car Color: ");
                car.Color = Console.ReadLine();
                if (fileContents.Count > 0)
                {
                    if (fileContents.Exists(carDet => carDet.ID == car.ID))
                    {
                        Console.WriteLine("\n\n\tThe Car is already exists with ID #: " + car.ID + "\n");
                    }
                    else
                    {
                        AddCarInfo(car, fileContents, carRespo);
                        Console.WriteLine("\n\n\t----------Car Successfully Added----------\n");
                    }
                }
                else
                {
                    AddCarInfo(car, fileContents, carRespo);
                    Console.WriteLine("\n\n----------Car Successfully Added----------\n");
                }
                Console.Write("\n\n\tDo you wish to add more Car? (Y | N): ");
                char choice = Console.ReadKey().KeyChar;

                switch (char.ToUpper(choice))
                {
                case 'Y':
                    AddCar(fileContents, carRespo);
                    break;

                case 'N':
                    int option1 = DisplayMenu();
                    MainCall(option1);
                    break;

                default:
                    Console.WriteLine("\n\n\t----------Some Error has Occured!! Please select the right option----------\n\n");
                    Console.WriteLine("----------------------------------------------------------------------------------------");
                    option1 = DisplayMenu();
                    MainCall(option1);
                    break;
                }
            }
            catch (Exception)
            {
                Console.WriteLine("\n\n\t----------Some Error has Occured!! Please select the right option----------\n\n");
                Console.WriteLine("----------------------------------------------------------------------------------------");
                int option1 = DisplayMenu();
                MainCall(option1);
            }
            return(fileContents);
        }