Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // First, establish the customer data
            Address addr;

            addr.Street = "121 Maple St.";
            addr.City   = "Springfield";
            addr.State  = State.IL;
            addr.Zip    = 33333;

            PreferredCustomer pc;

            pc = new PreferredCustomer("Homer", addr, 0.20);

            // Open a file to hold the data
            Stream s = File.OpenWrite("customer.soap");

            // Create the Soap formatter and serialize to file
            IFormatter formatter = new SoapFormatter();

            formatter.Serialize(s, pc);

            s.Close();

            DeserializeCustomer();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            PreferredCustomer myoldcustomer;
            Customer          mycustomer;

            PreferredCustomer mypreferredcustomer;
            Customer          mysecondcustomer;

            PreferredCustomer mynewcustomer;
            Customer          mythirdcustomer;

            PreferredCustomer myspecialcustomer;
            Customer          myfourthcustomer;

            myoldcustomer = new PreferredCustomer();
            mycustomer    = myoldcustomer;

            mypreferredcustomer = new PreferredCustomer();
            mysecondcustomer    = mypreferredcustomer;

            mynewcustomer   = new PreferredCustomer();
            mythirdcustomer = mynewcustomer;

            myspecialcustomer = new PreferredCustomer();
            myfourthcustomer  = myspecialcustomer;

            myoldcustomer.Purchase = "$500";
            myoldcustomer.Discount = "5 percent discount";

            mypreferredcustomer.Purchase = "$1000";
            mypreferredcustomer.Discount = "6 percent discount";

            mynewcustomer.Purchase = "$1500";
            mynewcustomer.Discount = "7 percent discount";

            myspecialcustomer.Purchase = "$2000";
            myspecialcustomer.Discount = "10 percent discount";

            Console.WriteLine($"When a preferred customer spends {myoldcustomer.Purchase}, " +
                              $"he or she gets a {myoldcustomer.Discount} on all future purchases.");

            Console.WriteLine($"When a preferred customer spends {mypreferredcustomer.Purchase}, " +
                              $"he or she gets a {mypreferredcustomer.Discount} on all future purchases.");

            Console.WriteLine($"When a preferred customer spends {mynewcustomer.Purchase}, " +
                              $"he or she gets a {mynewcustomer.Discount} on all future purchases.");

            Console.WriteLine($"When a preferred customer spends {myspecialcustomer.Purchase}, " +
                              $"or more, he or she gets a {myspecialcustomer.Discount} on all future purchases.");

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void DeserializeCustomer()
        {
            // Open the data file for reading
            Stream s = File.OpenRead("customer.soap");

            // Create the SoapFormatter, this time for deserialization purposes
            IFormatter formatter = new SoapFormatter();

            // Deserialize, cast returned object to PreferredCustomer
            PreferredCustomer pc = (PreferredCustomer)formatter.Deserialize(s);

            s.Close();

            // Use the PreferredCustomer object ...
        }
Ejemplo n.º 4
0
        public static void BuildACustomer(List <PreferredCustomer> inputList, bool loop, string input)
        {
            //Clear current screen
            Console.Clear();
            //Create customer object
            PreferredCustomer output = new PreferredCustomer();

            output.CustomerStatus = true;
            Console.WriteLine(StandardMessages.EnterCustomerInformationTitle());
            //Get customer name
            Console.Write(StandardMessages.EnterCustomerName());
            output.Name = Console.ReadLine();
            //Get customer ID#
            Console.Write(StandardMessages.EnterCustomerIDNumber());
            output.CustomerNumber = Console.ReadLine();
            //Get customer address
            Console.Write(StandardMessages.EnterCustomerAddress());
            output.Address = Console.ReadLine();
            //Get customer phone number
            Console.Write(StandardMessages.EnterCustomerPhoneNumber());
            output.PhoneNumber = Console.ReadLine();

            do
            {
                //Get customers mailing preference
                Console.Write("Do you wish to be on the mailing list yes/no? ==> ");
                input = Console.ReadLine().ToLower();
                //Decision structure for mailing preference
                if (input == "yes" || input == "y")
                {
                    output.MailingListOption = true;
                    loop = true;
                }
                else if (input == "no" || input == "n")
                {
                    output.MailingListOption = false;
                    loop = true;
                }
                else
                {
                    Console.WriteLine(StandardMessages.DisplayInvalidChoice());
                    Console.ReadLine();
                }
            } while (loop == false);
            inputList.Add(output);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            File.Delete("customer.xml");
            // First, establish the customer data
            Address addr = new Address();

            addr.Street = "121 Maple St.";
            addr.City   = "Springfield";
            addr.State  = State.IL;
            addr.Zip    = 33333;

            PreferredCustomer pc;

            pc = new PreferredCustomer("Homer", addr, 0.20);

            // Open a file to hold the data
            Stream s = File.OpenWrite("customer.xml");

            // Create the XmlSerializer and serialize customer to file
            XmlSerializer xs = new XmlSerializer(typeof(PreferredCustomer));

            xs.Serialize(s, pc);
            s.Close();

            DeserializeCustomer();

            File.Delete("order.xml");
            // Serialize the order history information
            OrderHistory history = new OrderHistory(1);

            s = File.OpenWrite("order.xml");

            xs = new XmlSerializer(typeof(OrderHistory));
            xs.Serialize(s, history);

            s.Close();
        }
