📄 course.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 Course : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//读取信息
if (!IsPostBack)
{
ScInfo();
}
}
//函数ScInfo()用于读取页面基本信息
private void ScInfo()
{
//检查课程编号是否有值
if (Session["scID"] != null)
{
//将Session实体化
int scID = Int32.Parse(Session["scID"].ToString());
//根据课程编号实例化课程信息
string strSql = "SELECT [scID],[scName],[scContent],[scNum],[scMax],[scTeacher] FROM [scInfo] WHERE [scID] ='" + scID + "'";
scInfo scinfo = new scInfo();
scinfo = DBHelper.sqlsclogin(strSql);
//显示课程名称
txtName.Text = scinfo.ScName;
//显示课程概要
txtContent.Text = scinfo.ScContent;
//显示已选学生人数
txtNum.Text = scinfo.ScNum.ToString();
//显示可选学生人数
txtMax.Text = scinfo.ScMax.ToString();
}
else
{
//若为新增则设置已选人数为0
txtNum.Text = "0";
}
}
//增加或修改选课信息
protected void Button1_Click(object sender, EventArgs e)
{
//进行非空判断,若为空则返回错误信息
if (!txtName.Text.Equals("") && !txtContent.Text.Equals("") && !txtMax.Text.Equals(""))
{
//判断可选学生数目是否为零,为零则返回错误信息
if (Int32.Parse(txtMax.Text) != 0)
{
//判断已选学生数目是否小于或等于可选学生数目,若大于则返回错误信息
if (Int32.Parse(txtNum.Text) <= Int32.Parse(txtMax.Text))
{
//实例化所填写的课程信息
scInfo scinfo = new scInfo();
scinfo.ScName = txtName.Text;
scinfo.ScContent = txtContent.Text;
scinfo.ScNum = Int32.Parse(txtNum.Text);
scinfo.ScMax = Int32.Parse(txtMax.Text);
//将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);
//读取用户姓名
scinfo.ScTeacher = userinfo.UserName;
//根据Session内容有无判断用户行为为修改或新增
if (Session["scID"] != null)
{
//读取课程编号
scinfo.ScID = Int32.Parse(Session["scID"].ToString());
//修改课程信息
strSql = "UPDATE [scInfo] SET [scName] = '" + scinfo.ScName + "',[scContent] = '" + scinfo.ScContent + "',[scNum] = '" + scinfo.ScNum + "',[scMax] = '" + scinfo.ScMax + "' WHERE [scID] = '" + scinfo.ScID + "'";
int i = DBHelper.sqlinit(strSql);
if (i > 0)
{
//清空用户编号的Session,并返回上一页面
Session["scID"] = null;
Response.Redirect("Teacher.aspx");
}
}
else
{
//增加新课程
strSql = "INSERT INTO [scInfo]([scName],[scContent],[scNum],[scMax],[scTeacher])VALUES('" + scinfo.ScName + "','" + scinfo.ScContent + "','" + scinfo.ScNum + "','" + scinfo.ScMax + "','" + scinfo.ScTeacher + "')";
int i = DBHelper.sqlinit(strSql);
if (i > 0)
{
//返回上一页面
Response.Redirect("Teacher.aspx");
}
}
}
else
{
txtMsg.Text = "可选学生数目不可小于已选学生数目!";
}
}
else
{
txtMsg.Text = "可选学生数目不可为零!";
}
}
else
{
txtMsg.Text = "输入信息不完整!";
}
}
//返回上一页面
protected void button2_Click(object sender, EventArgs e)
{
//清空用户编号的Session并返回上一页面
Session["scID"] = null;
Response.Redirect("Teacher.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -