📄 st_addstudent.aspx.cs.bak
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace STGROUP
{
/// <summary>
/// ST_addstudent 的摘要说明。
/// </summary>
public class ST_addstudent : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox st_tbx_id;
protected System.Web.UI.WebControls.TextBox st_tbx_name;
protected System.Web.UI.WebControls.TextBox st_tbx_nation;
protected System.Web.UI.WebControls.TextBox st_tbx_birthst_day;
protected System.Web.UI.WebControls.TextBox st_tbx_time;
protected System.Web.UI.WebControls.TextBox st_tbx_home;
protected System.Web.UI.WebControls.TextBox st_tbx_else;
protected System.Web.UI.WebControls.DropDownList st_ddl_sex;
protected System.Web.UI.WebControls.Button st_btn_ok;
protected System.Web.UI.WebControls.CustomValidator st_cv_id;
protected System.Web.UI.WebControls.Label st_lbl_note;
protected System.Web.UI.WebControls.Button st_btn_reset;
protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_name;
protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_id;
protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_nation;
protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_birthst_day;
protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_time;
protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_class;
protected System.Web.UI.WebControls.RequiredFieldValidator st_rfv_home;
protected System.Web.UI.WebControls.DropDownList st_ddl_class;
SqlConnection st_conn;
private void Page_Load(object sender, System.EventArgs e)
{//班级名称下拉列表框绑定
string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"];
SqlConnection st_conn1=new SqlConnection(st_connstr);
if(!IsPostBack)
{
st_conn1.Open ();
//查询所有的班级名称
string mysql="select * from ST_class";
SqlCommand st_comm1=new SqlCommand (mysql,st_conn1);
SqlDataReader st_dr1=st_comm1.ExecuteReader ();
//将查出的班级作为下拉列表的数据项
while(st_dr1.Read ())
{
st_ddl_class.Items .Add (new ListItem(st_dr1["ST_Class_name"].ToString() ,st_dr1["ST_Class_id"].ToString()) );
}
st_conn1.Close ();
}
// 在此处放置用户代码以初始化页面
st_conn=new SqlConnection(st_connstr);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.st_btn_ok.Click += new System.EventHandler(this.st_btn_ok_Click);
this.st_btn_reset.Click += new System.EventHandler(this.st_btn_reset_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void st_btn_ok_Click(object sender, System.EventArgs e)
{
SqlCommand st_comm=new SqlCommand("insert_student_1",st_conn);
st_comm.CommandType=CommandType.StoredProcedure;
try
{
st_comm.Parameters.Add(new SqlParameter("@Student_id",SqlDbType.VarChar,50));
st_comm.Parameters["@Student_id"].Value=st_tbx_id.Text;
st_comm.Parameters.Add(new SqlParameter("@Student_name",SqlDbType.VarChar,50));
st_comm.Parameters["@Student_name"].Value=st_tbx_name.Text;
st_comm.Parameters.Add(new SqlParameter("@Student_sex",SqlDbType.Char,10));
st_comm.Parameters["@Student_sex"].Value=st_ddl_sex.SelectedItem.Value;
st_comm.Parameters.Add(new SqlParameter("@Student_nation",SqlDbType.Char,10));
st_comm.Parameters["@Student_nation"].Value=st_tbx_nation.Text;
st_comm.Parameters.Add(new SqlParameter("@Student_birthday",SqlDbType.DateTime,8));
st_comm.Parameters["@Student_birthday"].Value=st_tbx_birthst_day.Text;
st_comm.Parameters.Add(new SqlParameter("@Student_time",SqlDbType.DateTime,8));
st_comm.Parameters["@Student_time"].Value=st_tbx_time.Text;
st_comm.Parameters.Add(new SqlParameter("@Student_classid",SqlDbType.VarChar,50));
st_comm.Parameters["@Student_classid"].Value=st_ddl_class.SelectedItem.Value;
st_comm.Parameters.Add(new SqlParameter("@Student_home",SqlDbType.VarChar,50));
st_comm.Parameters["@Student_home"].Value=st_tbx_home.Text;
st_comm.Parameters.Add(new SqlParameter("@Student_else",SqlDbType.VarChar,50));
st_comm.Parameters["@Student_else"].Value=st_tbx_else.Text;
st_comm.Connection.Open();
st_comm.ExecuteNonQuery();
st_comm.Connection.Close();
st_insert();
}
catch
{
st_lbl_note.Text="添加失败,请检查输入!";
st_lbl_note.Style["color"]="red";
}
}
public void st_insert()
{
string strsl="insert into ST_users(ST_User_id,ST_User_password,ST_User_power) values(@User_id,@User_pwd,0)";
SqlCommand st_comm=new SqlCommand(strsl,st_conn);
st_comm.Parameters.Add(new SqlParameter("@User_id",SqlDbType.VarChar,50));
st_comm.Parameters["@User_id"].Value=st_tbx_id.Text;
st_comm.Parameters.Add(new SqlParameter("@User_pwd",SqlDbType.VarChar,50));
st_comm.Parameters["@User_pwd"].Value=st_tbx_id.Text;
st_comm.Connection.Open();
try
{
st_comm.ExecuteNonQuery();
Response.Redirect("ST_student.aspx");
}
catch(SqlException)
{
st_lbl_note.Text="添加失败";
st_lbl_note.Style["color"]="red";
}
st_comm.Connection.Close();
}
private void st_btn_reset_Click(object sender, System.EventArgs e)
{
Response.Redirect("ST_addstudent.aspx");
}
private void st_cv_id_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"];
st_conn=new SqlConnection(st_connstr);
st_conn.Open();
SqlCommand st_comm=new SqlCommand("select_student_1",st_conn);
st_comm.CommandType=CommandType.StoredProcedure;
st_comm.Parameters.Add("@Student_id",SqlDbType.VarChar,50);
st_comm.Parameters["@Student_id"].Value=st_tbx_id.Text;
SqlDataReader st_dr=st_comm.ExecuteReader();
if(st_dr.Read())
{
args.IsValid=false;
}
else
{
args.IsValid=true;
}
st_conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -