XDF/MasterPage.Master.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace XDF
{
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
if (Session["UserRole"] == null)
Response.Redirect("~/Login.aspx");
// 判断用户角色
if (Session["UserRole"].ToString() == "学生")
SiteMapDataSource1.SiteMapProvider = "StudentSiteMapProvider";
else if (Session["UserRole"].ToString() == "教师")
SiteMapDataSource1.SiteMapProvider = "TeacherSiteMapProvider";
else if (Session["UserRole"].ToString() == "管理员")
SiteMapDataSource1.SiteMapProvider = "AdminSiteMapProvider";
string username = "";
username = getUserName(Session["UserID"].ToString(), Session["UserRole"].ToString());
LabelUserName.Text = username + "(" + Session["UserRole"].ToString() + ")";
}
}
private string getUserName(string userID, string userRole)
{
string result = "";
try
{
// 1. 创建连接
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["XDF"].ConnectionString);
// 2. 打开连接
connection.Open();
// 2.1 创建命令对象
SqlCommand command = null;
if (userRole == "学生")
{
command = new SqlCommand("select StuName from Student where StuID=@StuID", connection);
command.Parameters.AddWithValue("@StuID", userID);
}
else if (userRole == "教师")
{
command = new SqlCommand("select TeaName from Teacher where TeaID=@TeaID", connection);
command.Parameters.AddWithValue("@TeaID", userID);
}
else if (userRole == "管理员")
{
command = new SqlCommand("select AdminName from Admin where AdminID=@AdminID", connection);
command.Parameters.AddWithValue("@AdminID", userID);
}
后面还有 15 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。