示例#1
0
 public Frm_edit(int id)
 {
     InitializeComponent();
     db         = new CAKEMANAGEMENTEntities();
     cake       = db.cakes.Single(cake => cake.id == id);
     this.Load += Form3_Load;
 }
        private void btn_save_Click(object sender, EventArgs e)
        {
            cake cake = new cake();

            cake.cakename    = txt_cakeName.Text;
            cake.id_cakekind = (int)Cbb_kindName.SelectedValue;
            CAKEMANAGEMENTEntities db = new CAKEMANAGEMENTEntities();

            db.cakes.Add(cake);
            db.SaveChanges();
            MessageBox.Show("Thêm bánh mới thành công");
            this.Close();
        }
示例#3
0
        private void dELETEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dtgBakery.SelectedRows.Count == 1)
            {
                var row  = dtgBakery.SelectedRows[0];
                var cell = row.Cells["id"];
                int id   = (int)cell.Value;

                db = new CAKEMANAGEMENTEntities();
                cake cake = db.cakes.Where(ca => ca.id == id).ToList()[0];
                db.cakes.Remove(cake);
                db.SaveChanges();
                MessageBox.Show("Xóa bánh Thành công");
            }
            else
            {
                MessageBox.Show("Mời bạn chọn 1 dòng");
            }
            LoadDB();
        }