private void button1_Click(object sender, EventArgs e) { if (txtMaLop.Text.Trim() == "") { MessageBox.Show("Chưa nhập mã lớp", "Thông báo"); } else { if (context.tblLOPs.Find(txtMaLop.Text.Trim()) != null) { MessageBox.Show("Mã lớp đã tồn tại", "Thông báo"); } else { tblLOP g = new tblLOP(); g.MaLop = txtMaLop.Text; g.MaKhoa = cboKhoa.Text; g.TenLop = txtTenlop.Text; var result = new LOPF().Insert(g); dgrLop.DataSource = context.tblLOPs.ToList(); txtMaLop.Clear(); txtTenlop.Clear(); cboKhoa.Text = ""; } } }
public bool Delete(tblLOP model) { tblLOP dbEntry = context.tblLOPs.Find(model.MaLop); if (dbEntry == null) { return(false); } context.tblLOPs.Remove(dbEntry); context.SaveChanges(); return(true); }
public bool Insert(tblLOP model) { tblLOP dbEntry = context.tblLOPs.Find(model.MaLop); if (dbEntry != null) { return(false); } context.tblLOPs.Add(model); context.SaveChanges(); return(true); }
private void button2_Click(object sender, EventArgs e) { string id = txtMaLop.Text.Trim(); if (MessageBox.Show(string.Format("Sửa lớp có mã '{0}'?", id), "", MessageBoxButtons.OKCancel) == DialogResult.OK) { tblLOP g = new tblLOP(); g.MaLop = txtMaLop.Text; g.MaKhoa = cboKhoa.Text; g.TenLop = txtTenlop.Text; var result = new LOPF().Update(g); dgrLop.DataSource = context.tblLOPs.ToList(); } }
public bool Update(tblLOP model) { tblLOP dbEntry = context.tblLOPs.Find(model.MaLop); if (dbEntry == null) { return(false); } dbEntry.MaLop = model.MaLop; dbEntry.TenLop = model.TenLop; dbEntry.MaKhoa = model.MaKhoa; context.SaveChanges(); return(true); }
public tblLOP FindEntity(string ID) { tblLOP dbEntry = context.tblLOPs.Find(ID); return(dbEntry); }