Пример #1
0
        public Employee(IPayStrategy iPayStrategy, System.IO.StreamReader file)
        {
            PayStrategy = iPayStrategy;

            if (file != null)
            {
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    string[] array = line.Split(';');
                    revenue.Add(new WorkDay(DateTime.Parse(array[0]), Convert.ToInt32(array[1])));
                }
            }
        }
Пример #2
0
 public void ProcessOrder(IPayStrategy strategy)
 {
     strategy.CollectPaymentDetails();
     // Here we could collect and store payment data from the strategy.
 }
Пример #3
0
 public void SetPayStrategy(IPayStrategy payStrategy)
 {
     _payStrategy = payStrategy;
 }
Пример #4
0
 public Employee(IPayStrategy iPayStrategy) : this(iPayStrategy, null) { }
Пример #5
0
        static void Main(string[] args)
        {
            priceOnProducts.Add(1, 2200);
            priceOnProducts.Add(2, 1800);
            priceOnProducts.Add(3, 200);
            priceOnProducts.Add(4, 7200);

            while (!order.IsClosed())
            {
                int    cost = 0;
                string continueChoice;
                do
                {
                    Console.Write("Please, select a product:" + "\n" +
                                  "1 - Mother board" + "\n" +
                                  "2 - CPU" + "\n" +
                                  "3 - HDD" + "\n" +
                                  "4 - Memory" + "\n");

                    int choice = int.Parse(Console.ReadLine());
                    cost = priceOnProducts[choice];
                    Console.Write("Count: ");
                    int count = int.Parse(Console.ReadLine());
                    order.SetTotalCost(cost * count);
                    Console.WriteLine("Do you wish to continue selecting products? Y/N: ");
                    continueChoice = Console.ReadLine();
                } while (continueChoice.ToUpper().Equals("Y"));

                if (strategy is null)
                {
                    Console.Write("Please, select a payment method:" + "\n" +
                                  "1 - PalPay" + "\n" +
                                  "2 - Credit Card");

                    string paymentMethod = Console.ReadLine();
                    // Client creates different strategies based on input from user,
                    // application configuration, etc.
                    if (paymentMethod.Equals("1"))
                    {
                        strategy = new PayByPayPal();
                    }
                    else
                    {
                        strategy = new PayByCreditCard();
                    }

                    // Order object delegates gathering payment data to strategy
                    // object, since only strategies know what data they need to
                    // process a payment.
                    order.ProcessOrder(strategy);

                    Console.Write("Pay " + order.GetTotalCost() + " units or Continue shopping? P/C: ");
                    String proceed = Console.ReadLine();
                    if (proceed.ToUpper().Equals("P"))
                    {
                        // Finally, strategy handles the payment.
                        if (strategy.Pay(order.GetTotalCost()))
                        {
                            Console.WriteLine("Payment has been successful.");
                        }
                        else
                        {
                            Console.WriteLine("FAIL! Please, check your data.");
                        }

                        order.SetClosed();
                    }
                }
            }
        }