/// <summary> /// Update MenuItem event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnApplyStock_Click(object sender, EventArgs e) { if (listEditMenu.SelectedItems.Count < 1) { MessageBox.Show("Please select a menu item", "Fields required", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrWhiteSpace(txtItemName.Text) || String.IsNullOrWhiteSpace(txtCount.Text) || !System.Text.RegularExpressions.Regex.IsMatch(txtCount.Text, "^[0-9]*$")) { MessageBox.Show("Please fill the values properly", "Fields required", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ChapeauModel.MenuItem menuItem = (ChapeauModel.MenuItem)listEditMenu.SelectedItems[0].Tag; menuItem.Stock = int.Parse(txtCount.Text); menuItem.Name = txtItemName.Text; serviceItem.UpdateStockOfItem(menuItem); txtCount.Text = ""; txtItemName.Text = ""; MessageBox.Show("Stock has been updated", "Stock updated", MessageBoxButtons.OK, MessageBoxIcon.Information); // refresh the listview FillMenuItemListView(listEditMenu); }
private void btnAddItem_Click(object sender, EventArgs e) { txtPrice.Text = txtPrice.Text.Replace('.', ','); if (cmbCategory.SelectedIndex < 0 || String.IsNullOrWhiteSpace(txtName.Text) || String.IsNullOrWhiteSpace(txtStock.Text) || !System.Text.RegularExpressions.Regex.IsMatch(txtStock.Text, "^[0-9]*$") || String.IsNullOrWhiteSpace(txtPrice.Text) || !System.Text.RegularExpressions.Regex.IsMatch(txtPrice.Text, @"^[0-9]*(?:\,[0-9]+)?$")) { MessageBox.Show("Please fill the fields properly", "Process incomplete", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //Creating the menu item for dao class. ChapeauModel.MenuItem item = new ChapeauModel.MenuItem() { Name = txtName.Text, Price = float.Parse(txtPrice.Text), Stock = int.Parse(txtStock.Text), Category = ConvertToCategory(cmbCategory.SelectedItem.ToString()) }; serviceItem.CreateMenuItem(item); MessageBox.Show("Item has been created", "Process complete", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Text = ""; txtPrice.Text = ""; txtStock.Text = ""; cmbCategory.SelectedItem = null; }
private void SetActiveCard(ChapeauModel.MenuItem menuItem) { RemoveActiveMenuCardState(); /* * We need to set currentMenuItem variable to the 'menuItem'. * Otherwise the 'comment' textbox does not know what item is active, because we use 1 textbox for all items. */ currentMenuItem = menuItem; // Set the custom quantityinput user control max value to that of the stock. quantityInput.MaxValue = currentMenuItem.Stock; quantityInput.MinValue = 0; // Everytime the quantity is changed call the methods, to update the orderlist quantityInput.UpdateCount += (sender, EventArgs) => { // If quantity currentvalue is bigger than 0, add the item to the order if (quantityInput.CurrentValue > 0) { AddItemToOrderList(currentMenuItem, quantityInput.CurrentValue); } // If it is 0, remove it, and put the quantityinput and comment textbox back to the default values else { RemoveItemFromOrderList(currentMenuItem); ResetInputValues(); } }; // update quantityinput and comment textbox values UpdateInputValues(menuItem); }
public OrderingRow(OrderingScreen mainScreen, ChapeauModel.MenuItem menuItem, bool showEdit = false, int amount = 0) { InitializeComponent(); this.mainScreen = mainScreen; OrderItem = new OrderItem(menuItem, amount); lblAmount.Text = Amount.ToString(); lblName.Text = menuItem.Name; btnEdit.Visible = false; }
private void listEditMenu_SelectedIndexChanged(object sender, EventArgs e) { if (listEditMenu.SelectedItems.Count > 0) { ChapeauModel.MenuItem SelectedItem = (ChapeauModel.MenuItem)listEditMenu.SelectedItems[0].Tag; txtItemName.Text = SelectedItem.Name; txtCount.Text = SelectedItem.Stock.ToString(); } }
/// <summary> /// Finds the ordering row with the given menuitem in the given list /// </summary> OrderingRow FindMenuItem(List <OrderingRow> rows, ChapeauModel.MenuItem menuItem) { foreach (var row in rows) { if (menuItem == row.OrderItem.MenuItem) { return(row); } } return(null); }
/// <summary> /// Checks if the given menuitem is in the given list /// </summary> bool ContainsMenuItem(List <OrderingRow> rows, ChapeauModel.MenuItem menuItem) { foreach (var row in rows) { if (menuItem == row.OrderItem.MenuItem) { return(true); } } return(false); }
/* * Although we have a 'delete' button for an order, but if the user descreases the count to 0, we also need to remove it. * We loop over the list, and if the ItemId is found we remove it. */ public void RemoveItemFromOrderList(ChapeauModel.MenuItem menuItem) { foreach (OrderItem item in orderedItemsList) { if (item.MenuItem.ItemId == menuItem.ItemId) { orderedItemsList.Remove(item); return; } } }
private void listView_menu_edit_SelectedIndexChanged(object sender, EventArgs e) { if (listView_menu_edit.SelectedItems.Count > 0) { //storing selected items currentMenuItem = (ChapeauModel.MenuItem)listView_menu_edit.SelectedItems[0].Tag; //viewing items selected in txt & lbl boxes stock_txt.Text = currentMenuItem.Stock.ToString(); lbl_itemName.Text = currentMenuItem.Name.ToString(); } }
/* * Because we make use of one textbox, and quantity input, we need to check if the active item is already in the orderlist, * because thats where the 'comment' and 'count' is stored. * * If the menuItem is in the orderedItemsList we update the values, otherwise it gets put back to the default. */ private void UpdateInputValues(ChapeauModel.MenuItem menuItem) { foreach (OrderItem item in orderedItemsList) { if (item.MenuItem.ItemId == menuItem.ItemId) { input_comment.Text = item.Comment; quantityInput.CurrentValue = item.Count; return; } } ResetInputValues(); }
private void btn_menuItem_Click(object sender, EventArgs e) { Button button = (Button)sender; ChapeauModel.MenuItem menuItem = (ChapeauModel.MenuItem)button.Tag; ListViewItem li = new ListViewItem(menuItem.Name);//needs to fix this because stock quantity is taken rather than order quantity OrderMenuItem orderMenuItem = new OrderMenuItem(menuItem); li.Tag = orderMenuItem; //linking menuItem to the entry of the list li.SubItems.Add(menuItem.Price.ToString("0.00")); li.SubItems.Add(menuItem.Stock.ToString()); li.SubItems.Add(menuItem.Category.ToString()); lst_NewOrderItems.Items.Add(li); }
private void AddItemToOrderList(ChapeauModel.MenuItem menuItem, int currentQuantity) { // try finding if the order is already in the orderlist, if so, increase the Count. foreach (OrderItem item in orderedItemsList) { if (item.MenuItem.ItemId == menuItem.ItemId) { item.Count = currentQuantity; item.Comment = GetComment(); return; } } DateTime time = DateTime.Now; // If it is not in the orderlist add it. OrderItem orderItem = new OrderItem(menuItem, 1, GetComment(), OrderStatus.Taken, time, 0); orderedItemsList.Add(orderItem); }
//remove button private void RemoveBtn_Click(object sender, EventArgs e) { if (listRemoveMenuItem.SelectedItems.Count < 1) { MessageBox.Show("Please pick a menu item to remove from system.", "Missing information", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { //get's the id from combo box by splitting it. ChapeauModel.MenuItem ChosenMenuItem = (ChapeauModel.MenuItem)listRemoveMenuItem.SelectedItems[0].Tag; if (MessageBox.Show($"Are you sure you want to delete {ChosenMenuItem.Name} ", "Verification", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { serviceItem.DeleteMenuItem(ChosenMenuItem); MessageBox.Show("Employee has been removed.", "Employee removed", MessageBoxButtons.OK, MessageBoxIcon.Information); FillMenuItemListView(listRemoveMenuItem); } } }
private void SubmitOrder() { try { // Add the order order_service.AddOrder(table, employee, orderedItemsList); // Reset inpute values ResetInputValues(); // Remove active states RemoveActiveMenuCardState(); // Clear order list ClearOrderList(); // Reset currentMenuItem currentMenuItem = null; MessageBox.Show( "Order is succefully placed", // Exception Message "Order succefull", // Message box caption (title) MessageBoxButtons.OK, // Close button that return an exit code of '0'. MessageBoxIcon.Information // Message box theme. ); Overview overview = new Overview(employee); overview.Show(); this.Close(); } catch (Exception ex) { MessageBox.Show( ex.Message, // Exception Message "Adding order process error.", // Message box caption (title) MessageBoxButtons.OK, // Close button that return an exit code of '0'. MessageBoxIcon.Error // Message box theme. ); } }