Exemple #1
0
 public static bool AddUser(Users user)
 {
     #region 注册用户
     if (user.UserRoles == null)
     {
         user.UserRoles = UserRolesServer.GetUserRolesById(1);
     }
     if (user.UserStates == null)
     {
         user.UserStates = UserStatesServer.GetUserStatesById(1);
     }
     string         sql  = @"INSERT INTO Users(LoginId,LoginPwd,Name,Address,Phone,Mail,UserRoleId,UserStateId) 
                    VALUES(@LoginId,@LoginPwd,@Name,@Address,@Phone,@Mail,@UserRoleId,@UserStateId)";
     SqlParameter[] para =
     {
         new SqlParameter("@LoginId",     user.LoginId),
         new SqlParameter("@LoginPwd",    user.LoginPwd),
         new SqlParameter("@Address",     user.Address),
         new SqlParameter("@Phone",       user.Phone),
         new SqlParameter("@Mail",        user.Mail),
         new SqlParameter("@Name",        user.Name),
         new SqlParameter("@UserRoleId",  user.UserRoles.Id),
         new SqlParameter("@UserStateId", user.UserStates.Id)
     };
     int count = DbHelp.ExecuteCommand(sql, para);
     if (count > 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
     #endregion
 }
Exemple #2
0
        public static Users GetUserById(int Id)
        {
            #region 通过用户Id返回用户信息
            Users  users = new Users();
            string sql   = "SELECT * FROM Users WHERE Id=" + Id;
            using (SqlDataReader dr = DbHelp.GetReader(sql))
            {
                if (dr.Read())
                {
                    users.ID       = Convert.ToInt32(dr["ID"]);
                    users.LoginId  = dr["LoginId"].ToString();
                    users.LoginPwd = dr["LoginPwd"].ToString();
                    users.Name     = dr["Name"].ToString();
                    users.Phone    = dr["Phone"].ToString();
                    users.Address  = dr["Address"].ToString();
                    users.Mail     = dr["Mail"].ToString();
                    int userroleid    = Convert.ToInt32(dr["UserRoleId"]);
                    int userrolestate = Convert.ToInt32(dr["UserStateId"]);
                    dr.Close();
                    users.UserRoles  = UserRolesServer.GetUserRolesById(userroleid);
                    users.UserStates = UserStatesServer.GetUserStatesById(userrolestate);
                }
                else
                {
                    users = null;
                }
            }
            return(users);

            #endregion
        }