public List <CateringItem> ReadItems()
        {
            List <CateringItem> items = new List <CateringItem>();

            try
            {
                using (StreamReader sr = new StreamReader(fullPath))
                {
                    while (!sr.EndOfStream)
                    {
                        string   unsplit = sr.ReadLine();
                        string[] split   = unsplit.Split('|');

                        CateringItem tempObject = new CateringItem();
                        tempObject.Code  = split[0];
                        tempObject.Name  = split[1];
                        tempObject.Price = decimal.Parse(split[2]);
                        tempObject.Type  = split[3];

                        items.Add(tempObject);
                    }
                }
            }
            catch
            {
                items = new List <CateringItem>();
            }

            return(items);
        }
        public bool MakePurchase(string product, string quanity)
        {
            bool result = false;
            int  count  = int.Parse(quanity);

            foreach (CateringItem item in inventory)
            {
                if (item.ProductCode == product)
                {
                    Balance      -= item.Price * count;
                    item.Quanity -= count;

                    FileAccess fa = new FileAccess();
                    fa.WriteLog("Purchase " + item.ProductName, Balance + (item.Price * count), Balance);

                    CateringItem newItem = new CateringItem(item.ProductCode, item.ProductName,
                                                            item.Price, item.ProductType, count);
                    purchases.Add(newItem);

                    result = true;
                    break;
                }
            }
            return(result);
        }
Exemple #3
0
        public List <CateringItem> GetAndReadProductFile()
        {
            List <CateringItem> singleCateringItem = new List <CateringItem>();

            string fullPath = Path.Combine(filePath, filename);

            try
            {
                using (StreamReader sr = new StreamReader(fullPath))
                {
                    while (!sr.EndOfStream)
                    {
                        string   unSplit = sr.ReadLine();
                        string[] split   = unSplit.Split('|');

                        CateringItem temp = new CateringItem();
                        temp.Amount     = 50;
                        temp.Code       = split[0];
                        temp.Name       = split[1];
                        temp.Price      = double.Parse(split[2]);
                        temp.Type       = split[3];
                        temp.TotalPrice = "";

                        singleCateringItem.Add(temp);
                    }
                }
            }
            catch
            {
                singleCateringItem = new List <CateringItem>();
            }

            return(singleCateringItem);
        }
 /// <summary>
 /// Write to Log file. This specifically deals with purchased items.
 /// </summary>
 /// <param name="cateringItem"></param>
 /// <param name="accounting"></param>
 /// <param name="purchasedQuantity"></param>
 public void PurchasesLog(CateringItem cateringItem, Accounting accounting, int purchasedQuantity)
 {
     using (StreamWriter writer = new StreamWriter(Path.Combine(filePath, "Log.txt"), true))
     {
         writer.WriteLine($"{DateTime.Now} {purchasedQuantity} {cateringItem.Product} {cateringItem.ProductCode} {cateringItem.Price * purchasedQuantity} {accounting.DisplayMoney()}");
     }
 }
        public List <CateringItem> GetInventory()
        {
            List <CateringItem> items = new List <CateringItem>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(sql_GetInventory, conn);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        string       code  = Convert.ToString(reader["code"]);
                        string       name  = Convert.ToString(reader["name"]);
                        decimal      price = Convert.ToDecimal(reader["price"]);
                        string       type  = Convert.ToString(reader["type"]);
                        CateringItem item  = new CateringItem(code, name, price, type, 50);
                        items.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                items = new List <CateringItem>();
            }
            return(items);
        }
        public static bool LoadInventory()
        {
            Dictionary <string, CateringItem> inventory = new Dictionary <string, CateringItem>();

            try
            {
                using (StreamReader sr = new StreamReader(InventoryFile))
                {
                    while (!sr.EndOfStream)
                    {
                        CateringItem cateringItem = BuildItem(sr.ReadLine());
                        if (cateringItem != null)
                        {
                            inventory.Add(cateringItem.PID, cateringItem);
                        }
                    }
                }
                Catering.Inventory = inventory;
            }
            catch (IOException)
            {
                return(false);
            }
            return(true);
        }
Exemple #7
0
        public List <CateringItem> GetInventory()
        {
            string inventoryFullPath = Path.Combine(filePath, inventoryFile);

            List <CateringItem> inventory = new List <CateringItem>();

            try
            {
                using (StreamReader sr = new StreamReader(inventoryFullPath))
                {
                    while (!sr.EndOfStream)
                    {
                        string       line  = sr.ReadLine();
                        string[]     split = line.Split('|');
                        CateringItem item  = new CateringItem(split[0],
                                                              split[1],
                                                              decimal.Parse(split[2]),
                                                              split[3],
                                                              50);
                        inventory.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                inventory = new List <CateringItem>();
            }

            return(inventory);
        }
Exemple #8
0
        public List <CateringItem> SetUpCateringItems()
        {
            string fullPath = Path.Combine(filePath, fileName);

            List <CateringItem> cateringItems = new List <CateringItem>();

            try
            {
                using (StreamReader sr = new StreamReader(fullPath))
                {
                    while (!sr.EndOfStream)
                    {
                        string   unsplit = sr.ReadLine();
                        string[] split   = unsplit.Split('|');

                        CateringItem temp = new CateringItem(split[1], decimal.Parse(split[2]), split[0]);
                        cateringItems.Add(temp);
                    }
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("No inventory file present, Contact Technical Support.");
                Console.WriteLine("Press enter to close.");
                Console.ReadLine();
            }
            return(cateringItems);
        }
Exemple #9
0
        /// <summary>
        /// Select product method. Contains catches for not in inventory, sold out, insufficient stock, and insufficent funds.
        /// </summary>
        /// <param name="userInput"></param>
        private void SelectProduct(string userInput)
        {
            if (catering.SearchProductCode(userInput) == null)
            {
                Console.WriteLine("Sorry, the product you requested is not in our inventory. Please try again.");
            }
            else if (catering.ProductIsInStock(userInput) == null)
            {
                Console.WriteLine("Sorry, the product you requested is sold out. Please try again.");
            }
            else if (catering.ProductIsInStock(userInput) != null)
            {
                Console.WriteLine("How many do you want to purchase?");
                int userQuantityWanted = int.Parse(Console.ReadLine());

                if (catering.ProductIsInStock(userInput).QuantityInStock < userQuantityWanted)
                {
                    Console.WriteLine("Sorry, we have insufficient stock of that item.");
                }
                else if (catering.ProductIsInStock(userInput).Price *userQuantityWanted > accounting.DisplayMoney())
                {
                    Console.WriteLine("We're sorry, but you have insufficient funds to complete this transaction.");
                }
                else
                {
                    CateringItem itemPurchased = catering.SearchProductCode(userInput);
                    accounting.SubtractPurchase(catering, itemPurchased, userQuantityWanted);
                    files.PurchasesLog(itemPurchased, accounting, userQuantityWanted);
                }
            }
        }
 public void AuditLog(int intQuantityRequested, decimal balance, CateringItem itemObj) // for purchases
 {
     using (StreamWriter sw = new StreamWriter(@"c:\Catering\Log.txt", true))
     {
         sw.WriteLine(DateTime.Now + "  " + intQuantityRequested + "  " +
                      itemObj.Name + "  " + itemObj.Code + "  " + "$" +
                      (intQuantityRequested * itemObj.Price) + "  " + "$" + Balance);
     }
 }
 /// <summary>
 /// This method subtract money from the accountBalance. This also adds to the receipt printout. Since we have a built-in summation of products, this also prevents inaccurate repeats.
 /// </summary>
 /// <param name="catering"></param>
 /// <param name="cateringItem"></param>
 /// <param name="userQuantity"></param>
 public void SubtractPurchase(Catering catering, CateringItem cateringItem, int userQuantity)
 {
     accountBalance -= userQuantity * cateringItem.Price;
     if (cateringItem.QuantityInStock - userQuantity >= 0)
     {
         cateringItem.QuantityInStock -= userQuantity;
         if (!catering.AllPurchasedItems.Contains(cateringItem))
         {
             catering.PurchasedAdd(cateringItem);
         }
     }
 }
Exemple #12
0
        //this does the actual purchase of items
        public CateringItem purchaseItems(string itemCode, int qtyToPurchase)
        {
            //gets our item by the code given
            CateringItem item = this.items.Find(x => x.Code.Contains(itemCode));
            //final price
            decimal total = item.Price * qtyToPurchase;

            //updates quantity
            item.UpdateQuantity(qtyToPurchase);
            //spends the money and updates balance
            SpendMoney(total);
            return(item);
        }
        /// <summary>
        /// Checks if a product is in stock. If the catering item is in AllCateringItems and has a stock greater than 0, returns the cateringItem, otherwise null.
        /// </summary>
        /// <param name="productCode"></param>
        /// <returns></returns>
        public CateringItem ProductIsInStock(string productCode)
        {
            CateringItem cateringItem = SearchProductCode(productCode);

            if (cateringItem != null && cateringItem.QuantityInStock > 0)
            {
                return(cateringItem);
            }
            else
            {
                return(null);
            }
        }
Exemple #14
0
        // checks if the code user inputs is valid item
        public bool isCodeValid(string itemCode)
        {
            //gets our item by the code given if there, if invalid returns null
            CateringItem item = this.items.Find(x => x.Code.Contains(itemCode));

            if (item == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #15
0
        // checks that there is enough of an item in stock
        public bool isQuantityEnough(string itemCode, int qtyWanted)
        {
            //gets our item by the code given
            CateringItem item = this.items.Find(x => x.Code.Contains(itemCode));

            if (item.Quantity >= qtyWanted && qtyWanted > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #16
0
        // checks if an item is sold out
        public bool IsSoldOut(string itemCode)
        {
            //gets our item by the code given
            CateringItem item = this.items.Find(x => x.Code.Contains(itemCode));

            if (item.Quantity == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #17
0
        private string logPath  = @"C:\Catering\log.txt";            // File path for log file

        public void LoadCateringItems(Catering catering)             // Reads from csv file into cateringitems list
        {
            using (StreamReader reader = new StreamReader(filePath))
            {
                while (!reader.EndOfStream)
                {
                    string   line        = reader.ReadLine();
                    string[] type        = line.Split("|"); // Splits each line from csv into an array on "|"
                    string   priceString = type[2];
                    decimal  price       = decimal.Parse(priceString);

                    CateringItem Item = new CateringItem(type[1], type[3], type[0], price); // Uses array indexes to grab specific values
                    catering.Add(Item);
                }
            }
        }
Exemple #18
0
        // checks to see if we have enough money to purchase a given quantity of an item
        public bool EnoughMoney(int qtyToPurchase, string itemCode)
        {
            //gets our item by the code given
            CateringItem item = this.items.Find(x => x.Code.Contains(itemCode));
            //gets the final price
            decimal total = item.Price * qtyToPurchase;

            if (total > customerMoney)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        private static CateringItem BuildItem(string rawData)
        {
            string[]     strArray     = rawData.Split('|');
            CateringItem cateringItem = null;

            try
            {
                cateringItem = new CateringItem(strArray[0], strArray[1], decimal.Parse(strArray[2]), strArray[3]);
            }
            catch (FormatException ex)
            {
                // wasn't a cateringItem
            }


            return(cateringItem);
        }
        private string filePath = @"C:\Catering"; // You will likely need to create this folder on your machine

        /// <summary>
        /// Read from the Catering System file. File is a .csv with a pipe delimiter.
        /// </summary>
        /// <param name="catering"></param>
        public void ReadingCateringInventory(Catering catering)
        {
            using (StreamReader reader = new StreamReader(Path.Combine(filePath, "cateringsystem.csv")))
            {
                while (!reader.EndOfStream)
                {
                    // Reads line from file.
                    string line = reader.ReadLine();

                    // Split line into an array via the pipe symbol.
                    string[] parts = line.Split("|");

                    // Declare parts.
                    string  productCode = parts[0];
                    string  product     = parts[1];
                    decimal price       = decimal.Parse(parts[2]);
                    string  productType = parts[3];

                    // We want the internal symbol for productType to be replaced with something a human can read.
                    switch (productType)
                    {
                    case "B":
                        productType = "Beverage";
                        break;

                    case "E":
                        productType = "Entree";
                        break;

                    case "D":
                        productType = "Dessert";
                        break;

                    case "A":
                        productType = "Appetizer";
                        break;
                    }

                    // Create new instance of CateringItem.
                    CateringItem cateringItem = new CateringItem(productCode, product, price, productType);

                    // Add cateringItem to list within catering.
                    catering.Add(cateringItem);
                }
            }
        }
Exemple #21
0
        private double Menu2Option2(Catering catering, double accountBalanceSum)
        {
            Console.WriteLine("Enter the item ID you would like to purchase");
            string desiredID = Console.ReadLine();

            if (catering.GetCateringItem(desiredID) == null)
            {
                Console.WriteLine();
                return(accountBalanceSum);
            }
            CateringItem singleItem = catering.GetCateringItem(desiredID);

            Console.WriteLine("Enter the number of items you would like to purchase");
            int desiredAmount = int.Parse(Console.ReadLine());

            Console.WriteLine();



            if (singleItem.Amount == 0)
            {
                Console.WriteLine();
                Console.WriteLine("Product is Sold out");
                Console.WriteLine();
                return(accountBalanceSum);
            }
            else if (desiredAmount > singleItem.Amount)
            {
                Console.WriteLine();
                Console.WriteLine("Insufficient Stock");
                Console.WriteLine();
                return(accountBalanceSum);
            }
            else if (accountBalanceSum < singleItem.Price * desiredAmount)
            {
                Console.WriteLine();
                Console.WriteLine("Insufficient Funds");
                Console.WriteLine();
                return(accountBalanceSum);
            }

            newFileAccssed.WriteAuditLog2(desiredAmount, desiredID, accountBalanceSum.ToString());

            return(catering.RemoveMoney(accountBalanceSum, singleItem, desiredAmount, desiredID));
        }
        private static CateringItem ReadSalesReport(string input)
        {
            CateringItem cateringItem = null;

            try
            {
                string[] lineArray = input.Split("|");
                cateringItem = new CateringItem(lineArray[0], int.Parse(lineArray[1]));
            }
            catch (FormatException ex)
            {
                // not a CateringItem
            }
            catch (IndexOutOfRangeException ex)
            {
                // not a CateringItem
            }

            return(cateringItem);
        }
Exemple #23
0
        public void LoadCateringItems(Catering groupOfCateringItems)
        {
            using (StreamReader reader = new StreamReader(filePath))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();

                    string[] parts = line.Split("|");

                    string  productCode = parts[0];
                    string  name        = parts[1];
                    decimal price       = decimal.Parse(parts[2]);
                    string  type        = parts[3];


                    CateringItem item = new CateringItem(productCode, name, price, type);
                    groupOfCateringItems.AddNew(item);
                }
            }
        }
Exemple #24
0
        // This class should contain any and all details of access to files

        public void ConvertInfoToList()
        {
            string sourceFile = "C:\\Users\\carters\\Team Exercises\\team1-c-sharp-week4-pair-exercises\\19_Mini-Capstone\\cateringsystem.csv";

            if (File.Exists(sourceFile))
            {
                using (StreamReader sr = new StreamReader(sourceFile))
                {
                    while (!sr.EndOfStream)
                    {
                        string       line         = sr.ReadLine();
                        string[]     itemArray    = line.Split("|");
                        CateringItem cateringItem = new CateringItem();
                        cateringItem.ItemCode  = itemArray[0];
                        cateringItem.ItemName  = itemArray[1];
                        cateringItem.ItemPrice = decimal.Parse(itemArray[2]);
                        cateringItem.ItemClass = itemArray[3];
                        menu.Add(cateringItem);
                    }
                }
            }
        }
        // This class should contain any and all details of access to files


        public List <CateringItem> GetCateringItems()
        {
            List <CateringItem> items = new List <CateringItem>();

            using (StreamReader sr = new StreamReader(filePath))
            {
                while (!sr.EndOfStream)
                {
                    string   line   = sr.ReadLine();
                    string[] values = line.Split('|');

                    CateringItem temp = new CateringItem();
                    temp.Code  = values[0];
                    temp.Name  = values[1];
                    temp.Price = decimal.Parse(values[2]);


                    if (values[3] == "B")
                    {
                        temp.Type = "Beverage";
                    }
                    else if (values[3] == "E")
                    {
                        temp.Type = "Entree";
                    }
                    else if (values[3] == "D")
                    {
                        temp.Type = "Dessert";
                    }
                    else if (values[3] == "A")
                    {
                        temp.Type = "Appetizer";
                    }
                    items.Add(temp);
                }
            }
            return(items);
        }
Exemple #26
0
        public void FileReader(Catering catering)
        {
            using (StreamReader reader = new StreamReader(filePathRead))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();

                    string[] parts = line.Split("|");

                    string  code  = parts[0];
                    string  name  = parts[1];
                    decimal price = decimal.Parse(parts[2]);
                    string  type  = parts[3];

                    // make a catering item out of the strings we pulled out from file
                    CateringItem item = new CateringItem(code, name, price, type);

                    //add the item to our list of catering items
                    catering.addToList(item);
                }
            }
        }
Exemple #27
0
        public string SelectProduct(string productCode, int amount) // Takes in product code from user input, checks it against codes in catering item list, changes the category, adds them to purchased items list
        {
            foreach (CateringItem item in items)
            {
                if (item.Id == productCode && item.Quantity == 0)
                {
                    return("Item out of stock.");
                }

                if (item.Id == productCode && item.Quantity - amount < 0)
                {
                    return("Not enough stock to complete order.");
                }

                if (item.Id == productCode && item.Quantity > 0)
                {
                    item.Category = CategoryConvert(item.Category);

                    item.Quantity -= amount;
                    CateringItem purchasedItem = new CateringItem(item.Name, item.Category, item.Id, item.Price); // Creates new object of catering item to pass into purchaseditems list
                    purchasedItem.Quantity = amount;

                    purchasedItems.Add(purchasedItem);                    // Adds item to purchased items list
                    decimal priceTimesAmount = purchasedItem.Quantity * purchasedItem.Price;
                    if (PurchasesOverFiveThousandCheck(priceTimesAmount)) // Calls purchased over 5k to check if shopping cart has exceed max balance
                    {
                        return("Item added to cart. Complete transaction to purchase.");
                    }
                    else
                    {
                        purchasedItems.Remove(purchasedItem);
                        return("Items to purchase exceeds $5000 maximum balance. Item not purchased.");
                    }
                }
            }
            return("");
        }
        public double RemoveMoney(double accountBalanceSum, CateringItem singleItem, int desiredAmount, string desiredID)
        {
            CateringItem purchasedItem = new CateringItem();

            purchasedItem.Amount     = desiredAmount;
            purchasedItem.Name       = singleItem.Name;
            purchasedItem.Price      = singleItem.Price;
            purchasedItem.Type       = singleItem.Type;
            purchasedItem.Code       = singleItem.Code;
            purchasedItem.TotalPrice = (desiredAmount * singleItem.Price).ToString();


            if (desiredAmount <= singleItem.Amount && singleItem.Price * desiredAmount <= accountBalanceSum)
            {
                itemsPurchased.Add(purchasedItem);

                singleItem.Amount -= desiredAmount;
                accountBalanceSum -= (singleItem.Price * desiredAmount);
                return(accountBalanceSum);
            }


            return(accountBalanceSum);
        }
Exemple #29
0
 //adds an item to our items list
 public void addToList(CateringItem item)
 {
     this.items.Add(item);
 }
 /// <summary>
 /// As above, but for purchased items.
 /// </summary>
 /// <param name="cateringItem"></param>
 public void PurchasedAdd(CateringItem cateringItem)
 {
     this.purchasedItems.Add(cateringItem);
 }