private void btnUpdateFoodItem_Click(object sender, EventArgs e) { if (txtFoodName.Text == "") { MessageBox.Show("Please Enter Food Name", "", MessageBoxButtons.OK, MessageBoxIcon.Error); txtFoodName.Focus(); return; } if (txtPrice.Text == "") { MessageBox.Show("Please Enter Food Price", "", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPrice.Focus(); return; } MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat); byte[] img = ms.ToArray(); FoodItemDetails wd = new FoodItemDetails(); wd.Id = Convert.ToInt32(txtItemID.Text); wd.CategoryName = txtCategoryName.Text; wd.FoodName = txtFoodName.Text; wd.Price = txtPrice.Text; if (radioBtnActive.Checked) { wd.Status = 1.ToString(); } else { wd.Status = 0.ToString(); } if (chkIsSpecial.Checked) { wd.IsSpecial = 1.ToString(); } else { wd.IsSpecial = 0.ToString(); } wd.Discount = txtDiscount.Text; wd.Image = img; int i = bft.UpdateFoodItem(wd); if (i > 0) { //LoadGrid(); MessageBox.Show(" Fooditem updated Successfully", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information); //Clear(); } }
public int UpdateFoodItem(FoodItemDetails fd) { tbl_fooditems tf = _db.tbl_fooditems.Where(c => c.Id == fd.Id).FirstOrDefault(); tf.CategoryName = fd.CategoryName; tf.Price = fd.Price; tf.Status = Convert.ToByte(fd.Status); tf.IsSpecial = Convert.ToByte(fd.IsSpecial); tf.Discount = fd.Discount; tf.Image = fd.Image; tf.FoodName = fd.FoodName; return(_db.SaveChanges()); }
public int AddNewFoodItem(FoodItemDetails fd) { tbl_fooditems tf = new tbl_fooditems(); tf.CategoryName = fd.CategoryName; tf.Price = fd.Price; tf.Status = Convert.ToByte(fd.Status); tf.IsSpecial = Convert.ToByte(fd.IsSpecial); tf.Discount = fd.Discount; tf.Image = fd.Image; tf.FoodName = fd.FoodName; _db.tbl_fooditems.Add(tf); return(_db.SaveChanges()); }
private void btnAddFoodItems_Click(object sender, EventArgs e) { if (cmbCategoryName.SelectedIndex == 0) { MessageBox.Show("Please Select Category", "", MessageBoxButtons.OK, MessageBoxIcon.Error); cmbCategoryName.Focus(); return; } if (txtFoodName.Text == "") { MessageBox.Show("Please Enter Food Name", "", MessageBoxButtons.OK, MessageBoxIcon.Error); txtFoodName.Focus(); return; } if (txtPrice.Text == "") { MessageBox.Show("Please Enter Food Price", "", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPrice.Focus(); return; } MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat); byte[] img = ms.ToArray(); FoodItemDetails fd = new FoodItemDetails(); fd.CategoryName = cmbCategoryName.Text; fd.FoodName = txtFoodName.Text; fd.Price = txtPrice.Text; if (btnRadioActive.Checked) { fd.Status = 1.ToString(); } else { fd.Status = 0.ToString(); } if (isSpecialCheckBox.Checked) { fd.IsSpecial = 1.ToString(); } else { fd.IsSpecial = 0.ToString(); } if (txtDiscount.Text == "") { fd.Discount = 0.ToString(); } else { fd.Discount = txtDiscount.Text; } fd.Image = img; int i = bft.AddNewFoodItem(fd); if (i > 0) { LoadGrid(); MessageBox.Show("New Food Item Added Successfully", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information); Clear(); } }