Example #1
0
        /***********************************
        *  Caculates and returns a new total
        *  value with discounts applied to new
        *  total value, if any apply.
        ***********************************/
        static float caculateCost(PreferredCustomer customer, float total)
        {
            float newTotal = total; // newTotal varible used to caculate discount of total value.

            if (customer.setDiscount(newTotal))
            {
                return(total = newTotal - ((newTotal / 100) * (float)customer.getDiscountLevel()));
            }

            return(total);
        }
        /**************************
        *  Overload of above method,
        *  only returns a single
        *  customer from database.
        **************************/
        public static PreferredCustomer Loader(string find)
        {
            PreferredCustomer p = new PreferredCustomer();

            string        source       = "Data Source=COMPUTER\\ACEMAN;Integrated Security=True";
            string        getAcustomer = "select * from some4 where CustomerId = " + find;
            SqlConnection connect      = new SqlConnection(source);

            try
            {
                connect.Open();
                SqlCommand    cmd    = new SqlCommand(getAcustomer, connect);
                SqlDataReader reader = cmd.ExecuteReader();

                reader.Read();

                p.CustomerNumber = (string)reader[0];
                p.setFirstName((string)reader[1]);
                p.setLastName((string)reader[2]);
                p.setAddress((string)reader[3]);
                p.setCity((string)reader[4]);
                p.setState((string)reader[5]);
                p.setZip((string)reader[6]);
                p.setPhoneNumber((string)reader[7]);
            }
            catch (SqlException sql)
            {
                Console.WriteLine("An error has ocurred with the database...");
                Console.WriteLine("The error that ocurred is..." + sql.Message);
            }
            catch (InvalidOperationException notValid)
            {
                Console.WriteLine("An error has ocurred with the database...");
                Console.WriteLine("The error that ocurred is..." + notValid.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("An unknown error has ocurred...");
                Console.WriteLine("The error that ocurred was.." + ex.Message);
            }
            finally
            {
                connect.Close();
            }

            return(p);
        }
Example #3
0
        static void Main(string[] args)
        {
            float  total         = 0; // Holds total cost of ordered items.
            float  originalTotal = 0; //  Holds original total cost of ordered items.
            string choice;            //   Holds user choice string.
            string test;              //    Holds test string value.


            PreferredCustomer customer     = new PreferredCustomer(); // PreferredCustomer object.(derives from PersonData)
            ItemSet           queriedItems = new ItemSet();           //  Pulls a List of item data from the database.
            List <Item>       itemList     = new List <Item>();       //   Holds pulled item List data.
            List <Item>       tally        = new List <Item>();       //    Keeps a tally of all ordered items.
            Item aItem = new Item();

            Console.WriteLine("THIS PROGRAM WILL ALLOW THE USER TO ORDER ITEMS FROM A LIST " + // Program description banner.
                              "AND RETURN A TOTAL  VALUE PLUS ANY DISCOUNTS ASSOCIATED WITH " +
                              "THAT VALUE.\n");
            Console.WriteLine("PLEASE ENTER A CUSTOMER ID BETWEEN 1001 AND 1014.\n");

            itemList = queriedItems.getItems();

            Console.Write("Please enter a customer Number: ");
            string cusNo = Console.ReadLine();

            customer = LoadPreferredCustomer.Loader(cusNo);

            do // Do-while loop controls main flow of the driver program.
            {
                Console.WriteLine();
                Console.WriteLine("This is the order guide for " + customer.getFirstName()
                                  + " " + customer.getLastName());
                Console.WriteLine("Please enter the cooresponding number for each item to add it to your " +
                                  "currently existing order.");
                Console.WriteLine();
                do // Controls the orderGuide method call.
                {
                    tally.Add(orderGuide(customer.getFirstName(), customer.getLastName(), itemList));
                    Console.Write("\nDoes " + customer.getFirstName() + " wish to order another item? Yes or No(To finish ordering items please spell NO completely): ");
                    choice = Console.ReadLine();

                    test = null;
                    foreach (var letter in choice)
                    {
                        test += char.ToUpper(letter);
                    }
                } while (!(test.Equals("NO")));

                Console.WriteLine("\nThe Items " + customer.getFirstName() + " selected were:\n");
                foreach (var item in tally) // Writes out a list of all ordered items.
                {
                    Console.WriteLine(item.ItemType + " Cost: " + item.ItemCost);
                    total        += item.ItemCost;
                    originalTotal = total;

                    total = caculateCost(customer, total);
                }
                Console.WriteLine();
                Console.WriteLine("The total cost of all " + customer.getFirstName() + "'s items is {0:0.00}", total);

                if (originalTotal >= 1000.00) // If value greater than a 1000.00 prints original total before deduction to screen.
                {
                    Console.WriteLine(customer.getFirstName() + "'s original total was {0:0.00}", originalTotal);
                }

                Console.WriteLine(customer.getFirstName() + " saved a total of {0:0.00} dollars", originalTotal - total);

                tally.Clear(); // Clears tally Item List collection of all elements.
                total = 0;     //  Assigns 0 to total float variable for new amount accumulation.
                Console.Write("\nDoes " + customer.getFirstName() + " wish to start a new order? Yes or No(To end program  please spell NO completely): ");
                choice = Console.ReadLine();

                test = null;
                foreach (var letter in choice)
                {
                    test += char.ToUpper(letter);
                }
            } while (!(test.Equals("NO"))); //If test value is false re-iterates entire main driver.

            Console.WriteLine("\nPress enter to close program..");
            Console.ReadLine();
        }