Esempio n. 1
0
 /// <summary>
 /// 修改一条记录
 /// </summary>
 /// <param name="model">实体类</param>
 /// <returns></returns>
 public bool Update(SysUserEntity model)
 {
     using (IDbConnection conn = new SqlConnection(SqlHelper.connStr))
     {
         string            sql   = string.Format(@"Update SysUser set LoginName=@LoginName,Name=@Name,NickName=@NickName,DealerId=@DealerId,
                                  UserTypeId=@UserTypeId,LoginPwd=@LoginPwd,Email=@Email,Phone=@Phone,IsActivate=@IsActivate,
                                  Remark=@Remark where PKID=@PKID");
         DynamicParameters param = new DynamicParameters();
         param.Add("LoginName", model.LoginName);
         param.Add("Name", model.Name);
         param.Add("NickName", model.NickName);
         param.Add("DealerId", model.DealerId);
         param.Add("UserTypeId", model.UserTypeId);
         param.Add("LoginPwd", model.LoginPwd);
         param.Add("Email", model.Email);
         param.Add("Phone", model.Phone);
         param.Add("IsActivate", model.IsActivate);
         param.Add("Remark", model.Remark);
         param.Add("PKID", model.PKID);
         int result = conn.Execute(sql, param);
         if (result > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 根据名称和密码获取用户信息
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public UserDto CheckLogin(LoginInputDto inputDto)
        {
            SysUserEntity entity = _sysUserRepository.GetAll().Where(b => b.UserName.Equals(inputDto.Name) && b.Password.Equals(inputDto.Pwd)).FirstOrDefault();
            UserDto       dto    = AutoMapper.Mapper.Map <UserDto>(entity);

            return(dto);
        }
Esempio n. 3
0
        /// <summary>
        /// 判断当前节点是否已存在相同的
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int  ExistNum(SysUserEntity entity)
        {
            ///id=0,判断总数,ID>0判断除自己之外的总数
            string sql = @"Select count(1) from dbo.[SysUser] WITH(NOLOCK) ";

            string where = "where ";
            if (entity.Id == 0)
            {
                where = where + "  (UserCode=@UserCode) ";
            }
            else
            {
                where = where + " id<>@Id and  (UserCode=@UserCode) ";
            }
            sql = sql + where;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            if (entity.Id > 0)
            {
                db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            }

            db.AddInParameter(cmd, "@UserCode", DbType.String, entity.UserCode);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Esempio n. 4
0
        private async Task <AuthLoginResponse> getUserItem(SysUserEntity user)
        {
            var res = _mapper.Map <AuthLoginResponse>(user);

            #region 得到菜单数据
            AuthResourceResponse authResource = new AuthResourceResponse();
            var cacheKey = string.Format(CacheKeyTemplate.PermissionResourceList, user.PermissionId);
            if (await _cache.ExistsAsync(cacheKey))
            {
                authResource = await _cache.GetAsync <AuthResourceResponse>(cacheKey);
            }
            else
            {
                var resourceList = await _permissionDomain.GetPermissionResourcesAsync(user.PermissionId);

                var menuList          = resourceList.Where(x => new[] { ResourceType.Group, ResourceType.Menu }.Contains(x.ResourceType));
                var functionPointList = resourceList.Where(x => x.ResourceType == ResourceType.Func);

                authResource.Menus          = _mapper.Map <List <ResourceForMenuResponse> >(menuList);
                authResource.FunctionPoints = functionPointList.Select(x => menuList.Where(y => y.Id == x.ParentId).FirstOrDefault()?.Code + "." + x.Code).ToList();

                // 写入缓存
                await _cache.SetAsync(cacheKey, authResource);
            }
            #endregion


            res.Menus          = authResource.Menus;
            res.FunctionPoints = authResource.FunctionPoints;

            return(res);
        }
Esempio n. 5
0
        public SysUserEntity GetUserByUserCode(string code)
        {
            string    sql = @"SELECT  [Id],[UserCode],[UserName],[PassWord],[IsActive],[CreateTime],[UserLevel]
							FROM
							dbo.[SysUser] WITH(NOLOCK)	
							WHERE [UserCode]=@UserCode and IsActive=1"                            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@UserCode", DbType.String, code);
            SysUserEntity entity = new SysUserEntity();

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    entity.Id         = StringUtils.GetDbInt(reader["Id"]);
                    entity.UserCode   = StringUtils.GetDbString(reader["UserCode"]);
                    entity.UserName   = StringUtils.GetDbString(reader["UserName"]);
                    entity.PassWord   = StringUtils.GetDbString(reader["PassWord"]);
                    entity.IsActive   = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]);
                    entity.UserLevel  = StringUtils.GetDbInt(reader["UserLevel"]);
                }
            }
            return(entity);
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code">账号</param>
        /// <param name="password">密码</param>
        /// <param name="clienttype">客户端种类</param>
        /// <param name="ipaddress">ip地址</param>
        /// <param name="recommendcode">推荐码</param>
        /// <returns></returns>
        public AdminLoginEntity Register(string code, string password)
        {
            AdminLoginEntity _returnentity = new AdminLoginEntity();
            SysUserEntity    _entity       = new SysUserEntity();

            _entity.UserCode   = code;
            _entity.PassWord   = password;
            _entity.CreateTime = DateTime.Now;
            _entity.UserLevel  = 1;
            if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(password))
            {
                _returnentity.ResultCode = ((int)CommonStatus.RegisterEmpty).ToString();
                _returnentity.ResultMsg  = EnumShow.Instance.GetEnumDes(CommonStatus.RegisterEmpty);
                return(_returnentity);
            }
            if (SysUserBLL.Instance.IsExist(_entity))
            {
                _returnentity.ResultCode = ((int)CommonStatus.RegisterHasMember).ToString();
                _returnentity.ResultMsg  = EnumShow.Instance.GetEnumDes(CommonStatus.RegisterHasMember);
                return(_returnentity);
            }
            _entity.Id = SysUserBLL.Instance.AddSysUser(_entity);

            if (_entity.Id > 0)
            {
                _returnentity.ResultCode = ((int)CommonStatus.Success).ToString();
                _returnentity.ResultMsg  = EnumShow.Instance.GetEnumDes(CommonStatus.Success);
                _returnentity.Member     = _entity;
                return(_returnentity);
            }

            return(_returnentity);
        }
