コード例 #1
0
ファイル: UserDal.cs プロジェクト: yueyezu/normalApp-net
        /// <summary>
        /// 获取用户的信息,根据用户的帐号信息
        /// </summary>
        /// <param name="fAccount">用户账号</param>
        /// <returns>用户信息</returns>
        public UserModel GetUserByAccount(string fAccount)
        {
            DapperHelper dapperHelper = DapperFactory.GetDapperHelper();

            UserModel user = null;
            string    sql  = "select * from Sys_User u where u.F_Account=@Account";

            //TODO 想切换为dapper,暂时预留。
            //Dictionary<string, string> dics = new Dictionary<string, string>();
            //dics.Add("@Account", fAccount);
            //user = dapperHelper.FirstOrDefault<UserModel>(sql, dics);

            DbParameter[] parameters = new DbParameter[]
            {
                new SqlParameter("@Account", SqlDbType.NVarChar)
                {
                    Value = fAccount
                },
            };
            using (DbDataReader dr = DbHelper.ExecuteReader(sql, parameters))
            {
                if (dr.Read())
                {
                    user = new UserModel
                    {
                        F_Id           = dr["F_Id"].ToString(),
                        F_Account      = dr["F_Account"].ToString(),
                        F_RealName     = dr["F_RealName"].ToString(),
                        F_NickName     = dr["F_NickName"].ToString(),
                        F_HeadIcon     = dr["F_HeadIcon"].ToString(),
                        F_Sex          = dr["F_Sex"].ToString(),
                        F_WeChat       = dr["F_WeChat"].ToString(),
                        F_Phone        = dr["F_Phone"].ToString(),
                        F_Email        = dr["F_Email"].ToString(),
                        F_OrganizeId   = dr["F_OrganizeId"].ToString(),
                        F_DepartmentId = dr["F_DepartmentId"].ToString(),
                        F_RoleId       = dr["F_RoleId"].ToString(),
                        F_IsAdmin      = Convert.ToInt32(dr["F_IsAdmin"]),
                        F_EnableDelete = Convert.ToInt32(dr["F_EnableDelete"]),
                        F_DeleteFlag   = Convert.ToInt32(dr["F_DeleteFlag"]),
                        F_EnabledFlag  = Convert.ToInt32(dr["F_EnabledFlag"]),
                        F_SortNum      = Convert.ToInt32(dr["F_SortNum"].ToString()),
                        F_Remark       = dr["F_Remark"].ToString()
                    };
                    if (dr["F_Birthday"] != DBNull.Value)
                    {
                        user.F_Birthday = Convert.ToDateTime(dr["F_Birthday"].ToString());
                    }
                }
            }
            return(user);
        }