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 ShowProductList() { var db = new MondayEntities(); var list = db.sanphams.ToList(); this.grd_pick.DataSource = list; this.grd_pick.Columns["id"].Visible = false; // hide the id column this.grd_pick.Columns["Product"].Visible = false; // hide column }
private void FormEdit_Load(object sender, EventArgs e) { MondayEntities db = new MondayEntities(); this.sanphamBindingSource.DataSource = db.sanphams.ToList(); this.sanpham.ValueMember = "id"; // set value column this.sanpham.DisplayMember = "Name"; // set display column this.txtName.Text = sanpham.nameproduct; this.txtID.Text = sanpham.id.ToString(); this.TxtPrice.Text = sanpham.price.ToString(); this.txtsoluong.Text = sanpham.soluong.ToString(); }
private void btnSave_Click(object sender, EventArgs e) { try { var db = new MondayEntities(); var newSanpham = db.sanphams.Find(this.sanpham.id); newSanpham.nameproduct = this.txtName.Text; newSanpham.id = int.Parse(this.txtID.Text); newSanpham.price = int.Parse(this.TxtPrice.Text); newSanpham.soluong = int.Parse(this.txtsoluong.Text); db.Entry(newSanpham).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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); } }
private void FormAdd_Load(object sender, EventArgs e) { MondayEntities db = new MondayEntities(); this.sanphamBindingSource.DataSource = db.sanphams.ToList(); }