コード例 #1
0
 public ActionResult UpdateNV_DangNhap(string sMaNV, string sSoThe, string sAllow)
 {
     try
     {
         int      mnv  = int.Parse(sMaNV);
         string   Pass = MyClss.Encode(sSoThe);
         DangNhap dn   = db.DangNhaps.SingleOrDefault(r => r.MaNV == mnv);
         if (dn != null)
         {
             dn.Allow    = sAllow == "true" ? true : false;
             dn.Username = sSoThe;
             dn.Pass     = Pass;
         }
         else
         {
             dn          = new DangNhap();
             dn.MaNV     = mnv;
             dn.Username = sSoThe;
             dn.Allow    = sAllow == "true" ? true : false;
             dn.Pass     = Pass;
             db.DangNhaps.Add(dn);
         }
         db.SaveChanges();
         return(Json(1, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json("", JsonRequestBehavior.AllowGet));
     }
 }
コード例 #2
0
        public ActionResult UpdateNV(string sMaNV, string sSoThe, string sHoTen, int sGioiTinh, string sNhomNDID)
        {
            try
            {
                int      mnv  = int.Parse(sMaNV);
                string   Pass = MyClss.Encode(sSoThe);
                NhanVien nv   = db.NhanViens.SingleOrDefault(r => r.MaNV == mnv);
                if (nv != null)
                {
                    nv.SoThe    = sSoThe;
                    nv.HoTen    = sHoTen;
                    nv.GioiTinh = sGioiTinh;
                    nv.NhomNVID = sNhomNDID;

                    DangNhap dn = db.DangNhaps.SingleOrDefault(r => r.MaNV == mnv);
                    if (dn != null)
                    {
                        dn.Allow = true;
                        dn.Pass  = Pass;
                    }

                    db.SaveChanges();
                    return(Json(1, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json("", JsonRequestBehavior.AllowGet));
                }
            }
            catch
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
        public ActionResult ResetMK(string sSoThe, string sPass)
        {
            string passw = MyClss.Encode(sPass);

            try
            {
                var dangnhap = from a in db.DangNhaps
                               where a.Username.Equals(sSoThe)
                               select a;
                if (dangnhap.Count() == 0)
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    DangNhap dn = db.DangNhaps.SingleOrDefault(r => r.Username.Equals(sSoThe));
                    if (dn != null)
                    {
                        dn.Pass = passw;
                        db.SaveChanges();
                        return(Json(1, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json("", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
コード例 #4
0
        public ActionResult Login(string Username, string MatKhau, string LID)
        {
            string passw = MyClss.Encode(MatKhau);
            var    dn    = from a in db.DangNhaps
                           from b in db.NhanViens
                           where a.MaNV == b.MaNV && a.Allow == true && a.Username.Equals(Username) && a.Pass.Equals(passw)
                           select new { b.MaNV, b.SoThe, b.HoTen, b.HienThi, b.NhomNVID };

            if (dn.Count() > 0)
            {
                HttpCookie user = new HttpCookie("" + ConfigurationManager.AppSettings["CKUserLogin"], "" + Username);
                user.Expires = DateTime.Now.AddDays(30);
                HttpContext.Response.Cookies.Add(user);

                HttpCookie pass = new HttpCookie("" + ConfigurationManager.AppSettings["CKPass"], "" + passw);
                pass.Expires = DateTime.Now.AddDays(30);
                HttpContext.Response.Cookies.Add(pass);

                HttpCookie thdangnhap = new HttpCookie("" + ConfigurationManager.AppSettings["CKMaNV"], "" + dn.SingleOrDefault().MaNV);
                thdangnhap.Expires = DateTime.Now.AddDays(30);
                HttpContext.Response.Cookies.Add(thdangnhap);
                HttpCookie thusername = new HttpCookie("" + ConfigurationManager.AppSettings["CKHoTen"], "" + dn.SingleOrDefault().HoTen);
                thusername.Expires = DateTime.Now.AddDays(30);
                HttpContext.Response.Cookies.Add(thusername);

                HttpCookie derpartment = new HttpCookie("" + ConfigurationManager.AppSettings["CKPhongBan"], "" + dn.SingleOrDefault().NhomNVID);
                derpartment.Expires = DateTime.Now.AddDays(30);
                HttpContext.Response.Cookies.Add(derpartment);

                HttpCookie lid = new HttpCookie("" + ConfigurationManager.AppSettings["CKLang"], "" + LID);
                lid.Expires = DateTime.Now.AddDays(30);
                HttpContext.Response.Cookies.Add(lid);

                string urlweb = "";
                if (System.Web.HttpContext.Current.Session["WebID"] == null)
                {
                    urlweb = "Home";
                }
                else
                {
                    urlweb = System.Web.HttpContext.Current.Session["WebID"].ToString();
                }
                return(Json(urlweb, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("0", JsonRequestBehavior.AllowGet));
            }
        }
コード例 #5
0
        public ActionResult ChangPass(string MatKhau_old, string MatKhau_new)
        {
            int    manv      = int.Parse(CookieCls.GetMaNV());
            string passw_old = MyClss.Encode(MatKhau_old);
            string passw_new = MyClss.Encode(MatKhau_new);
            var    checkUser = from a in db.DangNhaps
                               where a.MaNV == manv && a.Pass.Equals(passw_old)
                               select a;

            if (checkUser.Count() <= 0)
            {
                return(Json("0", JsonRequestBehavior.AllowGet));//Pass old không đúng
            }
            else
            {
                var login = db.DangNhaps.Where(a => a.MaNV == manv).SingleOrDefault();
                login.Pass = passw_new;
                db.SaveChanges();
                return(Json("1", JsonRequestBehavior.AllowGet));//Update Pass success
            }
        }
コード例 #6
0
        public ActionResult InsertNV(string sSoThe, string sHoTen, int sGioiTinh, string sBoPhan, string sAllow)
        {
            try
            {
                NhanVien nv = db.NhanViens.SingleOrDefault(r => r.SoThe.Equals(sSoThe));
                if (nv != null)
                {
                }
                else
                {
                    int    mnv  = db.NhanViens.Select(x => x.MaNV).DefaultIfEmpty(0).Max() + 1;
                    string Pass = MyClss.Encode(sSoThe);
                    nv          = new NhanVien();
                    nv.MaNV     = mnv;
                    nv.SoThe    = sSoThe;
                    nv.HoTen    = sHoTen;
                    nv.GioiTinh = sGioiTinh;
                    nv.NhomNVID = sBoPhan;
                    nv.HienThi  = true;
                    db.NhanViens.Add(nv);

                    if (sAllow == "true")
                    {
                        DangNhap dn = new DangNhap();
                        dn.MaNV     = mnv;
                        dn.Username = sSoThe;
                        dn.Pass     = Pass;
                        dn.DuyetTin = false;
                        dn.Allow    = true;
                        db.DangNhaps.Add(dn);
                    }
                }
                db.SaveChanges();
                return(Json(1, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }