📄 chaxun.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 nicholasbjj
{
/// <summary>
/// Summary description for yonghuguanli.
/// </summary>
public class yonghuguanli : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!Page.IsPostBack)
{
string sql="select * from [company]";
string strConn="Server=(local);User ID=sa;Database=bjj;PassWord=temo456";
SqlConnection conn=new SqlConnection(strConn);
SqlCommand cmd=new SqlCommand();
SqlDataReader reader;
cmd.Connection=conn;
cmd.CommandText=sql;
conn.Open();
reader=cmd.ExecuteReader();
DropDownList1.DataSource=reader;
DropDownList1.DataTextField="comname";
DropDownList1.DataValueField="comid";
DropDownList1.DataBind();
reader.Close();
conn.Close();
string sql1="select * from [szbsj]";
string strConn1="Server=(local);User ID=sa;Database=bjj;PassWord=temo456";
SqlConnection conn1=new SqlConnection(strConn1);
SqlCommand cmd1=new SqlCommand();
SqlDataReader reader1;
cmd1.Connection=conn1;
cmd1.CommandText=sql1;
conn1.Open();
reader1=cmd1.ExecuteReader();
DropDownList2.DataSource=reader;
DropDownList2.DataTextField="time";
reader1.Close();
conn1.Close();
//bang ding datagrid
string sql2="SELECT dbo.szb.szbname AS 指标名称, dbo.company.comname AS 电厂名称, dbo.szbsj.sjz AS 设计值, dbo.szbsj.zhsp AS 最好水平, dbo.szbsj.yjh AS 月计划,";
sql2+=" dbo.szbsj.ysj AS 月实际, dbo.szbsj.njh AS 年计划, dbo.szbsj.nlj AS 年累计, dbo.szbsj.time AS 申报时间";
sql2+=" FROM dbo.company INNER JOIN";
sql2+=" dbo.szbsj ON dbo.company.comid = dbo.szbsj.comid INNER JOIN";
sql2+=" dbo.szb ON dbo.szbsj.szbid = dbo.szb.szbid";
string strConn2="Server=(local);User ID=sa;Database=bjj;PassWord=temo456";
SqlConnection conn2=new SqlConnection(strConn2);
SqlCommand cmd2=new SqlCommand();
SqlDataReader reader2;
cmd2.Connection=conn2;
cmd2.CommandText=sql2;
conn2.Open();
reader2=cmd2.ExecuteReader();
DataGrid1.DataSource=reader2;
DataGrid1.DataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
string sql="SELECT dbo.szb.szbname AS 指标名称, dbo.company.comname AS 电厂名称, dbo.szbsj.sjz AS 设计值, dbo.szbsj.zhsp AS 最好水平, dbo.szbsj.yjh AS 月计划,";
sql+=" dbo.szbsj.ysj AS 月实际, dbo.szbsj.njh AS 年计划, dbo.szbsj.nlj AS 年累计, dbo.szbsj.time AS 申报时间";
sql+=" FROM dbo.company INNER JOIN";
sql+=" dbo.szbsj ON dbo.company.comid = dbo.szbsj.comid INNER JOIN";
sql+=" dbo.szb ON dbo.szbsj.szbid = dbo.szb.szbid";
sql+= " where comname='" + DropDownList1.SelectedItem.Text +"'and time='"+ DropDownList2.SelectedItem.Text+"'";
string strConn="Server=(local);User ID=sa;Database=bjj;PassWord=temo456";
SqlConnection conn=new SqlConnection(strConn);
SqlCommand cmd=new SqlCommand();
SqlDataReader reader;
cmd.Connection=conn;
cmd.CommandText=sql;
conn.Open();
reader=cmd.ExecuteReader();
DataGrid1.DataSource=reader;
DataGrid1.DataBind();
}
private void Button3_Click(object sender, System.EventArgs e)
{
Response.Redirect("zhujiemian.aspx");
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -