Esempio n. 1
0
        //Method to read all products from file and return them in an array
        public Product[] GetProducts()
        {
            string[]        allLines = File.ReadAllLines("Database.txt", Encoding.UTF8);
            PhysicalProduct product  = new PhysicalProduct("", 10, 10, "");

            allProducts = new Product[allLines.Length];
            for (int i = 0; i < allLines.Length; i++)
            {
                allProducts[i] = product.ParseProduct(allLines[i]);
            }

            return(allProducts);
        }
Esempio n. 2
0
 //Method to parse a product from string
 public Product ParseProduct(string productText)
 {
     string[] productInfo = productText.Split(',');
     if (productInfo[3].Equals("Digital"))
     {
         DigitalProduct product = new DigitalProduct(productInfo[0], Convert.ToInt32(productInfo[1]), Convert.ToInt32(productInfo[2]), productInfo[4]);
         return(product);
     }
     else
     {
         PhysicalProduct product = new PhysicalProduct(productInfo[0], Convert.ToInt32(productInfo[1]), Convert.ToInt32(productInfo[2]), productInfo[4]);
         return(product);
     }
 }