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; } }
public static FoodItems getFood(int ItemId) { FoodItems fooditem = new FoodItems(); OracleConnection conn = new OracleConnection(DBConnect.oradb); conn.Open(); //connection name conn.open() String strSQL = "SELECT * FROM FoodItems WHERE ItemId = " + ItemId; OracleCommand cmd = new OracleCommand(strSQL, conn); //exceute the SQL Query and put result in OracleDataReader object OracleDataReader dr = cmd.ExecuteReader(); //read the first (only) value returned by query //If first itemId, assign value 1, otherwise add 1 to MAX value dr.Read(); if (!dr.IsDBNull(0)) { fooditem.setItemId(ItemId); fooditem.setItemName(dr.GetString(1)); fooditem.setDescription(dr.GetString(2)); fooditem.setFoodType(dr.GetString(3)); fooditem.setPrice(dr.GetDecimal(4)); fooditem.setStatus(dr.GetString(5)); } //close db connection conn.Close(); //return next ItemId return(fooditem); }
//Define a method that load the combo box with existing food type private void frmAddFoodItem_Load(object sender, EventArgs e) { txtNextItemId.Text = FoodItems.nextItemId().ToString(); //load food type combo box with food types and description DataSet ds = new DataSet(); ds = FoodTypes.getAllFoodType(ds); for (int i = 0; i < ds.Tables["ss"].Rows.Count; i++) { cboAddFoodItemType.Items.Add(ds.Tables[0].Rows[i][0].ToString().PadLeft(2) + " : " + ds.Tables[0].Rows[i][1].ToString()); } }
//Define a method that detect change in fooditemtype combo box and display all the food with that food type on the grid box private void cboChangeFoodItemType_SelectedIndexChange(object sender, EventArgs e) { //if resetting combo, ignore... if (cboChangeFoodItemType.SelectedIndex == -1) { return; } //Retrieve the food type and store the food type inside a variable and pass into the SQL //MessageBox.Show("Change Detected!"); string foodType = cboChangeFoodItemType.Text.Substring(0, 1); //Get the dataset by passing the foodtype as parameter to retrieve selectedFoodItem dataset DataSet DS = new DataSet(); DS = FoodItems.getSelectedFoodItem(DS, foodType); //remove previous item in the gridview //for(int r = 0 ; r < this.grdChangeFoodItemSelectFoodItem.Rows.Count ; r++) //{ // grd //} //load data from ds to grpChangeFoodItemSelectFood if (DS != null) { //grdChangeFoodItemSelectFoodItem.AutoGenerateColumns = true; //grdChangeFoodItemSelectFoodItem.DataSource = DS; grdChangeFoodItemSelectFoodItem.DataSource = DS.Tables["FoodItems"]; /*int row = DS.Tables["FoodItems"].Rows.Count - 1; * for(int r = 0; r <= row; r++) * { * grdChangeFoodItemSelectFoodItem.Rows.Add(); * grdChangeFoodItemSelectFoodItem.Rows[r].Cells[0].Value = DS.Tables["FoodItems"].Rows[r].ItemArray[0]; * grdChangeFoodItemSelectFoodItem.Rows[r].Cells[1].Value = DS.Tables["FoodItems"].Rows[r].ItemArray[1]; * grdChangeFoodItemSelectFoodItem.Rows[r].Cells[2].Value = DS.Tables["FoodItems"].Rows[r].ItemArray[2]; * grdChangeFoodItemSelectFoodItem.Rows[r].Cells[3].Value = DS.Tables["FoodItems"].Rows[r].ItemArray[3]; * grdChangeFoodItemSelectFoodItem.Rows[r].Cells[4].Value = DS.Tables["FoodItems"].Rows[r].ItemArray[4]; * }*/ } cboChangeFoodItemFoodType.SelectedIndex = cboChangeFoodItemType.SelectedIndex; }
//Define a method that will extract the food type and store into the foodtype variable in this class private void cboAddFoodItemType_SelectedIndexChange(object sender, EventArgs e) { //if resetting combo, ignore... if (cboAddFoodItemType.SelectedIndex == 1) { return; } //find food type details , create a new fooditems and store the food type details into food item FoodItems newFoodItem = new FoodItems(); newFoodItem.setFoodType(cboAddFoodItemType.Text.Substring(0, 1)); //Validation to prevent the food type is empty if (newFoodItem.getFoodType() == "") { MessageBox.Show("No food type selected", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); cboAddFoodItemType.Focus(); return; } }
private void btnChgFoodItemSubmit_Click(object sender, EventArgs e) { bool allCorrect = true; //validate data if (txtChangeFoodItem.Text.Equals("")) { MessageBox.Show("Food Item name must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (txtChangeFoodItemDesc.Text.Equals("")) { MessageBox.Show("Food item description must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } /*else if(txtChangeFoodItemDesc.Text.Length > 15) * { * MessageBox.Show("Food item name must shorter than 15", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); * allCorrect = false; * }*/ else if (cboChangeFoodItemFoodType.SelectedItem == null) { MessageBox.Show("Food item type must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (txtChgFoodItemPrice.Text.Equals("")) { MessageBox.Show("Food item price must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (cboChangeFoodItemFoodStatus.SelectedItem == null) { MessageBox.Show("Food item status must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else { //Price value must be greater than 0 Match validPrice1 = Regex.Match(txtChgFoodItemPrice.Text, @"\d\d\.\d\d"); Match validPrice2 = Regex.Match(txtChgFoodItemPrice.Text, @"\d"); Match validPrice3 = Regex.Match(txtChgFoodItemPrice.Text, @"\d\d"); Match validPrice4 = Regex.Match(txtChgFoodItemPrice.Text, @"\d.\d\d"); if (!validPrice1.Success && !validPrice2.Success && !validPrice3.Success && !validPrice4.Success) { MessageBox.Show("Food item price must be in decimal form and greater than 0"); allCorrect = false; } } if (allCorrect == true) { //save every details from the detail box into a food item FoodItems foodItem = new FoodItems(Convert.ToInt32(txtChangeFoodItemId.Text), txtChangeFoodItem.Text, txtChangeFoodItemDesc.Text, cboChangeFoodItemFoodType.Text.Substring(0, 1), Convert.ToDecimal(txtChgFoodItemPrice.Value), cboChangeFoodItemFoodStatus.Text.Substring(0, 1)); //Insert fooditem via written SQL method foodItem.updateFoodItem(); //show successful message MessageBox.Show("Food item changed successfully!"); //make sure the datasource output is updated too DataSet DS = new DataSet(); DS = FoodItems.getSelectedFoodItem(DS, foodItem.getStatus()); if (DS != null) { if (DS.Tables[0].Rows.Count != 0) { grdChangeFoodItemSelectFoodItem.DataSource = DS.Tables["FoodItems"]; } } //clear everything txtChangeFoodItem.Clear(); txtChangeFoodItemDesc.Clear(); txtChgFoodItemPrice.Value = 0; cboChangeFoodItemFoodStatus.SelectedIndex = -1; //cboChangeFoodItemFoodType.SelectedIndex = -1; grpChangeFoodItemSelectFood.Visible = true; grpChangeFoodItemChangeFood.Visible = false; string foodType = cboChangeFoodItemType.Text.Substring(0, 1); //Get the dataset by passing the foodtype as parameter to retrieve selectedFoodItem dataset DataSet ds = new DataSet(); ds = FoodItems.getSelectedFoodItem(ds, foodType); //load data from ds to grpChangeFoodItemSelectFood if (ds != null) { grdChangeFoodItemSelectFoodItem.DataSource = ds.Tables["FoodItems"]; } } }
private void btnAddFoodItemSubmit_Click(object sender, EventArgs e) { bool allCorrect = true; //validate data if (txtAddFoodItem.Text.Equals("")) { MessageBox.Show("Food Item name must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (txtAddFoodItemDesc.Text.Equals("")) { MessageBox.Show("Food item description must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (txtAddFoodItem.Text.Length > 15) { MessageBox.Show("Food items name must shorter than 15", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txtAddFoodItemDesc.Text.Length > 30) { MessageBox.Show("Food item description must lower or equal than 30", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (cboAddFoodItemType.SelectedItem == null) { MessageBox.Show("Food item type must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (txtAddFoodItemPrice.Text.Equals("")) { MessageBox.Show("Food item price must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (cboAddFoodItemStatus.SelectedItem == null) { MessageBox.Show("Food item status must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); allCorrect = false; } else if (txtAddFoodItemPrice.Value < 0) { MessageBox.Show("Food item price must greater than 0"); allCorrect = false; } if (allCorrect == true) { //save food item details into food item object FoodItems fooditem = new FoodItems(Convert.ToInt32(txtNextItemId.Text), txtAddFoodItem.Text, txtAddFoodItemDesc.Text, cboAddFoodItemType.Text.Substring(1, 1), Convert.ToDecimal(txtAddFoodItemPrice.Value), cboAddFoodItemStatus.Text.Substring(0, 1)); fooditem.addFoodItem(); //display successful message MessageBox.Show("Food item added successfully!"); //update itemId?? txtNextItemId.Text = FoodItems.nextItemId().ToString(); //clear all textbox txtAddFoodItem.Clear(); txtAddFoodItemDesc.Clear(); txtAddFoodItemPrice.ResetText(); cboAddFoodItemStatus.SelectedIndex = -1; cboAddFoodItemType.SelectedIndex = -1; } //display confirmation message //save food item details //clear the ui }
//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(); }