Advertisement
Guest User

????? FileNotFoundException

a guest
Apr 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.50 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. namespace ProductInventory
  6. {
  7.     public enum InventoryState
  8.     {
  9.         Full,
  10.         Selling,
  11.         Stocking,
  12.         Empty,
  13.         Unassigned
  14.     }
  15.  
  16.     public class Product
  17.     {
  18.         public string GetProductDirectory(string productName)
  19.         {
  20.             string finalPath = $"{Environment.CurrentDirectory}\\products\\{productName}.txt";
  21.             return finalPath;
  22.         }
  23.  
  24.         public string ProductType;
  25.         public double BulkPrice;
  26.         public double RetailPrice;
  27.         public int Quantity;
  28.         public int MaxQuantity;
  29.         public InventoryState Status;
  30.  
  31.  
  32.         public string FileName;
  33.         // defining the parameters for the constructor
  34.  
  35.         public Product(string FileName)
  36.         {
  37.             this.FileName = GetProductDirectory(FileName);
  38.             ProductType = File.ReadLines(FileName).ElementAt(1);
  39.             BulkPrice = Double.Parse(File.ReadLines(FileName).ElementAt(2));
  40.             RetailPrice = Double.Parse(File.ReadLines(FileName).ElementAt(3));
  41.             Quantity = Int32.Parse(File.ReadLines(FileName).ElementAt(4));
  42.             MaxQuantity = Int32.Parse(File.ReadLines(FileName).ElementAt(5));
  43.         } // the constructor
  44.     }
  45.     public class Program
  46.     {
  47.         public static string[] CommandList =
  48.         {
  49.             "status",
  50.             "help",
  51.             "exit"
  52.         };
  53.  
  54.         public static Product[] ProductList =
  55.         {
  56.             new Product("Apple"),
  57.             new Product("Blueberry")
  58.         }; // TODO: make these values based on text files
  59.  
  60.         public static void Main()
  61.         {
  62.             string inputCommand, unformattedProduct, selectedProduct, stringStatus;
  63.             bool isProduct = false;
  64.  
  65.             foreach (Product productName in ProductList)
  66.             {
  67.                 if (productName.Quantity == productName.MaxQuantity)
  68.                 {
  69.                     productName.Status = InventoryState.Full;
  70.                 }
  71.  
  72.                 else if (productName.Quantity <= (productName.MaxQuantity * (0.5)))
  73.                 {
  74.                     productName.Status = InventoryState.Stocking;
  75.                 }
  76.  
  77.                 else if (productName.Quantity == 0)
  78.                 {
  79.                     productName.Status = InventoryState.Empty;
  80.                 }
  81.  
  82.                 else
  83.                 {
  84.                     productName.Status = InventoryState.Selling;
  85.                 }
  86.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement