Beispiel #1
0
 /// <summary>
 /// 管理员注册
 /// </summary>
 /// <param name="Name"></param>
 /// <param name="Password"></param>
 public bool Insert(string Name, string Password)
 {
     using (XPMSEntities db = new XPMSEntities())
     {
         var query = from a in db.T_Admin
                     where a.Name.Equals(Name)
                     select a;
         if (query.Count() > 0)
         {
             //1.判断唯一性
             throw new Exception("用户名已存在");
         }
         else
         {
             //2.插入数据
             var     salt = Utils.Number(4);
             T_Admin obj  = new T_Admin()
             {
                 Name     = Name,
                 Password = DESEncrypt.Encrypt(Password, salt),
                 Salt     = salt,
                 IsDelete = false,
                 IsLock   = false
             };
             db.T_Admin.Add(obj);
             return(true);
         }
     }
 }
        public T_Admin Get_T_Admins(string User_name)
        {
            try
            {
                connection();

                T_Admin getlist1 = new T_Admin();

                string         GetQuery = "select tm.User_ID as uid from T_Admin as tm where tm.User_name = '" + User_name + "' ";
                SqlCommand     cmd      = new SqlCommand(GetQuery, conn);
                SqlDataAdapter adapter  = new SqlDataAdapter(cmd);
                DataTable      dt       = new DataTable();


                conn.Open();
                adapter.Fill(dt);
                conn.Close();

                foreach (DataRow dr in dt.Rows)
                {
                    getlist1.User_ID = Convert.ToInt16(dr["uid"]);
                }

                return(getlist1);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #3
0
        public string Scan_Account(T_Admin AdminMode)
        {
            string result = "false";

            using (SqlConnection conn = new SqlConnection(constr))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    result = "数据库打开失败!";
                }
                string sqlstr_scan_account = @"
                                                SELECT *
                                                FROM dbo.T_Admin
                                                WHERE UserName = @UserName
                                                  AND PassWord = @PassWord
                                            ";
                using (SqlCommand com = new SqlCommand())
                {
                    com.Connection  = conn;
                    com.CommandText = sqlstr_scan_account;
                    com.Parameters.Add(new SqlParameter("@UserName", AdminMode.UserName));
                    com.Parameters.Add(new SqlParameter("@PassWord", AdminMode.PassWord));
                    try
                    {
                        SqlDataReader  dr        = com.ExecuteReader();
                        List <T_Admin> adminlist = new List <T_Admin>();
                        while (dr.Read())
                        {
                            T_Admin adminmode = new T_Admin();
                            adminmode.UserName = dr["UserName"].ToString();
                            adminmode.PassWord = dr["PassWord"].ToString();
                            adminlist.Add(adminmode);
                        }
                        dr.Close();

                        if (adminlist.Count > 0)
                        {
                            result = "true";
                        }
                        else
                        {
                            result = "false";
                        }
                    }
                    catch (Exception ex)
                    {
                        result = "数据库操作执行出现异常,原因:" + ex.Message;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return(result);
        }
        public ActionResult LoginIndex(T_Admin t_Admin)
        {
            QueryCRUD query = new QueryCRUD();

            bool           chk     = query.CheckLogin(t_Admin.User_name, t_Admin.Password);
            List <T_Admin> listTic = new List <T_Admin>();
            QueryCRUD      qr      = new QueryCRUD();

            listTic = qr.T_Admins(t_Admin.User_name, t_Admin.Password);
            if (chk == true)
            {
                TempData["User_name"] = t_Admin.User_name;
                Session["User_name"]  = t_Admin.User_name;
                Session["Type"]       = listTic;



                return(RedirectToAction("Index", "Show"));
            }
            else
            {
                TempData["message"] = "User And Password Invalid";
                return(View());
            }
        }
Beispiel #5
0
        /// <summary>
        /// 确认按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string oldPassword = txtOldPassword.Text;
            string newPassword = txtNewPassword.Text;
            string confirm     = txtConfirm.Text;

            if (oldPassword == "" || newPassword == "" || confirm == "")
            {
                MLMGC.COMP.Jscript.ShowMsg("请认真填写以上内容", this);
                return;
            }
            if (newPassword != confirm)
            {
                MLMGC.COMP.Jscript.ShowMsg("两次密码输入不一致", this);
                return;
            }
            E_Admin data = new E_Admin();

            data.AdminID     = UserID;
            data.Password    = MLMGC.COMP.EncryptString.EncryptPassword(oldPassword);
            data.NewPassword = MLMGC.COMP.EncryptString.EncryptPassword(newPassword);
            bool flag = new T_Admin().UpdatePassword(data);

            MLMGC.COMP.Jscript.ShowMsg(string.Format("修改{0}!", flag?"成功":"失败"), this);
        }
        public static bool IsLogin()
        {
            T_Admin      model    = new T_Admin();
            AdminBll     bll      = new AdminBll();
            CookieHelper mycookie = new CookieHelper();
            string       token    = mycookie.getCookie("caketoken");
            bool         res      = false;

            if (!string.IsNullOrEmpty(token))
            {
                model = bll.GetAdminByToken(token);
                if (model == null)
                {
                    //  return  "没有权限,非法访问!";
                    res = false;
                }
                else
                {
                    res = true;
                }
            }
            else
            {
                res = false;
                //  return "未登陆,非法访问!";
                // Response.End();
            }
            return(res);
        }
Beispiel #7
0
 public bool AddAdmin(T_Admin model)
 {
     using (var db = new cakedbEntities())
     {
         db.T_Admin.Add(model);
         return(db.SaveChanges() > 0);
     }
 }
Beispiel #8
0
        /// <summary>
        /// 点击确定按钮处理事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string name     = txtName.Text.Trim();
            string password = txtPassword.Text.Trim();
            string confirm  = txtConfirm.Text.Trim();

            if (string.IsNullOrEmpty(name))
            {
                Jscript.ShowMsg("请输入用户名", this);
                return;
            }
            if (string.IsNullOrEmpty(password) & type == "add")
            {
                Jscript.ShowMsg("添加用户时必须输入密码", this);
                return;
            }
            if (password != confirm)
            {
                Jscript.ShowMsg("两次密码输入不一致", this);
                return;
            }

            E_Admin data = new E_Admin();

            data.AdminID  = id;
            data.UserName = name;
            data.Password = string.IsNullOrEmpty(password) ? "" : EncryptString.EncryptPassword(password);

            //先判断一下用户名是否存在
            bool b = new T_Admin().Exists(data);

            if (b)
            {
                Jscript.ShowMsg("用户名已存在", this);
                return;
            }

            bool flag = false;

            if (type == "add")
            {
                flag = new T_Admin().Add(data);
            }
            else if (type == "update")
            {
                flag = new T_Admin().Update(data);
            }
            if (flag)
            {
                Jscript.AlertAndRedirect(this, "操作成功", "adminlist.aspx");
            }
            else
            {
                Jscript.ShowMsg("操作失败", this);
            }
        }
Beispiel #9
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void databind()
        {
            E_Admin data = new E_Admin();

            data.AdminID = id;
            data         = new T_Admin().GetModel(data);
            if (data != null)
            {
                txtName.Text = data.UserName;
            }
        }
Beispiel #10
0
        public ActionResult LoginIndex(T_Admin t_Admin)
        {
            QueryCRUD query = new QueryCRUD();

            bool           chk     = query.CheckLogin(t_Admin.User_name, t_Admin.Password);
            List <T_Admin> listTic = new List <T_Admin>();
            QueryCRUD      qr      = new QueryCRUD();

            bool chkadmin = query.CheckAdmin(t_Admin.User_name, t_Admin.Password);

            if (t_Admin.User_name != null)
            {
                if (t_Admin.Password != null)
                {
                    if (chk == true)
                    {
                        if (chkadmin == true)
                        {
                            TempData["User_name"] = t_Admin.User_name;
                            Session["User_name"]  = t_Admin.User_name;

                            Session["Type"] = listTic;
                        }
                        else
                        {
                            Session["User_name2"] = t_Admin.User_name;
                        }


                        return(RedirectToAction("Index", "Show"));
                    }
                    else
                    {
                        TempData["message"] = "User And Password Invalid";
                        return(View());
                    }
                }
                else
                {
                    TempData["mgs"] = "Please Input Data !!!";
                    return(View());
                }
            }
            else
            {
                TempData["mgs"] = "Please Input Data !!!";
                return(View());
            }
        }
Beispiel #11
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            E_Admin data = new E_Admin();

            data.UserName = StringUtil.safety(UserName.Text);
            data.Password = EncryptString.EncryptPassword(StringUtil.safety(Password.Text.Trim()));
            T_Admin bll   = new T_Admin();
            E_Admin model = bll.UserLogin(data);

            if (model != null)
            {
                setSession(model.AdminID, model.UserName, model.Password);
                Response.Redirect("index.aspx");
            }
            Jscript.ShowMsg("帐号或密码错误,无法登录系统!", this);
        }
Beispiel #12
0
        /// <summary>
        /// 删除管理员
        /// </summary>
        private void AdminDelete()
        {
            int id;

            if (!int.TryParse(nv["id"], out id))
            {
                HttpContext.Current.Response.Write("参数错误");
                return;
            }
            E_Admin data = new E_Admin();

            data.AdminID = id;

            bool flag = new T_Admin().Delete(data);

            HttpContext.Current.Response.Write(flag ? "1" : "0");
        }
Beispiel #13
0
        /// <summary>
        /// 登陆确定、左键点击按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Login_OK_left_down(object sender, MouseButtonEventArgs e)
        {
            T_Admin tmode = new T_Admin();

            tmode.UserName = username.Text;
            tmode.PassWord = password.Password;
            D_Admin dmode = new D_Admin();

            string getResult_OK = dmode.Scan_Account(tmode);

            if (tmode.UserName == "" || tmode.PassWord == "")
            {
                if (tmode.UserName == "" && tmode.PassWord == "")
                {
                    MessageBox.Show("用户名和密码都不得为空");
                }
                if (tmode.UserName == "" && tmode.PassWord != "")
                {
                    MessageBox.Show("用户名不得为空");
                }
                if (tmode.UserName != "" && tmode.PassWord == "")
                {
                    MessageBox.Show("登陆密码不得为空");
                }
            }
            else
            {
                if (getResult_OK == "true")
                {
                    MessageBox.Show("登陆成功!");
                    WindowMain winMain = new WindowMain();
                    winMain.Show(); //打开新窗体
                    this.Close();   //关闭改窗体
                }
                if (getResult_OK == "false")
                {
                    username.Text     = "";
                    password.Password = "";
                    MessageBox.Show("登陆失败!账号或密码不正确");
                }
                if (getResult_OK != "true" && getResult_OK != "false")
                {
                    MessageBox.Show(getResult_OK);
                }
            }
        }
Beispiel #14
0
        private void Login(HttpContext context)
        {
            T_Admin  model    = new T_Admin();
            AdminBll bll      = new AdminBll();
            string   username = context.Request["username"];
            string   pwd      = context.Request["pwd"];

            if (bll.GetAdminModeByName(username, pwd))
            {
                CookieHelper mycookie = new CookieHelper();
                mycookie.setCookie("caketoken", username + pwd, 1);
                context.Response.Write("true");
            }
            else
            {
                context.Response.Write("false");
            }
        }
        public ActionResult ApprovedPR(PRandPRApp prandpra, T_Admin t_Admin)
        {
            QueryCRUD qr       = new QueryCRUD();
            T_Admin   t_Admins = new T_Admin();

            if (Session["User_name"] != null)
            {
                t_Admin.User_name = Session["User_name"].ToString();
                t_Admins          = qr.Get_T_Admins(t_Admin.User_name);

                int byid = t_Admins.User_ID;

                if (qr.EditPR(prandpra, byid))
                {
                    return(RedirectToAction("ShowPR"));
                }
            }
            return(View());
        }
Beispiel #16
0
        /// <summary>
        /// 判断管理员是否存在
        /// </summary>
        private void AdminExists()
        {
            int id;

            if (!int.TryParse(nv["id"], out id))
            {
                HttpContext.Current.Response.Write("参数错误");
                return;
            }
            string name = nv["name"];

            E_Admin data = new E_Admin();

            data.AdminID  = id;
            data.UserName = name;

            bool flag = new T_Admin().Exists(data);

            HttpContext.Current.Response.Write(flag ? "1" : "0");
        }
Beispiel #17
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            T_Admin  admin = new T_Admin();
            AdminBll bll   = new AdminBll();


            string username = this.txtuser.Value;
            string pwd      = this.txtpwd.Value;
            string realname = this.txtreal.Value;

            admin.CreateDate = DateTime.Now;
            admin.UserName   = username;
            admin.Pwd        = pwd;
            admin.RealName   = realname;
            admin.admintoken = MD5Helper.MD5JM(username + pwd);
            if (bll.AddAdmin(admin))
            {
                this.msg.InnerText = "添加成功!";
            }
            else
            {
                this.msg.InnerText = "添加失败!";
            }
        }
Beispiel #18
0
        public bool AddAdmin(T_Admin model)
        {
            AdminDal dal = new AdminDal();

            return(dal.AddAdmin(model));
        }