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 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.txtDate.Text = Request.Params["Date"]; } this.AnalyseData(); } #endregion #region 统计 /// /// 统计分析 /// /// /// 。 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 = "[]"; /// /// 统计方法 /// 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 listStr = new List(); 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 listStr = new List(); // listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); // SqlParameter[] parameter = listStr.ToArray(); // DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // Dictionary> data = new Dictionary>(); // legend = "["; // xAxis = "["; // HashSet xdic = new HashSet(); // HashSet unitdic = new HashSet(); // foreach (DataRow dr in tb.Rows) // { // xdic.Add(dr["QuestionTypeStr"].ToString()); // unitdic.Add(dr["QuestionDef"].ToString()); // Dictionary temp = null; // if (!data.ContainsKey(dr["QuestionDef"].ToString())) // { // data.Add(dr["QuestionDef"].ToString(), new Dictionary()); // } // 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 图形 /// /// 图形变换 /// /// /// 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 } }