📄 addclass.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = DB.createconnection();
con.Open();
}
}
protected void CustomValidator1_ServerValidate1(object source, ServerValidateEventArgs args)
{
try
{
SqlConnection con = new SqlConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from class where class_ID='" + TextBox1.Text + "'", con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
catch { }
}
protected void TextBox3_TextChanged(object sender, EventArgs e)
{
}
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
{
try
{
SqlConnection con = new SqlConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from class where class_Name ='" + TextBox2.Text + "'", con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
catch { }
}
protected void CustomValidator4_ServerValidate(object source, ServerValidateEventArgs args)
{
try
{
SqlConnection con = new SqlConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from class where teacher_Name='" + TextBox5.Text + "'", con);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
catch { }
}
protected void Button1_Click(object sender, EventArgs e)
{
//try
//{
SqlConnection con = DB.createconnection();
con.Open();
SqlCommand cmd = new SqlCommand();
int class_ID = Convert.ToInt32(this.TextBox1.Text);
string class_Name = this.TextBox2.Text;
string department_Name = this.TextBox3.Text;
int teacher_ID = Convert.ToInt32(this.TextBox5.Text);
string teacher_Name = this.TextBox6.Text;
int Count = Convert.ToInt32(this.TextBox7.Text);
cmd.CommandText = " insert into class (class_ID,class_Name,department_Name,teacher_ID,teacher_Name,student_Count) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "')";
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script >alert('添加成功!');</script>");
//}
//catch
//{
// Response.Write("<script>alert('添加失败!');</script>");
}
protected void Button2_Click1(object sender, EventArgs e)
{
this.TextBox1.Text = "";
this.TextBox2.Text = "";
this.TextBox3.Text = "";
this.TextBox5.Text = "";
this.TextBox6.Text = "";
this.TextBox7.Text = "";
Response.Write("<script>alert('请重新输入!');</script>");
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect(".aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -