示例#1
0
        private void Login()
        {
            if (txtUsername.Text.Trim() == "")
            {
                MessageBox.Show("Vui lòng nhập mã nhân viên");
                txtUsername.Focus();
                return;
            }
            if (txtPassword.Text.Trim() == "")
            {
                MessageBox.Show("Vui lòng nhập mật khẩu");
                txtPassword.Focus();
                return;
            }
            LoginModel model = new LoginModel();

            NhanVienLogin nv = model.login(txtUsername.Text.Trim().ToUpper(), txtPassword.Text.Trim());

            if (nv == null)
            {
                MessageBox.Show("Mã nhân viên hoặc mật khẩu sai.\nNếu bạn quyên mật khẩu vui lòng liên hệ phòng IT để lấy lại mật khẩu.");
                return;
            }
            if (checkBox1.Checked)
            {
                System.IO.File.WriteAllText("userlogin.txt", txtUsername.Text.Trim().ToUpper() + "~" + txtPassword.Text.Trim());
            }
            else
            {
                System.IO.File.WriteAllText("userlogin.txt", "");
            }
            lg(nv);
            this.Dispose();
        }
示例#2
0
        public IActionResult Login(NhanVienLogin Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            NhanVienLogin nhanVien = (from nv in context.NhanViens
                                      where nv.TaiKhoan == Model.TaiKhoan && nv.MatKhau == Model.MatKhau
                                      select new NhanVienLogin
            {
                IDNhanVien = nv.IDNhanVien,
                TaiKhoan = nv.TaiKhoan,
                MatKhau = nv.MatKhau,
                LoaiNhanVien = nv.LoaiNhanVien,
                IDChiNhanh = nv.IDChiNhanh
            }).SingleOrDefault();

            if (nhanVien == null)
            {
                ModelState.AddModelError("", "Sai tài khoản hoặc mật khẩu");
                return(View());
            }
            else
            {
                HttpContext.Session.SetInt32("IDNhanVien", nhanVien.IDNhanVien);
                HttpContext.Session.SetString("TaiKhoanNv", Model.TaiKhoan);
                HttpContext.Session.SetString("MatKhauNv", Model.MatKhau);
                HttpContext.Session.SetInt32("LoaiTaiKhoanNv", nhanVien.LoaiNhanVien);
                HttpContext.Session.SetInt32("IDChiNhanh", nhanVien.IDChiNhanh);
            }
            return(RedirectToAction("Index", "QuanLy"));
        }
示例#3
0
        public NhanVienLogin login(string username, string password)
        {
            NhanVienLogin nv = null;

            try
            {
                SqlParameter  manv    = new SqlParameter("@MANV", username);
                SqlParameter  matkhau = new SqlParameter("@MATKHAU", password);
                SqlDataReader read    = Reader("SpLogin", System.Data.CommandType.StoredProcedure, manv, matkhau);

                while (read.Read())
                {
                    nv         = new  NhanVienLogin();
                    nv.MaNV    = read[0].ToString();
                    nv.Ho      = read[1].ToString();
                    nv.Ten     = read[2].ToString();
                    nv.LaAdmin = (bool)read[3];
                }
                read.Dispose();
            }
            catch { }

            con.Close();
            return(nv);
        }
示例#4
0
        public IActionResult Login(NhanVienLogin Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            IEnumerable <NhanVienLogin> nhanVien = from nv in context.NhanViens
                                                   where nv.TaiKhoan == Model.TaiKhoan && nv.MatKhau == Model.MatKhau
                                                   select new NhanVienLogin
            {
                IDNhanVien   = nv.IDNhanVien,
                TaiKhoan     = nv.TaiKhoan,
                MatKhau      = nv.MatKhau,
                LoaiNhanVien = nv.LoaiNhanVien,
                IDChiNhanh   = nv.IDChiNhanh
            };
            List <NhanVienLogin> nhanvien = new List <NhanVienLogin>(nhanVien);

            if (nhanvien.Count == 0)
            {
                ModelState.AddModelError("", "Sai tài khoản hoặc mật khẩu");
                return(View());
            }
            else
            {
                HttpContext.Session.SetString("TaiKhoanNv", Model.TaiKhoan);
                HttpContext.Session.SetString("MatKhauNv", Model.MatKhau);
                HttpContext.Session.SetInt32("LoaiTaiKhoanNv", nhanvien[0].LoaiNhanVien);
                HttpContext.Session.SetInt32("IDChiNhanh", nhanvien[0].IDChiNhanh);
            }
            return(RedirectToAction("Details", "NhanVien", new { id = nhanvien[0].IDNhanVien }));
        }
示例#5
0
 public ActionResult DangNhapNhanVien(LoginModel model)
 {
     if (ModelState.IsValid)
     {
         var dao    = new NhanVienDao();
         var result = dao.DangNhapNhanVien(model.Username, Encrytor.MD5Hash(model.Password));
         if (result)
         {
             var nhanvien         = dao.getByName(model.Username);
             var nhanvien_Session = new NhanVienLogin();
             nhanvien_Session.UserId   = nhanvien.Id;
             nhanvien_Session.UserName = nhanvien.TenDangNhap;
             Session.Add(Common.Constants.NHANVIEN_SESSION, nhanvien_Session);
             return(RedirectToAction("Index", "HomeNhanVien"));
         }
         else
         {
             ModelState.AddModelError("", "đăng nhập không đúng");
         }
     }
     return(RedirectToAction("DangNhapNhanVien", "Login"));
 }