/// <summary> /// Initializes this ViewModel. /// </summary> private void PopulateKitchenOrderItemList() { try { OrderItem tempSelectedKitchenOrderItem = SelectedKitchenOrderItem; SelectedKitchenOrderItem = null; // get entire list EntireOrderItemList = _orderItemManager.GetList(); List <OrderItem> UpdatedOrderItemList = EntireOrderItemList.Where(o => o.IsKitchenProcessCompleted != true).ToList(); OrderItem searchItem = null; // check with current list, if there is changing, need update foreach (OrderItem item in UpdatedOrderItemList) { searchItem = this.KitchenOrderItemList.SingleOrDefault <OrderItem>(x => x.OrderId == item.OrderId && x.Sequence == item.Sequence); // no have in current list, it means it is new item if (searchItem == null) { /*item.EdittedQuantity = item.Quantity; * item.OldQuantity = item.Quantity; * item.Quantity = 0;*/ item.MarkAsChild(); item.MarkUpdated(); item.AddChangeLog("New order " + item.Quantity + " -> "); // add this item to list // add message into item // ... KitchenOrderItemList.Add(item); } // item exist in current list, check if there is change else { if (item.IsCancelled == true) { if (searchItem.IsCancelled != item.IsCancelled) { searchItem.MarkUpdated(); searchItem.MarkCancelled(); searchItem.AddChangeLog("Cancelled"); } } else { switch (searchItem.State) { case OrderItemState.Ordered: if (item.State != OrderItemState.Ordered) { searchItem.State = item.State; //searchItem.EdittedQuantity = item.Quantity - searchItem.Quantity; //searchItem.UpdatedQuantity = item.Quantity; searchItem.MarkUpdated(); searchItem.AddChangeLog(searchItem.State.ToString() + " -> "); } else { if (item.Quantity != searchItem.Quantity) { searchItem.State = item.State; searchItem.SetOldQuantity(); searchItem.Quantity = item.Quantity; //searchItem.UpdatedQuantity = item.Quantity; searchItem.MarkUpdated(); searchItem.AddChangeLog("Change quantity " + searchItem.EdittedQuantity.ToString() + " -> "); } } break; case OrderItemState.Processing: // do nothing // must care about problem: undo processing // can chage quantity at this state? Wondering Who will be permitted? if (item.State > OrderItemState.Processing) { searchItem.State = item.State; searchItem.MarkUpdated(); searchItem.AddChangeLog(searchItem.State.ToString() + " -> "); } break; case OrderItemState.Ready: // check new state (if there), dont care other state if (item.State == OrderItemState.Served) { searchItem.State = item.State; searchItem.MarkUpdated(); searchItem.AddChangeLog(searchItem.State.ToString() + " -> "); } break; case OrderItemState.Served: { // do nothing } break; default: break; } } } } // check with current list, is there item cancelled? foreach (OrderItem item in KitchenOrderItemList.ToList()) { searchItem = UpdatedOrderItemList.SingleOrDefault <OrderItem>(x => x.OrderId == item.OrderId && x.Sequence == item.Sequence); // no have in current list, it means it is new item if (searchItem == null) { // search in entire list searchItem = EntireOrderItemList.Where(o => o.IsKitchenProcessCompleted == true).SingleOrDefault <OrderItem>(x => x.OrderId == item.OrderId && x.Sequence == item.Sequence); if (searchItem != null) { // if this item is served if (item.State == OrderItemState.Served || item.IsCancelled == true) { // if user acknowledged this item if (item.IsAcknownledged == true) { // need remove it from list KitchenOrderItemList.Remove(item); } //else // user not acknowledge it, let it display for user } else { // after long time, list is updated but this item is remove from kitchen list item.State = searchItem.State; item.IsCancelled = searchItem.IsCancelled; item.Quantity = searchItem.Quantity; item.MarkUpdated(); item.AddChangeLog("Order item was processed out."); } } // order of this item is checked out or cancelled else { if (item.State == OrderItemState.OutOfKitchen) { if (item.IsAcknownledged == true) { // need remove it from list KitchenOrderItemList.Remove(item); } } else { item.State = OrderItemState.OutOfKitchen; item.MarkUpdated(); item.AddChangeLog("Order is checked out."); } } } } Sort(KitchenOrderItemList); if (tempSelectedKitchenOrderItem != null && tempSelectedKitchenOrderItem.IsUpdated != true) { SelectedKitchenOrderItem = tempSelectedKitchenOrderItem; } // update completed item list CompletedOrderItemList = new ObservableCollection <OrderItem>((List <OrderItem>)(KitchenOrderItemList as IEditableCollection).GetDeletedList()); } catch (Exception ex) { this.messageBoxService.ShowError(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message); } }