Пример #1
0
        public JsonResult AddUserAction(MesWeb.Model.T_User user)
        {
            var retData = new VM_Result_Data();

            if (!string.IsNullOrEmpty(user.UserName) && user.EmployeeID.Value > 0)
            {
                try {
                    var bllUser = new MesWeb.BLL.T_User();
                    user.Password = SecurityHelper.encryptPlainPwd("123456");
                    if (bllUser.Add(user) > 0)
                    {
                        retData.Code    = RESULT_CODE.OK;
                        retData.Content = "添加用户成功";
                    }
                } catch (Exception e) {
                    log = LogFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.FullName + ":" + MethodBase.GetCurrentMethod().Name);
                    log.Error("添加用户失败!", e);
                }
            }
            else
            {
                retData.Content = "名称或绑定员工不能为空";
            }
            return(Json(retData));
        }
Пример #2
0
        public JsonResult UpdateUserAction(MesWeb.Model.T_User user)
        {
            var retData = new VM_Result_Data();
            var bllUser = new MesWeb.BLL.T_User();

            retData.Content = "更新用户失败";
            if (user != null)
            {
                var oldUser = bllUser.GetModel(user.UserID);
                if (oldUser != null)
                {
                    //如果用户没有输入密码,则使用原来的密码
                    if (string.IsNullOrEmpty(user.Password))
                    {
                        user.Password = oldUser.Password;
                    }
                    else
                    {
                        //对用户的密码进行第二次加密
                        user.Password = SecurityHelper.encryptMD5Pwd(user.Password);
                    }
                    try {
                        if (bllUser.Update(user))
                        {
                            retData.Code    = RESULT_CODE.OK;
                            retData.Content = "更新用户成功";
                        }
                    } catch (Exception e) {
                        log = LogFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.FullName + ":" + MethodBase.GetCurrentMethod().Name);
                        log.Error("更新用户失败!", e);
                    }
                }
            }
            return(Json(retData));
        }
Пример #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(MesWeb.Model.T_User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into T_User(");
            strSql.Append("UserName,EmployeeID,AuthenticID,Password,IsValidate)");
            strSql.Append(" values (");
            strSql.Append("@UserName,@EmployeeID,@AuthenticID,@Password,@IsValidate)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserName",    SqlDbType.NVarChar, 50),
                new SqlParameter("@EmployeeID",  SqlDbType.Int,       4),
                new SqlParameter("@AuthenticID", SqlDbType.Int,       4),
                new SqlParameter("@Password",    SqlDbType.NVarChar, 50),
                new SqlParameter("@IsValidate",  SqlDbType.Bit, 1)
            };
            parameters[0].Value = model.UserName;
            parameters[1].Value = model.EmployeeID;
            parameters[2].Value = model.AuthenticID;
            parameters[3].Value = model.Password;
            parameters[4].Value = model.IsValidate;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #4
0
        public JsonResult Lgoin(MesWeb.Model.T_User user)
        {
            var isOpenVerify = false;
            var retData      = new VM_Result_Data();
            var bllUser      = new MesWeb.BLL.T_User();

            bool.TryParse(ConfigurationManager.AppSettings["openLoginVerify"], out isOpenVerify);
            //未开启登录验证
            if (isOpenVerify == false)
            {
                retData.Code    = RESULT_CODE.OK;
                retData.Content = "未开启登录验证,随意登录";
                Session[SecurityHelper.isLoginSessionId] = bllUser.GetModelList("UserName = '******'").FirstOrDefault();
            }
            else
            {
                retData.Content = "用户名或密码错误";
                if (user != null)
                {
                    var secUser = bllUser.GetModelList("UserName = '******'").FirstOrDefault();

                    if (secUser != null)
                    {
                        //允许登录
                        if (secUser.IsValidate == true)
                        {
                            user.Password = SecurityHelper.encryptMD5Pwd(user.Password);
                            if (secUser.Password == user.Password)
                            {
                                //设置session
                                Session[SecurityHelper.isLoginSessionId] = secUser;
                                retData.Code    = RESULT_CODE.OK;
                                retData.Content = "登录成功";
                            }
                        }
                        else
                        {
                            retData.Content = "该用户禁止登陆,请联系管理员";
                        }
                    }
                }
            }
            return(Json(retData));
        }
Пример #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public MesWeb.Model.T_User DataRowToModel(DataRow row)
 {
     MesWeb.Model.T_User model = new MesWeb.Model.T_User();
     if (row != null)
     {
         if (row["UserID"] != null && row["UserID"].ToString() != "")
         {
             model.UserID = int.Parse(row["UserID"].ToString());
         }
         if (row["UserName"] != null)
         {
             model.UserName = row["UserName"].ToString();
         }
         if (row["EmployeeID"] != null && row["EmployeeID"].ToString() != "")
         {
             model.EmployeeID = int.Parse(row["EmployeeID"].ToString());
         }
         if (row["AuthenticID"] != null && row["AuthenticID"].ToString() != "")
         {
             model.AuthenticID = int.Parse(row["AuthenticID"].ToString());
         }
         if (row["Password"] != null)
         {
             model.Password = row["Password"].ToString();
         }
         if (row["IsValidate"] != null && row["IsValidate"].ToString() != "")
         {
             if ((row["IsValidate"].ToString() == "1") || (row["IsValidate"].ToString().ToLower() == "true"))
             {
                 model.IsValidate = true;
             }
             else
             {
                 model.IsValidate = false;
             }
         }
     }
     return(model);
 }
Пример #6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(MesWeb.Model.T_User model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update T_User set ");
            strSql.Append("UserName=@UserName,");
            strSql.Append("EmployeeID=@EmployeeID,");
            strSql.Append("AuthenticID=@AuthenticID,");
            strSql.Append("Password=@Password,");
            strSql.Append("IsValidate=@IsValidate");
            strSql.Append(" where UserID=@UserID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserName",    SqlDbType.NVarChar, 50),
                new SqlParameter("@EmployeeID",  SqlDbType.Int,       4),
                new SqlParameter("@AuthenticID", SqlDbType.Int,       4),
                new SqlParameter("@Password",    SqlDbType.NVarChar, 50),
                new SqlParameter("@IsValidate",  SqlDbType.Bit,       1),
                new SqlParameter("@UserID",      SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserName;
            parameters[1].Value = model.EmployeeID;
            parameters[2].Value = model.AuthenticID;
            parameters[3].Value = model.Password;
            parameters[4].Value = model.IsValidate;
            parameters[5].Value = model.UserID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #7
0
        public JsonResult GetUserInfoAction(int userId)
        {
            var retData = new VM_Result_Data();
            var bllUser = new MesWeb.BLL.T_User();
            var user    = bllUser.GetModel(userId);

            if (user != null)
            {
                var retUser = new MesWeb.Model.T_User();
                retUser.UserName = user.UserName;
                retUser.UserID   = user.UserID;
                retData.Code     = RESULT_CODE.OK;
                retData.Appendix = retUser;
                retData.Content  = "加载用户成功";
            }
            else
            {
                retData.Content = "加载用户失败";
                log             = LogFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.FullName + ":" + MethodBase.GetCurrentMethod().Name);
                log.Error("加载用户失败!");
            }
            return(Json(retData));
        }
Пример #8
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public MesWeb.Model.T_User GetModel(int UserID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 UserID,UserName,EmployeeID,AuthenticID,Password,IsValidate from T_User ");
            strSql.Append(" where UserID=@UserID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID", SqlDbType.Int, 4)
            };
            parameters[0].Value = UserID;

            MesWeb.Model.T_User model = new MesWeb.Model.T_User();
            DataSet             ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }