⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addstudent.aspx.cs

📁 C# SQL遍写的学生选课系统 给大家看看 有点多 有点复杂
💻 CS
字号:
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 sms
{
	/// <summary>
	/// addstudent 的摘要说明。
	/// </summary>
	public partial class addstudent : System.Web.UI.Page
	{
        private DataAccess DataAs;
		protected void Page_Load(object sender, System.EventArgs e)
		{//班级名称下拉列表框绑定
			if(!IsPostBack)
		    {
				string mysql="select * from class";
                DataAs = new DataAccess();
                DataTable DT = DataAs.CreateDatatable(mysql);
                for (int i = 0; i < DT.Rows.Count; i++ )
                {
                    Ddl_class.Items.Add(new ListItem(DT.Rows[i][2].ToString(),DT.Rows[i][0].ToString()));
                }
				
			}
			// 在此处放置用户代码以初始化页面
			
		}

		#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.Cv_id.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.Cv_id_ServerValidate);

		}
		#endregion

		protected void Btn_ok_Click(object sender, System.EventArgs e)
		{

            string mysql = "insert into student(Student_id,Student_name,Student_sex,Student_nation,Student_birthday,Sturdent_time,Student_classid,Student_home,Student_else) values('" +
                           Tbx_id.Text + "','" + Tbx_name.Text + "','" + Ddl_sex.SelectedItem.Value + "','" + Tbx_nation.Text + "','" + Tbx_birthday.Text + "','" + Tbx_time.Text + "','" + Ddl_class.SelectedItem.Value + "','" + Tbx_home.Text + "','" + Tbx_else.Text + "')";
            DataAs = new DataAccess();
			bool Result = DataAs.ExecSql(mysql);
            if (Result)
			{
			    insert();
			}
			else
			{
				Lbl_note.Text="添加失败,请检查输入!";
				Lbl_note.Style["color"]="red";
			}

		}
		public void insert()
		{
		    string strsql="insert into users(User_id,User_password,User_power) values('"+Tbx_id.Text+"','"+Tbx_id.Text+"',0)";
	        DataAs = new DataAccess();
            bool Result = DataAs.ExecSql(strsql);
            if (Result)
			{
				Response.Redirect("student.aspx");
			}
			else
			{
				Lbl_note.Text="添加失败";
				Lbl_note.Style["color"]="red";
			}
	    }

		protected void Btn_reset_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("addstudent.aspx");
		}

		private void Cv_id_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
		{
            string strsql = "select * from student where Student_id ='" + Tbx_id.Text + "'";
            DataAs = new DataAccess();
            DataTable DT = DataAs.CreateDatatable(strsql);
			if(DT.Rows.Count>0)
			{
				args.IsValid=false;
			}
			else
			{
				args.IsValid=true;
			}
			
		}

        protected void Cv_id_ServerValidate1(object source, ServerValidateEventArgs args)
        {

        }
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -