Beispiel #1
0
        public List <QuanTriVien> DangNhap(QuanTriVien qtvien)
        {
            List <QuanTriVien> dsQuanTriVien = new List <QuanTriVien>();

            OpenConnection();
            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = "select TenDangNhap,MatKhau,Quyen,Id from QuanTriVien " +
                                  "where TenDangNhap='" + qtvien.TenDangNhap + "' and MatKhau='" + qtvien.MatKhau + "' ";
            command.Connection = conn;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                string tendangnhap = reader.GetString(0);
                string matkhau     = reader.GetString(1);
                string quyen       = reader.GetString(2);
                int    id          = reader.GetInt32(3);

                QuanTriVien qtv = new QuanTriVien();

                qtv.TenDangNhap = tendangnhap;
                qtv.MatKhau     = matkhau;
                qtv.Quyen       = quyen;
                qtv.ID          = id;

                dsQuanTriVien.Add(qtv);
            }
            return(dsQuanTriVien);
        }
        protected void QuanLyPhongMuon()
        {
            QuanTriVien _QuanTriVien = QuanTriVien.getByUserName(Convert.ToString(Session["UserName"]));

            ListPhieuMuonPhong = PhieuMuonPhong.getQuery().Where(c => c.nguoimuon.id == _QuanTriVien.id).ToList();
            if (ListPhieuMuonPhong.Count > 0)
            {
                CollectionPagerQuanLyPhongBanMuon.DataSource    = ListPhieuMuonPhong;
                CollectionPagerQuanLyPhongBanMuon.BindToControl = RepeaterQuanLyMuonPhong;
                RepeaterQuanLyPhongBanMuon.DataSource           = CollectionPagerQuanLyPhongBanMuon.DataSourcePaged;
                RepeaterQuanLyPhongBanMuon.DataBind();

                PanelQuanLyPhongBanMuon.Visible = true;
            }

            if (PermissionHelper.QuyenQuanLyMuonPhong())
            {
                lidanhsachgiangvienmuonphong.Visible = true;
                ListPhieuMuonPhong = PhieuMuonPhong.getQuery().OrderByDescending(c => c.id).ToList();
                if (ListPhieuMuonPhong.Count > 0)
                {
                    CollectionPagerQuanLyMuonPhong.DataSource    = ListPhieuMuonPhong;
                    CollectionPagerQuanLyMuonPhong.BindToControl = RepeaterQuanLyMuonPhong;
                    RepeaterQuanLyMuonPhong.DataSource           = CollectionPagerQuanLyMuonPhong.DataSourcePaged;
                    RepeaterQuanLyMuonPhong.DataBind();

                    PanelQuanLyMuonPhong.Visible = true;
                }
            }
        }
Beispiel #3
0
        public ActionResult Login(FormCollection collection)
        {
            var tendn   = collection["username"];
            var matkhau = collection["password"];

            if (String.IsNullOrEmpty(tendn))
            {
                ViewData["Loi1"] = "Phải nhập tên đăng nhập";
            }
            else if (String.IsNullOrEmpty(matkhau))
            {
                ViewData["Loi2"] = "Phải nhập mật khẩu";
            }
            else
            {
                QuanTriVien ad = data.QuanTriViens.SingleOrDefault(n => n.TenDangNhap == tendn && n.MatKhau == matkhau);
                if (ad != null)
                {
                    Session["Taikhoanadmin"] = ad;
                    return(RedirectToAction("Index", "Admin"));
                }
                else
                {
                    ViewBag.Thongbao = "Tên đăng nhập hoặc mật khẩu không đúng";
                }
            }
            return(View());
        }
Beispiel #4
0
 public void loadData(List <ViTriHienThi> list, QuanTriVien quantrivien)
 {
     try
     {
         treeListPhong.BeginUnboundLoad();
         treeListPhong.DataSource = list;
         treeListPhong.EndUnboundLoad();
         List <Phong> _list = quantrivien.phongs.ToList();
         foreach (Phong p in _list)
         {
             if (!p.id.Equals(Guid.Empty))
             {
                 TreeListNode node = treeListPhong.FindNodeByKeyID(p.id);
                 if (node != null)
                 {
                     treeListPhong.SetNodeCheckState(node, CheckState.Checked, true);
                     node.Selected = true;
                 }
             }
         }
         if (treeListPhong.Nodes.Count > 0)
         {
             treeListPhong.FocusedNode = treeListPhong.Nodes[0];
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->loadData: " + ex.Message);
     }
 }
Beispiel #5
0
        public int Create(TaiKhoanDTO account)
        {
            QuanTriVien qtv = db.QuanTriVien.Where(q => q.TaiKhoan.ToUpper().Trim() == account.TaiKhoan.ToUpper().Trim()).FirstOrDefault();

            if (qtv != null)
            {
                return(0);
            }
            else
            {
                qtv             = new QuanTriVien();
                qtv.DiaChi      = account.DiaChi;
                qtv.Email       = account.Email;
                qtv.IdQuyen     = account.IdQuyen;
                qtv.MatKhau     = account.MatKhau;
                qtv.SoDienThoai = account.SoDienThoai;
                qtv.TaiKhoan    = account.TaiKhoan;
                qtv.Ten         = account.Ten;
                if (account.TrangThai == 1)
                {
                    qtv.TrangThai = true;
                }
                else
                {
                    qtv.TrangThai = false;
                }
                db.QuanTriVien.Add(qtv);
                db.SaveChanges();
                return(1);
            }
        }
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            NguoiMuonSach nms = new NguoiMuonSach();

            nms.Id          = int.Parse(txtMa.Text);
            nms.HoTen       = txtTen.Text;
            nms.NamSinh     = int.Parse(txtNamSinh.Text);
            nms.SoDienThoai = txtSoDienThoai.Text;
            nms.DiaChi      = txtDiaChi.Text;
            nms.Email       = txtEmail.Text;
            NguoiMuonSachBLL nmsbll     = new NguoiMuonSachBLL();
            bool             capnhatnms = nmsbll.CapNhatDocGia(nms);

            QuanTriVien qtv = new QuanTriVien();

            qtv.DiaChi      = txtDiaChi.Text;
            qtv.Email       = txtEmail.Text;
            qtv.ID          = int.Parse(txtMa.Text);
            qtv.NamSinh     = int.Parse(txtNamSinh.Text);
            qtv.SoDienThoai = txtSoDienThoai.Text;
            qtv.HoTen       = txtTen.Text;
            QuanTriVienBLL qtvbll     = new QuanTriVienBLL();
            bool           capnhatqtv = qtvbll.ChinhSuaQuanTriVien(qtv);


            if (capnhatnms && capnhatqtv)
            {
                MessageBox.Show("Đã Thay Đổi Thành Công, Nhấn Cập Nhật Nhé ...", "Thông Báo");
                this.Close();
            }
        }
Beispiel #7
0
 /// <summary>
 /// Goi hien thi len Panel Thong tin chi tiet
 /// </summary>
 /// <param name="objQuanTriVienFilter"></param>
 private void setThongTinChiTiet(QuanTriVien obj)
 {
     try
     {
         if (obj == null)
         {
             return;
         }
         txtMaQuanTriVien.Text       = obj.subId;
         txtTaiKhoanQuanTriVien.Text = obj.username;
         txtTenQuanTriVien.Text      = obj.hoten;
         txtMatKhauQuanTriVien.Text  = txtXacNhanMK.Text = "";
         memoEdit_mota.Text          = obj.mota;
         dateCreated.DateTime        = (DateTime)(obj.date_create == null ? ServerTimeHelper.getNow() : obj.date_create);
         if (obj.group != null)
         {
             lookUpEdit_group.EditValue = obj.group.id;
         }
         editGUI("view");
         dxErrorProvider1.ClearErrors();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setThongTinChiTiet: " + ex.Message);
     }
 }
        private void DangKyUser()
        {
            QuanTriVien qtvien = new QuanTriVien();

            qtvien.HoTen       = txtTen.Text;
            qtvien.NamSinh     = int.Parse(txtNamSinh.Text);
            qtvien.TenDangNhap = txtTenDangNhap.Text;
            qtvien.SoDienThoai = txtSoDienThoai.Text;
            qtvien.Email       = txtEmail.Text;
            qtvien.DiaChi      = txtDiaChi.Text;
            qtvien.MatKhau     = txtMatKhau1.Text;
            qtvien.KeyRestore  = "resetpassword";
            qtvien.Quyen       = "User";

            QuanTriVienBLL qtvbbl    = new QuanTriVienBLL();
            bool           qtvienbll = qtvbbl.DangKy(qtvien);

            NguoiMuonSach nms = new NguoiMuonSach();

            nms.HoTen       = txtTen.Text;
            nms.SoDienThoai = txtSoDienThoai.Text;
            nms.DiaChi      = txtDiaChi.Text;
            nms.Email       = txtEmail.Text;
            nms.NamSinh     = int.Parse(txtNamSinh.Text);

            NguoiMuonSachBLL nmsbll = new NguoiMuonSachBLL();
            bool             nmsnew = nmsbll.ThemDocGia(nms);

            if (qtvienbll && nmsnew)
            {
                MessageBox.Show("Đăng Ký Thành Công", "Thông Báo");
                this.Close();
            }
        }
Beispiel #9
0
 private void setDataView()
 {
     try
     {
         if (gridViewQuanTriVien.RowCount > 0)
         {
             if (gridViewQuanTriVien.FocusedRowHandle > -1 && gridViewQuanTriVien.GetFocusedRow() != null)
             {
                 objQuanTriVien          = gridViewQuanTriVien.GetFocusedRow() as QuanTriVien;
                 txtMa.Text              = objQuanTriVien.subId;
                 txtTen.Text             = objQuanTriVien.hoten;
                 txtUsername.Text        = objQuanTriVien.username;
                 txtMota.Text            = objQuanTriVien.mota;
                 listPhong               = objQuanTriVien.phongs.ToList();
                 listBoxPhong.DataSource = listPhong;
             }
             else
             {
                 clearText();
                 objQuanTriVien = new QuanTriVien();
             }
         }
         else
         {
             clearText();
             objQuanTriVien = new QuanTriVien();
         }
         checkPermission();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setDataView: " + ex.Message);
     }
 }
Beispiel #10
0
        private void btnUser_Click(object sender, EventArgs e)
        {
            QuanTriVien qtv = new QuanTriVien();

            qtv.Quyen = "User";

            QuanTriVienBLL     qtvbll         = new QuanTriVienBLL();
            List <QuanTriVien> dsquanntrivien = qtvbll.TimQTVTheoQuyen(qtv);

            lvQuanTriVienDS.Items.Clear();
            foreach (QuanTriVien qtvien in dsquanntrivien)
            {
                ListViewItem lvi = new ListViewItem(qtvien.HoTen);
                lvi.SubItems.Add(qtvien.SoDienThoai);
                lvi.SubItems.Add(qtvien.TenDangNhap);
                lvi.SubItems.Add(qtvien.Quyen);
                lvi.SubItems.Add(qtvien.Email);
                lvi.SubItems.Add(qtvien.NamSinh + "");
                lvi.SubItems.Add(qtvien.DiaChi);
                lvi.SubItems.Add(qtvien.ID + "");
                lvi.SubItems.Add(qtvien.KeyRestore);
                lvi.SubItems.Add(qtvien.MatKhau);
                lvi.SubItems.Add(qtvien.Quyen);
                lvQuanTriVienDS.Items.Add(lvi);
            }
        }
Beispiel #11
0
        private void ThemMoiDG()
        {
            NguoiMuonSach nms = new NguoiMuonSach();

            nms.HoTen       = txtTen.Text;
            nms.NamSinh     = int.Parse(txtNamSinh.Text);
            nms.SoDienThoai = txtSoDienThoai.Text;
            nms.DiaChi      = txtDiaChi.Text;
            nms.Email       = txtEmail.Text;

            NguoiMuonSachBLL nmsbll = new NguoiMuonSachBLL();
            bool             nmsnew = nmsbll.ThemDocGia(nms);

            QuanTriVien qtv = new QuanTriVien();

            qtv.HoTen       = txtTen.Text;
            qtv.NamSinh     = int.Parse(txtNamSinh.Text);
            qtv.TenDangNhap = txtTenDangNhap.Text;
            qtv.SoDienThoai = txtSoDienThoai.Text;
            qtv.Email       = txtEmail.Text;
            qtv.DiaChi      = txtDiaChi.Text;
            qtv.MatKhau     = txtPass.Text;
            qtv.KeyRestore  = "123";
            qtv.Quyen       = "User";

            QuanTriVienBLL qtvbll = new QuanTriVienBLL();
            bool           qtvnew = qtvbll.ThemQuanTriVien(qtv);

            if (nmsnew && qtvnew)
            {
                MessageBox.Show("Nhấn Nút Cập Nhật Nhé.", "Thông Báo");
                this.Close();
            }
        }
Beispiel #12
0
        public async Task <IActionResult> UpdateTtDangNhap(TtDangNhapViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Thông tin không hợp lệ");
                }
                QuanTriVien _qtv = await uManager.FindByIdAsync(viewModel.Qtv.Id);

                if (_qtv == null)
                {
                    throw new Exception("Không tìm thấy quản trị viên");
                }
                _qtv.HoDem       = viewModel.Qtv.HoDem;
                _qtv.Ten         = viewModel.Qtv.Ten;
                _qtv.GioiTinh    = viewModel.Qtv.GioiTinh;
                _qtv.NoiSinh     = viewModel.Qtv.NoiSinh;
                _qtv.PhoneNumber = viewModel.Qtv.PhoneNumber;
                _qtv.UserName    = viewModel.Qtv.UserName;
                await uManager.UpdateAsync(_qtv);

                _context.SaveChanges();
            }
            catch (Exception err) { ModelState.AddModelError("", err.Message); }
            return(View("TtDangNhap", viewModel));
        }
 protected override void OnInit(EventArgs e)
 {
     if (!Convert.ToString(Session["Username"]).Equals(String.Empty))
     {
         PTB.Global.current_quantrivien_login = QuanTriVien.getByUserName(Session["UserName"].ToString());
     }
 }
Beispiel #14
0
        public List <QuanTriVien> KiemTraKey(QuanTriVien qtvien)
        {
            List <QuanTriVien> dsQuanTriVien = new List <QuanTriVien>();

            OpenConnection();
            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = "select TenDangNhap,KeyRestore from QuanTriVien " +
                                  "where TenDangNhap='" + qtvien.TenDangNhap + "' and KeyRestore='" + qtvien.KeyRestore + "' ";
            command.Connection = conn;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                string tendangnhap = reader.GetString(0);
                string KeyRestore  = reader.GetString(1);

                QuanTriVien qtv = new QuanTriVien();

                qtv.TenDangNhap = tendangnhap;
                qtv.KeyRestore  = KeyRestore;

                dsQuanTriVien.Add(qtv);
            }
            return(dsQuanTriVien);
        }
Beispiel #15
0
        public List <QuanTriVien> TimTenDangNhap(QuanTriVien qtvien)
        {
            List <QuanTriVien> dsQuanTriVien = new List <QuanTriVien>();

            OpenConnection();
            SqlCommand command = new SqlCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = "select Id,TenDangNhap from QuanTriVien where ID='" + qtvien.ID + "";
            command.Connection  = conn;
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                int         id          = reader.GetInt32(0);
                string      tendangnhap = reader.GetString(1);
                QuanTriVien qtv         = new QuanTriVien();
                qtv.ID          = id;
                qtv.TenDangNhap = tendangnhap;
                dsQuanTriVien.Add(qtv);
            }
            reader.Close();
            CloseConnection();
            return(dsQuanTriVien);
        }
        public IActionResult TtDangNhap()
        {
            QuanTriVien[] qtvs = uManager.Users.ToArray();
            Dictionary <QuanTriVien, string> model = new Dictionary <QuanTriVien, string>();

            foreach (QuanTriVien qtv in qtvs)
            {
                string roleName = uManager.GetRolesAsync(qtv).Result.First();
                model.Add(qtv, roleName);
            }
            QuanTriVien lastQtv   = uManager.Users.LastOrDefault();
            string      lastQtvId = null;

            if (lastQtv != null)
            {
                lastQtvId = lastQtv.Id;
            }
            else
            {
                lastQtvId = "QT00000000";
            }
            ViewBag.NextQtvId = String.Concat("QT", IncrementString(lastQtvId.Substring(2)));
            ViewBag.Roles     = roleManager.Roles;
            ViewBag.MaNhaXes  = _context.NhaXe.ToArray();
            return(View(model));
        }
Beispiel #17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         // Đặt tên để set class, đặt tên in hoa
         Default SetClassActive = this.Master as Default;
         SetClassActive.page = "MUONPHONG";
         try
         {
             if (Convert.ToString(Session["Username"]).Equals(String.Empty))
             {
                 PanelDangNhap.Visible = true;
             }
             else
             {
                 if (!PermissionHelper.QuyenMuonPhong())
                 {
                     PanelKhongPhaiGiangVien.Visible = true;
                 }
                 else
                 {
                     PanelMuonPhong.Visible = true;
                     QuanTriVien _QuanTriVien = QuanTriVien.getByUserName(Session["Username"].ToString());
                     TextBoxKhoa.Text = _QuanTriVien.donvi;
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex);
         }
     }
 }
 public ActionResult EditPassword(Models.ChangePasswordViewModel model)
 {
     if (ModelState.IsValid)
     {
         var session = (Models.AdminViewModel)Session["Taikhoanadmin"];
         if (session != null)
         {
             if (session.MatKhau.Equals(model.ExPassword))
             {
                 var _admin = new QuanTriVien();
                 _admin.MaAdmin = session.MaAdmin;
                 _admin.MatKhau = model.Password.ToString();
                 new Models.ChangePasswordViewModel().EditPassword(_admin);
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError("", "Nhập sai mật khẩu");
             }
         }
         else
         {
             ModelState.AddModelError("", "Không tồn tại tài khoản này");
         }
     }
     return(View(model));
 }
Beispiel #19
0
        protected void ButtonLuuThongTinCaNhan_Click(object sender, EventArgs e)
        {
            QuanTriVien _QuanTriVien = QuanTriVien.getByUserName(Convert.ToString(Session["UserName"]));

            Session["HoTen"] = _QuanTriVien.hoten = TextBoxHoTen.Text;
            ((Site)Page.Master).HoTen_Changed = Session["HoTen"].ToString();
            _QuanTriVien.email = TextBoxEmail.Text;
            if (!TextBoxMatKhauMoi.Text.Equals(""))
            {
                _QuanTriVien.setPassword(TextBoxMatKhauMoi.Text);
            }
            _QuanTriVien.donvi = TextBoxDonVi.Text;
            _QuanTriVien.mota  = TextBoxGhiChu.Text;
            if (_QuanTriVien.update() > 0 && DBInstance.commit() > 0)
            {
                Session["HoTen"] = _QuanTriVien.hoten;
                PanelThongBaoThanhCong.Visible = true;
                LabelThongBaoThanhCong.Text    = "Cập nhật thông tin tài khoản thành công";
                ShowPanelThongTinCaNhan(true);
                LoadThongTinCaNhan();
            }
            else
            {
                PanelThongBaoThatBai.Visible = true;
                LabelThongBaoThatBai.Text    = "Có lỗi trong khi chỉnh sửa. Vui lòng xem lại!";
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            QuanTriVien quanTriVien = db.QuanTriViens.Find(id);

            db.QuanTriViens.Remove(quanTriVien);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #21
0
        public ActionResult Edit(CrudModelQuanTriVien model)
        {
            QuanTriVien _model = new QuanTriVien();

            _model = _db.GetOne <QuanTriVien>(o => o.MaQuanTriVien == model.MaQuanTriVien);
            COMMON.Helpers.CopyObject <QuanTriVien>(model, ref _model);
            _db.Update <QuanTriVien>(_model);
            return(RedirectToAction("Index", "QuanTriVien"));
        }
        public async Task <IActionResult> UpdateTtDangNhap(QuanTriVien qtv, string roleName)
        {
            List <string> messages = new List <string>();

            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Thông tin không hợp lệ");
                }
                QuanTriVien _qtv = await uManager.FindByIdAsync(qtv.Id);

                if (_qtv == null)
                {
                    throw new Exception("Không tìm thấy quản trị viên");
                }
                _qtv.MaNhaXe     = qtv.MaNhaXe;
                _qtv.HoDem       = qtv.HoDem;
                _qtv.Ten         = qtv.Ten;
                _qtv.NamGioi     = qtv.NamGioi;
                _qtv.NoiSinh     = qtv.NoiSinh;
                _qtv.PhoneNumber = qtv.PhoneNumber;
                _qtv.UserName    = qtv.UserName;
                await uManager.UpdateAsync(_qtv);

                string _role = (await uManager.GetRolesAsync(_qtv)).FirstOrDefault();
                if (_role != null)
                {
                    await uManager.RemoveFromRoleAsync(_qtv, _role);
                }
                var res = await uManager.AddToRoleAsync(_qtv, roleName);

                if (!res.Succeeded)
                {
                    throw new Exception("Cập nhật không thành công");
                }
                _context.SaveChanges();
                messages.Add("redirect");
                messages.Add(Url.Action("TtDangNhap"));
            }
            catch (Exception err)
            {
                messages.Add(err.Message);
                foreach (var value in ModelState.Values)
                {
                    if (value.ValidationState == ModelValidationState.Invalid)
                    {
                        foreach (var modelErr in value.Errors)
                        {
                            messages.Add(modelErr.ErrorMessage);
                        }
                    }
                }
            }
            return(Json(messages.ToArray()));
        }
 public ActionResult Edit([Bind(Include = "UserName,Email,Pass,PhanQuyen")] QuanTriVien quanTriVien)
 {
     if (ModelState.IsValid)
     {
         db.Entry(quanTriVien).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(quanTriVien));
 }
