📄 scoretable.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;
namespace xx8910
{
/// <summary>
/// ScoreTable 的摘要说明。
/// </summary>
public class ScoreTable : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnQueryAll;
protected System.Web.UI.WebControls.Button btnQueryWithCond;
protected System.Web.UI.WebControls.TextBox txtQueryWithCond;
protected System.Web.UI.WebControls.Button btnQueryWithKey;
protected System.Web.UI.WebControls.TextBox txtQueryWithKey;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label lblScoreID;
protected System.Web.UI.WebControls.Label lblStudentID;
protected System.Web.UI.WebControls.Label lblCourseID;
protected System.Web.UI.WebControls.Label lblScore;
protected System.Web.UI.WebControls.Label lblRemark;
protected System.Web.UI.WebControls.Panel Panel2;
protected System.Web.UI.WebControls.Panel Panel3;
protected System.Web.UI.WebControls.TextBox txtInsertScoreID;
protected System.Web.UI.WebControls.TextBox txtInsertStudentID;
protected System.Web.UI.WebControls.TextBox txtInsertCourseID;
protected System.Web.UI.WebControls.TextBox txtInsertScore;
protected System.Web.UI.WebControls.TextBox txtInsertRemark;
protected System.Web.UI.WebControls.Button btnInsertOk;
protected System.Web.UI.WebControls.Button btnInsertGiveUp;
protected System.Web.UI.WebControls.TextBox txtEditScoreID;
protected System.Web.UI.WebControls.TextBox txtEditStudentID;
protected System.Web.UI.WebControls.TextBox txtEditCourseID;
protected System.Web.UI.WebControls.TextBox txtEditScore;
protected System.Web.UI.WebControls.TextBox txtEditRemark;
protected System.Web.UI.WebControls.Button btnEditOk;
protected System.Web.UI.WebControls.Button btnEditGiveUp;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
this.Bind();
}
this.DataGrid1.Visible=true;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnQueryAll.Click += new System.EventHandler(this.btnQueryAll_Click);
this.btnQueryWithCond.Click += new System.EventHandler(this.btnQueryWithCond_Click);
this.btnQueryWithKey.Click += new System.EventHandler(this.btnQueryWithKey_Click);
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.btnInsertOk.Click += new System.EventHandler(this.btnInsertOk_Click);
this.btnEditOk.Click += new System.EventHandler(this.btnEditOk_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
void Bind()
{
BusinessRules.ScoreTable myScoreTable=new BusinessRules.ScoreTable();
this.DataGrid1.DataSource=myScoreTable.Query();
this.DataGrid1.DataBind();
}
private void btnQueryAll_Click(object sender, System.EventArgs e)//查询所有
{
this.DataGrid1.Visible=true;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
this.Bind();
}
private void btnQueryWithCond_Click(object sender, System.EventArgs e)//条件查询
{
BusinessRules.ScoreTable myScoreTable=new BusinessRules.ScoreTable();
this.DataGrid1.DataSource=myScoreTable.Query(this.txtQueryWithCond.Text);
this.DataGrid1.DataBind();
this.DataGrid1.Visible=true;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
}
private void btnQueryWithKey_Click(object sender, System.EventArgs e)//根据主键查询
{
BusinessRules.ScoreTable myScoreTable=new BusinessRules.ScoreTable();
myScoreTable.QueryWithKey(this.txtQueryWithKey.Text);
this.lblScoreID.Text=myScoreTable.ScoreID;
this.lblStudentID.Text=myScoreTable.StudentID;
this.lblCourseID.Text=myScoreTable.CourseID;
this.lblScore.Text=myScoreTable.Score;
this.lblRemark.Text=myScoreTable.Remark;
this.DataGrid1.Visible=false;
this.Panel1.Visible=true;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
}
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)//添加命令
{
if(e.CommandName=="Insert")
{
this.DataGrid1.Visible=false;
this.Panel1.Visible=false;
this.Panel2.Visible=true;
this.Panel3.Visible=false;
}
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)//删除命令
{
string key=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
BusinessRules.ScoreTable myScoreTable=new BusinessRules.ScoreTable();
if(myScoreTable.Delete(key))
{
Response.Write("<script language='javascript'>alert('删除成功!');</script>");
}
this.Bind();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)//编辑命令
{
this.DataGrid1.Visible=false;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=true;
BusinessRules.ScoreTable myScoreTable=new BusinessRules.ScoreTable();
string key=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
this.txtEditScoreID.Text=key;//取,并显示主键值
myScoreTable.QueryWithKey(key);
this.txtEditStudentID.Text=myScoreTable.StudentID;
this.txtEditCourseID.Text=myScoreTable.CourseID;
this.txtEditScore.Text=myScoreTable.Score;
this.txtEditRemark.Text=myScoreTable.Remark;
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)//绑定激活
{
if((e.Item.ItemType == ListItemType.Item || (e.Item.ItemType == ListItemType.AlternatingItem) ))
{
LinkButton IsDelete=(LinkButton)e.Item.Cells[e.Item.Cells.Count-1].FindControl("lbtnDelete");
IsDelete.Attributes.Add("onclick","return confirm('确定删除吗?')");
}
}
private void btnInsertOk_Click(object sender, System.EventArgs e)//确定添加
{
BusinessRules.ScoreTable myScoreTable=new BusinessRules.ScoreTable();
myScoreTable.ScoreID=this.txtInsertScoreID.Text;
myScoreTable.StudentID=this.txtInsertStudentID.Text;
myScoreTable.CourseID=this.txtInsertCourseID.Text;
myScoreTable.Score=this.txtInsertScore.Text;
myScoreTable.Remark=this.txtInsertRemark.Text;
if(myScoreTable.Insert()>0)
{//添加时必须是StudentID,CourseID都必须在各自的表中都有
Response.Write("<script language='javascript'>alert('添加成功!');</script>");
}
this.Bind();
}
private void btnEditOk_Click(object sender, System.EventArgs e)//确定编辑
{
BusinessRules.ScoreTable myScoreTable=new BusinessRules.ScoreTable();
myScoreTable.ScoreID=this.txtEditScoreID.Text;
myScoreTable.StudentID=this.txtEditStudentID.Text;
myScoreTable.CourseID=this.txtEditCourseID.Text;
myScoreTable.Score=this.txtEditScore.Text;
myScoreTable.Remark=this.txtEditRemark.Text;
if(myScoreTable.UpdateWithKey(this.txtEditScoreID.Text)>0)
{
Response.Write("<script language='javascript'>alert('修改成功!');</script>");
}
this.Bind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -