Asp.NETPersonnalBlogSystem/Admin/UserList.aspx.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using Asp.NETPersonnalBlogSystem.BLL;
using Asp.NETPersonnalBlogSystem.Models;
namespace Asp.NETPersonnalBlogSystem.Admin
{
/// <summary>
/// 用户管理页面
/// 提供用户的管理功能
/// </summary>
public partial class UserList : System.Web.UI.Page
{
private UserService userService = new UserService();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadUsers();
}
}
/// <summary>
/// 加载用户列表
/// </summary>
private void LoadUsers()
{
List<User> users = userService.GetAllUsers();
gvUsers.DataSource = users;
gvUsers.DataBind();
}
/// <summary>
/// GridView行命令事件
/// </summary>
protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e)
{
int userId = Convert.ToInt32(e.CommandArgument);
var user = userService.GetUserById(userId);
var currentUser = Session["CurrentUser"] as User;
LogService logService = new LogService();
if (e.CommandName == "ToggleRole")
{
user.Role = user.Role == 1 ? 0 : 1;
userService.UpdateUser(user);
logService.LogInfo("User", "修改用户角色", "修改用户 " + user.UserName + " 角色为 " + (user.Role == 1 ? "管理员" : "普通用户"), currentUser?.UserId, currentUser?.UserName, Request.UserHostAddress);
LoadUsers();
}
else if (e.CommandName == "ToggleStatus")
{
user.Status = user.Status == 1 ? 0 : 1;
userService.UpdateUser(user);
logService.LogInfo("User", "修改用户状态", (user.Status == 1 ? "启用" : "禁用") + "用户 " + user.UserName, currentUser?.UserId, currentUser?.UserName, Request.UserHostAddress);
LoadUsers();
}
else if (e.CommandName == "ResetPassword")
后面还有 40 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
