?? 班評頁面.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 + -