📄 studentinfo.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>
/// StudentInfo 的摘要说明。
/// </summary>
public class StudentInfo : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtQueryWithKey;
protected System.Web.UI.WebControls.Button btnQueryWithKey;
protected System.Web.UI.WebControls.TextBox txtQueryWithCond;
protected System.Web.UI.WebControls.Button btnQueryWithCond;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label lStudentID;
protected System.Web.UI.WebControls.Label lOrganizationID;
protected System.Web.UI.WebControls.Label lGradeID;
protected System.Web.UI.WebControls.Label lRoleID;
protected System.Web.UI.WebControls.Label lNationCodeID;
protected System.Web.UI.WebControls.Label lStudentName;
protected System.Web.UI.WebControls.Label lSex;
protected System.Web.UI.WebControls.Label lBirthDay;
protected System.Web.UI.WebControls.Label lPassword;
protected System.Web.UI.WebControls.Panel Panel2;
protected System.Web.UI.WebControls.Button btnInsertOk;
protected System.Web.UI.WebControls.Button btnInsertGiveUp;
protected System.Web.UI.WebControls.TextBox txtInsertStudentID;
protected System.Web.UI.WebControls.TextBox txtInsertOrganizationID;
protected System.Web.UI.WebControls.TextBox txtInsertGradeID;
protected System.Web.UI.WebControls.TextBox txtInsertRoleID;
protected System.Web.UI.WebControls.TextBox txtInsertNationCodeID;
protected System.Web.UI.WebControls.TextBox txtInsertStudentName;
protected System.Web.UI.WebControls.TextBox txtInsertBirthDay;
protected System.Web.UI.WebControls.TextBox txtInsertPassword;
protected System.Web.UI.WebControls.Button btnEditGiveUp;
protected System.Web.UI.WebControls.Button btnEditOk;
protected System.Web.UI.WebControls.TextBox txtEditPassword;
protected System.Web.UI.WebControls.TextBox txtEditBirthDay;
protected System.Web.UI.WebControls.TextBox txtEditStudentName;
protected System.Web.UI.WebControls.TextBox txtEditNationCodeID;
protected System.Web.UI.WebControls.TextBox txtEditRoleID;
protected System.Web.UI.WebControls.TextBox txtEditGradeID;
protected System.Web.UI.WebControls.TextBox txtEditOrganizationID;
protected System.Web.UI.WebControls.TextBox txtEditStudentID;
protected System.Web.UI.WebControls.Panel Panel3;
protected System.Web.UI.WebControls.RadioButton rbtnInsertNan;
protected System.Web.UI.WebControls.RadioButton rbtnInsertNv;
protected System.Web.UI.WebControls.RadioButton rbtnEditNan;
protected System.Web.UI.WebControls.RadioButton rbtnEditNv;
protected System.Web.UI.WebControls.Button btnQueryAll;
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.StudentInfo myStudentInfo=new BusinessRules.StudentInfo();
this.DataGrid1.DataSource=myStudentInfo.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)//条件查询
{
this.DataGrid1.Visible=true;
this.Panel1.Visible=false;
this.Panel2.Visible=false;
this.Panel3.Visible=false;
BusinessRules.StudentInfo myStudentInfo=new BusinessRules.StudentInfo();
this.DataGrid1.DataSource=myStudentInfo.Query(this.txtQueryWithCond.Text);
this.DataGrid1.DataBind();
}
private void btnQueryWithKey_Click(object sender, System.EventArgs e)//主键查询
{
BusinessRules.StudentInfo myStudentInfo=new BusinessRules.StudentInfo();
myStudentInfo.QueryWithKey(this.txtQueryWithKey.Text);
this.lStudentID.Text=myStudentInfo.StudentID;
this.lOrganizationID.Text=myStudentInfo.OrganizationID;
this.lGradeID.Text=myStudentInfo.GradeID;
this.lRoleID.Text=myStudentInfo.RoleID;
this.lNationCodeID.Text=myStudentInfo.NationCodeID;
this.lStudentName.Text=myStudentInfo.StudentName;
this.lSex.Text=myStudentInfo.Sex;
this.lBirthDay.Text=myStudentInfo.BirthDay;
this.lPassword.Text=myStudentInfo.Password;
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 str;
string key=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
BusinessRules.StudentInfo myStudentInfo=new BusinessRules.StudentInfo();
str=myStudentInfo.IsDelete(key);
if(str==null)
{
myStudentInfo.Delete(key);
Response.Write("<script language='javascript'>alert('删除成功!');</script>");
this.Bind();
}
else
{
Response.Redirect("Error.aspx?"+"ErrorMsg="+str);
}
}
//myStudentInfo
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;
string key=this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
this.txtEditStudentID.Text=key;//取,显示 主键
BusinessRules.StudentInfo myStudentInfo=new BusinessRules.StudentInfo();//显示......
myStudentInfo.QueryWithKey(key);
this.txtEditOrganizationID.Text=myStudentInfo.OrganizationID;
this.txtEditGradeID.Text=myStudentInfo.GradeID;
this.txtEditRoleID.Text=myStudentInfo.RoleID;
this.txtEditNationCodeID.Text=myStudentInfo.NationCodeID;
this.txtEditStudentName.Text=myStudentInfo.StudentName;
if(myStudentInfo.Sex=="男")
{
this.rbtnEditNan.Checked=true;
}
else
{
this.rbtnEditNv.Checked=false;
}
this.txtEditBirthDay.Text=myStudentInfo.BirthDay;
this.txtEditPassword.Text=myStudentInfo.Password;
}
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.StudentInfo myStudentInfo=new BusinessRules.StudentInfo();
myStudentInfo.StudentID=this.txtInsertStudentID.Text;
myStudentInfo.OrganizationID=this.txtInsertOrganizationID.Text;
myStudentInfo.GradeID=this.txtInsertGradeID.Text;
myStudentInfo.RoleID=this.txtInsertRoleID.Text;
myStudentInfo.NationCodeID=this.txtInsertNationCodeID.Text;
myStudentInfo.StudentName=this.txtInsertStudentName.Text;
if(this.rbtnInsertNan.Checked)
{
myStudentInfo.Sex="男";
}
else
{
myStudentInfo.Sex="女";
}
myStudentInfo.BirthDay=this.txtInsertBirthDay.Text;
myStudentInfo.Password=this.txtInsertPassword.Text;
if(myStudentInfo.Insert()>0)
{
Response.Write("<script language='javascript'>alert('添加成功!');</script>");
}
this.Bind();
}
private void btnEditOk_Click(object sender, System.EventArgs e)//确定编辑
{
BusinessRules.StudentInfo myStudentInfo=new BusinessRules.StudentInfo();
myStudentInfo.StudentID=this.txtEditStudentID.Text;
myStudentInfo.OrganizationID=this.txtEditOrganizationID.Text;
myStudentInfo.GradeID=this.txtEditGradeID.Text;
myStudentInfo.RoleID=this.txtEditRoleID.Text;
myStudentInfo.NationCodeID=this.txtEditNationCodeID.Text;
myStudentInfo.StudentName=this.txtEditStudentName.Text;
if(this.rbtnEditNan.Checked)
{
myStudentInfo.Sex="男";
}
else //这个好像不能赋值
{
myStudentInfo.Sex="女";
}
myStudentInfo.BirthDay=this.txtEditBirthDay.Text;
myStudentInfo.Password=this.txtEditPassword.Text;
if(myStudentInfo.UpdateWithKey(this.txtEditStudentID.Text)>0)
{
Response.Write("<script language='javascript'>alert('修改成功!');</script>");
}
this.Bind();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -