Esempio n. 1
0
        //method to Save/Update the current inventory
        private static void SaveCurrentInventory()
        {
            //create new streamwriter object
            StreamWriter sw = new StreamWriter(@"..\CarLotCOMPLETE\CarLot\CarLotDB.txt");

            //iterate through our list of cars and first make CSV string out of the objects data, and then write that data to the CSV text file
            foreach (Car car in currentInventory)
            {
                //check if the object is a NewCar or a UsedCar
                if (car is NewCar)
                {
                    //if its a NewCar then we call the method that is in the NewCar class
                    sw.WriteLine(NewCar.CarToCSV((NewCar)car));
                }
                else
                {
                    //if it is a UsedCar then we call then methiod that is in the UsedCar class
                    sw.WriteLine(UsedCar.CarToCSV((UsedCar)car));
                }
            }

            //closed the connection saving data to the text file
            sw.Close();
        }