/// <summary> /// Fills all the panels with menu items /// </summary> void FillAllItemsPanel() { FlowLayoutPanel panel = null; subPanels = new List <FlowLayoutPanel>(); foreach (var categoryType in menu) { // select the correct panel if (categoryType.Key == "Drinks") { panel = flpDrinkItems; } else if (categoryType.Key == "Dinner") { panel = flpDinnerItems; } else if (categoryType.Key == "Lunch") { panel = flpLunchItems; } //add header for the category panel.Controls.Add(NewLabel(categoryType.Key, headerFont)); //loop over all the items in the category foreach (var category in categoryType.Value) { // add header for the sub category Label subHeader = NewLabel(category.Key, subHeaderFont, true); panel.Controls.Add(subHeader); FlowLayoutPanel subPanel = NewFlowPanel("flp" + category.Key); panel.Controls.Add(subPanel); subPanels.Add(subPanel); subHeader.Tag = subPanel; subPanel.Visible = false; subHeader.Click += (sender, e) => lblCategory_Click(this, e, subPanel); bool first = true; //loop over all the items in the sub category foreach (var menuItem in category.Value) { //add the usecontroll with the menu item info OrderingRow row = new OrderingRow(this, menuItem); row.first = first; first = false; subPanel.Controls.Add(row); allOrderItems.Add(row); } } } }
/// <summary> /// Updates the amount of the given orderRow in both the current order panel and the menu /// </summary> /// <param name="orderingRow">row to update the amount of</param> public void UpdateCurrentOrderItem(OrderingRow orderingRow) { //if the item is not yet in the current order panel, add it if (!ContainsMenuItem(currentOrderItems, orderingRow.OrderItem.MenuItem)) { orderingRow = new OrderingRow(this, orderingRow.OrderItem.MenuItem, true, orderingRow.Amount); currentOrderItems.Add(orderingRow); //add the order item row but keep the confirmation usercontroll at the bottom flpCurrentOrderItems.Controls.Remove(confirmControll); flpCurrentOrderItems.Controls.Add(orderingRow); flpCurrentOrderItems.Controls.Add(confirmControll); } else { //loop over the rows in the menu foreach (var row in allOrderItems) { //if the menuitem is the same update the ammount if (orderingRow.OrderItem.MenuItem == row.OrderItem.MenuItem) { row.Amount = orderingRow.Amount; break; } } //loop over the rows in the current order panel foreach (var row in currentOrderItems) { //if the menuitem is the same update the ammount if (orderingRow.OrderItem.MenuItem == row.OrderItem.MenuItem) { row.Amount = orderingRow.Amount; break; } } // if the new amount is 0, remove the row from the current order panel if (orderingRow.Amount == 0) { //get the correct row in the current panel OrderingRow row = FindMenuItem(currentOrderItems, orderingRow.OrderItem.MenuItem); currentOrderItems.Remove(row); flpCurrentOrderItems.Controls.Remove(row); } } }