Ejemplo n.º 1
0
        /// <summary>
        /// 获取实时数据
        /// </summary>
        /// <param name="point">测点名称</param>
        /// <param name="sTime">开始时间</param>
        /// <param name="type">查询类型   年:1 月:2 日:3</param>
        /// <returns></returns>
        public IList <Hashtable> GetValList(string point, string sTime, string type)
        {
            Plink     pk = new Plink();
            DateTime  dt = new DateTime();
            Hashtable h  = new Hashtable();

            val = "";
            Plink.OpenPi();
            if (type == "1")//年比
            {
                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-01-01 23:59:59"));
                for (int i = 0; i < 365; i++)
                {
                    h = new Hashtable();
                    h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                    pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    h.Add("去年", drv);
                    pk.GetHisValue(point, dt.ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    h.Add("今年", drv);
                    dt = dt.AddDays(1);
                    list.Add(h);
                }
            }
            else if (type == "2")//月比
            {
                int month = Convert.ToDateTime(sTime).Month;
                int year  = Convert.ToDateTime(sTime).Year;

                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-MM-1 11:59:59"));

                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                {
                    for (int i = 0; i < 62; i++)
                    {
                        h = new Hashtable();
                        h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                        pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        h.Add("去年", drv);
                        pk.GetHisValue(point, dt.ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        h.Add("今年", drv);
                        dt = dt.AddHours(12);
                        list.Add(h);
                    }
                }
                else if (month == 4 || month == 6 || month == 9 || month == 11)
                {
                    for (int i = 0; i < 60; i++)
                    {
                        h = new Hashtable();
                        h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                        pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        h.Add("去年", drv);
                        pk.GetHisValue(point, dt.ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        h.Add("今年", drv);
                        dt = dt.AddHours(12);
                        list.Add(h);
                    }
                }
                else
                {
                    if (year % 4 == 0)
                    {
                        for (int i = 0; i < 58; i++)
                        {
                            h = new Hashtable();
                            h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                            pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            h.Add("去年", drv);
                            pk.GetHisValue(point, dt.ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            h.Add("今年", drv);
                            dt = dt.AddHours(12);
                            list.Add(h);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 55; i++)
                        {
                            h = new Hashtable();
                            h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                            pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            h.Add("去年", drv);
                            pk.GetHisValue(point, dt.ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            h.Add("今年", drv);
                            dt = dt.AddHours(12);
                            list.Add(h);
                        }
                    }
                }
            }
            else if (type == "3")//日比
            {
                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-MM-dd 0:14:59"));
                for (int i = 0; i < 96; i++)
                {
                    h = new Hashtable();
                    h.Add("时间", dt.ToString("HH:ss:mm"));
                    pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    h.Add("去年", drv);
                    pk.GetHisValue(point, dt.ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    h.Add("今年", drv);
                    dt = dt.AddMinutes(15);
                    list.Add(h);
                }
            }

            Plink.closePi();
            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取实时数据
        /// </summary>
        /// <param name="point">测点名称</param>
        /// <param name="sTime">开始时间</param>
        /// <param name="type">查询类型   日:1 月:2 年:3</param>
        /// <returns></returns>
        public string GetVal(string point, string sTime, string type)
        {
            Plink    pk = new Plink();
            DateTime dt = new DateTime();

            val = "";
            Plink.OpenPi();
            if (type == "1")
            {
                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-01-01 23:59:59"));
                for (int i = 0; i < 365; i++)
                {
                    pk.GetHisValue(point, dt.ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    val += drv + ",";
                    dt   = dt.AddDays(1);
                }
            }
            else if (type == "2")
            {
                int month = Convert.ToDateTime(sTime).Month;
                int year  = Convert.ToDateTime(sTime).Year;

                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-MM-1 11:59:59"));

                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                {
                    for (int i = 0; i < 62; i++)
                    {
                        pk.GetHisValue(point, dt.ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        val += drv + ",";
                        dt   = dt.AddHours(12);
                    }
                }
                else if (month == 4 || month == 6 || month == 9 || month == 11)
                {
                    for (int i = 0; i < 60; i++)
                    {
                        pk.GetHisValue(point, dt.ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        val += drv + ",";
                        dt   = dt.AddHours(12);
                    }
                }
                else
                {
                    if (year % 4 == 0)
                    {
                        for (int i = 0; i < 58; i++)
                        {
                            pk.GetHisValue(point, dt.ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            val += drv + ",";
                            dt   = dt.AddHours(12);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 55; i++)
                        {
                            pk.GetHisValue(point, dt.ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            val += drv + ",";
                            dt   = dt.AddHours(12);
                        }
                    }
                }
            }
            else if (type == "3")
            {
                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-MM-dd 0:14:59"));
                for (int i = 0; i < 96; i++)
                {
                    pk.GetHisValue(point, dt.ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    val += drv + ",";
                    dt   = dt.AddMinutes(15);
                }
            }

            if (val.Length > 0)
            {
                //val = val.Substring(0, val.Length - 1);
                val = val.Remove(val.LastIndexOf(","), 1);
            }
            Plink.closePi();
            return(val);
        }