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

📄 教师评分.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;

public partial class graded : System.Web.UI.Page
{
    string temp;
    string strConnection = "server=F45F1B20D9B348B;database=Student;uid=sa;pwd=1017;";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["权限"].ToString() != "t") 
        {
            Response.Redirect("Login.aspx");
        }
            GridViewBind1();
            if (!Page.IsPostBack)
            {
                GridViewBind2();
            }
    }
    private void GridViewBind1()
    {
        SqlConnection myConnection = new SqlConnection();
        myConnection.ConnectionString = strConnection;
        string cmdString = "select * from homework";
        SqlDataAdapter myAdapter = new SqlDataAdapter(cmdString, myConnection);
        myConnection.Open();
        DataSet mySet = new DataSet();
        myAdapter.Fill(mySet);
        myGridView.DataSource = mySet;
        myGridView.DataBind();
        myConnection.Close();
    }
    private void GridViewBind2()
    {
        if (temp == null || temp == "") 
        {
            temp = "1";
        }
        SqlConnection myConnection = new SqlConnection();
        myConnection.ConnectionString = strConnection;
        string cmdString = "select 用户名 from STUDENT where 班级=" + temp;
        SqlDataAdapter myAdapter = new SqlDataAdapter(cmdString, myConnection);
        myConnection.Open();
        DataSet mySet = new DataSet();
        myAdapter.Fill(mySet);
        myGridView2.DataSource = mySet;
        myGridView2.DataBind();
        myConnection.Close();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        temp = DropDownList1.SelectedItem.Value;
        GridViewBind2();
    }
    protected void myGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtWorkName.Text = myGridView.SelectedRow.Cells[0].Text;
    }
    protected void myGridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtStuNo.Text = myGridView2.SelectedRow.Cells[0].Text;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtWorkName.Text != "" && txtStuNo.Text != "" && txtGrade.Text != "")
        {
            lblGrade.Text = "";
            SqlConnection myConnection = new SqlConnection();
            myConnection.ConnectionString = strConnection;
            try
            {
                string cmdString = "insert into Mark (ID,WorkName,UserName,Marks) values('" + txtWorkName.Text + txtStuNo.Text + "','" + txtWorkName.Text + "','" + txtStuNo.Text + " ','" + txtGrade.Text + "')";
                SqlCommand command = new SqlCommand(cmdString, myConnection);
                myConnection.Open();
                command.ExecuteNonQuery();
                myConnection.Close();
            }
            catch (Exception)
            {
                lblGrade.Text = "平分失败!您可以尝试使用修改按钮.";
            }
        }
        else 
        {
            lblGrade.Text = "未选择\"作业名称\"、\"学号\"或者\"分数\"尚未填写!";
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (txtWorkName.Text != "" && txtStuNo.Text != "" && txtGrade.Text != "")
        {
        lblGrade.Text = "";
        SqlConnection myConnection = new SqlConnection();
        myConnection.ConnectionString = strConnection; 
        try
        {
            string cmdString = "update Mark set Marks='"
            + txtGrade.Text + "'where ID='"
            + txtWorkName.Text + txtStuNo.Text + "'";
            SqlCommand command = new SqlCommand(cmdString, myConnection);
            myConnection.Open();
            command.ExecuteNonQuery();
            myConnection.Close();
            lblGrade.Text = "修改成功!";
        }
        catch (Exception)
        {
            lblGrade.Text = "修改失败!";
        }
        }
        else
        {
            lblGrade.Text = "未选择\"作业名称\"、\"学号\"或者\"分数\"尚未填写!";
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {

    }
}

⌨️ 快捷键说明

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