Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            UserInfo userInfo = GetModel();

            UserInfoBll bll = new UserInfoBll();

            if (UserId == 0)
            {
                DepartmentBll departmentBll = new DepartmentBll();
                DepartmentInfo departmentInfo = departmentBll.GetDepartmentById(DepartmentId);
                if (departmentInfo != null && departmentInfo.DepartmentId > 0)
                {
                    userInfo.DepartmentCode = departmentInfo.DepartmentCode;
                }
                bll.AddUserInfo(userInfo);

            }
            else
            {
                userInfo.UserId = UserId;
                bll.Update(userInfo);
            }

            Page.RegisterClientScriptBlock("", "<script>alert('保存成功');CloseWin();</script>");
        }
        public ActionResult Edit(string UName, string Pwd, string Name, string Tel, int id)
        {
            var userUpdate = UserInfoBll.LoadEntities(u => u.Id == id).FirstOrDefault();

            if (userUpdate != null)
            {
                userUpdate.UName = UName;
                if (!string.IsNullOrEmpty(Pwd))
                {
                    string MD5Pwd = Md5Helper.GetMd5(Pwd);
                    userUpdate.Pwd = MD5Pwd;
                }
                userUpdate.Name = Name;
                userUpdate.Tel  = Tel;
                if (UserInfoBll.Update(userUpdate))
                {
                    return(Content("ok"));
                }
                else
                {
                    return(Content("修改失败"));
                }
            }
            return(Content("数据为空"));
        }
Пример #3
0
        //保存
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string      id           = Request["UserId"];
            UserInfoBll bll          = new UserInfoBll();
            UserInfo    model        = new UserInfo();
            string      oldAdminName = string.Empty;

            if (!string.IsNullOrEmpty(id))//如果是修改操作
            {
                model = bll.GetModel(Convert.ToInt32(id));
            }
            else //如果是新增操作
            {
                model.UserPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtUserPwd.Text.Trim(), "MD5");
            }
            model.UserName = this.txtUserName.Text.Trim();
            model.RoleId   = "";
            for (int i = 0; i < this.chkListRole.Items.Count; i++)
            {
                if (this.chkListRole.Items[i].Selected)
                {
                    model.RoleId += this.chkListRole.Items[i].Value + ",";
                }
            }
            if (model.RoleId.IndexOf(',') != -1)
            {
                model.RoleId = model.RoleId.Substring(0, model.RoleId.Length - 1);
            }
            if (string.IsNullOrEmpty(model.RoleId))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择一个角色!');</script>");
                return;
            }
            model.IsLock = Convert.ToInt32(this.rdoList.SelectedValue);
            model.Desc   = this.txtDesc.Text.Trim();


            int n = 0;

            if (!string.IsNullOrEmpty(id))//如果是修改操作
            {
                n = bll.Update(model, null);
            }
            else //如果是新增操作
            {
                n = bll.Insert(model, null);
            }

            if (n > 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功!');</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存失败!');</script>");
            }
        }
        public JsonResponse ChangeCategoryName([FromBody] ChangeCategoryNameDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //获取更改者信息
            var userModel = UserInfoBll.GetModelById(dto.UserId);

            if (userModel == null)
            {
                return(BadResponse("用户信息出错,请重试!"));
            }
            //查询使用人数
            var categoryModel = AccountCategoryBll.GetModelByName(dto.OldName);

            if (categoryModel == null)
            {
                //此时代表数据库出问题了,应作出处理-----------------------------------------------------------------
                return(BadResponse("分类信息出错,请重试!"));
            }
            //若使用人数为1则直接更新名字
            if (categoryModel.UserNum <= 1)
            {
                categoryModel.Name = dto.NewName;
                if (!AccountCategoryBll.Update(categoryModel))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }
            //若有他人使用则新建一条,原条目使用人数-1,将UserInfo中的Category字段更换为新Id
            else
            {
                categoryModel.UserNum--;
                if (!AccountCategoryBll.Update(categoryModel))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
                categoryModel = new AccountCategory
                {
                    Name         = dto.NewName,
                    CreateUserId = dto.UserId
                };
                if (!AccountCategoryBll.Insert(categoryModel))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }
            userModel.Category = userModel.Category.Replace(dto.OldName, dto.NewName);
            if (!UserInfoBll.Update(userModel))
            {
                return(BadResponse("网络错误,请重试!"));
            }
            return(OkResponse(null, "修改成功!"));
        }
Пример #5
0
 public ActionResult Edit(UserInfo user)
 //public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         // TODO: Add update logic here
         userInfoBll.Update(user);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Пример #6
0
        public ActionResult btnSaveHideRefresh_Click(FormCollection fm)
        {
            int    ID;
            string n = fm["UName"];

            // 1. 这里放置保存窗体中数据的逻辑
            if (!string.IsNullOrEmpty(fm["UID"]) && int.TryParse(fm["UID"], out ID))
            {
                UserInfo user = userInfoBll.GetEntities(u => u.ID == ID).FirstOrDefault();
                if (user != null)
                {
                    user.UName    = fm["UName"];
                    user.Pwd      = fm["Pwd"];
                    user.Remark   = fm["Remark"];
                    user.ShowName = fm["ShowName"];
                    user.SubTime  = Convert.ToDateTime(fm["SubTime"]);

                    //MatchCollection mc = rx.Matches(fm["RoleList[]"]);
                    //if (mc != null && mc.Count > 0)
                    //{
                    //    RoleInfo role;
                    //    foreach (var m in mc)
                    //    {
                    //        int intm = Convert.ToInt32(m.ToString());
                    //        role = roleInfoBll.GetEntities(r => r.ID == intm).FirstOrDefault();
                    //        user.RoleInfo.Add(role);
                    //    }
                    //}
                    MatchCollection mc = rx.Matches(fm["RoleList"]);
                    if (mc != null && mc.Count > 0)
                    {
                        user.RoleInfo.Clear();
                        RoleInfo role;
                        foreach (var m in mc)
                        {
                            int intm = Convert.ToInt32(m.ToString());
                            role = roleInfoBll.GetEntities(r => r.ID == intm).FirstOrDefault();
                            user.RoleInfo.Add(role);
                        }
                    }
                }
                userInfoBll.Update(user);
            }

            // 2. 隐藏本窗体,然后刷新父窗体
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());

            return(UIHelper.Result());
        }
Пример #7
0
        public ActionResult login()
        {
            string validatecode = Session["validateCode"] == null ? string.Empty : Session["validateCode"].ToString();

            if (string.IsNullOrEmpty(validatecode))
            {
                return(Content("no:验证码错误!"));
            }
            Session["validateCode"] = null;//清空session保存的验证码
            string txtCode = Request["vCode"];

            //如果两个字符串不想等
            if (!validatecode.Equals(txtCode, StringComparison.CurrentCultureIgnoreCase))
            {
                return(Content("errorCode:验证码错误!"));
            }
            //校验用户名和密码
            string userName = Request["LoginCode"];
            string userPwd  = Request["LoginPwd"];
            string pwd      = Md5Helper.GetMd5(userPwd);

            if (userName == "" || userPwd == "")
            {
                return(Content("no:用户名或密码不能为空!"));
            }
            else
            {
                var users = UserInfoBll.LoadEntities(u => u.UName == userName && u.Pwd == pwd && u.State == "1" && u.DelFlag == 0).FirstOrDefault();
                if (users != null)
                {
                    //  --------------------- 用户memcached模拟Session-----------------------------
                    Guid guid = Guid.NewGuid();
                    //guid为key,以登录用户为value放到memcached里面去
                    Common.CacheHelper.WriteCache(guid.ToString(), users, DateTime.Now.AddMinutes(250));
                    //把guid写到cookies里面去
                    Response.Cookies["mySessionId"].Value = guid.ToString();
                    users.Last_login_Time = DateTime.Now;
                    users.Login_Num       = users.Login_Num + 1;
                    UserInfoBll.Update(users);
                    return(Content("ok:登录成功!"));
                }
                else
                {
                    return(Content("fail:用户名或密码错误!"));
                }
            }
        }
        public JsonResponse AddCategory([FromBody] AccountCategoryDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //查询有没有
            var model = AccountCategoryBll.GetModelByName(dto.Name);

            //有的话则UserNum+1
            if (model != null)
            {
                model.UserNum = model.UserNum + 1;
                if (!AccountCategoryBll.Update(model))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }
            //没有则添加
            else
            {
                model = new AccountCategory
                {
                    Name         = dto.Name,
                    CreateUserId = dto.UserId
                };
                if (!AccountCategoryBll.Insert(model))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }
            //将Category的Id添加到UserInfo的Category字段中
            model = AccountCategoryBll.GetModelByName(dto.Name);
            var user = UserInfoBll.GetModelById(dto.UserId);

            if (user == null)
            {
                return(BadResponse("用户信息出错,请重试!"));
            }
            user.Category += (model.Name + ",");
            if (!UserInfoBll.Update(user))
            {
                return(BadResponse("网络错误,请重试!"));
            }
            return(OkResponse(null, "添加成功!"));
        }
Пример #9
0
        //UserInfo copy to Database
        private void listenClient_OnNewUser(UserInfoModel user)
        {
            var userModel = UserInfoBll.Get(user.PIN);
            int nRtn      = 0;

            if (null == userModel)
            {
                nRtn = _userInfoBll.Add(user);
            }
            else
            {
                nRtn = _userInfoBll.Update(user);
            }
            if (nRtn > 0 && _currentPageId == (int)PageIdEnum.User && m_lastfrm != null)
            {
                ((UCUser)m_lastfrm).LoadAllUsers();
            }
        }
Пример #10
0
        public ActionResult EditPwd()
        {
            //1.采集用户的输入
            string oldPwd        = Request.Form["oldPwd"].Trim() as string;
            string Md5oldPwd     = Md5Helper.GetMd5(oldPwd);
            string newPwd        = Request.Form["newPwd"].Trim() as string;
            string confirmPwd    = Request.Form["confirmPwd"].Trim() as string;
            string Md5confirmPwd = Md5Helper.GetMd5(confirmPwd);

            //2.校验两次输入的新密码是否正确
            if (newPwd == confirmPwd)
            {
                //3.校验旧密码是否正确
                //根据guid拿到当前登录的用户
                string guid = Request["mySessionId"];
                if (!string.IsNullOrEmpty(guid))
                {
                    //从分布式缓存拿出来的对象不能进行延迟加载。
                    var loginAdmin = Common.CacheHelper.Get(guid) as UserInfo;
                    if (loginAdmin != null)
                    {
                        UserInfo user = UserInfoBll.LoadEntities(u => u.Id == loginAdmin.Id).FirstOrDefault();
                        if (user.Pwd == Md5oldPwd)
                        {
                            //4.修改密码
                            user.Pwd = Md5confirmPwd;
                            if (UserInfoBll.Update(user))
                            {
                                return(Content("ok"));
                            }
                            else
                            {
                                return(Content("fail"));
                            }
                        }
                        else
                        {
                            return(Content("oldPwdError"));
                        }
                    }
                }
            }
            return(Content("different"));
        }
        public JsonResponse DeleteUserCategory([FromBody] AccountCategoryDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            //查询该类别的Id
            var categoryModel = AccountCategoryBll.GetModelByName(dto.Name);
            //从UserInfo中的Category字段里删除该类别
            var userModel = UserInfoBll.GetModelById(dto.UserId);

            if (userModel == null)
            {
                return(BadResponse("用户信息出错,请重试!"));
            }
            userModel.Category = userModel.Category.Replace((categoryModel.Name + ","), "");
            if (!UserInfoBll.Update(userModel))
            {
                return(BadResponse("网络错误,请重试!"));
            }
            if (categoryModel == null)
            {
                //此时代表数据库出问题了,应作出处理-----------------------------------------------------------------
                return(OkResponse(null, "删除成功!"));
            }
            //类别表中该类别使用数-1,若使用数为0则删除该类别
            if (categoryModel.UserNum == 1)
            {
                AccountCategoryBll.ExecuteSql("delete from AccountCategory where Name='" + categoryModel.Name + "'");
            }
            else
            {
                categoryModel.UserNum--;
                if (AccountCategoryBll.Update(categoryModel))
                {
                    return(BadResponse("网络错误,请重试!"));
                }
            }

            return(OkResponse(null, "删除成功!"));
        }
        public ActionResult ChangeUsersState(int id)
        {
            UserInfo user = new UserInfo()
            {
                Id = id,
            };

            if (user != null)
            {
                var userState = UserInfoBll.LoadEntities(u => u.Id == id).FirstOrDefault();
                //当前用户状态等于0的改变为1
                if (userState.State == "0")
                {
                    userState.State = "1";

                    if (UserInfoBll.Update(userState))
                    {
                        return(Content("ok"));
                    }
                    else
                    {
                        return(Content("fail"));
                    }
                }
                else
                {
                    userState.State = "0";
                    if (UserInfoBll.Update(userState))
                    {
                        return(Content("ok"));
                    }
                    else
                    {
                        return(Content("fail"));
                    }
                }
            }
            else
            {
                return(Content("empty"));
            }
        }
