private void btnDelete_Click(object sender, EventArgs e) { var db = new MondayEntities(); if (MessageBox.Show("Do you want to delete", "Confirm", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { for (int i = 0; i < this.grd_pick.SelectedRows.Count; i++) { var row = this.grd_pick.SelectedRows[i]; var item = (sanpham)row.DataBoundItem; try { sanpham sp = db.sanphams.Find(item.id); db.sanphams.Remove(sp); db.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Cannot deletclass: " + item.id); } this.ShowProductList(); } } }
private void btnAdd_Click(object sender, EventArgs e) { sanpham sanpham = new sanpham(); sanpham.nameproduct = this.txtName.Text; sanpham.price = int.Parse(this.TxtPrice.Text); sanpham.soluong = int.Parse(this.txtsoluong.Text); sanpham.id = int.Parse(this.txtID.Text); try { MondayEntities db = new MondayEntities(); db.sanphams.Add(sanpham); db.SaveChanges(); this.Close(); MessageBox.Show("Thêm Sản phẩm Thành Công!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public FormEdit(sanpham sanpham) { InitializeComponent(); this.sanpham = sanpham; }