protected void Page_Load(object sender, EventArgs e) { _cityId = int.Parse(Request.QueryString["cityId"]); DateTime now = DateTime.Now; DateTime endtime = new DateTime(now.Year, now.Month, 1); DateTime stattime = endtime.AddMonths(-1); DataSet historyDataDs = _bll.GetList(4, stattime, endtime, 1, _cityId); foreach (DataRow drRow in historyDataDs.Tables[0].Rows) { drRow["TPAVG"] = (double)drRow["TPAVG"] / 1000.0; drRow["PM25AVG"] = (double)drRow["PM25AVG"] / 1000.0; drRow["PM100AVG"] = (double)drRow["PM100AVG"] / 1000.0; } gvProjectCompare.DataSource = historyDataDs; gvProjectCompare.DataBind(); }
protected void btnSubmit_Click(object sender, EventArgs e) { _cityId = int.Parse(hiddencityId.Value.Trim()); string strYear = ddlSelectYear.SelectedValue; string strDate = strYear + "-" + "01"; DateTime startTime = DateTime.Parse(strDate); DateTime endTime = startTime.AddYears(1); int indexKind = Convert.ToInt16(ddlPolutionKind.SelectedValue); DataSet reportDs = _bll.GetList(1, startTime, endTime, indexKind, _cityId); if (indexKind == 1) { foreach (DataRow drRow in reportDs.Tables[0].Rows) { drRow["IndexAVG"] = string.Format("{0:F}", (double)drRow["IndexAVG"] / 1000.0); drRow["IndexMAX"] = string.Format("{0:F}", (double)drRow["IndexMAX"] / 1000.0); drRow["IndexMIN"] = string.Format("{0:F}", (double)drRow["IndexMIN"] / 1000.0); } } else { foreach (DataRow drRow in reportDs.Tables[0].Rows) { drRow["IndexAVG"] = string.Format("{0:F}", (double)drRow["IndexAVG"]); drRow["IndexMAX"] = string.Format("{0:F}", (double)drRow["IndexMAX"]); drRow["IndexMIN"] = string.Format("{0:F}", (double)drRow["IndexMIN"]); } } DataSet avgDs = _bll.GetList(2, startTime, endTime, indexKind, _cityId); gvReportShow.DataSource = reportDs; gvReportShow.DataBind(); DataTable reportDt = reportDs.Tables[0]; DataTable avarageDt = avgDs.Tables[0]; if (reportDt.Rows.Count > 0) { if (indexKind == 1) { StringBuilder strBuilderReturnValue = new StringBuilder(); strBuilderReturnValue.Append("["); strBuilderReturnValue.Append("{name: '颗粒物浓度',data: ["); for (int i = 0; i < reportDt.Rows.Count; i++) { string strName = reportDt.Rows[i]["IndexAVG"].ToString(); strBuilderReturnValue.Append(strName); strBuilderReturnValue.Append(","); } strBuilderReturnValue.Remove(strBuilderReturnValue.ToString().LastIndexOf(','), 1); strBuilderReturnValue.Append("]}]"); ReturnValue = strBuilderReturnValue.ToString(); StringBuilder strBuilderxAxisCategories = new StringBuilder(); strBuilderxAxisCategories.Append("["); for (int i = 0; i < reportDt.Rows.Count; i++) { string strName = reportDt.Rows[i]["StatName"].ToString(); strBuilderxAxisCategories.Append("'"); strBuilderxAxisCategories.Append(strName); strBuilderxAxisCategories.Append("'"); strBuilderxAxisCategories.Append(","); } strBuilderxAxisCategories.Remove(strBuilderxAxisCategories.ToString().LastIndexOf(','), 1); strBuilderxAxisCategories.Append("]"); XAxisCategories = strBuilderxAxisCategories.ToString(); lblAvgShow.Text = ddlSelectYear.SelectedItem.Value + "年" + "颗粒物平均浓度为:" + String.Format("{0:N1}", float.Parse(avarageDt.Rows[0]["IndexAVG"].ToString()) / 1000.0); lblAvgShow.Visible = true; } if (indexKind == 2) { StringBuilder strBuilderReturnValue = new StringBuilder(); strBuilderReturnValue.Append("["); strBuilderReturnValue.Append("{name: '噪音大小',data: ["); for (int i = 0; i < reportDt.Rows.Count; i++) { string strName = reportDt.Rows[i]["IndexAVG"].ToString(); strBuilderReturnValue.Append(strName); strBuilderReturnValue.Append(","); } strBuilderReturnValue.Remove(strBuilderReturnValue.ToString().LastIndexOf(','), 1); strBuilderReturnValue.Append("]}]"); ReturnValue = strBuilderReturnValue.ToString(); StringBuilder strBuilderxAxisCategories = new StringBuilder(); strBuilderxAxisCategories.Append("["); for (int i = 0; i < reportDt.Rows.Count; i++) { string strName = reportDt.Rows[i]["StatName"].ToString(); strBuilderxAxisCategories.Append("'"); strBuilderxAxisCategories.Append(strName); strBuilderxAxisCategories.Append("'"); strBuilderxAxisCategories.Append(","); } strBuilderxAxisCategories.Remove(strBuilderxAxisCategories.ToString().LastIndexOf(','), 1); strBuilderxAxisCategories.Append("]"); XAxisCategories = strBuilderxAxisCategories.ToString(); lblAvgShow.Text = ddlSelectYear.SelectedItem.Value + "年" + "噪音平均大小为:" + String.Format("{0:N1}", float.Parse(avarageDt.Rows[0]["IndexAVG"].ToString())); lblAvgShow.Visible = true; } if (indexKind == 3) { StringBuilder strBuilderReturnValue = new StringBuilder(); strBuilderReturnValue.Append("["); strBuilderReturnValue.Append("{name: 'PM2.5',data: ["); for (int i = 0; i < reportDt.Rows.Count; i++) { string strName = reportDt.Rows[i]["IndexAVG"].ToString(); strBuilderReturnValue.Append(strName); strBuilderReturnValue.Append(","); } strBuilderReturnValue.Remove(strBuilderReturnValue.ToString().LastIndexOf(','), 1); strBuilderReturnValue.Append("]}]"); ReturnValue = strBuilderReturnValue.ToString(); StringBuilder strBuilderxAxisCategories = new StringBuilder(); strBuilderxAxisCategories.Append("["); for (int i = 0; i < reportDt.Rows.Count; i++) { string strName = reportDt.Rows[i]["StatName"].ToString(); strBuilderxAxisCategories.Append("'"); strBuilderxAxisCategories.Append(strName); strBuilderxAxisCategories.Append("'"); strBuilderxAxisCategories.Append(","); } strBuilderxAxisCategories.Remove(strBuilderxAxisCategories.ToString().LastIndexOf(','), 1); strBuilderxAxisCategories.Append("]"); XAxisCategories = strBuilderxAxisCategories.ToString(); lblAvgShow.Text = ddlSelectYear.SelectedItem.Value + "年" + "PM2.5平均浓度为:" + String.Format("{0:N1}", float.Parse(avarageDt.Rows[0]["IndexAVG"].ToString()) / 1000.0); lblAvgShow.Visible = true; } if (indexKind == 4) { StringBuilder strBuilderReturnValue = new StringBuilder(); strBuilderReturnValue.Append("["); strBuilderReturnValue.Append("{name: 'PM10',data: ["); for (int i = 0; i < reportDt.Rows.Count; i++) { string strName = reportDt.Rows[i]["IndexAVG"].ToString(); strBuilderReturnValue.Append(strName); strBuilderReturnValue.Append(","); } strBuilderReturnValue.Remove(strBuilderReturnValue.ToString().LastIndexOf(','), 1); strBuilderReturnValue.Append("]}]"); ReturnValue = strBuilderReturnValue.ToString(); StringBuilder strBuilderxAxisCategories = new StringBuilder(); strBuilderxAxisCategories.Append("["); for (int i = 0; i < reportDt.Rows.Count; i++) { string strName = reportDt.Rows[i]["StatName"].ToString(); strBuilderxAxisCategories.Append("'"); strBuilderxAxisCategories.Append(strName); strBuilderxAxisCategories.Append("'"); strBuilderxAxisCategories.Append(","); } strBuilderxAxisCategories.Remove(strBuilderxAxisCategories.ToString().LastIndexOf(','), 1); strBuilderxAxisCategories.Append("]"); XAxisCategories = strBuilderxAxisCategories.ToString(); lblAvgShow.Text = ddlSelectYear.SelectedItem.Value + "年" + "PM10平均浓度为:" + String.Format("{0:N1}", float.Parse(avarageDt.Rows[0]["IndexAVG"].ToString()) / 1000.0); lblAvgShow.Visible = true; } lblShowError.Visible = false; } else { lblShowError.Text = "此阶时间段内无数据"; lblShowError.Visible = true; } }