Beispiel #24
0
        public bool Authorize(string role, string userName)
        {
            QuanTriVien qtv = db.QuanTriVien.Where(q => q.TaiKhoan.Trim().ToUpper() == userName.Trim().ToUpper() && q.IdQuyenNavigation.TenQuyen == role).FirstOrDefault();

            if (qtv != null)
            {
                return(true);
            }
            return(false);
        }
Beispiel #25
0
        public ActionResult Edit(long MaQuanTriVien)
        {
            _db.DbContext.Configuration.ProxyCreationEnabled = false;
            QuanTriVien          model  = _db.GetOne <QuanTriVien>(o => o.MaQuanTriVien == MaQuanTriVien);
            CrudModelQuanTriVien _model = new CrudModelQuanTriVien();

            WebMVC.COMMON.Helpers.CopyObject <CrudModelQuanTriVien>(model, ref _model);
            initialCategoryEditAction(_model);
            return(View(_model));
        }
Beispiel #26
0
        protected void DangNhap()
        {
            try
            {
                string Username     = TextBoxTaiKhoan.Text;
                string HashPassword = HiddenFieldMatKhau.Value;

                if (Username == "")
                {
                    PanelThongBao.Visible = true;
                    LabelThongBao.Text    = "Tài khoản không được trống";
                    return;
                }
                if (HashPassword == "")
                {
                    PanelThongBao.Visible = true;
                    LabelThongBao.Text    = "Mật khẩu không được trống";
                    return;
                }

                Boolean KiemTraDangNhap = QuanTriVien.checkLoginByUserName(Username, HashPassword);

                if (KiemTraDangNhap)
                {
                    if (CheckBoxNhoDangNhap.Checked == true)
                    {
                        Response.Cookies["Username_Remember"].Value       = Username;
                        Response.Cookies["HashPassword_Remember"].Value   = HashPassword;
                        Response.Cookies["Username_Remember"].Expires     = DateTime.Now.AddDays(30);
                        Response.Cookies["HashPassword_Remember"].Expires = DateTime.Now.AddDays(30);
                    }
                    else
                    {
                        Response.Cookies["Username_Remember"].Expires     = DateTime.Now.AddDays(-1);
                        Response.Cookies["HashPassword_Remember"].Expires = DateTime.Now.AddDays(-1);
                    }
                    Session["Username"] = Username;
                    QuanTriVien _QuanTriVien = QuanTriVien.getByUserName(Username);
                    TSCD.Global.current_quantrivien_login = _QuanTriVien;
                    Session["HoTen"] = _QuanTriVien.hoten;
                    Response.Redirect(Request.RawUrl);
                }
                else
                {
                    PanelThongBao.Visible = true;
                    LabelThongBao.Text    = "Tài khoản hoặc mật khẩu không chính xác";
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
                PanelThongBao.Visible = true;
                LabelThongBao.Text    = "<strong>Có lỗi xảy ra !</strong> Vui lòng kiểm tra lại thông tin.";
            }
        }
        public ActionResult Create([Bind(Include = "ID,username,pass")] QuanTriVien quanTriVien)
        {
            if (ModelState.IsValid)
            {
                db.QuanTriViens.Add(quanTriVien);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(quanTriVien));
        }
        public ActionResult Create([Bind(Include = "UserName,Email,Pass,PhanQuyen")] QuanTriVien quanTriVien)
        {
            if (ModelState.IsValid)
            {
                db.QuanTriViens.Add(quanTriVien);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(quanTriVien));
        }
        protected string _QuyenXoaQuanTriVien()
        {
            Guid        id           = GUID.From(Eval("id"));
            QuanTriVien _QuanTriVien = new QuanTriVien();

            _QuanTriVien = QuanTriVien.getById(id);
            if (PermissionHelper.QuyenXoaQuanTriVien())
            {
                return("<li><a href=\"?op=xoa&id=" + Eval("id") + "\" onclick=\"return confirm('Bạn chắc chắn muốn xóa tài khoản " + Eval("username") + "?');\"><span class=\"glyphicon glyphicon-remove\"></span>&nbsp;Xóa</a></li>");
            }
            return("");
        }
        protected string _QuyenSuaQuanTriVien()
        {
            Guid        id           = GUID.From(Eval("id"));
            QuanTriVien _QuanTriVien = new QuanTriVien();

            _QuanTriVien = QuanTriVien.getById(id);
            if (PermissionHelper.QuyenSuaQuanTriVien())
            {
                return("<li><a href=\"#\" onclick=\"ShowCapNhat('" + Eval("id") + "','" + Eval("group_id") + "');\" data-target=\"#PopupQuanLyTaiKhoan\" data-toggle=\"modal\"><span class=\"glyphicon glyphicon-pencil\"></span>&nbsp;Cập nhật</a></li>");
            }
            return("");
        }
        protected void ButtonThemMoi_Click(object sender, EventArgs e)
        {
            try
            {
                if (!PermissionHelper.QuyenThemQuanTriVien())
                {
                    PanelThatBai.Visible = true;
                    LabelThongBaoThatBai.Text = "Bạn không có quyền thêm mới tài khoản";
                    return;
                }

                QuanTriVien _QuanTriVien = new QuanTriVien();
                _QuanTriVien.hoten = TextBoxHoTen.Text;
                _QuanTriVien.email = TextBoxEmail.Text;
                _QuanTriVien.group = Group.getById(GUID.From(DropDownListNhom.SelectedValue));
                _QuanTriVien.username = TextBoxTaiKhoan.Text;
                _QuanTriVien.setPassword(TextBoxMatKhau.Text);
                _QuanTriVien.donvi = TextBoxKhoa.Text;
                _QuanTriVien.mota = TextBoxGhiChu.Text;
                if (_QuanTriVien.add() > 0 && DBInstance.commit() > 0)
                {
                    PanelThanhCong.Visible = true;
                    LabelThongBaoThanhCong.Text = "Thêm mới tài khoản <strong>" + _QuanTriVien.username + "</strong> thành công";
                    _QuanLyTaiKhoan();
                }
                else
                {
                    PanelThatBai.Visible = true;
                    LabelThongBaoThatBai.Text = "Có lỗi trong khi thêm";
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
        }
        protected void ButtonLuu_Click(object sender, EventArgs e)
        {
            try
            {

                PhieuMuonPhong _PhieuMuonPhong = new PhieuMuonPhong();
                _PhieuMuonPhong = PhieuMuonPhong.getById(GUID.From(HiddenFieldID.Value));
                _PhieuMuonPhong.trangthai = Convert.ToInt32(DropDownListTrangThai.SelectedValue);
                _PhieuMuonPhong.ghichu = TextBoxGhiChu.Text;
                QuanTriVien _QuanTriVien = new QuanTriVien();
                _QuanTriVien = QuanTriVien.getByUserName(Session["username"].ToString());
                _PhieuMuonPhong.nguoiduyet = _QuanTriVien;
                if (_PhieuMuonPhong.update() > 0 && DBInstance.commit() > 0)
                {
                    HideAllAlert();
                    ucSuccess.LabelInfo.Text = "Duyệt phòng thành công. ";
                    ucSuccess.Visible = true;

                    if (CheckBoxGuiMailThongBao.Checked == true)
                    {
                        string to = _PhieuMuonPhong.nguoiduyet.email;
                        string sub = PTB_WEB.Libraries.StringHelper.TitleContent(_PhieuMuonPhong);
                        switch (_PhieuMuonPhong.trangthai)
                        {
                            case -1:
                                tinhtrang = "đã bị hủy bỏ";
                                break;
                            case 0:
                                tinhtrang = "đang được xét duyệt";
                                break;
                            case 1:
                                tinhtrang = "đã được chấp nhận";
                                break;
                        }
                        string msg = PTB_WEB.Libraries.StringHelper.MailContent(_PhieuMuonPhong, tinhtrang);
                        if (PTB.Libraries.EmailHelper.sendMail(to, sub, msg) > 0)
                        {
                            HideAllAlert();
                            ucSuccess.LabelInfo.Text += "Đã gửi mail thông báo đến giảng viên mượn phòng";
                            ucSuccess.Visible = true;
                        }
                        else
                        {
                            HideAllAlert();
                            ucWarning.LabelInfo.Text = "Đã xảy ra lỗi. Mail không gửi được đến giảng viên mượn phòng";
                            ucWarning.Visible = true;
                        }
                    }
                    QuanLyPhongMuon();
                }
                else
                {
                    HideAllAlert();
                    ucDanger.LabelInfo.Text = "Có lỗi xảy ra trong khi duyệt. Vui lòng kiểm tra lại";
                    ucDanger.Visible = true;
                }
            }
            catch (Exception ex)
            {
                HideAllAlert();
                ucDanger.LabelInfo.Text = "Có lỗi xảy ra trong khi duyệt. Vui lòng kiểm tra lại";
                ucDanger.Visible = true;
                Console.Write(ex);
            }
        }
 /// <summary>
 /// Goi hien thi len Panel Thong tin chi tiet
 /// </summary>
 /// <param name="objQuanTriVienFilter"></param>
 private void setThongTinChiTiet(QuanTriVien obj)
 {
     try
     {
         if (obj == null)
         {
             return;
         }
         txtMaQuanTriVien.Text = obj.subId;
         txtTaiKhoanQuanTriVien.Text = obj.username;
         txtTenQuanTriVien.Text = obj.hoten;
         txtMatKhauQuanTriVien.Text = txtXacNhanMK.Text = "";
         memoEdit_mota.Text = obj.mota;
         dateCreated.DateTime = (DateTime)(obj.date_create == null ? ServerTimeHelper.getNow() : obj.date_create);
         if (obj.group != null)
         {
             lookUpEdit_group.EditValue = obj.group.id;
         }
         editGUI("view");
         dxErrorProvider1.ClearErrors();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setThongTinChiTiet: " + ex.Message);
     }
 }
 private void gridViewPhanQuyen_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
 {
     try
     {
         if (gridViewPhanQuyen.GetFocusedRow() != null)
         {
             groupControl1.Text = "Thông tin";
             objQuanTriVien = ((QuanTriVienFilter)gridViewPhanQuyen.GetFocusedRow()).quantrivien;
             //Truyen qua cho View Thong Tin
             setThongTinChiTiet(objQuanTriVien);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->gridViewPhanQuyen_FocusedRowChanged: " + ex.Message);
     }
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //lear previos error
                dxErrorProvider1.ClearErrors();
                //load to object
                if (function.Equals("add"))
                {
                    objQuanTriVien = new QuanTriVien();
                }
                objQuanTriVien.subId = txtMaQuanTriVien.Text;
                objQuanTriVien.username = txtTaiKhoanQuanTriVien.Text;
                if (objQuanTriVien.username.Equals(""))
                {
                    dxErrorProvider1.SetError(txtTaiKhoanQuanTriVien, "Tài khoản không được rỗng");
                    return;
                }
                objQuanTriVien.date_create = (DateTime)dateCreated.EditValue;
                objQuanTriVien.group = lookUpEdit_group.GetSelectedDataRow() as Group;
                objQuanTriVien.hoten = txtTenQuanTriVien.Text;
                if (objQuanTriVien.hoten.Equals(""))
                {
                    dxErrorProvider1.SetError(txtTenQuanTriVien, "Họ tên không được rỗng");
                    return;
                }
                objQuanTriVien.mota = memoEdit_mota.Text;

                //call function
                if (function.Equals("edit"))
                {
                    //try to change pass first
                    if (
                        txtMatKhauQuanTriVien.Text.Equals("")
                        &&
                        txtXacNhanMK.Text.Equals("")
                        )
                    {
                        //ignore
                    }
                    else if (!txtMatKhauQuanTriVien.Text.Equals(txtXacNhanMK.Text))
                    {
                        dxErrorProvider1.SetError(txtMatKhauQuanTriVien, "Mật khẩu không khớp!");
                        dxErrorProvider1.SetError(txtXacNhanMK, "Mật khẩu không khớp!");
                        return;
                    }
                    else
                    {
                        objQuanTriVien.changePassword(txtMatKhauQuanTriVien.Text);
                    }

                    //call update
                    int re = objQuanTriVien.update();
                    if (re > 0)
                    {
                        if (DBInstance.commit() > 0)
                        {
                            XtraMessageBox.Show("Sửa thành công!");
                            dxErrorProvider1.ClearErrors();
                            reLoad();
                            return;
                        }
                    }
                    else if (re == -7)
                    {
                        dxErrorProvider1.SetError(txtTaiKhoanQuanTriVien,"Trùng tài khoản đã có");
                        return;
                    }
                    XtraMessageBox.Show("Sửa KHÔNG thành công!");
                    return;
                }
                else if (function.Equals("add"))
                {
                    objQuanTriVien.setPassword(txtMatKhauQuanTriVien.Text);
                    int re = objQuanTriVien.add();
                    if (re > 0)
                    {
                        if (DBInstance.commit() > 0)
                        {
                            XtraMessageBox.Show("Thêm thành công!");
                            //reload
                            reLoad();
                            return;
                        }
                    }
                    else if (re == -7)
                    {
                        dxErrorProvider1.SetError(txtTaiKhoanQuanTriVien, "Trùng tài khoản đã có");
                        return;
                    }
                    XtraMessageBox.Show("Có lỗi xảy ra!");
                    return;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(this.Name + "->btnOK_Click: " + ex.Message);
            }
        }
        /// <summary>
        /// Tạo Group và QuanTriVien mau
        /// </summary>
        internal void forceSeed()
        {
            try
            {
                //DATETIME
                String mota = "Hệ thống tự động tạo";
                //GROUP
                if (this.GROUPS.Where(c => c.ten.ToLower().Equals("root")).Count() <= 0)
                {
                    Group gp = new Group();
                    gp.mota = mota;
                    gp.date_create = gp.date_modified = ServerTimeHelper.getNow();
                    gp.ten = "root";
                    gp.subId = gp.ten;
                    gp.key = gp.ten;

                    if (this.QUANTRIVIENS.Where(c => c.username.ToLower().Equals("root")).Count() <= 0)
                    {
                        //QUANTRIVIEN
                        QuanTriVien qtv = new QuanTriVien();
                        qtv.date_create = qtv.date_modified = ServerTimeHelper.getNow();
                        qtv.username = "******";
                        qtv.setPassword(qtv.username); //hashPassword("root") => "2B1ED923B31D1B0990A28C932565156D11F9F7D9"
                        qtv.hoten = "root";
                        qtv.mota = mota;
                        qtv.subId = qtv.username;
                        qtv.group = gp;
                        this.QUANTRIVIENS.Add(qtv);
                    }
                }

                //final commit
                SaveChanges();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
 private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         if (checkInput())
         {
             switch (function)
             {
                 case "add":
                     objQTV = new QuanTriVien();
                     setDataObj();
                     objQTV.setPassword(txtMatKhauQuanTriVien.Text);
                     if (objQTV.add() > 0 && DBInstance.commit() > 0)
                     {
                         XtraMessageBox.Show("Thêm quản trị viên thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         Guid id = objQTV.id;
                         reloadAndFocused(id);
                     }
                     else
                     {
                         XtraMessageBox.Show("Thêm quản trị viên không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }
                     break;
                 case "edit":
                     setDataObj();
                     if (!txtMatKhauQuanTriVien.Text.Equals("") && !txtXacNhanMK.Text.Equals(""))
                         objQTV.changePassword(txtMatKhauQuanTriVien.Text);
                     if (objQTV.update() > 0 && DBInstance.commit() > 0)
                     {
                         XtraMessageBox.Show("Sửa quản trị viên thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         Guid id = objQTV.id;
                         reloadAndFocused(id);
                     }
                     else
                     {
                         XtraMessageBox.Show("Sửa quản trị viên không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }
                     break;
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->btnOk_Click: " + ex.Message);
     }
 }
 private void setDataView()
 {
     try
     {
         dxErrorProviderInfo.ClearErrors();
         if (!function.Equals("view"))
             editGUI("view");
         if (gridViewQTV.RowCount > 0)
         {
             if (gridViewQTV.GetFocusedRow() != null)
             {
                 objQTV = (gridViewQTV.GetFocusedRow() as QuanTriVienHienThi).quantrivien;
                 txtMaQuanTriVien.Text = objQTV.subId;
                 txtTaiKhoanQuanTriVien.Text = objQTV.username;
                 txtTenQuanTriVien.Text = objQTV.hoten;
                 txtMatKhauQuanTriVien.Text = txtXacNhanMK.Text = "";
                 memoEdit_mota.Text = objQTV.mota;
                 dateCreated.DateTime = (DateTime)(objQTV.date_create == null ? ServerTimeHelper.getNow() : objQTV.date_create);
                 if (objQTV.group != null)
                 {
                     lookUpEdit_group.EditValue = objQTV.group.id;
                 }
             }
             else
             {
                 clearText();
                 objQTV = new QuanTriVien();
             }
         }
         else
         {
             enableButton(false);
             clearText();
             objQTV = new QuanTriVien();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setDataView: " + ex.Message);
     }
 }
 private void setDataView()
 {
     try
     {
         if (gridViewQuanTriVien.RowCount > 0)
         {
             if (gridViewQuanTriVien.FocusedRowHandle > -1 && gridViewQuanTriVien.GetFocusedRow() != null)
             {
                 objQuanTriVien = gridViewQuanTriVien.GetFocusedRow() as QuanTriVien;
                 txtMa.Text = objQuanTriVien.subId;
                 txtTen.Text = objQuanTriVien.hoten;
                 txtUsername.Text = objQuanTriVien.username;
                 txtMota.Text = objQuanTriVien.mota;
                 listPhong = objQuanTriVien.phongs.ToList();
                 listBoxPhong.DataSource = listPhong;
             }
             else
             {
                 clearText();
                 objQuanTriVien = new QuanTriVien();
             }
         }
         else
         {
             clearText();
             objQuanTriVien = new QuanTriVien();
         }
         checkPermission();
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->setDataView: " + ex.Message);
     }
 }
 public void loadData(List<ViTriHienThi> list, QuanTriVien quantrivien)
 {
     try
     {
         treeListPhong.BeginUnboundLoad();
         treeListPhong.DataSource = list;
         treeListPhong.EndUnboundLoad();
         List<Phong> _list = quantrivien.phongs.ToList();
         foreach (Phong p in _list)
         {
             if (!p.id.Equals(Guid.Empty))
             {
                 TreeListNode node = treeListPhong.FindNodeByKeyID(p.id);
                 if (node != null)
                 {
                     treeListPhong.SetNodeCheckState(node, CheckState.Checked, true);
                     node.Selected = true;
                 }
             }
         }
         if (treeListPhong.Nodes.Count > 0)
             treeListPhong.FocusedNode = treeListPhong.Nodes[0];
     }
     catch (Exception ex)
     {
         Debug.WriteLine(this.Name + "->loadData: " + ex.Message);
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "no-cache";
            Response.AddHeader("Pragma", "no-cache");
            Response.Expires = -1;

            if (!IsPostBack)
            {
                // Đặt tên để set class, đặt tên in hoa
                Default SetClassActive = this.Master as Default;
                SetClassActive.page = "QUANLYTAIKHOAN";

                try
                {
                    if (Convert.ToString(Session["Username"]).Equals(String.Empty))
                        PanelDangNhap.Visible = true;
                    else
                    {
                        if (PermissionHelper.QuyenHienThiQuanTriVien())
                        {
                            PanelQuanLyTaiKhoan.Visible = true;
                            _QuanLyTaiKhoan();
                        }
                        else
                            PanelKhongPhaiQuanTriVien.Visible = true;

                        if (!PermissionHelper.QuyenThemQuanTriVien())
                            ButtonThemMoiTaiKhoan.Visible = false;
                    }

                    if (!String.IsNullOrEmpty(Request["op"]))
                    {
                        if (Request["op"].Equals("xoa"))
                        {
                            Guid id = GUID.From(Request["id"]);
                            QuanTriVien _QuanTriVien = new QuanTriVien();
                            _QuanTriVien = QuanTriVien.getById(id);

                            if (!PermissionHelper.QuyenXoaQuanTriVien())
                            {
                                PanelThatBai.Visible = true;
                                LabelThongBaoThatBai.Text = "Bạn không có quyền xóa tài khoản này";
                                return;
                            }

                            if (_QuanTriVien.delete() > 0 && DBInstance.commit() > 0)
                            {
                                PanelThanhCong.Visible = true;
                                LabelThongBaoThanhCong.Text = "Đã xóa tài khoản <strong>" + _QuanTriVien.username + "</strong> ra khỏi hệ thống";
                                _QuanLyTaiKhoan();
                            }
                            else
                            {
                                PanelThatBai.Visible = true;
                                LabelThongBaoThatBai.Text = "Giảng viên này đã tạo phiếu mượn phòng. Không thể xóa!";
                            }
                        }

                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
 protected string _QuyenSuaQuanTriVien()
 {
     Guid id = GUID.From(Eval("id"));
     QuanTriVien _QuanTriVien = new QuanTriVien();
     _QuanTriVien = QuanTriVien.getById(id);
     if (PermissionHelper.QuyenSuaQuanTriVien())
         return "<li><a href=\"#\" onclick=\"ShowCapNhat('" + Eval("id") + "','" + Eval("group_id") + "');\" data-target=\"#PopupQuanLyTaiKhoan\" data-toggle=\"modal\"><span class=\"glyphicon glyphicon-pencil\"></span>&nbsp;Cập nhật</a></li>";
     return "";
 }
 protected string _QuyenXoaQuanTriVien()
 {
     Guid id = GUID.From(Eval("id"));
     QuanTriVien _QuanTriVien = new QuanTriVien();
     _QuanTriVien = QuanTriVien.getById(id);
     if (PermissionHelper.QuyenXoaQuanTriVien())
         return "<li><a href=\"?op=xoa&id=" + Eval("id") + "\" onclick=\"return confirm('Bạn chắc chắn muốn xóa tài khoản " + Eval("username") + "?');\"><span class=\"glyphicon glyphicon-remove\"></span>&nbsp;Xóa</a></li>";
     return "";
 }