コード例 #1
0
 public UserInterface()
 {
     this.catering = new Catering();
     this.files    = new FileAccess();
     this.money    = new Money();
     //this.cateringItem = new CateringItem();
 }
コード例 #2
0
        private void DisplayCateringItems(Catering catering)
        {
            CateringItem[] tempCateringArray = catering.cateringList;

            for (int i = 0; i < tempCateringArray.Length; i++)
            {
                Console.WriteLine(tempCateringArray[i].ToString());
            }
        }
コード例 #3
0
        public string GiveChange(Catering catering)
        {
            int     nickel       = 0;
            int     dime         = 0;
            int     quarter      = 0;
            int     oneDollar    = 0;
            int     fiveDollar   = 0;
            int     tenDollar    = 0;
            int     twentyDollar = 0;
            decimal temp         = catering.AccountBalance;



            while (catering.AccountBalance > 0)
            {
                if (catering.AccountBalance >= 20)
                {
                    twentyDollar++;
                    catering.AccountBalance -= 20;
                }
                else if (catering.AccountBalance >= 10)
                {
                    tenDollar++;
                    catering.AccountBalance -= 10;
                }
                else if (catering.AccountBalance >= 5)
                {
                    fiveDollar++;
                    catering.AccountBalance -= 5;
                }
                else if (catering.AccountBalance >= 1)
                {
                    oneDollar++;
                    catering.AccountBalance -= 1;
                }
                else if (catering.AccountBalance >= .25M)
                {
                    quarter++;
                    catering.AccountBalance -= .25M;
                }
                else if (catering.AccountBalance >= .10M)
                {
                    dime++;
                    catering.AccountBalance -= .10M;
                }
                else if (catering.AccountBalance >= .05M)
                {
                    nickel++;
                    catering.AccountBalance -= .05M;
                }
            }
            fileAccess.Audit($"{DateTime.Now} GIVE CHANGE: ${temp} ${catering.AccountBalance}");
            return($"You were given {twentyDollar} 20's, {tenDollar} 10's, {fiveDollar} 5's, {oneDollar} 1's, {quarter} quarters, {dime} dimes, and {nickel} nickels. Thanks!");
        }
 /// <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);
         }
     }
 }
コード例 #5
0
        public void WriteAuditLog2(double desiredAmount, string desiredID, string accountBalanceSum)
        {
            try
            {
                Catering newCatering = new Catering();
                string   outputPath  = Path.Combine(filePath, output);

                File.AppendAllText(outputPath, DateTime.Now + " " + desiredAmount.ToString() + " " + newCatering.GetCateringItem(desiredID).Name + " " + desiredID + " $" + (desiredAmount * newCatering.GetCateringItem(desiredID).Price) + " $" + accountBalanceSum + Environment.NewLine);
            }
            catch
            {
            }
        }
コード例 #6
0
        public void WriteAddMoney(int amount, Catering catering)

        {
            string sourceFile = "C:\\Users\\carters\\Team Exercises\\team1-c-sharp-week4-pair-exercises\\19_Mini-Capstone\\Log.txt";

            if (File.Exists(sourceFile))
            {
                using (StreamWriter sw = new StreamWriter(sourceFile))
                {
                    sw.Write(DateTime.Now + " ");
                    sw.Write("ADD MONEY: ");
                    sw.Write(amount + " ");
                    sw.WriteLine(catering.Balance + amount);
                }
            }
        }
コード例 #7
0
ファイル: FileAccess.cs プロジェクト: breydongates/capstone1
        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);
                }
            }
        }
        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);
                }
            }
        }
コード例 #9
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));
        }
コード例 #10
0
        public void RunInterface()
        {
            Console.WriteLine("Use database? (no/YES)");
            string userSelection = Console.ReadLine();

            if (userSelection == "" ||
                userSelection.ToUpper().StartsWith('Y'))
            {
                da       = new DatabaseAccess();
                catering = new Catering(da);
            }
            else
            {
                da       = new FileAccess();
                catering = new Catering(da);
            }

            bool done = false;

            while (!done)
            {
                string result = DisplayMainMenu();

                switch (result.ToLower())
                {
                case "1":
                    DisplayInventory();
                    break;

                case "2":
                    PurchaseMenu();
                    break;

                case "3":
                    done = true;
                    continue;

                default:
                    Console.WriteLine("Please make a valid selection.");
                    break;
                }
            }
            return;
        }
        private void DisplayItems(Catering items)
        {
            List <CateringItem> displayList = new List <CateringItem>();

            CateringItem[] tempItem = items.ItemList; // to review later/ask Matt

            for (int i = 0; i < tempItem.Length; i++)
            {
                string temp = tempItem[i].ToString();

                string tempSub2 = temp.Substring(0, temp.Length - 2);
                string tempSub  = temp.Substring(temp.Length - 2, 2);
                if (tempSub == " 0")
                {
                    tempSub = "SOLD OUT";
                }
                Console.WriteLine(tempSub2 + tempSub);
            }
        }
