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

📄 student_scre_enter.aspx.cs

📁 本套软件适用于各大高校、中小学、幼儿园、培训机构等单位的教学管理软件。
💻 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;
using jianke;
public partial class Student_scre_enter : System.Web.UI.Page
{

    
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        this.Panel1.Visible = false;
        this.ListBox1.Items.Clear();
        if (this.TextBox1.Text == "")
        {

            Response.Write("<script>alert('请输入学号!');</script>");
        }
        else
        {

            SqlConnection Conn = DB.creatconnection();
            Conn.Open();

            String str0 = "Select student_sno from Student where student_sno='" + this.TextBox1.Text + "'";
            SqlCommand com0 = new SqlCommand(str0, Conn);
            SqlDataReader dr0 = com0.ExecuteReader();

            //学生表中有此学生学号记录
            if (!dr0.Read())
            {

                dr0.Close();
                Response.Write("<script>alert('你输入的学号错误或不存在!');</script>");
            }
            else
            {

                dr0.Close();

                String str1 = "Select student_sno from student_course_choice where student_sno='" + this.TextBox1.Text + "' and grade='" + this.DropDownList1.SelectedItem.Text + "'";
                SqlCommand com1 = new SqlCommand(str1, Conn);
                SqlDataReader dr1 = com1.ExecuteReader();


                if (!dr1.Read())
                {
                    dr1.Close();
                    Response.Write("<script>alert('该学生该学期没有选课!');</script>");

                }
                else
                {
                    this.ListBox1.Items.Clear();
                    dr1.Close();
                    SqlCommand com = new SqlCommand("select   course_name from student_course_choice where student_sno='" + this.TextBox1.Text + "' and grade='" + this.DropDownList1.SelectedItem.Text.ToString() + "'", Conn);

                    SqlDataReader dr = com.ExecuteReader();

                    while (dr.Read())
                    {
                        this.ListBox1.Items.Add(new ListItem(dr.GetString(0)));
                    }
                    dr.Close();
                    this.ListBox1.Items[0].Selected = true;
                    this.Label5.Visible = true;
                    this.Label8.Visible = true;
                  
                    this.Label5.Text = this.ListBox1.Items[0].Text.ToString() ;
                 

                   
                }
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (this.ListBox1.Items.Count != 0)
        {
            this.ListBox1.Items[0].Selected = true;
            this.Label5.Visible = true;
            this.Label8.Visible = true;
            this.Label5.Text = this.ListBox1.Items[0].Text.ToString();



            SqlConnection Conn = DB.creatconnection();
            Conn.Open();



            string str = "insert into Score(student_sno,grade,course_name,exam_score,usu_score)values('" + this.TextBox1.Text + "','" + this.DropDownList1.SelectedValue + "','" + this.ListBox1.SelectedItem.Text + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text + "')";
            SqlCommand cmd = new SqlCommand(str, Conn);
            cmd.ExecuteNonQuery();
            Conn.Close();
            this.TextBox2.Text = "";
            this.TextBox3.Text = "";

            Response.Write("<script>alert('录入成功!');</script>");
            ListBox1.Items.Remove(ListBox1.SelectedItem);
            if (this.ListBox1.Items.Count == 0)
            {
                Response.Write("<script>alert('该学生该学期所选课程全部录入完毕!');</script>");

                this.Label5.Visible = false;
                this.Label8.Visible = false;
            }
            else 
            
            {

                this.ListBox1.Items[0].Selected = true;
                this.Label5.Visible = true;
                this.Label8.Visible = true;
                this.Label5.Text = this.ListBox1.Items[0].Text.ToString();
            
            
            }

        }
        else
        {
            Response.Write("<script>alert('该学生该学期所选课程全部录入完毕!');</script>");
        
        }





      //if (this.ListBox1.Items.Count != 0)
      //  {
      //      // Response.Write("<script>alert('该学生该学期所选课程全部录入完毕!');</script>");


           
           
            
      //      ListBox1.Items.Remove(ListBox1.SelectedItem);

            

      //      if (this.ListBox1.Items.Count == 0)
      //      {
      //          Response.Write("<script>alert('该学生该学期所选课程全部录入完毕!');</script>");
      //        //  this.TextBox1.Text = "";
      //          this.Label5.Visible = false;
      //          this.Label8.Visible = false;
      //      }
      //      else 
      //      {
      //          this.ListBox1.Items[0].Selected = true;
      //          this.Label5.Text =  this.ListBox1.Items[0].Text.ToString();



      //          SqlConnection Conn = DB.creatconnection();
      //          Conn.Open();



      //          string str = "insert into Score(student_sno,grade,course_name,exam_score,usu_score)values('" + this.TextBox1.Text + "','" + this.DropDownList1.SelectedValue + "','" + this.ListBox1.SelectedItem.Text + "','" + this.TextBox2.Text+ "','" + this.TextBox3.Text + "')";
      //          SqlCommand cmd = new SqlCommand(str, Conn);
      //          cmd.ExecuteNonQuery();
      //          Conn.Close();
      //          this.TextBox2.Text = "";
      //          this.TextBox3.Text = "";
      //          Response.Write("<script>alert('录入成功!');</script>");



      //      }
      // }
      // else 
      //     Response.Write("<script>alert('该学生该学期所选课程全部录入完毕!');</script>");
       
   }

    protected void Button3_Click(object sender, EventArgs e)
    {
        this.Panel1.Visible = true;
        Score_Bind();
    }

    public void Score_Bind()
    {
        SqlConnection Conn = DB.creatconnection();
        Conn.Open();


        SqlDataAdapter da = new SqlDataAdapter("Select * from Score  where student_sno='" + this.TextBox1.Text + "' and grade='" + this.DropDownList1.SelectedValue + "' ", Conn); // 绑定到满足条件的 数据上  ?
        DataSet ds = new DataSet();
        da.Fill(ds);
        dg.DataSource = ds;
        dg.DataBind();
        Conn.Close();

    }
   

    protected void cancel(object source, DataGridCommandEventArgs e)
    {
        dg.EditItemIndex = -1;
        Score_Bind();
    }
    protected void edit(object source, DataGridCommandEventArgs e)
    {
        dg.EditItemIndex = (int)e.Item.ItemIndex;
        Score_Bind();
    }
    protected void update(object source, DataGridCommandEventArgs e)
    {
        SqlConnection Conn = DB.creatconnection();
        Conn.Open();
        String str = "UPDATE  Score SET  exam_score='" + ((TextBox)e.Item.Cells[1].Controls[0]).Text + "' ,usu_score= '" + ((TextBox)e.Item.Cells[2].Controls[0]).Text + "' where  id='" + dg.DataKeys[e.Item.ItemIndex] + "' ";
        SqlCommand com = new SqlCommand(str, Conn);
        com.ExecuteNonQuery();

        Conn.Close();
        Score_Bind();
    }

}
             









































//                if (dr1.Read()!=null)
//                {
//                    dr1.Close();
//                    Conn.Close();
//                    Conn.Open();
//                    SqlCommand com = new SqlCommand("select   course_name from student_course_choice where student_sno='" + this.TextBox1.Text + "' and grade='" + this.DropDownList1.SelectedItem.Text.ToString() + "'", Conn);

//                    SqlDataReader dr = com.ExecuteReader();

//                    while (dr.Read())
//                    {
//                        this.ListBox1.Items.Add(new ListItem(dr.GetString(0)));
//                    }
//                    dr.Close();
//                }
//                else
//                {
//                    dr1.Close();
//                    Response.Write("<script>alert('该学生该学期没有选课!');</script>");
//                }
//            }

//            else
//            {
//                dr0.Close();
//                Response.Write("<script>alert('你输入的学号错误或不存在!');</script>");
//            }

//        }
//    }
//}

⌨️ 快捷键说明

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