private void QueryData() { string beginTime = Request["beginTime"] == null ? string.Empty : Request["beginTime"].ToString(); string endTime = string.Empty; string timeType = Request["timeType"] == null ? string.Empty : Request["timeType"].ToString(); string quarterType = Request["quarterType"] == null ? string.Empty : Request["quarterType"].ToString(); //根据选择的时间段,设置quarterType开始时间和结束时间 switch (timeType) { case "1"://月度平均值 DateTime dt1 = new DateTime(); dt1 = Convert.ToDateTime(beginTime.Substring(0, 7) + "-01"); beginTime = dh.GetFirstDayOfMonth(dt1).ToString().Replace("/", "-"); endTime = dh.GetLastDayOfMonth(dt1).ToString().Replace("/", "-"); break; case "2"://季度平均值 switch (quarterType) { case "0"://一季度 string ti = beginTime.Substring(0, 4) + "-01-01 00:00:00"; beginTime = ti; endTime = beginTime.Substring(0, 4) + "-03-31 23:59:59"; break; case "1"://二季度 string ti1 = beginTime.Substring(0, 4) + "-04-01 00:00:00"; beginTime = ti1; endTime = beginTime.Substring(0, 4) + "-06-30 23:59:59"; break; case "2"://三季度 string ti2 = beginTime.Substring(0, 4) + "-07-01 00:00:00"; beginTime = ti2; endTime = beginTime.Substring(0, 4) + "-09-30 23:59:59"; break; case "3"://四季度 string ti3 = beginTime.Substring(0, 4) + "-10-01 00:00:00"; beginTime = ti3; endTime = beginTime.Substring(0, 4) + "-12-31 23:59:59"; break; } break; case "3"://年度平均值 string tim = beginTime.Substring(0, 4); beginTime = tim + "-01-01 00:00:00"; endTime = tim + "-12-31 23:59:59"; break; } //先根据paraId,取出所有paraId的outtable,循环outtable,取平均值。 AllInfo allInfo = new AllInfo(); ArrayList list = new ArrayList(); IList<Hashtable> iList = new List<Hashtable>(); Hashtable ht = null; List<ConsumeInfo> infoList; infoList = bl.get(beginTime, endTime, out errMsg); //记录七月份数据,供分项比例用 List<ConsumeInfo> tmpList = new List<ConsumeInfo>(); List<ConsumeInfo> beforInfoList; infos tmpZhuTu = new infos(); double tmpCount = 0.00; string beforBeginTime = DateTime.Parse(beginTime).AddMonths(-1).ToString("yyyy-MM-dd HH:mm:ss"); string beforEndTime = DateTime.Parse(beforBeginTime).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss"); beforInfoList = bl.get(beforBeginTime, beforEndTime, out errMsg); for (int j = 0; j < 4; j++) { ht = new Hashtable(); //总耗差 double allCount = 0; //infoList = new List<ConsumeInfo>(); switch (j) { case 0: ht.Add("记录时间", DateTime.Parse(beginTime).Month + "月份耗差平均"); tmpList = infoList; allCount = infoList.Select(info => info.Count).Sum(); ht.Add("总耗差", Math.Round(allCount,4)); //平均值柱状图 ArrayList name = new ArrayList(); ArrayList value = new ArrayList(); foreach (ConsumeInfo tmp in infoList) { ht.Add(tmp.Name, Math.Round(tmp.Count, 3)); name.Add(tmp.Name); value.Add(Math.Round(tmp.Count, 3)); } tmpZhuTu.name = name; tmpZhuTu.value = value; tmpCount = allCount; //ht.Add("总耗差", allCount); iList.Add(ht); break; case 1: ht.Add("记录时间", DateTime.Parse(beginTime).Month +"月份分项比列"); ht.Add("总耗差", 100.00); if (tmpCount > 0) { foreach (ConsumeInfo tmp in tmpList) { ht.Add(tmp.Name, Math.Round((tmp.Count / tmpCount) * 100, 3)); } } else { foreach (ConsumeInfo tmp in tmpList) { ht.Add(tmp.Name, 0); } } iList.Add(ht); break; case 2: ht.Add("记录时间", DateTime.Parse(beforBeginTime).Month + "月份耗差平均"); allCount = beforInfoList.Select(info => info.Count).Sum(); ht.Add("总耗差", allCount); foreach (ConsumeInfo tmp in beforInfoList) { ht.Add(tmp.Name, Math.Round(tmp.Count, 3)); // allCount += tmp.Count; } //ht.Add("总耗差", allCount); iList.Add(ht); break; case 3: ht.Add("记录时间", DateTime.Parse(beginTime).Month + "月份环比" + DateTime.Parse(beforBeginTime).Month + "月份增长"); foreach (ConsumeInfo infos in tmpList) { ConsumeInfo c = beforInfoList.Where(t => t.Name == infos.Name).FirstOrDefault(); //SsHb.name.Add(c.Name); if (infos.Count > 0) { //SsHb.value.Add(Math.Round(((infos.Count - c.Count) / infos.Count) * 100, 2)); ht.Add(c.Name, Math.Round(((infos.Count - c.Count) / infos.Count) * 100, 2)); } else { ht.Add(c.Name,0); } } iList.Add(ht); break; } } string str = this.CreateDataGridColumnModel(iList); object obj = new { rows = iList, columns = str }; string result = JsonConvert.SerializeObject(obj); Response.Write(result); Response.End(); }
private void QueryData(string time, string timeType, string quarterType) { //先根据paraId,取出所有paraId的outtable,循环outtable,取平均值。 AllInfo allInfo = new AllInfo(); //info allInfo = new info(); ArrayList list = new ArrayList(); IList<Hashtable> iList = new List<Hashtable>(); //IList<ArrayList> iList = new List<ArrayList>(); Hashtable ht = null;//BLL.NoSortHashtable ht = null; //ArrayList ht = null; List<ConsumeInfo> infoList; //记录七月份数据,供分项比例用 List<ConsumeInfo> tmpList=new List<ConsumeInfo> (); // List<infos> zhutu=new List<infos> (); infos tmpZhuTu = new infos(); double tmpCount=0.00; for (int j = 0; j < 4; j++) { ht = new Hashtable(); //总耗差 double allCount = 0; infoList = new List<ConsumeInfo>(); switch (j) { case 0: ht.Add("记录时间", "七月份耗差平均"); infoList = bl.get(time, timeType, quarterType, out errMsg); tmpList = infoList; allCount=infoList.Select(info => info.Count).Sum(); ht.Add("总耗差", allCount); //平均值柱状图 ArrayList name=new ArrayList (); ArrayList value=new ArrayList (); foreach (ConsumeInfo tmp in infoList) { ht.Add(tmp.Name,Math.Round(tmp.Count,3)); name.Add(tmp.Name); value.Add(Math.Round(tmp.Count,3)); //allCount += tmp.Count; } tmpZhuTu.name=name; tmpZhuTu.value=value; tmpCount = allCount; //ht.Add("总耗差", allCount); iList.Add(ht); break; case 1: ht.Add("记录时间", "七月份分项比列"); ht.Add("总耗差", 100.00); foreach (ConsumeInfo tmp in tmpList) { ht.Add(tmp.Name, Math.Round((tmp.Count / tmpCount) * 100,3)); } iList.Add(ht); break; case 2: ht.Add("记录时间", "六月份耗差平均"); infoList = bl.get(time, timeType, quarterType, out errMsg); allCount=infoList.Select(info => info.Count).Sum(); ht.Add("总耗差", allCount); foreach (ConsumeInfo tmp in infoList) { ht.Add(tmp.Name, Math.Round(tmp.Count,3)); // allCount += tmp.Count; } //ht.Add("总耗差", allCount); iList.Add(ht); break; case 3: ht.Add("记录时间", "七月份环比六月份增长"); iList.Add(ht); break; //} //else //{ // ht.Add(i.ToString(), "test"); //} //iList.Add(ht); } } string str = this.CreateDataGridColumnModel(iList); object obj = new { rows = iList, columns = str }; //string result = JsonConvert.SerializeObject(obj); allInfo.table = str; allInfo.ZhuTu = tmpZhuTu; string content = allInfo.ToJsonItem(); Response.Write(content); Response.End(); }
private void QueryData() { string beginTime = Request["beginTime"] == null ? string.Empty : Request["beginTime"].ToString(); string endTime = string.Empty; string timeType = Request["timeType"] == null ? string.Empty : Request["timeType"].ToString(); string quarterType = Request["quarterType"] == null ? string.Empty : Request["quarterType"].ToString(); //根据选择的时间段,设置quarterType开始时间和结束时间 switch (timeType) { case "1": //月度平均值 DateTime dt1 = new DateTime(); dt1 = Convert.ToDateTime(beginTime.Substring(0, 7) + "-01"); beginTime = dh.GetFirstDayOfMonth(dt1).ToString().Replace("/", "-"); endTime = dh.GetLastDayOfMonth(dt1).ToString().Replace("/", "-"); break; case "2": //季度平均值 switch (quarterType) { case "0": //一季度 string ti = beginTime.Substring(0, 4) + "-01-01 00:00:00"; beginTime = ti; endTime = beginTime.Substring(0, 4) + "-03-31 23:59:59"; break; case "1": //二季度 string ti1 = beginTime.Substring(0, 4) + "-04-01 00:00:00"; beginTime = ti1; endTime = beginTime.Substring(0, 4) + "-06-30 23:59:59"; break; case "2": //三季度 string ti2 = beginTime.Substring(0, 4) + "-07-01 00:00:00"; beginTime = ti2; endTime = beginTime.Substring(0, 4) + "-09-30 23:59:59"; break; case "3": //四季度 string ti3 = beginTime.Substring(0, 4) + "-10-01 00:00:00"; beginTime = ti3; endTime = beginTime.Substring(0, 4) + "-12-31 23:59:59"; break; } break; case "3": //年度平均值 string tim = beginTime.Substring(0, 4); beginTime = tim + "-01-01 00:00:00"; endTime = tim + "-12-31 23:59:59"; break; } //先根据paraId,取出所有paraId的outtable,循环outtable,取平均值。 AllInfo allInfo = new AllInfo(); ArrayList list = new ArrayList(); IList <Hashtable> iList = new List <Hashtable>(); Hashtable ht = null; List <ConsumeInfo> infoList; infoList = bl.get(beginTime, endTime, out errMsg); //记录七月份数据,供分项比例用 List <ConsumeInfo> tmpList = new List <ConsumeInfo>(); List <ConsumeInfo> beforInfoList; infos tmpZhuTu = new infos(); double tmpCount = 0.00; string beforBeginTime = DateTime.Parse(beginTime).AddMonths(-1).ToString("yyyy-MM-dd HH:mm:ss"); string beforEndTime = DateTime.Parse(beforBeginTime).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss"); beforInfoList = bl.get(beforBeginTime, beforEndTime, out errMsg); for (int j = 0; j < 4; j++) { ht = new Hashtable(); //总耗差 double allCount = 0; //infoList = new List<ConsumeInfo>(); switch (j) { case 0: ht.Add("记录时间", DateTime.Parse(beginTime).Month + "月份耗差平均"); tmpList = infoList; allCount = infoList.Select(info => info.Count).Sum(); ht.Add("总耗差", Math.Round(allCount, 4)); //平均值柱状图 ArrayList name = new ArrayList(); ArrayList value = new ArrayList(); foreach (ConsumeInfo tmp in infoList) { ht.Add(tmp.Name, Math.Round(tmp.Count, 3)); name.Add(tmp.Name); value.Add(Math.Round(tmp.Count, 3)); } tmpZhuTu.name = name; tmpZhuTu.value = value; tmpCount = allCount; //ht.Add("总耗差", allCount); iList.Add(ht); break; case 1: ht.Add("记录时间", DateTime.Parse(beginTime).Month + "月份分项比列"); ht.Add("总耗差", 100.00); if (tmpCount > 0) { foreach (ConsumeInfo tmp in tmpList) { ht.Add(tmp.Name, Math.Round((tmp.Count / tmpCount) * 100, 3)); } } else { foreach (ConsumeInfo tmp in tmpList) { ht.Add(tmp.Name, 0); } } iList.Add(ht); break; case 2: ht.Add("记录时间", DateTime.Parse(beforBeginTime).Month + "月份耗差平均"); allCount = beforInfoList.Select(info => info.Count).Sum(); ht.Add("总耗差", allCount); foreach (ConsumeInfo tmp in beforInfoList) { ht.Add(tmp.Name, Math.Round(tmp.Count, 3)); // allCount += tmp.Count; } //ht.Add("总耗差", allCount); iList.Add(ht); break; case 3: ht.Add("记录时间", DateTime.Parse(beginTime).Month + "月份环比" + DateTime.Parse(beforBeginTime).Month + "月份增长"); foreach (ConsumeInfo infos in tmpList) { ConsumeInfo c = beforInfoList.Where(t => t.Name == infos.Name).FirstOrDefault(); //SsHb.name.Add(c.Name); if (infos.Count > 0) { //SsHb.value.Add(Math.Round(((infos.Count - c.Count) / infos.Count) * 100, 2)); ht.Add(c.Name, Math.Round(((infos.Count - c.Count) / infos.Count) * 100, 2)); } else { ht.Add(c.Name, 0); } } iList.Add(ht); break; } } string str = this.CreateDataGridColumnModel(iList); object obj = new { rows = iList, columns = str }; string result = JsonConvert.SerializeObject(obj); Response.Write(result); Response.End(); }