private void createOrder(string storeName, int price)
        {
            int senderId = int.Parse(storeName);                                                                        //store senderId as string

            OrderClass newOrder      = new OrderClass(senderId, getCardNo(senderId), suggestedOrderCalc(price), price); //create new order
            string     encodedObject = orderEncoder.encode(newOrder);                                                   //encode order before sending

            ChickenEcommerceApplication.mb.setOneCell(encodedObject);                                                   //write order to the buffer
        }
示例#2
0
        private static void processOrder(OrderClass newOrder)
        {
            Console.WriteLine("Farmer has recieved new order from Store {0}", newOrder.getSenderId());

            Thread processOrder = new Thread(new ParameterizedThreadStart(OrderProcessing.processOrder));

            processOrder.Name = "Order Processer";
            processOrder.Start(newOrder);
            orderProcessingThreads.Add(processOrder);
        }
示例#3
0
        public static void processOrder(object _order)
        {
            OrderClass order = (OrderClass)_order;             //cast to order object

            if (validateCreditCard(order.getSenderId(), order.getCardNo()))
            {
                order.setTotalAmount(totalChargeAmount(order.getAmount(), order.getPrice()));
                order.setOrderConfirmedDate(DateTime.Now);
                orderConfirmation(order);                 //confirms the orders
            }
            else
            {
                Console.WriteLine("Invalid Credit Card Number. Order not confirmed.");
            }
        }
        public string encode(OrderClass order)
        {
            //Converts Order Object into a string
            string encodedString = "";

            encodedString += order.getSenderId();
            encodedString += "+";             //terminal token
            encodedString += order.getAmount();
            encodedString += "+";             //terminal token
            encodedString += order.getCardNo();
            encodedString += "+";             //terminal token
            encodedString += order.getOrderDate();
            encodedString += "+";             //terminal token
            encodedString += order.getPrice();
            return(encodedString);
        }
        public OrderClass decode(string encodedObject)
        {
            //Converts encodedObject string into orderObject
            //Decode object into seperate attributes of object
            string[] attributes = new string[5];
            attributes = encodedObject.Split('+');
            //Store attributes
            int      senderId  = int.Parse(attributes[0]); //id of sender (thread_id)
            int      amount    = int.Parse(attributes[2]); //number of chickens to order
            int      cardNo    = int.Parse(attributes[1]); //credit card number
            DateTime orderDate = DateTime.Parse(attributes[3]);
            int      price     = int.Parse(attributes[4]);

            OrderClass decodedObject = new OrderClass(senderId, amount, cardNo, price);

            decodedObject.setOrderDate(orderDate);

            return(decodedObject);
        }
 public void orderConfirmed(OrderClass confirmedOrder)
 {
     Console.WriteLine("\tOrder has been confirmed. Here is your reciept of purchase:");
     Console.WriteLine("\t----------------------------------------------------------");
     Console.WriteLine(confirmedOrder.ToString());
 }