/// <summary> ///获取单个记录 /// </summary> /// <param name="sqlstr"></param> /// <param name="con"></param> /// <param name="error"></param> /// <returns></returns> public static string ExecuteScalar(string sqlstr) { string temp = ""; String ConnStr = GetSqlConnection(); using (SqlConnection conn = new SqlConnection(ConnStr)) { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = sqlstr; //int i = 0; try { conn.Open(); temp = cmd.ExecuteScalar().ToString(); } catch (Exception e) { WriteLog.WriteLogs("获取单值时报错:" + e.ToString()); } finally { conn.Close(); conn.Dispose(); } return(temp); } }
/// <summary> /// 执行SQL语句并返回数据表 /// </summary> /// <param name="Sqlstr">SQL语句</param> /// <returns></returns> public static DataTable ExecuteDt(String Sqlstr) { String ConnStr = GetSqlConnection(); using (SqlConnection conn = new SqlConnection(ConnStr)) { SqlDataAdapter da = new SqlDataAdapter(Sqlstr, conn); DataTable dt = new DataTable(); try { conn.Open(); da.Fill(dt); } catch (Exception E) { WriteLog.WriteLogs("获取数据表时报错: " + E.ToString()); } finally { conn.Close(); conn.Dispose(); } return(dt); } }
/// <summary> /// 执行不带参数的SQL语句 /// </summary> /// <param name="Sqlstr"></param> /// <returns></returns> public static int ExecuteSql(String Sqlstr) { int i = 0; try { String ConnStr = GetSqlConnection(); using (SqlConnection conn = new SqlConnection(ConnStr)) { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = Sqlstr; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); conn.Dispose(); i = 1; } } catch (Exception e) { WriteLog.WriteLogs("执行sql语句出错" + e.Message); WriteLog.WriteLogs("InnerException:" + e.InnerException.Message); WriteLog.WriteLogs("ErrorSource:" + e.Source.ToString()); WriteLog.WriteLogs("ErrorSource:" + e.TargetSite.Attributes.ToString()); } return(i); }
/// <param name="dblhnhw">热网回水温度</param> /// <param name="dblnqqout">凝汽器出水温度</param> /// <param name="dblnqqP">凝汽器压力</param> /// <returns>第二条棒图子线数值</returns> public static double calC2() { double douRet = 0; try { #region 供热计算 计算过程 //大气压力 double dqy = DQY.PreChangeValue(4); if (Convert.ToDouble(dqy) == ConstYXYH.ReplaceValue) { CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F3"] = ConstYXYH.ReplaceValue; return(ConstYXYH.ReplaceValue); } //标注:供热凝汽器进水温度(热网回水温度) double dblhnhw = DQY.PreChangeValue(150);; //热网回水温度 if (Convert.ToDouble(dblhnhw) == ConstYXYH.ReplaceValue) { CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F3"] = ConstYXYH.ReplaceValue; return(ConstYXYH.ReplaceValue); } double dblnqqout = DQY.PreChangeValue(151);; //凝汽器出水温度 if (Convert.ToDouble(dblnqqout) == ConstYXYH.ReplaceValue) { CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F3"] = ConstYXYH.ReplaceValue; return(ConstYXYH.ReplaceValue); } double temp_dblnqqP = DQY.PreChangeValue(126);; //凝汽器压力 if (Convert.ToDouble(dblhnhw) == ConstYXYH.ReplaceValue) { CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F3"] = ConstYXYH.ReplaceValue; return(ConstYXYH.ReplaceValue); } double dblnqqP = dqy + Math.Abs(temp_dblnqqP);//凝汽器(绝对)压力 douRet = BarLength(dblnqqP); //保存数据 CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F3"] = douRet.ToString(); #endregion } catch (Exception e) { WriteLog.WriteLogs("按供热计算出错" + e.Message); WriteLog.WriteLogs("InnerException:" + e.InnerException.Message); WriteLog.WriteLogs("ErrorSource:" + e.Source.ToString()); WriteLog.WriteLogs("ErrorSource:" + e.TargetSite.Attributes.ToString()); } return(douRet); }
public static string getTableNameByDate(DateTime dtDay) { string sTable = "tagdata"; string sSql = "select top 1 convert(char(10),convert(datetime,'" + dtDay + "'),112) from tags"; try { string sDate = SQLHelper.ExecuteScalar(sSql); sTable += sDate; } catch (Exception E) { WriteLog.WriteLogs("根据时间获取表名时报错 " + E.ToString()); } return(sTable); }
//获取昨日数据表名 public static string getYesTableName() { string sTable = "tagdata"; string sSql = "select top 1 convert(char(10),DATEADD(day,-1,getdate()),112) from tags"; try { string sDate = SQLHelper.ExecuteScalar(sSql); sTable += sDate; } catch (Exception E) { WriteLog.WriteLogs("获取昨日表名时报错 " + E.ToString()); } return(sTable); }
/// <summary> /// /// </summary> /// <param name="MidInP">低压缸进汽压力</param> /// <param name="LowOutP">低压缸排汽压力</param> /// <returns>返回值为kPa</returns> public static double calC1() { double decRet = 0; try { #region 计算过程 //低压缸进汽压力 表压 double dou_jqyl = Convert.ToDouble(CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F111"].ToString()); double dqy = Convert.ToDouble(CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F4"].ToString()); if (Convert.ToDouble(dou_jqyl) == ConstYXYH.ReplaceValue) { DataRow[] dtrarr = CJPrj.Cls.CalTree.dtTagsSet.Select("ExcelCell='F111'"); if (string.IsNullOrEmpty(dtrarr[0]["setvalue"].ToString())) { CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F2"] = ConstYXYH.ReplaceValue; return(ConstYXYH.ReplaceValue); } dou_jqyl = Convert.ToDouble(dtrarr[0]["setvalue"]); } if (Convert.ToDouble(dqy) == ConstYXYH.ReplaceValue) { DataRow[] dtrarr = CJPrj.Cls.CalTree.dtTagsSet.Select("ExcelCell='F4'"); if (string.IsNullOrEmpty(dtrarr[0]["setvalue"].ToString())) { CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F2"] = ConstYXYH.ReplaceValue; return(ConstYXYH.ReplaceValue); } dqy = Convert.ToDouble(dtrarr[0]["setvalue"]); } dou_jqyl = dou_jqyl + dqy; //低压缸进汽绝对压力 double dou_pqyl = Math.Round(Convert.ToDouble(CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F126"].ToString()), 5); //低压缸排汽压力f126*100 59 //string tempStr1 = CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F126"].ToString(); //string tempStr2 = CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F4"].ToString(); if (Convert.ToDouble(dou_pqyl) == ConstYXYH.ReplaceValue) { DataRow[] dtrarr = CJPrj.Cls.CalTree.dtTagsSet.Select("ExcelCell='F126'"); if (string.IsNullOrEmpty(dtrarr[0]["setvalue"].ToString())) { return(7); } dou_pqyl = Convert.ToDouble(dtrarr[0]["setvalue"]); } double K = 0; if (dou_jqyl < 0.1361) //低压缸进气压力低于0.17Mpa时 { K = 20; //低压缸排汽压力限制值为20KP decRet = 100 + (dou_pqyl - K) / 0.2; } else if (dou_jqyl > 0.43) //低压缸进气压力高于0.43Mpa时 { K = 58; //低压缸排汽压力限制值为58KP decRet = 100 + (dou_pqyl - K) / 0.2; } else//低压缸进气压力在0.17和0.43Mpa之间时 { //限制值为:(146.154*低压缸进汽压力的绝对值-4.846) K = dou_jqyl * 146.154 - 4.846; decRet = 100 + (dou_pqyl - K) / 0.2; } //保存数据 CJPrj.Cls.CalTree.CalDataTable.Rows[0]["F2"] = decRet.ToString(); #endregion } catch (Exception e) { WriteLog.WriteLogs("按压力计算出错:" + e.Message); WriteLog.WriteLogs("InnerException:" + e.InnerException.Message); WriteLog.WriteLogs("ErrorSource:" + e.Source.ToString()); WriteLog.WriteLogs("ErrorSource:" + e.TargetSite.Attributes.ToString()); } finally { } return(decRet); }