xinjiang/SGGL/FineUIPro.Web/CQMS/ConstructionLog/Weather.aspx.cs

217 lines
7.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
namespace FineUIPro.Web.CQMS.ConstructionLog
{
public partial class Weather : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtDate.Text = Request.Params["Date"];
}
this.AnalyseData();
}
#endregion
#region
/// <summary>
/// 统计分析
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>。
protected void BtnAnalyse_Click(object sender, EventArgs e)
{
this.AnalyseData();
PageContext.RegisterStartupScript(@" setTimeout(function () { rendChart(" + legend + "," + xAxis + "," + series + ");},1000); ");
}
public string legend = "[]";
public string xAxis = "[]";
public string series = "[]";
/// <summary>
/// 统计方法
/// </summary>
private void AnalyseData()
{
string city = string.Empty;
var project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
if (project != null)
{
city = project.City;
}
if (this.rblState.SelectedValue == "0")
{
string strSql = @" select *
from CQMS_ConstructionLogWeather ";
strSql += " where Date ='" + this.txtDate.Text.Trim() + "' and City='" + city + "'";
strSql += " order by UpdateTime ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
legend = "[ \"实时温度\"]";
xAxis = "[";
string series2 = "[";
string series3 = "[";
foreach (DataRow dr in tb.Rows)
{
DateTime d = Convert.ToDateTime(dr["UpdateTime"].ToString());
xAxis += "\"" + d.Hour.ToString() + ":" + d.Minute.ToString() + "\",";
series2 += "" + dr["Tem"].ToString() + ",";
series3 += "" + dr["Tem2"].ToString() + ",";
}
xAxis = xAxis.TrimEnd(',');
xAxis += "]";
series2 = series2.TrimEnd(',');
series2 += "]";
series3 = series3.TrimEnd(',');
series3 += "]";
series = @"[
{
name: '实时温度',
type: 'line',
barWidth: 20,
label: {
show: true,
position: 'top'
},
emphasis: {
focus: 'series'
},
data: " + series2 + @"
}]";
}
//else
//{
// string strSql = @" select *
// from CQMS_ConstructionLogWeather ";
// strSql += " where Date ='" + this.txtDate.Text.Trim() + "' and City='" + city + "'";
// strSql += " order by UpdateTime ";
// List<SqlParameter> listStr = new List<SqlParameter>();
// listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// Dictionary<string, Dictionary<string, string>> data = new Dictionary<string, Dictionary<string, string>>();
// legend = "[";
// xAxis = "[";
// HashSet<string> xdic = new HashSet<string>();
// HashSet<string> unitdic = new HashSet<string>();
// foreach (DataRow dr in tb.Rows)
// {
// xdic.Add(dr["QuestionTypeStr"].ToString());
// unitdic.Add(dr["QuestionDef"].ToString());
// Dictionary<string, string> temp = null;
// if (!data.ContainsKey(dr["QuestionDef"].ToString()))
// {
// data.Add(dr["QuestionDef"].ToString(), new Dictionary<string, string>());
// }
// temp = data[dr["QuestionDef"].ToString()];
// if (!temp.ContainsKey(dr["QuestionTypeStr"].ToString()))
// {
// temp.Add(dr["QuestionTypeStr"].ToString(), "0");
// }
// temp[dr["QuestionTypeStr"].ToString()] = dr["count"].ToString();
// }
// foreach (string types in xdic)
// {
// xAxis += "\"" + types + "\",";
// }
// xAxis += "]";
// legend += "]";
// series = "[";
// foreach (string unit in data.Keys)
// {
// string tempseries = "";
// foreach (string types in xdic)
// {
// if (data[unit].ContainsKey(types))
// {
// tempseries += "" + data[unit][types] + ",";
// }
// else
// {
// tempseries += ",";
// }
// }
// //stack: '未闭合',
// series += @"{
// name: '" + unit.Replace("\n", "").Replace("\r", "") + @"',
// type: 'bar',
// barWidth: 10,
// label: {
// show: true,
// position: 'top'
// },
// emphasis: {
// focus: 'series'
// },
// data: [" + tempseries + @"]
// },";
// }
// series = series.TrimEnd(',');
// series += "]";
//}
}
#endregion
#region
/// <summary>
/// 图形变换
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpChartType_SelectedIndexChanged(object sender, EventArgs e)
{
this.AnalyseData();
PageContext.RegisterStartupScript(@"setTimeout(function () { rendChart(" + legend + "," + xAxis + "," + series + ");}, 1000); ");
}
protected void ckbShow_CheckedChanged(object sender, CheckedEventArgs e)
{
this.AnalyseData();
PageContext.RegisterStartupScript(@"setTimeout(function () { rendChart(" + legend + "," + xAxis + "," + series + ");}, 1000);");
}
#endregion
}
}