//Thêm public bool them_NoiQuy(NOIQUY nq) { try { data.NOIQUYs.InsertOnSubmit(nq); data.SubmitChanges(); return(true); } catch { return(false); } }
//Xóa public bool xoa_NoiQuy(string pMaNQ) { try { NOIQUY nq = data.NOIQUYs.Where(t => t.MANOIQUY == pMaNQ).FirstOrDefault(); data.NOIQUYs.DeleteOnSubmit(nq); data.SubmitChanges(); return(true); } catch { return(false); } }
//Sửa public bool sua_NoiQuy(NOIQUY pNoiQuy) { try { NOIQUY nq = data.NOIQUYs.Where(t => t.MANOIQUY == pNoiQuy.MANOIQUY).FirstOrDefault(); if (nq != null) { nq.NOIDUNG = pNoiQuy.NOIDUNG; nq.HINHPHAT = pNoiQuy.HINHPHAT; data.SubmitChanges(); } return(true); } catch { return(false); } }
private void grv_noiquy_Click(object sender, EventArgs e) { NOIQUY nq = new NOIQUY(); btn_xoa.Enabled = btn_sua.Enabled = btn_huy.Enabled = true; btn_them.Enabled = false; int position = gridView_noiquy.FocusedRowHandle; try { nq.NOIDUNG = gridView_noiquy.GetRowCellValue(position, "NOIDUNG").ToString(); nq.MANOIQUY = gridView_noiquy.GetRowCellValue(position, "MANOIQUY").ToString(); nq.HINHPHAT = gridView_noiquy.GetRowCellValue(position, "HINHPHAT").ToString(); txt_manoiquy.Text = nq.MANOIQUY.ToString(); txt_hinhphat.Text = nq.HINHPHAT.ToString(); txt_noidung.Text = nq.NOIDUNG.ToString(); } catch { } }
private void btn_luu_Click(object sender, EventArgs e) { NOIQUY nq = new NOIQUY(); if (btn_them.Enabled == true) { nq.MANOIQUY = txt_manoiquy.Text; nq.NOIDUNG = txt_noidung.Text; nq.HINHPHAT = txt_hinhphat.Text; if (txt_manoiquy.Text == string.Empty && txt_noidung.Text == string.Empty && txt_hinhphat.Text == string.Empty) { MessageBox.Show("không được để trống"); return; } //kiểm tra khóa chính if (noiquy.ktkc_NoiQuy(nq.MANOIQUY) == true) { MessageBox.Show("Trùng khóa chính"); return; } if (noiquy.them_NoiQuy(nq) == true) { grv_noiquy.DataSource = noiquy.loadBang_NoiQuy(); MessageBox.Show("Thành công"); } else { MessageBox.Show("Thất bại"); } frm_noiquy_Load(sender, e); } if (btn_sua.Enabled == true) { try { if (txt_hinhphat.Text == string.Empty) { MessageBox.Show("Hình phạt không được để trống"); return; } if (txt_noidung.Text == string.Empty) { MessageBox.Show("Nội dung không được để trống"); return; } nq.MANOIQUY = txt_manoiquy.Text; nq.NOIDUNG = txt_noidung.Text; nq.HINHPHAT = txt_hinhphat.Text; if (noiquy.sua_NoiQuy(nq) == true) { grv_noiquy.DataSource = noiquy.loadBang_NoiQuy(); MessageBox.Show("Thành công"); } } catch { MessageBox.Show("thất bại"); } } frm_noiquy_Load(sender, e); }
//Sửa public bool sua_NoiQuy(NOIQUY pNoiQuy) { return(noiquy.sua_NoiQuy(pNoiQuy)); }
//Thêm public bool them_NoiQuy(NOIQUY pNoiQuy) { return(noiquy.them_NoiQuy(pNoiQuy)); }