private void button1_Click(object sender, EventArgs e) { try { String s = dM_MANHINHDataGridView.CurrentRow.Cells[0].Value.ToString(); String v = qL_NHOMNDComboBox.SelectedValue.ToString(); var kt = from pqu in ql.QL_PHANQUYENs where pqu.MANHOM == v && pqu.MAMANHINH == s select pqu; if (kt.Count() > 0) { MessageBox.Show("trùng "); return; } QL_PHANQUYEN pq = new QL_PHANQUYEN(); pq.MAMANHINH = s; pq.MANHOM = v; ql.QL_PHANQUYENs.InsertOnSubmit(pq); ql.SubmitChanges(); loaddl(); MessageBox.Show("Thành công"); } catch { MessageBox.Show("thất bại"); } }
public bool XoaPhanQuyenUser(string ma) { try { QL_PHANQUYEN p = qlkho.QL_PHANQUYENs.Where(t => t.TENDANGNHAP == ma).FirstOrDefault(); qlkho.QL_PHANQUYENs.DeleteOnSubmit(p); qlkho.SubmitChanges(); return(true); } catch { return(false); } }
public bool PhanQuyenUser(QL_PHANQUYEN pq) { try { qlkho.QL_PHANQUYENs.InsertOnSubmit(pq); qlkho.SubmitChanges(); return(true); } catch { return(false); } }
private void btnThem_Click(object sender, EventArgs e) { if (txtTenTaiKhoan.Text == string.Empty) { MessageBox.Show("Bạn chưa nhập tên tài khoản"); txtTenTaiKhoan.Focus(); return; } if (txtMatKhau.Text == string.Empty) { MessageBox.Show("Bạn chưa nhập mật khẩu"); txtMatKhau.Focus(); return; } else { QL_NGUOIDUNG user = new QL_NGUOIDUNG(); user.TENDANGNHAP = txtTenTaiKhoan.Text.Trim(); user.MATKHAU = txtMatKhau.Text.Trim(); if (qlnd.ThemNguoiDung(user)) { QL_PHANQUYEN pq = new QL_PHANQUYEN(); pq.TENDANGNHAP = user.TENDANGNHAP; if (radiobtAdmin.Checked == true) { pq.MANHOM = "ad"; } else { pq.MANHOM = "nv"; } if (qlnd.PhanQuyenUser(pq)) { MessageBox.Show("Bạn đã thêm người dùng " + user.TENDANGNHAP); txtTenTaiKhoan.Text = string.Empty; txtMatKhau.Text = string.Empty; txtTenTaiKhoan.Focus(); } else { MessageBox.Show("Thêm thất bại"); } } else { MessageBox.Show("Đã có tài khoản"); } } }