Ejemplo n.º 6
0
        //Preferred customer transaction method
        public static void CustomerItemPurchasePreferred(List <PreferredCustomer> inputList, string input, bool loop)
        {
            decimal           purchasePrice;
            decimal           discountPrice;
            PreferredCustomer transaction = new PreferredCustomer();

            transaction.PurchaseAmount = 0.0m;
            do
            {
                //Get input from user and validate if user inputs a number or character
                Console.Write("Enter total purchase ==> ");
                input = Console.ReadLine();
                decimal.TryParse(input, out purchasePrice);
                if (decimal.TryParse(input, out purchasePrice) && purchasePrice <= 499.99m && purchasePrice >= 0)
                {
                    transaction.DiscountLevel  = 0m;
                    discountPrice              = purchasePrice * transaction.DiscountLevel;
                    purchasePrice              = purchasePrice - discountPrice;
                    transaction.PurchaseAmount = purchasePrice;
                    Console.WriteLine("\n**Sorry! No discount for this transaction.**");
                    //Display reciept
                    DisplayCustomerTransaction.DisplayPreferredTransaction(transaction.PurchaseAmount, transaction.DiscountLevel, discountPrice);
                    loop = true;
                }
                else if (decimal.TryParse(input, out purchasePrice) && purchasePrice >= 500.00m && purchasePrice <= 999.99m)
                {
                    transaction.DiscountLevel  = .05m;
                    discountPrice              = purchasePrice * transaction.DiscountLevel;
                    purchasePrice              = purchasePrice - discountPrice;
                    transaction.PurchaseAmount = purchasePrice;
                    DisplayCustomerTransaction.DisplayPreferredTransaction(transaction.PurchaseAmount, transaction.DiscountLevel, discountPrice);
                    loop = true;
                }
                else if (decimal.TryParse(input, out purchasePrice) && purchasePrice >= 1000.00m && purchasePrice <= 1499.99m)
                {
                    transaction.DiscountLevel  = .06m;
                    discountPrice              = purchasePrice * transaction.DiscountLevel;
                    purchasePrice              = purchasePrice - discountPrice;
                    transaction.PurchaseAmount = purchasePrice;
                    DisplayCustomerTransaction.DisplayPreferredTransaction(transaction.PurchaseAmount, transaction.DiscountLevel, discountPrice);
                    loop = true;
                }
                else if (decimal.TryParse(input, out purchasePrice) && purchasePrice >= 1500.00m && purchasePrice <= 1999.99m)
                {
                    transaction.DiscountLevel  = .07m;
                    discountPrice              = purchasePrice * transaction.DiscountLevel;
                    purchasePrice              = purchasePrice - discountPrice;
                    transaction.PurchaseAmount = purchasePrice;
                    DisplayCustomerTransaction.DisplayPreferredTransaction(transaction.PurchaseAmount, transaction.DiscountLevel, discountPrice);;
                    loop = true;
                }
                else if (decimal.TryParse(input, out purchasePrice) && purchasePrice >= 2000.00m)
                {
                    transaction.DiscountLevel  = .10m;
                    discountPrice              = purchasePrice * transaction.DiscountLevel;
                    purchasePrice              = purchasePrice - discountPrice;
                    transaction.PurchaseAmount = purchasePrice;
                    DisplayCustomerTransaction.DisplayPreferredTransaction(transaction.PurchaseAmount, transaction.DiscountLevel, discountPrice);
                    loop = true;
                }

                else
                {
                    //If user enters anything other than a number display invalid input.
                    Console.WriteLine(StandardMessages.DisplayInvalidChoice());
                    Console.ReadLine();
                }
            } while (loop == false);
            Console.WriteLine(StandardMessages.DisplayEnterMessage());
            Console.ReadLine();
        }