Esempio n. 7
0
        public void SetUserBusinesses(SysUserEntity User, List <BusinessSystemInfo> Businesses)
        {
            var allKeys = this.All(false).Select(s => s.Key);

            var addSysKeys = Businesses.Select(s => s.Key);

            var deleteSys = allKeys.Except(addSysKeys);

            foreach (var key in deleteSys)
            {
                _IBaseConfig.Delete(string.Format("BusinessSystem.{0}.User.{1}", key, User.ID));
            }

            foreach (var b in Businesses)
            {
                var part = string.Format("BusinessSystem.{0}.User.{1}", b.Key, User.ID);

                if (!_IBaseConfig.Exists(c => c.Key == part))
                {
                    _IBaseConfig.Add(new ConfigEntity()
                    {
                        Key       = part,
                        Value     = User.Account,
                        IsDeleted = false,
                        Type      = "1"
                    });
                }
            }
        }
Esempio n. 8
0
        public void SetUserRoles(SysUserEntity User, List <OrgInfo> Roles)
        {
            var rolePart = string.Format("{0}.{1}", CONST_Origanization, CONST_Role);

            var userPart = string.Format("{0}.{1}", CONST_User, User.ID);

            var allConfigs = _IBaseConfig.GetConfigEntitys(c => c.Key.StartsWith(rolePart) && c.Key.EndsWith(userPart));

            var userRoleIDs = new List <string>();

            Roles.ForEach(r =>
            {
                var allPart = string.Format("{0}.{1}.{2}", rolePart, r.Key, userPart);

                userRoleIDs.Add(allPart);

                var role = allConfigs.FirstOrDefault(c => c.Key == allPart);

                if (role == null)
                {
                    // add
                    _IBaseConfig.Add(new ConfigEntity()
                    {
                        Key       = allPart,
                        Value     = User.Name,
                        IsDeleted = false,
                        Type      = "1"
                    });
                }
            });

            var qUserRoleIDs = userRoleIDs.AsQueryable();

            _IBaseConfig.Delete(c => c.Key.StartsWith(rolePart) && c.Key.EndsWith(userPart) && !qUserRoleIDs.Contains(c.Key));
        }
Esempio n. 9
0
        public AdminLoginEntity Login(string code, string password)
        {
            AdminLoginEntity _returnentity = new AdminLoginEntity();

            if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(password))
            {
                _returnentity.ResultCode = ((int)CommonStatus.LoginEmpty).ToString();
                _returnentity.ResultMsg  = EnumShow.Instance.GetEnumDes(CommonStatus.LoginEmpty);
                return(_returnentity);
            }
            SysUserEntity _entity = SysUserBLL.Instance.GetUserByUserCode(code);

            if (_entity == null)
            {
                _returnentity.ResultCode = ((int)CommonStatus.LoginNoMemCode).ToString();
                _returnentity.ResultMsg  = EnumShow.Instance.GetEnumDes(CommonStatus.LoginNoMemCode);
                return(_returnentity);
            }
            string passmd5 = CryptMD5.Encrypt(password);

            if (_entity.PassWord != passmd5)
            {
                _returnentity.ResultCode = ((int)CommonStatus.LoginError).ToString();
                _returnentity.ResultMsg  = EnumShow.Instance.GetEnumDes(CommonStatus.LoginError);
                return(_returnentity);
            }
            _returnentity.Member     = _entity;
            _returnentity.ResultCode = ((int)CommonStatus.Success).ToString();
            _returnentity.ResultMsg  = EnumShow.Instance.GetEnumDes(CommonStatus.Success);

            return(_returnentity);
        }
Esempio n. 10
0
        /// <summary>
        /// 根据用户信息创建 token
        /// </summary>
        /// <param name="account">账户名(暂时存用户ID)</param>
        /// <param name="tokenDateDuring">过期时间(小时)</param>
        /// <returns></returns>
        public string CreateToken(SysUserEntity account, int tokenDateDuring = 24 * 30)
        {
            var now = DateTime.UtcNow;

            // 创建 token描述信息
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                // 设置已颁发令牌中包含的输入声明
                Subject = new ClaimsIdentity(new Claim[] {
                    new Claim(ClaimTypes.Name, account.ID.ToString()), // 登录账户
                    new Claim(ClaimTypes.Role, "users")                // 所属角色
                }),

                // 设置用于对令牌进行签名的凭据
                SigningCredentials = new SigningCredentials(
                    new InMemorySymmetricSecurityKey(TokenConfig.SymmetricKey),
                    "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",
                    "http://www.w3.org/2001/04/xmlenc#sha256"
                    ),

                AppliesToAddress = TokenConfig.Audience,

                TokenIssuerName = TokenConfig.Issuer,

                Lifetime = new Lifetime(now, now.AddHours(tokenDateDuring)),
            };

            var tokenHandler = new JwtSecurityTokenHandler();
            var token        = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }
Esempio n. 11
0
        public int Insert(SysUserEntity model)
        {
            StringBuilder strsql = new StringBuilder();

            strsql.Append("insert into sys_user(usercode,username,userpwd,rolenames,orgnames,configjson,isenable,createby,createdate,jobcode,positions) ");
            strsql.Append(" values(@usercode,@username,@userpwd,@rolenames,@orgnames,@configjson,@isenable,@createby,@createdate,@jobcode,@positions)");
            return(SqlHelper.Execute(strsql.ToString(), model));
        }
Esempio n. 12
0
        public int Update(SysUserEntity model)
        {
            StringBuilder strsql = new StringBuilder();

            strsql.Append("update sys_user set  ");
            strsql.Append("usercode=@usercode,username=@username,userpwd=@userpwd,rolenames=@rolenames,orgnames=@orgnames,configjson=@configjson,isenable=@isenable,createby=@createby,createdate=@createdate,jobcode=@jobcode,positions=@positions");
            strsql.Append(" where id=@id ");
            return(SqlHelper.Execute(strsql.ToString(), model));
        }
Esempio n. 13
0
        public UserOutputDto GetForm(string keyword)
        {
            SysUserEntity userEntityList = _sysUserRepository.Get(keyword);
            UserDto       userDtoList    = AutoMapper.Mapper.Map <UserDto>(userEntityList);
            UserOutputDto outputDto      = new UserOutputDto();

            outputDto.UserDtoSingle = userDtoList;
            return(outputDto);
        }