Пример #13
0
        public JsonResponse ModifyPassword([FromBody] ModifyPasswordDto dto)
        {
            //判断用户是否登录
            if (!TokenHelper.CheckLoginStateByUserId(dto.UserId))
            {
                return(BadResponse("用户未登录", null, false));
            }
            if (dto.UserId == null || dto.OldPassword == null || dto.NewPassword == null || dto.Verify == null || dto.VerifyId == null)
            {
                return(BadResponse("参数提供不完整"));
            }
            //判断验证码是否输入正确
            if (!TokenHelper.CheckVerify(dto.VerifyId, dto.Verify))
            {
                return(BadResponse("验证码错误"));
            }
            UserInfo model = new UserInfo();

            model = UserInfoBll.GetModelById(dto.UserId);

            //判断用户是否存在
            if (model == null)
            {
                return(BadResponse("用户不存在"));
            }
            //新密码加密
            dto.NewPassword = PasswordHelper.PwdStrToHashStr(dto.NewPassword);
            //判断新旧密码是否相同
            if (dto.NewPassword == model.Password)
            {
                return(BadResponse("旧密码与新密码相同"));
            }
            //若不相同新密码写入数据库
            model.Password = dto.NewPassword;
            if (!UserInfoBll.Update(model))
            {
                return(BadResponse("网络错误,请重试"));
            }
            return(OkResponse(null, "密码修改成功"));
        }
        /// <summary>
        /// 保存用户按钮事件
        /// </summary>

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtPin.Text))
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text    = "Please input user id.";
                return;
            }
            lblMsg.Visible = false;
            UserInfoModel user = _bll.Get(txtPin.Text.Trim());  //数据库中获取对应pin的用户信息

            if (user == null)
            {
                user = new UserInfoModel();
            }
            user.PIN      = txtPin.Text;
            user.UserName = txtUserName.Text;
            user.Passwd   = txtPassword.Text;
            user.IDCard   = txtCard.Text;
            user.Pri      = cmbPrivilege.SelectedValue.ToString();

            int ret = 0;

            try
            {
                //数据库中没有对应的用户,则增加
                if (user.ID == 0)
                {
                    ret = _bll.Add(user);
                    if (ret > 0)
                    {
                        LoadAllUsers();  //更新用户列表
                        this.lblMsg.Visible = true;
                        this.lblMsg.Text    = "Add successful.";
                    }
                    else
                    {
                        this.lblMsg.Visible = true;
                        this.lblMsg.Text    = "Add fail.";
                    }
                }
                else
                {
                    //数据库找到对应的用户,则更新
                    ret = _bll.Update(user);
                    if (ret > 0)
                    {
                        LoadAllUsers();  //更新用户列表
                        this.lblMsg.Visible = true;
                        this.lblMsg.Text    = "Update successful.";
                    }
                    else
                    {
                        this.lblMsg.Visible = true;
                        this.lblMsg.Text    = "Update fail.";
                    }
                }

                if (ret > 0)
                {
                    //保存用户photoiD
                    string strDesPath = "";
                    strDesPath = System.Environment.CurrentDirectory + "\\Photo\\" + txtPin.Text + ".jpg";

                    if (picUserPhoto.ImageLocation != null)
                    {
                        File.Copy(picUserPhoto.ImageLocation, strDesPath, true); //notice,picturebox的ImageLocation使用前,需要手动给他附上值
                    }
                    txtPin.Enabled = false;                                      //保存了之后pin不可再编辑
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text    = ex.ToString();
            }
        }
Пример #15
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string name = txtname.Text.Trim();
            string pwd1 = txtpwd1.Text.Trim();
            string pwd2 = txtpwd2.Text.Trim();
            string qx   = comboBox1.SelectedIndex.ToString(); //0 普通用户  1管理员

            string userId = labuserid.Text;

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd1) || string.IsNullOrEmpty(pwd2))
            {
                MessageBox.Show("请完善信息");
            }
            else
            {
                if (pwd1.Length != 6)
                {
                    MessageBox.Show("密码必须是6位");
                    txtpwd1.Text = "";
                    txtpwd2.Text = "";
                }
                else
                {
                    if (pwd1 != pwd2)
                    {
                        MessageBox.Show("两次密码不一致");
                        txtpwd1.Text = "";
                        txtpwd2.Text = "";
                    }
                    else
                    {
                        if (userInfobll.Exists(name) && Convert.ToInt32(userId) <= 0)
                        {
                            //已存在
                            MessageBox.Show("该用户已存在");
                        }
                        else
                        {
                            UserInfo m = new UserInfo();
                            m.createtime = DateTime.Now;
                            m.username   = name;
                            m.userpwd    = Common.GetMD532(pwd1, "");
                            m.qx         = qx;
                            if (Convert.ToInt32(userId) > 0)
                            {
                                m.id         = Convert.ToInt32(userId);
                                m.createtime = DateTime.Now;

                                string oldpwd = Common.GetMD532(txtoldpwd.Text, "");
                                if (oldpwd != label6.Text)
                                {
                                    MessageBox.Show("和原来密码不一致");
                                    return;
                                }

                                //编辑
                                if (userInfobll.Update(m))
                                {
                                    MessageBox.Show("修改成功");
                                    Common.Add("登陆用户:" + _userId, ",用户信息修改成功" + DateTime.Now);
                                }
                                else
                                {
                                    MessageBox.Show("修改失败");
                                }
                                this.Close();
                            }
                            else
                            {
                                //新增
                                if (userInfobll.Add(m))
                                {
                                    MessageBox.Show("添加成功");
                                    Common.Add("登陆用户:" + _userId, ",新用户添加成功" + DateTime.Now);
                                }
                                else
                                {
                                    MessageBox.Show("添加失败");
                                }
                                this.Close();
                            }
                        }
                    }
                }
            }
        }