/// <summary> /// 循环遍历ParaId,获取集团的ParaId的平均值(得到集团的ParaId的平均值) /// </summary> /// <param name="AllParaId">所有ParaId</param> /// <param name="errMsg"></param> /// <returns></returns> public List<ReportInfo> GetCompanyInfos(string beginTime, string endTime, out string errMsg) { this.init(); errMsg = ""; //counts = 0; List<ReportInfo> cInfoList = new List<ReportInfo>(); //获取outtable表 List<ParaTableInfo> infoList = GetCompanyInfo(out errMsg); //获取所有ParaId //string ParaId = GetParaId(out counts,out errMsg); if (infoList.Count > 0) { for (int i = 0; i < infoList.Count; i++) { //foreach (var info in infoList) //{ if (!string.IsNullOrEmpty(infoList[i].OutTableName)) { ReportInfo pa = new ReportInfo(); string sql = "select avg(D_VALUE) as value from " + infoList[i].OutTableName + " where T_PARAID='" + infoList[i].ParaId + "' "; if (!String.IsNullOrEmpty(beginTime) && !String.IsNullOrEmpty(endTime)) { sql += " and T_DATETIME between '" + beginTime + "' and '" + endTime + "'"; } else { if (!String.IsNullOrEmpty(beginTime)) { sql += " and T_DATETIME>'" + beginTime + "'"; } if (!String.IsNullOrEmpty(endTime)) { sql += " and T_DATETIME<'" + endTime + "'"; } } //sql += " group by T_PARAID"; DataTable dt = new DataTable(); if (rlDBType == "SQL") { } else { dt = DBdb2.RunDataTable(sql, out errMsg); } if (dt != null && dt.Rows.Count > 0) { pa.ParaDesc = infoList[i].ParaDesc; pa.ParaValue = string.IsNullOrEmpty(dt.Rows[0]["value"].ToString()) ? 0 : Convert.ToDouble(dt.Rows[0]["value"].ToString()); cInfoList.Add(pa); } } //} //删除已经计算过的参数(为什么:因为获取的outtable各个机组的都有 有重复的) //List<ParaTableInfo> tmp = infoList.Where(infos => infos.ParaId == infoList[i].ParaId).ToList(); //foreach (var tmpInfo in tmp) //{ // infoList.Remove(tmpInfo); //} } } return cInfoList; }
/// <summary> /// 循环遍历ParaId,获取机组的各个ParaId的平均值(得到集团的ParaId的平均值) /// </summary> /// <param name="AllParaId">所有ParaId</param> /// <param name="errMsg"></param> /// <returns></returns> public List<ReportInfo> GetUnitParaInfo(string beginTime, string endTime, out string errMsg) { this.init(); errMsg = ""; //counts = 0; List<ReportInfo> cInfoList = new List<ReportInfo>(); //获取outtable表 List<ParaTableInfo> infoList = GetInfo(out errMsg); //获取所有ParaId //string ParaId = GetParaId(out counts,out errMsg); if (infoList.Count > 0) { for (int i = 0; i < infoList.Count; i++) { //foreach (var info in infoList) //{ if (!string.IsNullOrEmpty(infoList[i].OutTableName)) { ReportInfo pa = new ReportInfo(); string sql = "select T_PARAID,T_UNITID, avg(D_VALUE) as value from " + infoList[i].OutTableName + " where T_PARAID='" + infoList[i].ParaId + "' and T_UNITID='"+infoList[i].UnitId+"' "; if (!String.IsNullOrEmpty(beginTime) && !String.IsNullOrEmpty(endTime)) { sql += " and T_DATETIME between '" + beginTime + "' and '" + endTime + "'"; } else { if (!String.IsNullOrEmpty(beginTime)) { sql += " and T_DATETIME>'" + beginTime + "'"; } if (!String.IsNullOrEmpty(endTime)) { sql += " and T_DATETIME<'" + endTime + "'"; } } sql += " group by T_UNITID,T_PARAID"; DataTable dt = new DataTable(); if (rlDBType == "SQL") { // sql = "select ID_KEY,班次名,起始时间,结束时间 from 班次时间表 order by ID_KEY"; //dt = DBsql.RunDataTable(sql, out errMsg); } else { dt = DBdb2.RunDataTable(sql, out errMsg); } if (dt != null && dt.Rows.Count > 0) { pa.UnitName = infoList[i].UnitName; pa.ParaDesc = infoList[i].ParaDesc; pa.ParaValue = string.IsNullOrEmpty(dt.Rows[0]["value"].ToString()) ? 0 : Convert.ToDouble(dt.Rows[0]["value"].ToString()); cInfoList.Add(pa); } } } } return cInfoList; }