public void edit(Food_Size obj) { using (ModelContext db = new ModelContext()) { db.Entry <Food_Size>(obj).State = EntityState.Modified; db.SaveChanges(); } }
public Food_Size insert(Food_Size obj) { using (ModelContext db = new ModelContext()) { db.size_list.Attach(obj); db.Entry <Food_Size>(obj).State = EntityState.Added; db.SaveChanges(); return(obj); } }
public void insert(string DishName, double DishPrice, string DishDescription, string DishImage, string TypeName, string SizeName, int DStock) { using (ModelContext db = new ModelContext()) { Food_Size fsi = db.size_list.FirstOrDefault(fsize => fsize.name == SizeName); Food_Type ftyp = db.type_list.FirstOrDefault(ftype => ftype.nameType == TypeName); db.dish_list.Add(new Food_Dish { name = DishName, price = DishPrice, description = DishDescription, imaGeURL = DishImage, TypeId = ftyp.Id, SizeId = fsi.Id, stock = DStock }); db.SaveChanges(); } }
private void btnSearch_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSearch.Text)) { MessageBox.Show("Search field is empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { foodSizeBindingSource.DataSource = Food_SizeBUS.search(txtSearch.Text); Food_Size fsi = foodSizeBindingSource.Current as Food_Size; } txtSearch.Clear(); }
private void btnDelete_Click(object sender, EventArgs e) { try { Food_Size obj = foodSizeBindingSource.Current as Food_Size; if (MessageBox.Show("Are you sure want to delete this name ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { Food_SizeBUS.delete(obj); MessageBox.Show("Delete successfully!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); foodSizeBindingSource.RemoveCurrent(); } } catch { MessageBox.Show("Can not delete this name!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void edit(Food_Dish dishEdit, string E_Dname, double E_DPrice, string E_DDescription, string E_DImage, string E_DType, string E_DSize, int E_DId, int E_DStock) { using (ModelContext db = new ModelContext()) { Food_Size fsi = db.size_list.FirstOrDefault(fsize => fsize.name == E_DSize); Food_Type ftyp = db.type_list.FirstOrDefault(typ => typ.nameType == E_DType); dishEdit = (from dish in db.dish_list where dish.Id == E_DId select dish).First(); dishEdit.name = E_Dname; dishEdit.price = E_DPrice; dishEdit.description = E_DDescription; dishEdit.imaGeURL = E_DImage; dishEdit.TypeId = ftyp.Id; dishEdit.SizeId = fsi.Id; dishEdit.stock = E_DStock; db.SaveChanges(); } }
private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSizeName.Text)) { MessageBox.Show("Name field is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSizeName.Focus(); } else { Food_Size obj = foodSizeBindingSource.Current as Food_Size; if (obj.Id == 0) { if (Food_SizeBUS.checkName(txtSizeName.Text)) { MessageBox.Show("This name is already exist", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSizeName.Focus(); } else { Food_SizeBUS.insert(obj); foodSizeBindingSource.DataSource = Food_SizeBUS.GetAll(); foodSizeBindingSource.MoveLast(); MessageBox.Show("Add successfully!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); panCRUD.Enabled = true; panSave.Enabled = false; } } else { Food_SizeBUS.edit(obj); MessageBox.Show("Update successfully!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); panCRUD.Enabled = true; panSave.Enabled = false; } } }
public static void delete(Food_Size obj) { size_act.delete(obj); }
public static void edit(Food_Size obj) { size_act.edit(obj); }
public static Food_Size insert(Food_Size obj) { return(size_act.insert(obj)); }
private void dataGird_CellClick(object sender, DataGridViewCellEventArgs e) { Food_Size obj = foodSizeBindingSource.Current as Food_Size; }
private void btnSave_Click(object sender, EventArgs e) { Food_Dish fdish = foodDishBindingSource.Current as Food_Dish; Food_Size fsize = foodSizeBindingSource.Current as Food_Size; Food_Type ftype = foodTypeBindingSource.Current as Food_Type; string sizeName = fsize.name; string typeName = ftype.nameType; string D_Name = txtD_Name.Text; double D_Price = double.Parse(txtD_Price.Text); string D_Descript = txtD_Description.Text; string D_ImageURL = fdish.imaGeURL; int D_Stock = int.Parse(txtStock.Text); int D_Id = fdish.Id; if (fdish == null) { MessageBox.Show("Nothing to edit!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error); foodDishBindingSource.DataSource = Food_DishBUS.GetAll(); return; } else { if (string.IsNullOrEmpty(txtD_Name.Text) || string.IsNullOrEmpty(txtD_Price.Text) || string.IsNullOrEmpty(txtD_Description.Text)) { MessageBox.Show("Please type all the information!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (fdish.Id == 0) { if (Food_DishBUS.chekName(txtD_Name.Text)) { MessageBox.Show("This name is already exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtD_Name.Clear(); txtD_Price.Clear(); txtD_Description.Clear(); } else { Food_DishBUS.insert(D_Name, D_Price, D_Descript, D_ImageURL, typeName, sizeName, D_Stock); MessageBox.Show("Insert successfully!", "Insert dish name", MessageBoxButtons.OK, MessageBoxIcon.Information); foodDishBindingSource.DataSource = Food_DishBUS.GetAll(); foodDishBindingSource.MoveLast(); panCRUD.Enabled = true; panFilter.Enabled = true; panSave.Enabled = false; dataGridDish.Enabled = true; } } else { Food_DishBUS.edit(fdish, D_Name, D_Price, D_Descript, D_ImageURL, typeName, sizeName, D_Id, D_Stock); MessageBox.Show("Update successfully!", "Update dish name", MessageBoxButtons.OK, MessageBoxIcon.Information); foodDishBindingSource.DataSource = Food_DishBUS.GetAll(); panCRUD.Enabled = true; panSave.Enabled = false; panFilter.Enabled = true; dataGridDish.Enabled = true; } } } }