private void btnChangeFoodItemSelectFoodItemButton_Click(object sender, EventArgs e) { if (grdChangeFoodItemSelectFoodItem.SelectedRows.Count < 0) { MessageBox.Show("Please select the food item to change"); } else if (grdChangeFoodItemSelectFoodItem.SelectedRows.Count > 1) { MessageBox.Show("Please select one food item to change only"); } else { //save the selected row into a food item object //first we have to get the row index from datagridview to retrieve the row int rowIndex = grdChangeFoodItemSelectFoodItem.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = grdChangeFoodItemSelectFoodItem.Rows[rowIndex]; //create fooditem object based on the selected row FoodItems selectedItem = new FoodItems(Convert.ToInt32(selectedRow.Cells[0].Value), Convert.ToString(selectedRow.Cells[1].Value), Convert.ToString(selectedRow.Cells[2].Value), Convert.ToString(selectedRow.Cells[3].Value), Convert.ToDecimal(selectedRow.Cells[4].Value), Convert.ToString(selectedRow.Cells[5].Value)); //set all the text to the corresponding food items variable this.txtChangeFoodItemId.Text = Convert.ToString(selectedItem.getItemId()); this.txtChangeFoodItem.Text = selectedItem.getItemName(); this.txtChangeFoodItemDesc.Text = selectedItem.getDescription(); this.cboChangeFoodItemType.Text = selectedItem.getFoodType(); this.txtChgFoodItemPrice.Value = selectedItem.getPrice(); //this.cboChangeFoodItemFoodStatus.Text = selectedItem.getStatus(); rtnStatus(selectedItem.getStatus()); //display change food item group grpChangeFoodItemSelectFood.Visible = false; grpChangeFoodItemChangeFood.Visible = true; } }
//method that prompt everything a table button is clicked. private void buttonClicked(int tableNo) { frmFoodOrder frmFoodOrder = new frmFoodOrder(); //check the tableList if the table is not empty if (Table.tableList[tableNo] != 0) { int orderNo = Table.tableList[tableNo]; //retrieve all the order with the given orderNo, fill the order inside the grdOrder Orders.foodOrder = Orders.getSelectedFoodOrder(Orders.foodOrder, orderNo); //Add all the order into the orderItems list for (int i = 0; i < Orders.foodOrder.Tables[0].Rows.Count; i++) { int[] order = new int[2]; order[0] = Convert.ToInt32(Orders.foodOrder.Tables[0].Rows[i][1]); order[1] = Convert.ToInt32(Orders.foodOrder.Tables[0].Rows[i][2]); Orders.orderItems.Add(order); } //Orders.valueStore = Convert.ToDecimal(Orders.foodOrder.Tables[0].Rows[0]["Value"]); frmFoodOrder.lbl_OrderNo.Text = Convert.ToString(orderNo); frmFoodOrder.Order.OrderNo = orderNo; frmFoodOrder.setOrderPlaced(true); Orders.foodOrder.Clear(); } else { frmFoodOrder.lbl_OrderNo.Text = Convert.ToString(Orders.nextOrderNo()); frmFoodOrder.Order.OrderNo = Orders.nextOrderNo(); } if (Orders.staff != null)//if theres staff signed in { frmFoodOrder.lblStaffName.Text = Convert.ToString(Orders.staff); frmFoodOrder.Order.StaffId = Convert.ToInt32(frmFoodOrder.lblStaffName.Text.Trim().Substring(0, 2)); } //display all the order on the gridview foreach (int[] orderitem in Orders.orderItems) { DataGridViewRow gridViewRow = (DataGridViewRow)frmFoodOrder.grdOrder.Rows[0].Clone(); FoodItems fooditem = FoodItems.getFood(orderitem[0]); gridViewRow.Cells[0].Value = fooditem.getItemName(); //Set the food name column to selected food name gridViewRow.Cells[1].Value = orderitem[1]; //Set the number of food ordered column to number value gridViewRow.Cells[2].Value = fooditem.getPrice(); //Set the food price column to food unit price gridViewRow.Cells[3].Value = fooditem.getPrice() * orderitem[1]; //Set the total price of the food frmFoodOrder.grdOrder.Rows.Add(gridViewRow); frmFoodOrder.totalPrice += Convert.ToDecimal(gridViewRow.Cells[3].Value); frmFoodOrder.totalQty += Convert.ToInt32(gridViewRow.Cells[1].Value); } frmFoodOrder.lblTableNumber.Text = Convert.ToString(tableNo); frmFoodOrder.Order.TableNo = tableNo; frmFoodOrder.grdOrder.Rows[0].Cells[1].Value = frmFoodOrder.totalQty; frmFoodOrder.grdOrder.Rows[0].Cells[3].Value = frmFoodOrder.totalPrice; Orders.setCurrentPage("S"); Orders.state = 1; frmFoodOrder.Show(); //close the table interface this.Close(); }