private void button1_Click(object sender, EventArgs e) { if (txtMaMon.Text.Trim() == "") { MessageBox.Show("Mã lớp chưa nhập", "Thông báo"); } else { if (context.tblMONs.Find(txtMaMon.Text) != null) { MessageBox.Show("Mã môn đã tồn tại", "Thông báo"); } else { tblMON m = new tblMON(); m.TenMon = txtTenMon.Text; m.SoDVHT = Convert.ToInt32(numsdvht.Text); m.MaMon = txtMaMon.Text; m.MaKhoa = cboKhoa.Text; m.HocKi = txtHocKy.Text; MONHOCF mh = new MONHOCF(); mh.Insert(m); dgrMON.DataSource = context.tblMONs.ToList(); txtHocKy.Clear(); txtMaMon.Clear(); numsdvht.Value = 0; txtTenMon.Clear(); cboKhoa.Text = ""; } } }
public bool Delete(tblMON model) { tblMON re = context.tblMONs.Find(model.MaMon); if (re == null) { return(false); } context.tblMONs.Remove(re); context.SaveChanges(); return(true); }
public bool Insert(tblMON model) { tblMON result = context.tblMONs.Find(model.MaMon); if (result != null) { return(false); } context.tblMONs.Add(model); context.SaveChanges(); return(true); }
public bool Update(tblMON model) { tblMON re = context.tblMONs.Find(model.MaMon); if (re == null) { return(false); } re.MaMon = model.MaMon; re.MaKhoa = model.MaKhoa; re.SoDVHT = model.SoDVHT; re.HocKi = model.HocKi; re.TenMon = model.TenMon; context.SaveChanges(); return(true); }
private void button2_Click(object sender, EventArgs e) { string id = txtMaMon.Text.Trim(); if (MessageBox.Show(string.Format("Sửa môn học có mã '{0}'?", id), "", MessageBoxButtons.OKCancel) == DialogResult.OK) { tblMON m = new tblMON(); m.TenMon = txtTenMon.Text; m.SoDVHT = Convert.ToInt32(numsdvht.Text); m.MaMon = txtMaMon.Text; m.MaKhoa = cboKhoa.Text; m.HocKi = txtHocKy.Text; MONHOCF mh = new MONHOCF(); mh.Update(m); dgrMON.DataSource = context.tblMONs.ToList(); } }
public tblMON FindEntity(string id) { tblMON result = context.tblMONs.Find(id); return(result); }