示例#1
0
        public TaiKhoan(string MaTaiKhoan,
                        string TenDangNhap,
                        string MatKhau,
                        string quyenHan)
        {
            this.MaTaiKhoan  = MaTaiKhoan;
            this.TenDangNhap = TenDangNhap;
            this.MatKhau     = MatKhau;

            switch (quyenHan)
            {
            case "0":
            case "Admin":
                this.quyenHan = QuyenHan.Admin;
                break;

            case "1":
            case "User":
                this.quyenHan = QuyenHan.User;
                break;

            default:
                this.quyenHan = QuyenHan.Anonymous;
                break;
            }
        }
示例#2
0
        public JsonResult CapNhat(string strQuyenHan)
        {
            JavaScriptSerializer serialiser = new JavaScriptSerializer();
            QuyenHan             quyenHan   = serialiser.Deserialize <QuyenHan>(strQuyenHan);
            bool   status  = false;
            string message = string.Empty;
            ScriptFunctionsDataContext function = new ScriptFunctionsDataContext();
            QuyenHan qh = new QuyenHan()
            {
                MaQuyenHan  = quyenHan.MaQuyenHan,
                TenQuyenHan = quyenHan.TenQuyenHan,
                MaNghiepVu  = quyenHan.MaNghiepVu,
                MoTa        = quyenHan.MoTa
            };

            if (bll.CapNhat(qh) == true)
            {
                status = true;
            }

            return(Json(new
            {
                status = status
            }));
        }
示例#3
0
        public JsonResult LoadData(int page, int pageSize)
        {
            IQueryable <QuyenHan> lstQuyenHan = bll.LayTatCa() as IQueryable <QuyenHan>;

            int             totalRow = lstQuyenHan.Count();
            List <QuyenHan> lst      = new List <QuyenHan>();

            foreach (var item in lstQuyenHan)
            {
                QuyenHan nv = new QuyenHan()
                {
                    MaQuyenHan  = item.MaQuyenHan,
                    TenQuyenHan = item.TenQuyenHan,
                    MaNghiepVu  = item.MaNghiepVu,
                    MoTa        = item.MoTa
                };
                lst.Add(nv);
            }
            return(Json(new
            {
                data = lst.Skip((page - 1) * pageSize).Take(pageSize),
                total = totalRow,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public bool ThemMoi(QuyenHan item)
        {
            QuyenHanDAL dal = new QuyenHanDAL(db);

            try
            {
                if (item != null)
                {
                    if (TimKiemTheoMa(item.MaNghiepVu) != item)
                    {
                        return(dal.ThemMoi(item));
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#5
0
        public QuyenHan QuyenHanIDataReader(IDataReader Reader)
        {
            QuyenHan obj = new QuyenHan();

            obj.MaQuyenHan  = (Reader["MaQuyenHan"] is DBNull) ? int.MinValue : (int)Reader["MaQuyenHan"];
            obj.TenQuyenHan = (Reader["TenQuyenHan"] is DBNull) ? string.Empty : (string)Reader["TenQuyenHan"];
            return(obj);
        }
示例#6
0
        public ActionResult DeleteQHs(int idqh)
        {
            QuyenHan qh = db.QuyenHans.SingleOrDefault(s => s.ID == idqh);

            db.QuyenHans.Remove(qh);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#7
0
 public ActionResult EditQH(QuyenHan qh, FormCollection form)
 {
     if (ModelState.IsValid)
     {
         db.Entry(qh).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
示例#8
0
 public ActionResult CreateQH(QuyenHan qh)
 {
     if (ModelState.IsValid)
     {
         db.QuyenHans.Add(qh);
         db.SaveChanges();
         return(RedirectToAction("Index", "QuyenHan"));
     }
     return(View(qh));
 }
示例#9
0
 public bool ChinhSua(QuyenHan entity)
 {
     try
     {
         var nhom = db.QuyenHans.Find(entity.MaQuyenHan);
         nhom.TenQuyenHan = entity.TenQuyenHan;
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#10
0
        public JsonResult GetDetail(string id)
        {
            QuyenHan quyenHan = bll.TimKiemTheoMa(id);

            QuyenHan qh = new QuyenHan()
            {
                MaQuyenHan  = quyenHan.MaQuyenHan,
                TenQuyenHan = quyenHan.TenQuyenHan,
                MaNghiepVu  = quyenHan.MaNghiepVu,
                MoTa        = quyenHan.MoTa
            };

            return(Json(new
            {
                data = qh,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
示例#11
0
 public ActionResult Edit(QuyenHan qh)
 {
     if (ModelState.IsValid)
     {
         var dao    = new QuyenhanDao();
         var result = dao.ChinhSua(qh);
         if (result)
         {
             SetAlert("Cập nhật thành công", "success");
             return(RedirectToAction("Index", "QuyenHan"));
         }
         else
         {
             ModelState.AddModelError("", "Cập nhật thất bại");
         }
     }
     return(View("Index"));
 }
示例#12
0
 public ActionResult ThemMoi(QuyenHan quyenhan)
 {
     if (quyenhan.TenQuyenHan != null)
     {
         var dao = new QuyenhanDao();
         int id  = dao.ThemMoi(quyenhan);
         if (id > 0)
         {
             SetAlert("Thêm quyền thành công", "success");
             return(RedirectToAction("Index", "QuyenHan"));
         }
         else
         {
             return(RedirectToAction("ThemMoi", "QuyenHan"));
         }
     }
     return(View());
 }
示例#13
0
 public int SuaQuyenHan(QuyenHan obj)
 {
     using (SqlConnection conn = getConnect())
     {
         try
         {
             conn.Open();
             SqlCommand myCommand = new SqlCommand("Update QuyenHan set TenQuyenHan = '" + obj.TenQuyenHan + "' where MaQuyenHan = '" + obj.MaQuyenHan + "' ", conn);
             myCommand.CommandType = CommandType.Text;
             myCommand.ExecuteNonQuery();
             conn.Close();
             return(1);
         }
         catch
         {
             return(0);
         }
     }
 }
示例#14
0
 public void deleteQuyen(QuyenHan q)
 {
     try
     {
         openConnection();
         SqlCommand cmd = new SqlCommand("XoaQH", Conn);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@ID_QuyenHan", q.ID_QuyenHan);
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         new Exception("Error: " + ex.Message);
     }
     finally
     {
         closeConnection();
     }
 }
示例#15
0
 public int ThemQuyenHan(QuyenHan obj)
 {
     using (SqlConnection conn = getConnect())
     {
         try
         {
             conn.Open();
             SqlCommand myCommand = new SqlCommand("Insert into QuyenHan values('" + obj.TenQuyenHan + "') ", conn);
             myCommand.CommandType = CommandType.Text;
             myCommand.ExecuteNonQuery();
             conn.Close();
             return(1);
         }
         catch
         {
             return(0);
         }
     }
 }
示例#16
0
        public JsonResult CapNhatDanhSachNghiepVu()
        {
            ReflectionController rc = new ReflectionController();
            List <Type>          listControllerType = rc.GetControllers("ResWebsite.UI.Areas.Admin");
            List <string>        listControllerOld  = bll.LayTatCa().Select(c => c.MaNghiepVu).ToList();
            List <string>        listPermissionOld  = quyenHanBll.LayTatCa().Select(p => p.TenQuyenHan).ToList();

            foreach (var c in listControllerType)
            {
                if (!listControllerOld.Contains(c.Name))
                {
                    NghiepVu nv = new NghiepVu()
                    {
                        MaNghiepVu  = c.Name,
                        TenNghiepVu = "Chưa có mô tả",
                        GhiChu      = "Chưa có ghi chú",
                    };
                    bll.ThemMoi(nv);
                }
                List <string> listPermisson         = rc.GetActions(c);
                ScriptFunctionsDataContext function = new ScriptFunctionsDataContext();
                foreach (var p in listPermisson)
                {
                    if (!listPermissionOld.Contains(c.Name + "-" + p))
                    {
                        QuyenHan quyenHan = new QuyenHan
                        {
                            MaQuyenHan  = function.auto_maQH(),
                            TenQuyenHan = c.Name + "-" + p,
                            MoTa        = "Chưa có mô tả",
                            MaNghiepVu  = c.Name
                        };
                        quyenHanBll.ThemMoi(quyenHan);
                    }
                }
            }
            return(Json(
                       new
            {
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
示例#17
0
        public bool CapNhat(QuyenHan item)
        {
            QuyenHanDAL dal = new QuyenHanDAL(db);

            try
            {
                if (item != null)
                {
                    return(dal.CapNhat(item));
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#18
0
 public void insertQuyen(QuyenHan qh)
 {
     try
     {
         openConnection();
         SqlCommand cmd = new SqlCommand("ThemQH", Conn);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("ID_QuyenHan", qh.ID_QuyenHan);
         cmd.Parameters.AddWithValue("Them", qh.Them);
         cmd.Parameters.AddWithValue("Sua", qh.Sua);
         cmd.Parameters.AddWithValue("Xoa", qh.Xoa);
         cmd.Parameters.AddWithValue("Ad", qh.Admin);
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         new Exception("Error: " + ex.Message);
     }
     finally
     {
         closeConnection();
     }
 }
示例#19
0
        public TaiKhoan(DataRow row)
        {
            this.MaTaiKhoan  = row["MATAIKHOAN"].ToString();
            this.TenDangNhap = row["TENDANGNHAP"].ToString();
            this.MatKhau     = row["MATKHAU"].ToString();

            switch (row["QUYENHAN"].ToString())
            {
            case "0":
            case "Admin":
                this.quyenHan = QuyenHan.Admin;
                break;

            case "1":
            case "User":
                this.quyenHan = QuyenHan.User;
                break;

            default:
                this.quyenHan = QuyenHan.Anonymous;
                break;
            }
        }
示例#20
0
        public JsonResult Search(int page, int pageSize, string information)
        {
            IQueryable <QuyenHan> danhSachQuyenHan = null;

            if (string.IsNullOrEmpty(information))
            {
                danhSachQuyenHan = bll.LayTatCa() as IQueryable <QuyenHan>;
                //lstNhanVien = db.NhanViens as IQueryable<NhanVien>;
            }
            else
            {
                danhSachQuyenHan = bll.TimKiemGanDungTheoTen(information) as IQueryable <QuyenHan>;
                //lstNhanVien = db.NhanViens.Where(x => x.TenNhanVien.Contains(information)) as IQueryable<NhanVien>;
            }


            int             totalRow = danhSachQuyenHan.Count();
            List <QuyenHan> lst      = new List <QuyenHan>();

            foreach (var item in danhSachQuyenHan)
            {
                QuyenHan nv = new QuyenHan()
                {
                    MaQuyenHan  = item.MaQuyenHan,
                    TenQuyenHan = item.TenQuyenHan,
                    MaNghiepVu  = item.MaNghiepVu,
                    MoTa        = item.MoTa
                };
                lst.Add(nv);
            }
            return(Json(new
            {
                data = lst.Skip((page - 1) * pageSize).Take(pageSize),
                total = totalRow,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
示例#21
0
        public JsonResult SearchMaNghiepVu(int page, int pageSize, string information)
        {
            IQueryable <QuyenHan> danhSachQuyenHan = bll.TimKiemTheoMaNghiepVu(information) as IQueryable <QuyenHan>;
            int             totalRow = danhSachQuyenHan.Count();
            List <QuyenHan> lst      = new List <QuyenHan>();

            foreach (var item in danhSachQuyenHan)
            {
                QuyenHan nv = new QuyenHan()
                {
                    MaQuyenHan  = item.MaQuyenHan,
                    TenQuyenHan = item.TenQuyenHan,
                    MaNghiepVu  = item.MaNghiepVu,
                    MoTa        = item.MoTa
                };
                lst.Add(nv);
            }
            return(Json(new
            {
                data = lst.Skip((page - 1) * pageSize).Take(pageSize),
                total = totalRow,
                status = true
            }, JsonRequestBehavior.AllowGet));
        }
示例#22
0
 public void editQuyen(QuyenHan q)
 {
     try
     {
         //string query = "update QUYENHAN set Them = @Them, Sua = @Sua, Xoa = @Xoa, Ad = @Ad where MaQuyen = @MaQuyen";
         openConnection();
         SqlCommand cmd = new SqlCommand("SuaQH", Conn);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@ID_QuyenHan", q.ID_QuyenHan);
         cmd.Parameters.AddWithValue("@Them", q.Them);
         cmd.Parameters.AddWithValue("@Sua", q.Sua);
         cmd.Parameters.AddWithValue("@Xoa", q.Xoa);
         cmd.Parameters.AddWithValue("@Ad", q.Admin);
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         new Exception("Error: " + ex.Message);
     }
     finally
     {
         closeConnection();
     }
 }
示例#23
0
 public int ThemMoi(QuyenHan ma)
 {
     db.QuyenHans.Add(ma);
     db.SaveChanges();
     return(ma.MaQuyenHan);
 }
示例#24
0
        // -------------------------------------------------------------------------------
        public ActionResult DeleteQH(int idqh)
        {
            QuyenHan qh = db.QuyenHans.SingleOrDefault(s => s.ID == idqh);

            return(View(qh));
        }
示例#25
0
 public TaiKhoan()
 {
     this.quyenHan = QuyenHan.Anonymous;
 }