📄 addcourse.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;
using System.Data.SqlClient;
public partial class addcourse : System.Web.UI.Page
{
SqlConnection connections;
protected void Page_Load(object sender, EventArgs e)
{
if((Session["user_id"] == null || (int)Session["user_lever"] != 1))
{
Response.Redirect("default.aspx");
}
this.Title = "添加新课程";
string strconn = System.Configuration.ConfigurationManager.AppSettings["connstring"];
connections = new SqlConnection(strconn);
connections.Open();
}
protected void lbtnOK_Click(object sender, EventArgs e)
{
if (txtNo.Text == "" || txtName.Text == "" || txtPeriod.Text == "" || txtCredit.Text == "")
{
Response.Write("<script language=javascript>alert('除【备注】外其他字段不能为空!');</script>");
return;
}
SqlCommand commnd = new SqlCommand("addcour", connections);
commnd.CommandType = CommandType.StoredProcedure;
try
{
commnd.Parameters.Add(new SqlParameter("@Crid", SqlDbType.VarChar, 50));
commnd.Parameters["@Crid"].Value = txtNo.Text;
commnd.Parameters.Add(new SqlParameter("@Crname", SqlDbType.VarChar, 50));
commnd.Parameters["@Crname"].Value = txtName.Text;
commnd.Parameters.Add(new SqlParameter("@Crper", SqlDbType.Int, 4));
commnd.Parameters["@Crper"].Value = txtPeriod.Text;
commnd.Parameters.Add(new SqlParameter("@Crcre", SqlDbType.Int, 4));
commnd.Parameters["@Crcre"].Value = txtCredit.Text;
commnd.Parameters.Add(new SqlParameter("@Crkind", SqlDbType.VarChar, 50));
commnd.Parameters["@Crkind"].Value = dropKind.SelectedItem.Value;
commnd.Parameters.Add(new SqlParameter("@Crelse", SqlDbType.VarChar, 50));
commnd.Parameters["@Crelse"].Value = txtElse.Text;
//commnd.Connection.Open();
commnd.ExecuteNonQuery();
Response.Write("<script language=javascript>alert('课程添加成功!');</script>");
}
catch (SqlException ex)
{
Response.Write("<script language=javascript>alert('课程添加失败!');</script>");
Response.Write(ex.Message);
}
commnd.Connection.Close();
}
protected void lbtnBack_Click(object sender, EventArgs e)
{
Response.Redirect("admin_course.aspx");
}
protected void lbtnReset_Click(object sender, EventArgs e)
{
txtNo.Text = "";
txtNo.Focus();
txtName.Text = "";
txtPeriod.Text = "";
txtCredit.Text = "";
txtElse.Text = "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -