public string GetHazardSickImage(string year, string risk) { string wheresql = ""; ERCHTMS.Code.Operator user = ERCHTMS.Code.OperatorProvider.Provider.Current(); if (user.IsSystem) { wheresql = ""; } else { string where = new ERCHTMS.Busines.AuthorizeManage.AuthorizeBLL().GetModuleDataAuthority(ERCHTMS.Code.OperatorProvider.Provider.Current(), HttpContext.Request.Cookies["currentmoduleId"].Value); wheresql += " and " + where; } List <string> yValues = new List <string>(); List <object> dic = new List <object>(); List <int> num = new List <int>(); List <int> CBnum = new List <int>(); List <double> Cblist = new List <double>(); HazarddetectionBLL habll = new HazarddetectionBLL(); int years = Convert.ToInt32(year); DataTable dt = habll.GetStatisticsHazardTable(years, risk, true, wheresql); //全部统计数据 DataTable dtCb = habll.GetStatisticsHazardTable(years, risk, false, wheresql); //超标统计数据 int[] Month = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; //先设定月份 int dtRow = 0; //第几行数据 int dtCbRow = 0; for (int i = 0; i < Month.Length; i++) { yValues.Add(Month[i].ToString()); //验证是否有这一年数据 if (dtRow < dt.Rows.Count) { int mon = Convert.ToInt32(dt.Rows[dtRow][0]); if (mon == Month[i]) //如果有这个年份直接添加 { int Sum = Convert.ToInt32(dt.Rows[dtRow][1]); num.Add(Sum); if (dtCbRow < dtCb.Rows.Count) { int monCb = Convert.ToInt32(dtCb.Rows[dtCbRow][0]); if (monCb == Month[i]) { int Cb = Convert.ToInt32(dtCb.Rows[dtCbRow][1]); CBnum.Add(Cb); double c = Convert.ToDouble(string.Format("{0:0.00}", (Convert.ToDouble(Cb) / Sum) * 100)); Cblist.Add(c); dtCbRow++; } else { CBnum.Add(0); Cblist.Add(0); } } else { CBnum.Add(0); Cblist.Add(0); } dtRow++; } else { num.Add(0); CBnum.Add(0); Cblist.Add(0); } } else { num.Add(0); CBnum.Add(0); Cblist.Add(0); } } dic.Add(new { name = "超标数量", type = "column", yAxis = 1, data = CBnum }); dic.Add(new { name = "监测数量", type = "column", yAxis = 1, data = num }); dic.Add(new { name = "超标率%", type = "spline", yAxis = 0, data = Cblist });//, tooltip = "{valueSuffix: ' %'}" return(Newtonsoft.Json.JsonConvert.SerializeObject(new { x = dic, y = yValues })); }
public ActionResult GetHazardSick(string year, string risk) { string wheresql = ""; ERCHTMS.Code.Operator user = ERCHTMS.Code.OperatorProvider.Provider.Current(); if (user.IsSystem) { wheresql = ""; } else { string where = new ERCHTMS.Busines.AuthorizeManage.AuthorizeBLL().GetModuleDataAuthority(ERCHTMS.Code.OperatorProvider.Provider.Current(), HttpContext.Request.Cookies["currentmoduleId"].Value); wheresql += " and " + where; } HazarddetectionBLL habll = new HazarddetectionBLL(); int years = Convert.ToInt32(year); DataTable dt = habll.GetStatisticsHazardTable(years, risk, true, wheresql); //全部统计数据 DataTable dtCb = habll.GetStatisticsHazardTable(years, risk, false, wheresql); //超标统计数据 List <OccStatisticsEntity> stlist = new List <OccStatisticsEntity>(); int[] Month = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };//先设定月份 int Sum = 0; int CbSum = 0; int dtRow = 0;//第几行数据 int dtCbRow = 0; for (int i = 0; i < Month.Length; i++) { //验证是否有这一年数据 if (dtRow < dt.Rows.Count) { int mon = Convert.ToInt32(dt.Rows[dtRow][0]); if (mon == Month[i]) //如果有这个年份直接添加 { //先获取DataTable中数据 OccStatisticsEntity st = new OccStatisticsEntity(); st.Sicktype = Convert.ToInt32(dt.Rows[dtRow][0]).ToString(); st.SickUserNum = Convert.ToInt32(dt.Rows[dtRow][1]); if (dtCbRow < dtCb.Rows.Count) { int monCb = Convert.ToInt32(dtCb.Rows[dtCbRow][0]); if (monCb == Month[i]) { st.SickValue = dtCb.Rows[dtCbRow][1].ToString(); CbSum += Convert.ToInt32(dtCb.Rows[dtCbRow][1]); dtCbRow++; } else { st.SickValue = "0"; } } else { st.SickValue = "0"; } Sum += Convert.ToInt32(dt.Rows[dtRow][1]); stlist.Add(st); dtRow++; } else { OccStatisticsEntity st = new OccStatisticsEntity(); st.Sicktype = Month[i].ToString(); st.SickUserNum = 0; st.SickValue = "0"; stlist.Add(st); } } else { OccStatisticsEntity st = new OccStatisticsEntity(); st.Sicktype = Month[i].ToString(); st.SickUserNum = 0; st.SickValue = "0"; stlist.Add(st); } } OccStatisticsEntity Hj = new OccStatisticsEntity(); Hj.Sicktype = "合计"; Hj.SickUserNum = Sum; Hj.SickValue = CbSum.ToString(); stlist.Add(Hj); //遍历修改其比例和合计 for (int i = 0; i < stlist.Count; i++) { if (stlist[i].SickValue != "0") { stlist[i].Proportion = string.Format("{0:0.00%}", Convert.ToDouble(stlist[i].SickValue) / Convert.ToDouble(stlist[i].SickUserNum)); } else { stlist[i].Proportion = "0.00%"; } } return(ToJsonResult(stlist)); }