示例#1
0
        /// <summary>
        /// Used to enter a rebate
        /// </summary>
        static public void EnterRebate()
        {
            DateTime date;

            while (true)
            {
                Console.Write("Enter the date(mm/dd/yyyy): ");
                try
                {
                    string[] tempDate = Console.ReadLine().Split('/');
                    date = new DateTime(Convert.ToInt32(tempDate[2]), Convert.ToInt32(tempDate[0]), Convert.ToInt32(tempDate[1]));
                    break;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid Entry");
                }
            }

            Console.Write("Enter the transaction ID: ");
            int ID = Convert.ToInt32(Console.ReadLine());

            while (!AllTransactions.CheckID(ID, AllTransactions.Transactions))
            {
                Console.Write("That ID does not exist, try again: ");
                ID = Convert.ToInt32(Console.ReadLine());
            }

            string      name = AllTransactions.Transactions[ID].Name;
            Transaction rebateTransaction = AllTransactions.Transactions[ID];

            Console.Write("Enter customer's address: ");
            string address = Console.ReadLine();

            Console.Write("Enter customer's email: ");
            string email = Console.ReadLine();

            decimal discount;

            Console.Write("Enter the discount precent: ");
            discount = Convert.ToDecimal(Console.ReadLine());
            discount = discount / 100;
            Rebate rebate = new Rebate(name, address, email, date, discount);

            AllRebates.AddRebate(rebateTransaction, rebate);
            Console.WriteLine();
        }
示例#2
0
        /// <summary>
        /// Main Program starts here
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            /* TEST CASES */
            //AllTransactions.test();
            //AllRebates.test();

            while (true) //loop until close
            {
                Console.Write(
                    "Would you like to create a " +
                    "sales transaction (T), " +
                    "return item(s) (I), " +
                    "enter rebate (R), " +
                    "generate rebate check (C), " +
                    "print receipt (P), " +
                    "or close application (X)?" +
                    "\nEnter T, I, R, C, P, or X: ");
                string response = Console.ReadLine().ToUpper();

                bool valid = false;
                while (!valid)           //loop until valid response
                {
                    if (response == "T") //sales transaction
                    {
                        Console.WriteLine();
                        CreateTransaction();
                        valid = true;
                    }
                    else if (response == "I") //return item
                    {
                        Console.WriteLine();
                        ReturnItem();
                        valid = true;
                    }
                    else if (response == "R") //create rebate
                    {
                        Console.WriteLine();
                        EnterRebate();
                        valid = true;
                    }
                    else if (response == "C") //generate rebate checks
                    {
                        Console.WriteLine();
                        DateTime date;
                        while (true)
                        {
                            Console.Write("Enter the date(mm/dd/yyyy): ");
                            try
                            {
                                string[] tempDate = Console.ReadLine().Split('/');
                                date = new DateTime(Convert.ToInt32(tempDate[2]), Convert.ToInt32(tempDate[0]), Convert.ToInt32(tempDate[1]));
                                break;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Invalid Entry");
                            }
                        }

                        DateTime endJuly = new DateTime(2018, 07, 30);

                        if (DateTime.Compare(date, endJuly) >= 0)
                        {
                            AllRebates.GenerateChecks();
                        }
                        else
                        {
                            Console.WriteLine("Rebate refunds checks are not generated till the end of July!");
                        }

                        valid = true;
                        Console.WriteLine();
                    }
                    else if (response == "P")
                    {
                        Console.WriteLine();
                        Console.Write("Enter the transaction ID: ");
                        int ID = Convert.ToInt32(Console.ReadLine());
                        while (!AllTransactions.CheckID(ID, AllTransactions.Transactions))
                        {
                            Console.Write("That ID does not exist, try again: ");
                            ID = Convert.ToInt32(Console.ReadLine());
                        }
                        Console.WriteLine(AllTransactions.TransactionString(ID));
                        valid = true;
                    }
                    else if (response == "X")
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.Write("Invalid entry, Enter T, I, R, C, P or X: ");
                        response = Console.ReadLine().ToUpper();
                    }
                }
            }
        }