/// <summary> /// Constructor. /// Connects to the Controller Layer /// Retrieves from the controller layer all order headers and shows them in the datagrid /// </summary> public MainView() { InitializeComponent(); this.layer = new LogicLayer(); allOrderHeaders = layer.GetOrderHeaders(); dgMainMenu.ItemsSource = allOrderHeaders; this.Topmost = true; }
/// <summary> /// 1. Assigns the orderheader object to the order header id /// 2. If an orderheader(from 1. ) is not found, then a new one is created /// 3. Hides "Add" button and "Submit" button if order state is "Complete". /// 4. Displays the order items inside the datagrid /// 5. Adds each order item price and calculates the total /// 6. Displays all the information inside textboxes. /// </summary> public void UpdateInfo() { bool exitLoop = false; List <OrderHeader> allOrders = layer.GetOrderHeaders(); DateTime orderTime; int orderHeaderState; //1. Assigns the orderheader object to the order header id for (int i = 0; i < allOrders.Count; i++) { if (allOrders.ElementAt(i).Id == orderHeaderId) { orderTime = allOrders.ElementAt(i).DateTime; orderHeaderState = allOrders.ElementAt(i).State; currentOrderHeader = new OrderHeader(orderTime, orderHeaderId, orderHeaderState); exitLoop = true; } } // 2. If an orderheader(from 1. ) is not found, then a new one is created switch (exitLoop) { case false: orderTime = DateTime.Now; orderHeaderState = (int)Enum.Parse(typeof(OrderStates), "New"); currentOrderHeader = new OrderHeader(orderTime, orderHeaderId, orderHeaderState); break; } // 3. Hides "Add" button and "Submit" button if order state is "Complete". if (currentOrderHeader.State == (int)Enum.Parse(typeof(OrderStates), "Complete")) { Btn_Add_Order.Visibility = Visibility.Hidden; Btn_Submit.Visibility = Visibility.Hidden; } // 4. Displays the order items inside the datagrid currentOrders = layer.ProcessOrder(currentOrderHeader.Id); dgOrderItem.ItemsSource = currentOrders; // 5. Adds each order item price and calculates the total double total = 0; for (int i = 0; i < currentOrders.Count; i++) { total += currentOrders.ElementAt(i).Total; } // 6. Displays all the information inside textboxes. textbox_order.Text = "Order : #" + orderHeaderId; OrderStates currentState = (OrderStates)currentOrderHeader.State; textbox_datetime.Text = "Order Time : " + currentOrderHeader.DateTime; textbox_state.Text = "State : " + currentState; textbox_total.Text = "Total : " + String.Format("{0:c}", total); }