private void btnSua_Click(object sender, EventArgs e) { if (CNguoiDung.CheckQuyen(_mnu, "Sua")) { if (_selectedindex != -1) { Nhom nhom = _cNhom.GetByMaNhom(int.Parse(dgvNhom["MaNhom", _selectedindex].Value.ToString())); nhom.TenNhom = txtTenNhom.Text.Trim(); _cNhom.Sua(nhom); DataTable dt = ((DataView)gridView.DataSource).Table; foreach (DataRow item in dt.Rows) { PhanQuyenNhom phanquyennhom = _cPhanQuyenNhom.GetByMaMenuMaNhom(int.Parse(item["MaMenu"].ToString()), nhom.MaNhom); if (phanquyennhom.Xem != bool.Parse(item["Xem"].ToString()) || phanquyennhom.Them != bool.Parse(item["Them"].ToString()) || phanquyennhom.Sua != bool.Parse(item["Sua"].ToString()) || phanquyennhom.Xoa != bool.Parse(item["Xoa"].ToString()) || phanquyennhom.QuanLy != bool.Parse(item["QuanLy"].ToString())) { phanquyennhom.Xem = bool.Parse(item["Xem"].ToString()); phanquyennhom.Them = bool.Parse(item["Them"].ToString()); phanquyennhom.Sua = bool.Parse(item["Sua"].ToString()); phanquyennhom.Xoa = bool.Parse(item["Xoa"].ToString()); phanquyennhom.QuanLy = bool.Parse(item["QuanLy"].ToString()); _cPhanQuyenNhom.Sua(phanquyennhom); } } Clear(); MessageBox.Show("Thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Bạn không có quyền Thêm Sửa này", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnThem_Click(object sender, EventArgs e) { if (CNguoiDung.CheckQuyen(_mnu, "Them")) { if (txtTenNhom.Text.Trim() != "") { Nhom nhom = new Nhom(); nhom.TenNhom = txtTenNhom.Text.Trim(); ///tự động thêm quyền cho nhóm mới foreach (var item in _cMenu.GetDS()) { PhanQuyenNhom phanquyennhom = new PhanQuyenNhom(); phanquyennhom.MaMenu = item.MaMenu; phanquyennhom.MaNhom = nhom.MaNhom; nhom.PhanQuyenNhoms.Add(phanquyennhom); } _cNhom.Them(nhom); Clear(); MessageBox.Show("Thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Bạn không có quyền Thêm Form này", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//2. update quyen public bool update_Quyen(int idNhom, int idManHinh, bool Quyen) { PhanQuyenNhom pqn = db.PhanQuyenNhoms.Single(p => p.id_nhom_nguoi_dung == idNhom && p.id_man_hinh == idManHinh); pqn.quyen = Quyen; db.SubmitChanges(); return(true); }
private void btnCapNhatMenu_Click(object sender, EventArgs e) { frmMain frm = new frmMain(); foreach (ToolStripMenuItem itemParent in frm.MainMenuStrip.Items) { int STT = 1; if (itemParent.Name == "mnuHeThong") { continue; } foreach (ToolStripMenuItem itemChild in itemParent.DropDownItems) { if (!_cMenu.CheckExistByTenMenu(itemChild.Name)) { Database.Menu menu = new Database.Menu(); menu.STT = STT++; menu.TenMenu = itemChild.Name; menu.TextMenu = itemChild.Text; menu.TenMenuCha = itemParent.Name; menu.TextMenuCha = itemParent.Text; foreach (var item in _cNhom.GetDS()) { PhanQuyenNhom phanquyennhom = new PhanQuyenNhom(); phanquyennhom.MaMenu = menu.MaMenu; phanquyennhom.MaNhom = item.MaNhom; phanquyennhom.CreateBy = CNguoiDung.MaND; phanquyennhom.CreateDate = DateTime.Now; menu.PhanQuyenNhoms.Add(phanquyennhom); } foreach (var item in _cNguoiDung.GetDS()) { PhanQuyenNguoiDung phanquyennguoidung = new PhanQuyenNguoiDung(); phanquyennguoidung.MaMenu = menu.MaMenu; phanquyennguoidung.MaND = item.MaND; phanquyennguoidung.CreateBy = CNguoiDung.MaND; phanquyennguoidung.CreateDate = DateTime.Now; if (item.MaND == 0) { phanquyennguoidung.Xem = true; phanquyennguoidung.Them = true; phanquyennguoidung.Sua = true; phanquyennguoidung.Xoa = true; } menu.PhanQuyenNguoiDungs.Add(phanquyennguoidung); } _cMenu.Them(menu); } else { Database.Menu menu = _cMenu.GetByTenMenu(itemChild.Name); menu.STT = STT++; _cMenu.Sua(menu); } } } }
public bool Xoa(PhanQuyenNhom phanquyennhom) { try { _db.PhanQuyenNhoms.DeleteOnSubmit(phanquyennhom); _db.SubmitChanges(); return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Thông Báo", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return(false); } }
public bool Sua(PhanQuyenNhom phanquyennhom) { try { phanquyennhom.ModifyDate = DateTime.Now; phanquyennhom.ModifyBy = CNguoiDung.MaND; _db.SubmitChanges(); return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Thông Báo", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return(false); } }
private void btnCapNhatPhanQuyenNhom_Click(object sender, EventArgs e) { foreach (var itemMenu in _cMenu.GetDS()) { foreach (var itemNhom in _cNhom.GetDS()) { if (!_cPhanQuyenNhom.CheckByMaMenuMaNhom(itemMenu.MaMenu, itemNhom.MaNhom)) { PhanQuyenNhom phanquyennhom = new PhanQuyenNhom(); phanquyennhom.MaMenu = itemMenu.MaMenu; phanquyennhom.MaNhom = itemNhom.MaNhom; _cPhanQuyenNhom.Them(phanquyennhom); } } } }
public bool Them(PhanQuyenNhom phanquyennhom) { try { phanquyennhom.CreateDate = DateTime.Now; phanquyennhom.CreateBy = CNguoiDung.MaND; _db.PhanQuyenNhoms.InsertOnSubmit(phanquyennhom); _db.SubmitChanges(); return(true); } catch (Exception ex) { Refresh(); System.Windows.Forms.MessageBox.Show(ex.Message, "Thông Báo", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return(false); } }