📄 columnlist.ascx.cs
字号:
namespace RWSB
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.SessionState;
using System.Web.UI;
using RWSB.DatabaseOper;
/// <summary>
/// columnlist 的摘要说明。
/// </summary>
public partial class columnlist : System.Web.UI.UserControl
{
DatabaseConnect Dbc = new DatabaseConnect();
ListItem newitem;
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!this.IsPostBack)
{
dataBind();
for (int i = 2008; i < 2030; i++)
{
newitem = new ListItem(i.ToString());
this.syDDL.Items.Add(newitem);
this.eyDDL.Items.Add(newitem);
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
private void dataBind()
{
zycjDDL_Bind();
BindGridToSource();
}
private void zycjDDL_Bind()
{
string sqlstring = "select id,bmname,showorder from ExigenceDegree order by showorder asc ";
string strconn = ConfigurationSettings.AppSettings["conn"];
SqlConnection myconn = new SqlConnection(strconn);
myconn.Open();
SqlCommand mycmd = new SqlCommand(sqlstring, myconn);
SqlDataReader dr = mycmd.ExecuteReader();
this.zycjDDL.DataSource = dr;
this.zycjDDL.DataTextField = "bmname";
this.zycjDDL.DataValueField = "showorder";
this.zycjDDL.DataBind();
myconn.Close();
}
protected void BindGridToSource()
{
int startY, startM, startD, endY, endM, endD;
//计算开始时间
if (this.syDDL.SelectedItem.Text.Trim() != "请选择")
{
startY = Int32.Parse(this.syDDL.SelectedItem.Text.Trim());
}
else
{
startY = DateTime.Today.Year;
}
if (this.smDDL.SelectedItem.Text.Trim() != "请选择")
{
startM = Int32.Parse(this.smDDL.SelectedItem.Text.Trim());
}
else
{
startM = DateTime.Today.Month;
}
if (this.sdDDL.SelectedItem.Text.Trim() != "请选择")
{
startD = Int32.Parse(this.sdDDL.SelectedItem.Text.Trim());
}
else
{
startD = DateTime.Today.Day;
}
DateTime startDate = new DateTime(startY,startM,startD);
//计算截止时间
if (this.eyDDL.SelectedItem.Text.Trim() != "请选择")
{
endY = Int32.Parse(this.eyDDL.SelectedItem.Text.Trim());
}
else
{
endY = DateTime.Today.Year;
}
if (this.emDDL.SelectedItem.Text.Trim() != "请选择")
{
endM = Int32.Parse(this.emDDL.SelectedItem.Text.Trim());
}
else
{
endM = DateTime.Today.Month;
}
if (this.edDDL.SelectedItem.Text.Trim() != "请选择")
{
endD = Int32.Parse(this.edDDL.SelectedItem.Text.Trim());
}
else
{
endD = DateTime.Today.Day;
}
DateTime endDate = new DateTime(endY,endM,endD);
//当前时间
DateTime now = DateTime.Today;
//设定的统计开始日期
DateTime start = new DateTime(2008,5,1);
//Response.Write(startDate);
//Response.Write(endDate);
//Response.Write(now);
//Response.Write(start);
// Response.End();
//如果截止日期在开始日期之前,则报错
if (endDate < startDate)
{
Response.Write("<script>alert('截止日期必须在开始日期之后!');location.href='default.aspx';</script>");
}
//如果开始日期在统计日期之前
if ( startDate < start)
{
//如果截止日期在统计日期之后,则统计日期为新的开始日期,否则报错
if (endDate > start)
{
startDate = start;
}
else
{
Response.Write("<script>alert('截止日期必须在开始日期之后!');location.href='default.aspx';</script>");
}
}
//如果截止日期在当前日期之后
if (endDate > now)
{
//如果开始日期在当前日期之前,则当前日期为新的截止日期,否则报错
if (startDate < now)
{
endDate = now;
}
else
{
Response.Write("<script>alert('截止日期必须在开始日期之后!');location.href='default.aspx';</script>");
}
}
string con1,con2;
if ((startDate != endDate) && (startDate != now))
{
con1 = " having ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "') ";
}
else if (startDate != now)
{
con1 = " having sbsj = '" + Convert.ToDateTime(startDate.ToString()) + "' ";
}
else
{
startDate = start;
endDate = now;
}
//Response.Write(con1);
//Response.End();
if (this.zycjDDL.SelectedItem.Text.Trim() == "")
{
con2 = "";
}
else
{
con2 = " having zycj = '" + this.zycjDDL.SelectedItem.Text.Trim() + "' ";
}
//Response.Write(con2);
//Response.End();
string sqlstring = "select zycj as '车间名称', ";
sqlstring += " (select sum(qmjc) from rwxx where (zycj = t.zycj) and ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "' )) as '全面检查(km)' , ";
sqlstring += " (select sum(mdgj) from rwxx where (zycj = t.zycj) and ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "' )) as '锚段关节(组)', ";
sqlstring += " (select sum(xc) from rwxx where (zycj = t.zycj) and ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "' )) as '线岔(组)', ";
sqlstring += " (select sum(fd) from rwxx where (zycj = t.zycj) and ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "' )) as '分段(组)', ";
sqlstring += " (select sum(fx) from rwxx where (zycj = t.zycj) and ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "' )) as '分相(组)', ";
sqlstring += " (select sum(gdx) from rwxx where (zycj = t.zycj) and ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "' )) as '供电线(米)', ";
sqlstring += " (select sum(jypp) from rwxx where (zycj = t.zycj) and ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "' )) as '绝缘子(片)', ";
sqlstring += " (select sum(jypb) from rwxx where (zycj = t.zycj) and ( sbsj between '" + Convert.ToDateTime(startDate.ToString()) + "' and '" + Convert.ToDateTime(endDate.ToString()) + "' )) as '绝缘子(棒)' ";
sqlstring += " from rwxx t group by zycj ";
sqlstring +=" " + con2;
//sqlstring += " " + con1 + con2;
//Response.Write(sqlstring);
//Response.End();
string strconn = ConfigurationSettings.AppSettings["conn"];
SqlConnection myconn = new SqlConnection(strconn);
try
{
myconn.Open();
SqlDataAdapter mycmd = new SqlDataAdapter(sqlstring, myconn);
DataSet ds = new DataSet();
mycmd.Fill(ds, "rwxx");
tjGV.DataSource = ds.Tables["rwxx"].DefaultView;
tjGV.DataBind();
}
catch (Exception exception)
{
//Response.Write("<script>alert('统计查询出错!');</script>");
Response.Write(exception.Message);
Response.End();
myconn.Close();
return;
}
}
protected void tjBT_Click(object sender, EventArgs e)
{
BindGridToSource();
}
protected void syDDL_SelectedIndexChanged(object sender, EventArgs e)
{
//对开始日进行清除
this.sdDDL.Items.Clear();
newitem = new ListItem("请选择");
this.sdDDL.Items.Add(newitem);
if (this.syDDL.SelectedItem.Text.Trim() != "请选择")
{
//对月分进行清理
this.smDDL.Items.Clear();
newitem = new ListItem("请选择");
this.smDDL.Items.Add(newitem);
for (int i = 1; i <= 12; i++)
{
newitem = new ListItem(i.ToString());
this.smDDL.Items.Add(newitem);
}
}
else
{
this.smDDL.Items.Clear();
newitem = new ListItem("请选择");
this.smDDL.Items.Add(newitem);
}
}
protected void eyDDL_SelectedIndexChanged(object sender, EventArgs e)
{
//对开始日进行清除
this.edDDL.Items.Clear();
newitem = new ListItem("请选择");
this.edDDL.Items.Add(newitem);
if (this.eyDDL.SelectedItem.Text.Trim() != "请选择")
{
//对月分进行清理
this.emDDL.Items.Clear();
newitem = new ListItem("请选择");
this.emDDL.Items.Add(newitem);
for (int i = 1; i <= 12; i++)
{
newitem = new ListItem(i.ToString());
this.emDDL.Items.Add(newitem);
}
}
else
{
this.emDDL.Items.Clear();
newitem = new ListItem("请选择");
this.emDDL.Items.Add(newitem);
}
}
protected void smDDL_SelectedIndexChanged(object sender, EventArgs e)
{
this.sdDDL.Items.Clear();
newitem = new ListItem("请选择");
this.sdDDL.Items.Add(newitem);
if (this.smDDL.SelectedItem.Text.Trim() != "请选择")
{
int syear = Int32.Parse(this.syDDL.SelectedItem.Text.Trim());
int smonth = Int32.Parse(this.smDDL.SelectedItem.Text.Trim());
for (int i = 1; i <= DateTime.DaysInMonth(syear, smonth); i++)
{
newitem = new ListItem(i.ToString());
this.sdDDL.Items.Add(newitem);
}
}
}
protected void emDDL_SelectedIndexChanged(object sender, EventArgs e)
{
this.edDDL.Items.Clear();
newitem = new ListItem("请选择");
this.edDDL.Items.Add(newitem);
if (this.emDDL.SelectedItem.Text.Trim() != "请选择")
{
int eyear = Int32.Parse(this.eyDDL.SelectedItem.Text.Trim());
int emonth = Int32.Parse(this.emDDL.SelectedItem.Text.Trim());
for (int i = 1; i <= DateTime.DaysInMonth(eyear, emonth); i++)
{
newitem = new ListItem(i.ToString());
this.edDDL.Items.Add(newitem);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -