📄 resultmanage.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 myResult
{
/// <summary>
/// resultmanage 的摘要说明。
/// </summary>
public class resultmanage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnsearch;
protected System.Web.UI.WebControls.DropDownList ddlclass;
protected SqlConnection conn;
protected SqlDataAdapter myDa;
protected SqlCommand myCmd;
protected System.Web.UI.WebControls.DropDownList ddlcourse;
protected System.Web.UI.WebControls.TextBox txtterm;
protected System.Web.UI.WebControls.Button btnsubmit;
protected System.Web.UI.WebControls.TextBox txtteacher;
protected System.Web.UI.WebControls.DataGrid dg_show;
protected System.Web.UI.WebControls.DataGrid dg_result;
protected DataSet ds;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
// string str_user=Session["Auser"].ToString();//Session传值
// if(Session["Auser"]==null)
// {
// Response.Redirect("adminlogin.aspx");
// }
// else
// {
conn=connDB.createConn();
ds=new DataSet();
if(!IsPostBack)
{
this.bindDdl();
this.bindDdlCourse();
}
// }
}
private void bindDdl()
{
string str_sel="select ClassNumber from Class";
myDa=new SqlDataAdapter(str_sel,conn);
myDa.Fill(ds,"Class");
ddlclass.DataSource=ds.Tables["Class"].DefaultView;
ddlclass.DataTextField="ClassNumber";
ddlclass.DataBind();
}
private void bindDdlCourse()
{
string str_sel="select CourseId,CourseName from Course";
myDa=new SqlDataAdapter(str_sel,conn);
myDa.Fill(ds,"Course");
ddlcourse.DataSource=ds.Tables["Course"].DefaultView;
ddlcourse.DataTextField="CourseName";
ddlcourse.DataBind();
}
private void bindDgshow()
{
string str_class=this.ddlclass.SelectedValue.ToString();
myDa=new SqlDataAdapter("procResult",conn);
myDa.SelectCommand.CommandType=CommandType.StoredProcedure;
SqlParameter param=new SqlParameter("@Aclass",SqlDbType.VarChar,50);
param.Direction=ParameterDirection.Input;
param.Value=str_class;
myDa.SelectCommand.Parameters.Add(param);
myDa.Fill(ds,"Show");
dg_show.DataSource=ds.Tables["Show"].DefaultView;
dg_show.DataBind();
}
private void bindDg()
{
string str_class=this.ddlclass.SelectedValue.ToString();
myDa=new SqlDataAdapter("procSelResult",conn);
myDa.SelectCommand.CommandType=CommandType.StoredProcedure;
SqlParameter param=new SqlParameter("@Aclass",SqlDbType.VarChar,50);
param.Direction=ParameterDirection.Input;
param.Value=str_class;
myDa.SelectCommand.Parameters.Add(param);
myDa.Fill(ds,"Result");
dg_result.DataSource=ds.Tables["Result"].DefaultView;
dg_result.DataBind();
}
private void ExecuteInsert( int i)
{
string str_class=dg_show.Items[i].Cells[0].Text.ToString();
string str_Snumber=dg_show.Items[i].Cells[1].Text.ToString();
string str_Sname=dg_show.Items[i].Cells[2].Text.ToString();
TextBox tb=(TextBox)dg_show.Items[i].FindControl("txtresult");
string str_result=tb.Text.ToString();
string str_course=ddlcourse.SelectedValue.ToString();
string str_term=this.txtterm.Text.Trim().Replace("'","''");
string str_teacher=this.txtteacher.Text.Trim().Replace("'","''");
if(conn.State==ConnectionState.Closed)
{
conn.Open();
}
myCmd=new SqlCommand("procInsertResult",conn);
myCmd.CommandType=CommandType.StoredProcedure;
myCmd.Parameters.Add("@ASnumber",SqlDbType.Int);
myCmd.Parameters.Add("@ASname",SqlDbType.VarChar,50);
myCmd.Parameters.Add("@Aresult",SqlDbType.SmallInt);
myCmd.Parameters.Add("@Acourse",SqlDbType.VarChar,50);
myCmd.Parameters.Add("@Aterm",SqlDbType.VarChar,50);
myCmd.Parameters.Add("@Ateacher",SqlDbType.VarChar,50);
myCmd.Parameters.Add("@Aclass",SqlDbType.VarChar,50);
myCmd.Parameters.Add("@Atime",SqlDbType.DateTime);
myCmd.Parameters["@ASnumber"].Value=Convert.ToInt32(str_Snumber);
myCmd.Parameters["@ASname"].Value=str_Sname;
myCmd.Parameters["@Aresult"].Value=Convert.ToInt16(str_result);
myCmd.Parameters["@Acourse"].Value=str_course;
myCmd.Parameters["@Aterm"].Value=str_term;
myCmd.Parameters["@Ateacher"].Value=str_teacher;
myCmd.Parameters["@Aclass"].Value=str_class;
myCmd.Parameters["@Atime"].Value=System.DateTime.Now;
myCmd.ExecuteNonQuery();
conn.Close();
string Dhtmlalert="";
Dhtmlalert += "<script language=javascript>";
Dhtmlalert += "alert('添加成功!');";
Dhtmlalert += "</script>";
Page.RegisterClientScriptBlock("alert_news",Dhtmlalert);
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnsearch.Click += new System.EventHandler(this.btnsearch_Click);
this.btnsubmit.Click += new System.EventHandler(this.btnsubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnsearch_Click(object sender, System.EventArgs e)
{
if(this.IsValid)
{
bindDgshow();
}
}
private void btnsubmit_Click(object sender, System.EventArgs e)
{
if(this.IsValid)
{
int size=this.dg_show.PageSize;
int count=this.dg_show.PageCount;
int list=size*count;
for(int i=0;i<=list;i++)
{
this.ExecuteInsert(i);
}
this.dg_show.CurrentPageIndex=0;
this.bindDg();
}
//
//创建保存SQL语句的ArrayList对象
//
// ArrayList sqlList = new ArrayList();
// int size = this.dg_show.PageSize;
// int count = this.dg_show.PageCount;
// int list = size*count;
// for(int i=0; i<=list; i++)
// {
// /*
// 逐个构建SQL语句,并添加到集合中
// */
// }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -