/// <summary> /// 获取数据库中分公司 /// </summary> /// <returns></returns> public DataSet Get_Company_Info(out string errMsg) { errMsg = ""; DataSet DS = new DataSet(); string sql = "select T_COMPANYID,T_COMPANYDESC from T_BASE_COMPANY"; DS = dl.RunDataSet(sql, out errMsg); return(DS); }
//临时函数,读取DB2中表的数据,作为数据源给前台空间用,如 DropdownList DataSet PopDatasource() { string strSql = "select PARAID from " + tableName; return(dl.RunDataSet(strSql, out errMsg)); //string strConn = "Provider=IBMDADB2;Data Source=SACSIS;UID=Administrator;PWD=1qazXSW@;"; // string strSql = "select PARAID from STATPARA"; //using (OleDbConnection conn = new OleDbConnection(strConn)) //{ // OleDbCommand cmd = new OleDbCommand(strSql, conn); // try // { // conn.Open(); // OleDbDataAdapter adp = new OleDbDataAdapter(cmd); // DataSet ds = new DataSet(); // adp.Fill(ds); // return ds; // } // catch (Exception) // { // return null; // } //} }
/// <summary> /// 值报 /// </summary> /// <param name="repName"></param> /// <param name="unit"></param> /// <returns></returns> public ArrayList GetChartData(string Trendid, string sdate, string edate) { double drvA = 0; int ret = 0; string pName = null; ArrayList list = new ArrayList(); count = pm.GetCountByChart(Trendid); //countKey = pm.GetCountkey(repName, 1); DateTime dtNow = DateTime.Now; string[] de = null; //describe 趋势参数描述 string[] un = null; //单位 string[] dv = null; //值 string[] ma = new string[7]; //mark xy轴刻度 LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 值报开始......."); LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " count Value=" + count); try { de = new string[count]; un = new string[count]; dv = new string[count]; //判断是否多y轴,判断是否自动y轴刻度,如果是则取出y轴刻度 sql = "select T_MULITYAXIS, T_YMAX, T_YMIN, T_YAUTO from administrator.T_INFO_CHART_USERTEMPLATE where T_CHARTID='" + Trendid + "'"; DataTable dtInfo = null; //if (rlDBType == "SQL") // dtInfo = DBsql.RunDataTable(sql, out errMsg); //else // dtInfo = DBdb2.RunDataTable(sql, out errMsg); dtInfo = dl.RunDataTable(sql, out errMsg); if (dtInfo != null && dtInfo.Rows.Count > 0) { ma[0] = dtInfo.Rows[0]["T_MULITYAXIS"].ToString(); ma[1] = dtInfo.Rows[0]["T_YAUTO"].ToString(); ma[2] = dtInfo.Rows[0]["T_YMAX"].ToString(); ma[3] = dtInfo.Rows[0]["T_YMIN"].ToString(); } else { LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 读取[xy轴刻度]信息失败......"); } //ID_KEY, CHARTID, PARAID, PARADESC, PARATYPE, SQL, REALTIME, PERIOD, SHIFT, YMAX, YMIN, YAUTO, UNIT sql = "select count(*) from administrator.T_INFO_CHART_CHARTPARA where T_CHARTID = '" + Trendid + "' "; DataTable dtLevBZ = null; int a = 0; //if (rlDBType == "SQL") //{ // dtLevBZ = DBsql.RunDataTable(sql, out errMsg); //} //else //{ // dtLevBZ = DBdb2.RunDataTable(sql, out errMsg); //} dtLevBZ = dl.RunDataTable(sql, out errMsg); if (dtLevBZ != null && Convert.ToInt32(dtLevBZ.Rows[0][0].ToString()) > 0) { #region SQL sql = "select * from administrator.T_INFO_CHART_CHARTPARA where T_CHARTID = '" + Trendid + "' and T_PARATYPE='SQL' "; DataTable dtSQL = null; DataSet dssql = null; //if (rlDBType == "SQL") //{ // dtSQL = DBsql.RunDataTable(sql, out errMsg); //} //else //{ // dtSQL = DBdb2.RunDataTable(sql, out errMsg); //} dtSQL = dl.RunDataTable(sql, out errMsg); if (dtSQL != null && dtSQL.Rows.Count > 0) { for (int i = 0; i < dtSQL.Rows.Count; i++) { de[a] = dtSQL.Rows[i]["T_PARADESC"].ToString(); un[a] = dtSQL.Rows[i]["T_UNIT"].ToString(); ma[4] += dtSQL.Rows[i]["T_YAUTO"].ToString() + ","; ma[5] += dtSQL.Rows[i]["T_YMAX"].ToString() + ","; ma[6] += dtSQL.Rows[i]["T_YMIN"].ToString() + ","; sql = dtSQL.Rows[i]["T_SQL"].ToString(); if (sql.Contains("&bt&") && sql.Contains("&et&")) { sql = sql.Replace("&bt&", DateTime.Parse(sdate).AddSeconds(Convert.ToDouble(dtSQL.Rows[i]["T_SHIFT"].ToString())).ToString()); sql = sql.Replace("&et&", DateTime.Parse(edate).AddSeconds(Convert.ToDouble(dtSQL.Rows[i]["T_SHIFT"].ToString())).ToString()); } //if (rlDBType == "SQL") //{ // dssql = DBsql.RunDataSet(sql, out errMsg); //} //else //{ // dssql = DBdb2.RunDataSet(sql, out errMsg); //} dssql = dl.RunDataSet(sql, out errMsg); for (int j = 0; j < dssql.Tables[0].Rows.Count; j++) { dv[a] += dssql.Tables[0].Rows[j][0].ToString() + "+" + dssql.Tables[0].Rows[j][1].ToString(); if (j != dssql.Tables[0].Rows.Count - 1) { dv[a] += ","; } else { dv[a] += ";"; } } a++; } } #endregion #region 实时数据库 sql = "select * from administrator.T_INFO_CHART_CHARTPARA where T_CHARTID = '" + Trendid + "' and T_PARATYPE='RT' "; DataTable dtAvg = null; DateTime dtsql = DateTime.Now; //if (rlDBType == "SQL") //{ // dtAvg = DBsql.RunDataTable(sql, out errMsg); //} //else //{ // dtAvg = DBdb2.RunDataTable(sql, out errMsg); //} dtAvg = dl.RunDataTable(sql, out errMsg); if (dtAvg != null && dtAvg.Rows.Count > 0) { for (int i = 0; i < dtAvg.Rows.Count; i++) { de[a] = dtAvg.Rows[i]["T_PARADESC"].ToString(); un[a] = dtAvg.Rows[i]["T_UNIT"].ToString(); pName = dtAvg.Rows[i]["T_REALTIME"].ToString(); DateTime date = DateTime.Parse(sdate); while (date < DateTime.Parse(edate)) { if (rtDBType == "EDNA") { //ek.GetHisValueByTime(pName, sdate, ref ret, ref drvA); } else { // pk.GetHisValue(pName, sdate, ref drvA); } dv[a] += sdate + "+" + drvA.ToString() + ","; date = date.AddSeconds(Convert.ToDouble(dtAvg.Rows[i]["T_SHIFT"].ToString())); } a++; } } #endregion } } catch (Exception ce) { LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 程序异常: " + ce.Message); } list.Add(de); list.Add(un); list.Add(dv); list.Add(ma); return(list); }
public IList <Hashtable> Get_Required_data(string unit_id, string[] para_id, string[] per, string hanshu, string stime, string etime, out string[] hanshu_gongshi, out string errMsg) { errMsg = ""; hanshu_gongshi = new string[hanshu.Split(',').Length]; ArrayList list = new ArrayList(); DataSet DS = new DataSet(); IList <Hashtable> listdata = new List <Hashtable>(); Hashtable ht = new Hashtable(); //循环曲线个数 for (int i = 0; i < per.Length; i++) { //获取每条曲线标准负荷 string sql = "SELECT T_INFO_RL,T_POWERTAG FROM ADMINISTRATOR.T_BASE_POINT_UNIT where T_UNITID=(select distinct u.T_UNITID from T_BASE_CHARTPARAID b inner join ADMINISTRATOR.T_BASE_UNIT u on b.T_LEVEL1=u.T_UNITDESC where b.T_LEVEL1='" + unit_id + "')"; DS = dl.RunDataSet(sql, out errMsg); if (DS != null) { ht = new Hashtable(); ArrayList ld = new ArrayList(); ArrayList ldd = new ArrayList(); ArrayList lt = new ArrayList(); ArrayList ltt = new ArrayList(); double min_data = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString()) * Convert.ToDouble(per[i].Split('|')[0]) / 100; double max_data = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString()) * Convert.ToDouble(per[i].Split('|')[1]) / 100; int seconds = Convert.ToInt32((Convert.ToDateTime(etime) - Convert.ToDateTime(stime)).TotalSeconds) / 300; DateTime dtt = Convert.ToDateTime(stime); int count = 0; ArrayList _listTime = new ArrayList(); while (dtt < Convert.ToDateTime(etime)) { double val = new double(); Plink.OpenPi(); pk.GetHisValue(DS.Tables[0].Rows[0][1].ToString(), dtt.ToString(), ref val); if (val >= min_data && val <= max_data) { count++; _listTime.Add(dtt); } dtt = dtt.AddSeconds(seconds); } if (_listTime.Count > 0) { double[] x = new double[count]; double[] y = new double[count]; for (int k = 0; k < _listTime.Count; k++) { ld = new ArrayList(); double val = new double(); Plink.OpenPi(); pk.GetHisValue(para_id[0], _listTime[k].ToString(), ref val); if (k == 0) { min_data = val; max_data = val; } else { if (val > max_data) { max_data = val; } if (val < min_data) { min_data = val; } } x[k] = val; ld.Add(val); Plink.OpenPi(); pk.GetHisValue(para_id[1], _listTime[k].ToString(), ref val); y[k] = val; ld.Add(val); lt.Add(ld); } if (hanshu.Split(',')[0].Trim() == "多项式") { string gongshi = ""; double[] z = new double[Convert.ToInt32(hanshu.Split(',')[1]) + 1]; funPolynomial(x, y, Convert.ToInt32(hanshu.Split(',')[1]), out gongshi, out z); hanshu_gongshi[i] = gongshi; double num = (max_data - min_data) / 20; for (double m = min_data; m < max_data; m = m + num) { ldd = new ArrayList(); ldd.Add(m); double y_data = 0; for (int j = z.Length - 1; j >= 0; j--) { y_data += z[j] * (Math.Pow(m, j)); } ldd.Add(y_data); ltt.Add(ldd); } } else if (hanshu.Split(',')[0].Trim() == "线性") { string gongshi = "", a = "", b = ""; funXianxing(x, y, out gongshi, out a, out b); hanshu_gongshi[i] = gongshi; double num = (max_data - min_data) / 20; for (double m = min_data; m < max_data; m = m + num) { ldd = new ArrayList(); ldd.Add(m); ldd.Add(Convert.ToDouble(a) * m + Convert.ToDouble(b)); ltt.Add(ldd); } } else if (hanshu.Split(',')[0].Trim() == "指数") { //y=a*exp(b*x) string gongshi = "", a = "", b = ""; funExponent(x, y, out gongshi, out a, out b); hanshu_gongshi[i] = gongshi; double num = (max_data - min_data) / 20; for (double m = min_data; m < max_data; m = m + num) { ldd = new ArrayList(); ldd.Add(m); ldd.Add(Convert.ToDouble(a) * (Math.Exp(Convert.ToDouble(b) * m))); ltt.Add(ldd); } } else if (hanshu.Split(',')[0].Trim() == "对数") { //y=a*ln(x)+b string gongshi = "", a = "", b = ""; funLogarithm(x, y, out gongshi, out a, out b); hanshu_gongshi[i] = gongshi; double num = (max_data - min_data) / 20; for (double m = min_data; m < max_data; m = m + num) { ldd = new ArrayList(); ldd.Add(m); ldd.Add(Convert.ToDouble(a) * Math.Log(m) + Convert.ToDouble(b)); ltt.Add(ldd); } } else if (hanshu.Split(',')[0].Trim() == "幂") { //y=a*(x^b) string gongshi = "", a = "", b = ""; funPower(x, y, out gongshi, out a, out b); hanshu_gongshi[i] = gongshi; double num = (max_data - min_data) / 20; for (double m = min_data; m < max_data; m = m + num) { ldd = new ArrayList(); ldd.Add(m); ldd.Add(Convert.ToDouble(a) * (Math.Pow(m, Convert.ToDouble(b)))); ltt.Add(ldd); } } ht.Add("data", lt); ht.Add("type", "scatter"); ht.Add("name", "散点图"); listdata.Add(ht); ht = new Hashtable(); ht.Add("data", ltt); ht.Add("type", "line"); ht.Add("name", "拟合公式曲线图"); listdata.Add(ht); } } } //for (int i = 0; i < per.Length; i++) //{ // string sql_Required = "select T_PARAID,T_OUTTABLE from T_BASE_CALCPARA where T_UNITID ='" + unit_id + "' and (T_PARAID ='Pel' or T_PARAID='" + para_id[0] + "' or T_PARAID ='" + para_id[1] + "')"; // //string sql = "select T_TYPE from T_BASE_CALCPARA where T_UNITID =" + unit_id + "' and T_PARAID='" + para_id+","; // DS = dl.RunDataSet(sql_Required, out errMsg); // if ((DS.Tables[0].Rows.Count > 0) && (DS.Tables[0].Rows[0]["T_OUTTABLE"].ToString() != "") && (DS.Tables[0].Rows[1]["T_OUTTABLE"].ToString() != "") && (DS.Tables[0].Rows[2]["T_OUTTABLE"].ToString() != "")) // { // ht = new Hashtable(); // ArrayList ld = new ArrayList(); // ArrayList ldd = new ArrayList(); // ArrayList lt = new ArrayList(); // ArrayList ltt = new ArrayList(); // string str1 = "", str2 = "", str3 = ""; // for (int j = 0; j < DS.Tables[0].Rows.Count; j++) // { // if (DS.Tables[0].Rows[j]["T_PARAID"].ToString() == "Pel") // { // str1 = "select ss.D_VALUE as " + para_id[0] + ",sss.D_VALUE as " + para_id[1] + " from (select s.D_VALUE,s. T_DATETIME from (select D_VALUE,T_DATETIME from " + DS.Tables[0].Rows[j]["T_OUTTABLE"].ToString() + ", " + // "(select T_UNITID,\"D_CAPABILITY\" from T_BASE_UNIT where T_UNITID ='" + unit_id + "') as a where a.T_UNITID = T_INFO_CALCDATA.T_UNITID and " + // "T_INFO_CALCDATA.T_PARAID = 'Pel' and T_INFO_CALCDATA.D_VALUE between a.\"D_CAPABILITY\"*" + Convert.ToDouble(per[i].Split('|')[0]) / 100 + // " and a.\"D_CAPABILITY\"*" + Convert.ToDouble(per[i].Split('|')[1]) / 100 + " ) as s where s.T_DATETIME between '" + stime + "' and '" + etime + // "' group by s.D_VALUE,s. T_DATETIME order by s.T_DATETIME asc) as q, "; // } // else if (DS.Tables[0].Rows[j]["T_PARAID"].ToString() == para_id[0]) // { // str2 = "(select D_VALUE,T_DATETIME from " + DS.Tables[0].Rows[j]["T_OUTTABLE"].ToString() + " where T_UNITID ='" + unit_id + "' and T_PARAID='" + para_id[0] + "' ) as ss,"; // } // else if (DS.Tables[0].Rows[j]["T_PARAID"].ToString() == para_id[1]) // { // str3 = "(select D_VALUE,T_DATETIME from " + DS.Tables[0].Rows[j]["T_OUTTABLE"].ToString() + " where T_UNITID ='" + unit_id + "' and T_PARAID='" + para_id[1] + "' ) as sss where q.T_DATETIME = ss.T_DATETIME and q.T_DATETIME =sss.T_DATETIME "; // } // } // string append_sql = str1 + str2 + str3; // DS = dl.RunDataSet(append_sql, out errMsg); // if (DS.Tables[0].Rows.Count > 0) // { // double[] x = new double[DS.Tables[0].Rows.Count]; // double[] y = new double[DS.Tables[0].Rows.Count]; // double min_data = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString()); // double max_data = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString()); // for (int j = 0; j < DS.Tables[0].Rows.Count; j++) // { // ld = new ArrayList(); // ld.Add(Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString())); // if (min_data > Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString())) // { // min_data = Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString()); // } // if (max_data < Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString())) // { // max_data = Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString()); // } // x[j] = Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString()); // ld.Add(Convert.ToDouble(DS.Tables[0].Rows[j][1].ToString())); // y[j] = Convert.ToDouble(DS.Tables[0].Rows[j][1].ToString()); // lt.Add(ld); // } // if (hanshu.Split(',')[0].Trim() == "多项式") // { // string gongshi = ""; // double[] z = new double[Convert.ToInt32(hanshu.Split(',')[1]) + 1]; // funPolynomial(x, y, Convert.ToInt32(hanshu.Split(',')[1]), out gongshi, out z); // hanshu_gongshi[i] = gongshi; // double num = (max_data - min_data) / 20; // for (double m = min_data; m < max_data; m = m + num) // { // ldd = new ArrayList(); // ldd.Add(m); // double y_data = 0; // for (int j = z.Length - 1; j >= 0; j--) // { // y_data += z[j] * (Math.Pow(m, j)); // } // ldd.Add(y_data); // ltt.Add(ldd); // } // } // else if (hanshu.Split(',')[0].Trim() == "线性") // { // string gongshi = "", a = "", b = ""; // funXianxing(x, y, out gongshi, out a, out b); // hanshu_gongshi[i] = gongshi; // double num = (max_data - min_data) / 20; // for (double m = min_data; m < max_data; m = m + num) // { // ldd = new ArrayList(); // ldd.Add(m); // ldd.Add(Convert.ToDouble(a) * m + Convert.ToDouble(b)); // ltt.Add(ldd); // } // } // else if (hanshu.Split(',')[0].Trim() == "指数") // { // //y=a*exp(b*x) // string gongshi = "", a = "", b = ""; // funExponent(x, y, out gongshi, out a, out b); // hanshu_gongshi[i] = gongshi; // double num = (max_data - min_data) / 20; // for (double m = min_data; m < max_data; m = m + num) // { // ldd = new ArrayList(); // ldd.Add(m); // ldd.Add(Convert.ToDouble(a) * (Math.Exp(Convert.ToDouble(b) * m))); // ltt.Add(ldd); // } // } // else if (hanshu.Split(',')[0].Trim() == "对数") // { // //y=a*ln(x)+b // string gongshi = "", a = "", b = ""; // funLogarithm(x, y, out gongshi, out a, out b); // hanshu_gongshi[i] = gongshi; // double num = (max_data - min_data) / 20; // for (double m = min_data; m < max_data; m = m + num) // { // ldd = new ArrayList(); // ldd.Add(m); // ldd.Add(Convert.ToDouble(a) * Math.Log(m) + Convert.ToDouble(b)); // ltt.Add(ldd); // } // } // else if (hanshu.Split(',')[0].Trim() == "幂") // { // //y=a*(x^b) // string gongshi = "", a = "", b = ""; // funPower(x, y, out gongshi, out a, out b); // hanshu_gongshi[i] = gongshi; // double num = (max_data - min_data) / 20; // for (double m = min_data; m < max_data; m = m + num) // { // ldd = new ArrayList(); // ldd.Add(m); // ldd.Add(Convert.ToDouble(a) * (Math.Pow(m, Convert.ToDouble(b)))); // ltt.Add(ldd); // } // } // ht.Add("data", lt); // ht.Add("type", "scatter"); // ht.Add("name", "散点图"); // listdata.Add(ht); // ht = new Hashtable(); // ht.Add("data", ltt); // ht.Add("type", "line"); // ht.Add("name", "拟合公式曲线图"); // listdata.Add(ht); // } // } //} return(listdata); }