Esempio n. 14
0
        public int UpdateUser(SysUserEntity model, SysUserinfoEntity userinfoModel, List <SysUserReumeEntity> userreumeList,
                              List <SysOrganizeuserEntity> orguserList, List <SysUserroleEntity> userroleList)
        {
            bool resulte = SqlHelper.ExecuteTranSql((con, tran) =>
            {
                int r = 0;
                try
                {
                    StringBuilder strsql = new StringBuilder();
                    strsql.Append("update sys_user set  ");
                    strsql.Append("usercode=@usercode,username=@username,userpwd=@userpwd,jobcode=@jobcode,rolenames=@rolenames,positions=@positions,orgnames=@orgnames,configjson=@configjson,isenable=@isenable,createby=@createby,createdate=@createdate,jobcodeName=@jobcodeName,positionsName=@positionsName");
                    strsql.Append(" where id=@id ");
                    r = SqlHelper.ExecuteCon(strsql.ToString(), model, tran, null, CommandType.Text, con);

                    StringBuilder sqluserinfo = new StringBuilder();
                    sqluserinfo.Append("update sys_userinfo set  ");
                    sqluserinfo.Append("realname=@realname,sex=@sex,birthdate=@birthdate,nation=@nation,political=@political,maritalstatus=@maritalstatus,presentaddress=@presentaddress,placeorigin=@placeorigin,education=@education,university=@university,specialty=@specialty,hobby=@hobby,perspecialty=@perspecialty,comprehensive=@comprehensive,telephone=@telephone,email=@email,photo=@photo,selfevaluation=@selfevaluation,createby=@createby,createdate=@createdate");
                    sqluserinfo.Append(" where usercode=@usercode ");
                    r = SqlHelper.ExecuteCon(sqluserinfo.ToString(), userinfoModel, tran, null, CommandType.Text, con);
                    if (userreumeList != null && userreumeList.Count > 0)
                    {
                        r = SqlHelper.ExecuteCon("delete from  sys_userresume where usercode=@Usercode", new { Usercode = model.Usercode }, tran, null, CommandType.Text, con);
                        StringBuilder strsqlresume = new StringBuilder();
                        strsqlresume.Append("insert into sys_userresume(usercode,retype,beginendyear,content,majorduty) ");
                        strsqlresume.Append(" values(@usercode,@retype,@beginendyear,@content,@majorduty)");
                        r = SqlHelper.ExecuteCon(strsqlresume.ToString(), userreumeList, tran, null, CommandType.Text, con);
                    }
                    if (orguserList != null && orguserList.Count > 0)
                    {
                        r = SqlHelper.ExecuteCon("delete from  sys_organizeuser where usercode=@Usercode", new { Usercode = model.Usercode }, tran, null, CommandType.Text, con);
                        StringBuilder strsqlorguser = new StringBuilder();
                        strsqlorguser.Append("insert into sys_organizeuser(orgcode,usercode) ");
                        strsqlorguser.Append(" values(@orgcode,@usercode)");
                        r = SqlHelper.ExecuteCon(strsqlorguser.ToString(), orguserList, tran, null, CommandType.Text, con);
                    }
                    if (userroleList != null && userroleList.Count > 0)
                    {
                        r = SqlHelper.ExecuteCon("delete from  sys_userrole where usercode=@Usercode", new { Usercode = model.Usercode }, tran, null, CommandType.Text, con);
                        StringBuilder strsqluserrole = new StringBuilder();
                        strsqluserrole.Append("insert into sys_userrole(usercode,rolecode) ");
                        strsqluserrole.Append(" values(@usercode,@rolecode)");
                        r = SqlHelper.ExecuteCon(strsqluserrole.ToString(), userroleList, tran, null, CommandType.Text, con);
                    }
                }
                catch (Exception ex)
                {
                    Log4NetHelper.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType).Debug(ex.Message);
                    r = 0;
                }

                return(r);
            });

            return(resulte ? 1 : 0);
        }
Esempio n. 15
0
        /// <summary>
        /// 登录后设置cookie
        /// </summary>
        /// <param name="model"></param>
        private void LoginSetCookie(SysUserEntity model)
        {
            var userData = new UserData
            {
                Phone  = model.Phone,
                Name   = model.Name,
                UserID = model.FID,
                Token  = UserTokenHelper.GetUserTokenHelper(model.FID),
            };

            FormsAuthenticationAuthority <UserData> .SetAuthenticationCookie(userData.UserID, userData);
        }
Esempio n. 16
0
 /// <summary>
 /// 更新用户,只更新部分信息
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool ModifySysUser(SysUserEntity model)
 {
     return(_service.Update <SysUserEntity>(new
     {
         model.UserName,
         model.UserCode,
         model.IsLock,
         model.Status,
         model.OrgId,
         model.RoleId
     }, t => t.UserId == model.UserId));
 }
Esempio n. 17
0
        public ActionResult CreateUser()
        {
            SysPower(SysMenuConstant.MENU_USER_MANAGE, SysMenuConstant.FUN_ADD, UserInfo.UserCode);
            var model = new SysUserEntity();

            model.Isenable = true;
            model.Usercode = RequestHelper.GetTakeCode();
            ViewBag.Photo  = "/Content/images/user.png";

            ViewBag.ZwList = ContainerBuilderHelper.Instance.GetDictionary(" and dictype='ZW' ");
            ViewBag.ZjList = ContainerBuilderHelper.Instance.GetDictionary(" and dictype='ZJ' ");
            return(View("EditUser", model));
        }
Esempio n. 18
0
 /// <summary>
 /// 根据登录名获取用户信息
 /// </summary>
 /// <param name="username">登录名</param>
 /// <returns></returns>
 public SysUserEntity GetSysUserByLoginName(string username)
 {
     using (IDbConnection conn = new SqlConnection(SqlHelper.connStr))
     {
         string            sql   = string.Format(@"select DL.PKID as DealerId,DL.Name as DealerName,SU.* from SYsUser SU
                                 left join Dealer DL on SU.DealerId = DL.PKID  where SU.LoginName=@LoginName");
         DynamicParameters param = new DynamicParameters();
         param.Add("LoginName", username);
         SysUserEntity list = new SysUserEntity();
         list = conn.Query <SysUserEntity>(sql, param).SingleOrDefault();
         return(list);
     }
 }
Esempio n. 19
0
 /// <summary>
 /// 检索是否存在该用户名称
 /// </summary>
 /// <param name="loginName">用户名称</param>
 /// <returns></returns>
 public SysUserEntity UserLogin(string loginName, string password)
 {
     using (IDbConnection conn = new SqlConnection(SqlHelper.connStr))
     {
         StringBuilder strSql = new StringBuilder();
         strSql.Append(@" select * from SysUser where LoginName=@LoginName and LoginPwd=@Password and IsActivate=1");
         DynamicParameters param1 = new DynamicParameters();
         param1.Add("LoginName", loginName);
         param1.Add("Password", password);
         SysUserEntity model = new SysUserEntity();
         model = conn.Query <SysUserEntity>(strSql.ToString(), param1).FirstOrDefault();
         return(model);
     }
 }
Esempio n. 20
0
        public ActionResult <object> ModifySysUser([FromForm] SysUserEntity model)
        {
            if (model.UserName.IsNullOrWhiteSpace())
            {
                return(false.ResponseDataError());
            }
            model.UserName = model.UserName.Trim();
            var user = _repository.GetSysUserCountByIdAndName(model.UserName);

            if (user > 1)
            {
                return(false.ResponseDataError());
            }
            return(_repository.ModifySysUser(model).ResponseSuccessFailure());
        }
Esempio n. 21
0
 /// <summary>
 /// 插入一条记录到表SysUser,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。
 /// 该方法提供给界面等UI层调用
 /// </summary>
 /// <param name="sysUser">要添加的SysUser数据实体对象</param>
 public int AddSysUser(SysUserEntity sysUser)
 {
     if (sysUser.Id > 0)
     {
         return(UpdateSysUser(sysUser));
     }
     else if (SysUserBLL.Instance.IsExist(sysUser))
     {
         return((int)CommonStatus.ADD_Fail_Exist);
     }
     else
     {
         return(SysUserDA.Instance.AddSysUser(sysUser));
     }
 }
Esempio n. 22
0
        /// <summary>
        /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。
        /// 如果数据库有数据被更新了则返回True,否则返回False
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="sysUser">待更新的实体对象</param>
        public int UpdateSysUser(SysUserEntity entity)
        {
            string    sql = @" UPDATE dbo.[SysUser] SET
                       [UserCode]=@UserCode,[UserName]=@UserName,[PassWord]=@PassWord,[IsActive]=@IsActive,[CreateTime]=@CreateTime,[UserLevel]=@UserLevel
                       WHERE [Id]=@id";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            db.AddInParameter(cmd, "@UserCode", DbType.String, entity.UserCode);
            db.AddInParameter(cmd, "@UserName", DbType.String, entity.UserName);
            db.AddInParameter(cmd, "@PassWord", DbType.String, entity.PassWord);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime);
            db.AddInParameter(cmd, "@UserLevel", DbType.Int32, entity.UserLevel);
            return(db.ExecuteNonQuery(cmd));
        }
