📄 manager.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Manager : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//读取信息
if (!IsPostBack)
{
BindData();
}
}
//函数BindData用于读取页面基本信息
private void BindData()
{
//将Session实体化
int userID = Int32.Parse(Session["uid"].ToString());
//根据用户编号实例化用户信息
string strSql = "SELECT [userID],[userLoginID],[userPwd],[userName],[userStauts],[scID] FROM [userInfo] WHERE [userID] ='" + userID + "'";
UserInfo userinfo = new UserInfo();
userinfo = DBHelper.sqllogin(strSql);
//显示用户姓名
txtName.Text = userinfo.UserName;
//读取非管理员用户的信息,并与GridView绑定
strSql = "SELECT [userID],[userLoginID],[userPwd],[userName],[userStauts] FROM [userInfo] WHERE [userStauts]!=0";
userGV.DataSource = DBHelper.sqlLoad(strSql);
userGV.DataBind();
}
//删除单条用户信息
protected void userGV_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//将选择的用户编号实体化
string userID = userGV.Rows[e.RowIndex].Cells[0].Text;
//根据用户编号实例化用户信息
string strSql = "SELECT [userID],[userLoginID],[userPwd],[userName],[userStauts],[scID] FROM [userInfo] WHERE [userID] ='" + userID + "'";
UserInfo userinfo = new UserInfo();
userinfo = DBHelper.sqllogin(strSql);
int i;
//进行被删除用户身份的判断
if (userinfo.UserStauts == 1)
{
//用户为学生用户,若无选课信息则直接删除,若有选课信息则将其强制退选后再删除
if (userinfo.ScID == 0)
{
strSql = "DELETE FROM [userInfo] WHERE [userID] ='" + userID + "'";
i = DBHelper.sqlinit(strSql);
if (i > 0)
{
txtMsg.Text = "删除成功!";
}
}
else
{
strSql = "UPDATE [scInfo] SET [scNum]=[scNum]-1 WHERE [scID] ='" + userinfo.ScID + "'";
i = DBHelper.sqlinit(strSql);
strSql = "DELETE FROM [userInfo] WHERE [userID] ='" + userID + "'";
i = DBHelper.sqlinit(strSql);
if (i > 0)
{
txtMsg.Text = "删除成功!";
}
}
}
else if (userinfo.UserStauts == 2)
{
//用户为教师用户,若无课程安排则直接删除,若有则不可删除
strSql = "SELECT [scID],[scName],[scContent],[scNum],[scMax] FROM [scInfo] Where [scTeacher] ='" + userinfo.UserName + "'";
if (DBHelper.sqlLoad(strSql).Rows.Count == 0)
{
strSql = "DELETE FROM [userInfo] WHERE [userID] ='" + userID + "'";
i = DBHelper.sqlinit(strSql);
if (i > 0)
{
txtMsg.Text = "删除成功!";
}
}
else
{
txtMsg.Text = "教师已有课程安排,无法删除!";
}
}
BindData();
}
//增加新用户
protected void Button1_Click(object sender, EventArgs e)
{
//跳转至“增加新用户”页面
Response.Redirect("User.aspx");
}
//退出
protected void exitLB_Click(object sender, EventArgs e)
{
//清除Session储存内容,并跳转至登录界面
Session.Clear();
Response.Redirect("Login.aspx");
}
//进行数据转换
protected void userGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[4].Text == "1")
{
e.Row.Cells[4].Text = "学生";
}
else if (e.Row.Cells[4].Text == "2")
{
e.Row.Cells[4].Text = "教师";
}
}
}
//修改
protected void userGV_RowCommand(object sender, GridViewCommandEventArgs e)
{
//读取指令名称
if (e.CommandName == "edit")
{
//将所选取的行号实体化
int index = int.Parse(e.CommandArgument.ToString());
//利用Session传递用户编号至编辑页
Session["userID"] = userGV.Rows[index].Cells[0].Text;
Response.Redirect("User.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -