예제 #1
0
        /// <summary>
        /// 查找历史数据最小值
        /// </summary>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public static double MinOfHistory(string tagName)
        {
            try
            {
                string    filtString = "tagName=" + "'" + tagName + "'";
                DataRow[] drs        = HistoryDataTable.Select(filtString);
                //return decimal.Parse(dr[2].ToString());//返回查找到的数值
                double min = double.MaxValue;
                foreach (DataRow dr in drs)
                {
                    double d = double.Parse(dr[2].ToString());
                    if (d < min)
                    {
                        min = d;
                    }
                }
                return(min);
            }
            catch (Exception ex)
            {
                return(0);

                throw ex;                //抛出异常
            }
        }
예제 #2
0
        /// <summary>
        /// 读取历史数据
        /// </summary>
        /// <param name="tagName"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static decimal GetHistoryData(string tagName, string dateTime)
        {
            try
            {
                string  filtString = "time=" + "'" + dateTime + "'" + " and tagName=" + "'" + tagName + "'";
                DataRow dr         = HistoryDataTable.Select(filtString).First();
                return(decimal.Parse(dr[2].ToString()));//返回查找到的数值
            }
            catch (Exception ex)
            {
                return(0);

                throw ex;//抛出异常
            }
        }
예제 #3
0
        /// <summary>
        /// 历史数据第一个值
        /// </summary>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public static double firstOfHistory(string tagName)
        {
            double value = 0.0;

            try
            {
                string    filtString = "tagName=" + "'" + tagName + "'";
                DataRow[] drs        = HistoryDataTable.Select(filtString);
                value = double.Parse(drs.First()[2].ToString());
                return(value);
            }
            catch (Exception ex)
            {
                return(0);

                throw ex;                //抛出异常
            }
        }
예제 #4
0
        /// <summary>
        /// 历史数据求和
        /// </summary>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public static decimal GetHistoryDataSum(string tagName, int exceptFirst)
        {
            //exceptFirst 是否舍去8点的数据,这里并不具有通用型,后续需要钙胶囊
            try
            {
                string    filtString = "tagName=" + "'" + tagName + "'";
                DataRow[] drs        = HistoryDataTable.Select(filtString);
                int       firstHour  = DateTime.Parse(drs[0][0].ToString()).Hour;
                decimal   sum        = 0;
                if (exceptFirst == 0)
                {
                    for (int i = 0; i < drs.Length; i++)
                    {
                        sum += decimal.Parse(drs[i][2].ToString());
                    }
                }
                else
                {
                    if (firstHour == 8)
                    {
                        for (int i = 1; i < drs.Length; i++)
                        {
                            sum += decimal.Parse(drs[i][2].ToString());
                        }
                    }
                    else
                    {
                        for (int i = 0; i < drs.Length; i++)
                        {
                            sum += decimal.Parse(drs[i][2].ToString());
                        }
                    }
                }
                return(sum);
            }
            catch (Exception ex)
            {
                return(0);

                throw ex;                //抛出异常
            }
        }
예제 #5
0
        /// <summary>
        /// 计算历史数据平均值
        /// </summary>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public static double avgOfHistory(string tagName)
        {
            try
            {
                string    filtString = "tagName=" + "'" + tagName + "'";
                DataRow[] drs        = HistoryDataTable.Select(filtString);
                //return decimal.Parse(dr[2].ToString());//返回查找到的数值
                double avg = 0.0;
                double sum = 0.0;
                foreach (DataRow dr in drs)
                {
                    double d = double.Parse(dr[2].ToString());
                    sum += d;
                }
                avg = sum / drs.Length;
                return(avg);
            }
            catch (Exception ex)
            {
                return(0);

                throw ex;                //抛出异常
            }
        }