コード例 #12
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);
                }
            }
        }
コード例 #13
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);
                }
            }
        }
コード例 #14
0
        public void WriteReceipt(string desiredItem, int desiredQty, Catering catering)
        {
            foreach (CateringItem item in menu)
            {
                if (item.ItemCode == desiredItem)
                {
                    decimal totalCost = item.ItemPrice * desiredQty;

                    string sourceFile = "C:\\Users\\carters\\Team Exercises\\team1-c-sharp-week4-pair-exercises\\19_Mini-Capstone\\Log.txt";
                    if (File.Exists(sourceFile))
                    {
                        using (StreamWriter sw = new StreamWriter(sourceFile))
                        {
                            sw.Write(DateTime.Now + " ");
                            sw.Write(item.ItemQty + " ");
                            sw.Write(item.ItemName + " ");
                            sw.Write(item.ItemCode + " ");
                            sw.Write(totalCost + " ");
                            sw.WriteLine(catering.Balance - totalCost);
                        }
                    }
                }
            }
        }
コード例 #15
0
        public void OrderMenu()
        {
            Console.WriteLine("(1) Add Money");
            Console.WriteLine("(2) Select Products");
            Console.WriteLine("(3) Complete Transaction");
            Console.WriteLine($"Current Account Balance: ${CustomerAccount.Balance}");

            int input = 0;

            try
            {
                input = int.Parse(Console.ReadLine());
            } catch (FormatException ex)
            {
                Console.WriteLine("Please enter in a valid integer for selection.");
                return;
            }


            switch (input)
            {
            case 1:
                Console.WriteLine("How much would you like to add?");
                decimal amountToAdd;
                try
                {
                    amountToAdd = decimal.Parse(Console.ReadLine());
                } catch (FormatException ex)
                {
                    Console.WriteLine("Invalid input for amount. Please enter a valid number.");
                    return;
                }

                if (!Transaction.AddMoney(amountToAdd))
                {
                    Console.WriteLine("You are unable to have more than $5000.00 in your account.");
                }
                ;
                Console.WriteLine($"New Account Balance: {CustomerAccount.Balance}");

                break;

            case 2:
                Console.WriteLine("Enter the PID of the Item you would like to order:");
                string PID = Console.ReadLine();
                Console.WriteLine("How many would you like to order:");
                int amountOrdered;
                try
                {
                    amountOrdered = int.Parse(Console.ReadLine());
                }
                catch (FormatException ex)
                {
                    Console.WriteLine("Invalid input for amount. Please enter a valid number.");
                    return;
                }

                Console.WriteLine(Catering.AddToCart(PID, amountOrdered));
                Console.WriteLine("Press enter to continue.");
                Console.ReadLine();
                break;

            case 3:
                Console.WriteLine(Transaction.MakeChange());
                decimal totalAmount = 0.00M;

                foreach (KeyValuePair <string, CateringItem> kvp in Catering.Cart)
                {
                    decimal totalItemPrice = kvp.Value.AmountSold * kvp.Value.Price;
                    Console.WriteLine(String.Format("{0, -5} | {1, -15} | {2, -35} | {3, -10} | {4, -5 }",
                                                    kvp.Value.PID, kvp.Value.DisplayName, kvp.Value.Name, kvp.Value.Price, totalItemPrice));
                    totalAmount += totalItemPrice;
                }
                Console.WriteLine("\n $Total: " + totalAmount);
                Console.WriteLine("---------------------------------------------------------");
                break;

            default:
                Console.WriteLine("Please enter a valid response.");
                break;
            }
        }
コード例 #16
0
 public UserInterface()
 {
     this.catering   = new Catering();
     this.files      = new FileAccess();
     this.accounting = new Accounting();
 }
コード例 #17
0
 public UserInterface()
 {
     fa       = new FileAccess();
     catering = new Catering(fa);
 }