Esempio n. 23
0
        protected string SetLoginToken(SysUserEntity user, List <int> roleIds)
        {
            var sessionUser = new LoginUserView
            {
                //OrgId = user.OrgId,
                UserName = user.UserName,
                //UserCode = user.UserCode,
                UserId  = user.UserId,
                RoleIds = roleIds
            };

            //HttpContext.Session.SetString(LoginSessionKey, sessionUser.JsonSerialize());     //存入缓存

            //建议用redis存取加密密钥,和用户登录状态
            //DES加密用户信息给出Token
            return(CryptogramHelper.DESEncrypt(sessionUser.JsonSerialize(), DateTime.Now.ToString("yyyyMMdd")));
        }
Esempio n. 24
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 private static SysUserEntity GetSysUserModel(DataTable dt)
 {
     if (dt != null && dt.Rows != null && dt.Rows.Count > 0)
     {
         SysUserEntity model = new SysUserEntity();
         if (dt.Rows[0]["ID"].ToString() != "")
         {
             model.ID = int.Parse(dt.Rows[0]["ID"].ToString());
         }
         model.UserName = dt.Rows[0]["UserName"].ToString();
         return(model);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 25
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <SysUserEntity> GetSysUserList(int pagesize, int pageindex, ref int recordCount)
        {
            string sql = @"SELECT   [Id],[UserCode],[UserName],[PassWord],[IsActive],[CreateTime],[UserLevel]
						FROM
						(SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER,
						 [Id],[UserCode],[UserName],[PassWord],[IsActive],[CreateTime],[UserLevel] from dbo.[SysUser] WITH(NOLOCK)	
						WHERE  1=1 ) as temp 
						where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize"                        ;

            string sql2 = @"Select count(1) from dbo.[SysUser] with (nolock) ";
            IList <SysUserEntity> entityList = new List <SysUserEntity>();
            DbCommand             cmd        = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex);
            db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize);

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    SysUserEntity entity = new SysUserEntity();
                    entity.Id         = StringUtils.GetDbInt(reader["Id"]);
                    entity.UserCode   = StringUtils.GetDbString(reader["UserCode"]);
                    entity.UserName   = StringUtils.GetDbString(reader["UserName"]);
                    entity.PassWord   = StringUtils.GetDbString(reader["PassWord"]);
                    entity.IsActive   = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]);
                    entity.UserLevel  = StringUtils.GetDbInt(reader["UserLevel"]);
                    entityList.Add(entity);
                }
            }
            cmd = db.GetSqlStringCommand(sql2);
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    recordCount = StringUtils.GetDbInt(reader[0]);
                }
                else
                {
                    recordCount = 0;
                }
            }
            return(entityList);
        }
Esempio n. 26
0
        public void SubmitForm(UserInputDto userInputDto, UserInfo userinfo)
        {
            if (!string.IsNullOrEmpty(userInputDto.Id)) //更新
            {
                SysUserEntity entity = _sysUserRepository.Get(userInputDto.Id);
                entity.UserName    = userInputDto.UserName;
                entity.TrueName    = userInputDto.TrueName;
                entity.QQ          = userInputDto.QQ;
                entity.PhoneNumber = userInputDto.PhoneNumber;
                if (!string.IsNullOrEmpty(userInputDto.RoleId))
                {
                    SysRole2UserEntity roleEntity = _sysRole2UserRepository.GetAll().Where(t => t.SysRoleId.Equals(userInputDto.Id)).FirstOrDefault();
                    if (roleEntity != null)
                    {
                        roleEntity.SysRoleId = userInputDto.RoleId;
                        _sysRole2UserRepository.Update(roleEntity);
                    }
                    else
                    {
                        roleEntity           = new SysRole2UserEntity();
                        roleEntity.Id        = Guid.NewGuid().ToString();
                        roleEntity.SysRoleId = userInputDto.RoleId;
                        roleEntity.SysUserId = entity.Id;
                        _sysRole2UserRepository.Insert(roleEntity);
                    }
                }
                _sysUserRepository.Update(entity);
            }
            else
            {
                SysUserEntity entity = AutoMapper.Mapper.Map <SysUserEntity>(userInputDto);
                entity.Id           = Guid.NewGuid().ToString();
                entity.Password     = Common.Utils.Md5.GetMD5("123456");
                entity.CreatePerson = userinfo.UserID;
                entity.CreateTime   = DateTime.Now;
                _sysUserRepository.Insert(entity);

                SysRole2UserEntity roleEntity = new SysRole2UserEntity();
                roleEntity.Id        = Guid.NewGuid().ToString();
                roleEntity.SysRoleId = userInputDto.RoleId;
                roleEntity.SysUserId = entity.Id;
                _sysRole2UserRepository.Insert(roleEntity);
            }
        }
Esempio n. 27
0
        public async Task <IResponseEntity> LoginAsync(AuthLoginRequest req)
        {
            var           password = MD5Encrypt.Encrypt32(req.Password);
            SysUserEntity user     = new SysUserEntity();

            using (_userRepository.DataFilter.Disable("Group"))
            {
                user = await _userRepository.GetAsync(a => a.UserName == req.UserName && a.Password == password);
            }

            if (user?.Id == "")
            {
                return(ResponseEntity.Error("账号或密码错误!"));
            }

            var res = await getUserItem(user);

            return(ResponseEntity.Ok(res));
        }
Esempio n. 28
0
        public void SetUserDept(SysUserEntity User, string Key)
        {
            // 一个员工只能在一个部门下,删除该员工在其他部门的配置
            var otherDept = GetUserDept(User.ID);

            if (otherDept != null)
            {
                _IBaseConfig.Delete(string.Format("{0}.User.{1}", otherDept.Key, User.ID));
            }

            var userKey = string.Format("{0}.User.{1}", Key, User.ID);

            _IBaseConfig.Add(new ConfigEntity()
            {
                Key       = userKey,
                Value     = User.Name,
                IsDeleted = false,
                Type      = "1"
            });
        }
Esempio n. 29
0
    /// <summary>
    /// 填充系统用户界面
    /// </summary>
    private void SetUserUI()
    {
        SysUserEntity Result = m_User.GetSysUser(UserID);

        if (Result == null)
        {
            return;
        }
        UserID = Result.UserNo;
        txtUserAccount.Text           = Result.UserAccount;
        txtUserName.Text              = Result.UserName;
        txtPosition.Text              = Result.Position;
        txtLinkTel.Text               = Result.LinkTel;
        txtMobile.Text                = Result.Mobile;
        drpDeparts.SelectedValue      = Result.DeptNo + "";
        drpUserCategory.SelectedValue = Result.UserCategory;
        Password = Result.PassWord;
        //txtPassWord.Text = Result.PassWord;
        //txtEmail.Text = Result.EMail;
        //txtOrderNo.Text = Result.OrderNo + "";
    }
Esempio n. 30
0
        /// <summary>
        /// 插入一条记录到表SysUser,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="sysUser">待插入的实体对象</param>
        public int AddSysUser(SysUserEntity entity)
        {
            string    sql = @"insert into SysUser( [UserCode],[UserName],[PassWord],[IsActive],[CreateTime],[UserLevel])VALUES
			            ( @UserCode,@UserName,@PassWord,@IsActive,@CreateTime,@UserLevel);
			SELECT SCOPE_IDENTITY();"            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@UserCode", DbType.String, entity.UserCode);
            db.AddInParameter(cmd, "@UserName", DbType.String, entity.UserName);
            db.AddInParameter(cmd, "@PassWord", DbType.String, CryptMD5.Encrypt(entity.PassWord));
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime);
            db.AddInParameter(cmd, "@UserLevel", DbType.Int32, entity.UserLevel);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }