private void btnXoa_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn có chắc chắn muốn xoá lớp học phần này?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DataLopHPDataContext db = new DataLopHPDataContext(); try { var r = from hp in db.tblLopHPs where hp.maLHP.ToString().Contains(txtMaLHP.Text.ToString()) select hp; db.tblLopHPs.DeleteAllOnSubmit(r); db.SubmitChanges(); LoadData(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnThem_Click(object sender, EventArgs e) { try { DataLopHPDataContext db = new DataLopHPDataContext(); lhp.maHP = txtMaHP.Text; lhp.maLHP = txtMaLHP.Text; lhp.tenLHP = txtTenLHP.Text; lhp.maGV = txtGV.Text; lhp.maHK = int.Parse(txtMaHK.Text); lhp.sSMax = int.Parse(txtSSMax.Text); lhp.sSDK = int.Parse(txtSSDK.Text); db.tblLopHPs.InsertOnSubmit(lhp); db.SubmitChanges(); MessageBox.Show("Đã thêm"); LoadData(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSua_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn có muốn sửa lớp học phần này?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { DataLopHPDataContext db = new DataLopHPDataContext(); lhp = db.tblLopHPs.Where(s => s.maLHP == txtMaLHP.Text.ToString()).Single(); lhp.maHP = txtMaHP.Text; lhp.tenLHP = txtTenLHP.Text; lhp.maHK = int.Parse(txtMaHK.Text); lhp.sSMax = int.Parse(txtSSMax.Text); lhp.sSDK = int.Parse(txtSSDK.Text); db.SubmitChanges(); LoadData(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }