📄 courseview.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 courseView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["adminId"] == null)
{
Response.Redirect("Default.aspx");
}
else {
if (!IsPostBack) {
// DataSet ds=new DataSet();
this.ListBox1.DataSource = (new projClass()).getCourses();
this.ListBox1.DataTextField = "courseName";
this.ListBox1.DataValueField = "courseId";
this.ListBox1.DataBind();
}
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
String courseName = this.ListBox1.SelectedItem.Text;
String courseId=(new projClass()).getCourseIdAsCourseName(courseName);
string teacherName = (new projClass()).getTeacherNameAsCourseId(courseId);
this.tbxTeacherName.Text = teacherName;
this.Label2.Text = courseId;
this.TextBox1.Text = courseName;
bool isTest;
isTest = (new projClass()).getIsTestAsCourseId(courseId);
if (isTest)
cbx_istest.Checked = true;
else cbx_istest.Checked = false;
}
//删除事件
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
if (ListBox1.SelectedIndex == -1)
this.Label3.Text = "请选择一门科目!";
else
{
string courseId = this.Label2.Text.Trim();
int count = (new projClass()).deleteCourseInfo(courseId);
if (count == 0)
{
this.Label3.Text = "删除失败!";
}
this.Label3.Text = "删除成功!";
this.ListBox1.DataSource = (new projClass()).getCourses();
this.ListBox1.DataTextField = "courseName";
this.ListBox1.DataValueField = "courseId";
this.ListBox1.DataBind();
}
}
//修改事件
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
if (ListBox1.SelectedIndex == -1)
this.Label3.Text = "请选择一门科目!";
else
{
string courseId = this.Label2.Text.Trim();
string courseName = this.TextBox1.Text.Trim();
string teacherName = this.tbxTeacherName.Text.Trim();
if ((new projClass()).selectTeacherAsTeacherName(teacherName) == 0)
{
this.Label3.Text = "此教师不存在!!";
}
else {
bool isTest = this.cbx_istest.Checked;
int count = (new projClass()).updateCourseInfo(courseId, courseName, isTest);
int count2 = (new projClass()).updateTeacherInfoAsCourseId(teacherName, courseId);
this.Label3.Text = count.ToString();
if (count == 1&&count2==1)
{
if (isTest)
{
this.Label3.Text = "修改成功!这门课可以进行考试!!!";
this.ListBox1.DataSource = (new projClass()).getCourses();
this.ListBox1.DataTextField = "courseName";
this.ListBox1.DataValueField = "courseId";
this.ListBox1.DataBind();
}
else
{
this.Label3.Text = "修改成功!这门课不可以进行考试!!!";
this.ListBox1.DataSource = (new projClass()).getCourses();
this.ListBox1.DataTextField = "courseName";
this.ListBox1.DataValueField = "courseId";
this.ListBox1.DataBind();
}
}
else
this.Label3.Text = "修改失败!!!";
}
}
}
//新增事件
protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
{
string courseId = this.txb_courseId.Text.Trim();
string courseName = this.txb_courseName.Text.Trim();
if (courseId == "" || courseName == "")
this.Label3.Text = "请输入完整内容!";
else
{
int exist = (new projClass()).ifCourseExist(courseId, courseName);
if (exist == 1)
this.Label3.Text = "请不要输入重复的课程名称或课程ID!";
else
{
int count = (new projClass()).insertCourseInfo(courseId, courseName, false);
if (count == 0)
this.Label3.Text = "插入失败!";
this.Label3.Text = "插入成功!";
this.ListBox1.DataSource = (new projClass()).getCourses();
this.ListBox1.DataTextField = "courseName";
this.ListBox1.DataValueField = "courseId";
this.ListBox1.DataBind();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -