📄 班评页面.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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.Data.SqlClient;
namespace 学生综合素质测评系统
{
/// <summary>
/// 班评页面 的摘要说明。
/// </summary>
public class 班评页面 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.HyperLink HyperLink4;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
ICollection CreateTable()
{
string SQL="select 班表.细表表号,班表.学号,细表.评价内容,细表.评价标准和办法,班表.自评,班表.班评 from 班表 join 细表 on 班表.细表表号=细表.细表表号 ";
DataSet ds=new DataSet();
SqlConnection myc =new SqlConnection("server=.;database=学生综合素质测评系统;user=sa;password=");
SqlDataAdapter adapter=new SqlDataAdapter(SQL,myc);
adapter.Fill(ds,"班表");
return ds.Tables["班表"].DefaultView;
}
public void bindgrid()
{
DataView dv=(DataView)CreateTable();
DataGrid1.DataSource=dv;
DataGrid1.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection myc =new SqlConnection("server=.;database=学生综合素质测评系统;user=sa;password=");
myc.Open();
if (!Page.IsPostBack)
{
bindgrid();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
bindgrid();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=(int)e.Item.ItemIndex;
bindgrid();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
bindgrid();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string xuehao=e.Item.Cells[0].Text;
//string neirong=e.Item.Cells[2].Text;
//string chengji=e.Item.Cells[4].Text;
string xibiaobiaohao=e.Item.Cells[1].Text;
string banping = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
string SQL="update 班表 set 班评="+banping+" where 学号='"+xuehao+"'and 细表表号='"+xibiaobiaohao+"' ";
SqlConnection myc =new SqlConnection("server=.;database=学生综合素质测评系统;user=sa;password=");
SqlCommand cmd = new SqlCommand(SQL,myc);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
DataGrid1.EditItemIndex=-1;
bindgrid();
}
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection myc =new SqlConnection("server=.;database=学生综合素质测评系统;user=sa;password=");
SqlCommand cmd = new SqlCommand("INSERT INTO 班评总分表(学号,班评总分) SELECT 学号,SUM(班评) FROM 班表 GROUP BY 学号 " ,myc);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -