wxr
2022-05-17 4c586bb23cdcae56ae4e4c62e90e148dc10b9d90
HDL_ON/UI/UI2/FuntionControlView/1ContorlPage/CacDayHistoryPage.cs
New file
@@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    public class CacDayHistoryPage : FrameLayout
    {
        CacDayHistoryPage bodyView;
        EchartsOption_BrokenLine brokenLine;
        MyEchartsViewOn myEchartsView_Line;
        string curQueryType = "hour";
        string queryTime;
        string functionId;
        string time;
        public CacDayHistoryPage(string functionId,string queryType, string time)
        {
            this.time = time;
            this.functionId = functionId;
            curQueryType = queryType;
            bodyView = this;
            queryTime = time;
        }
        /// <summary>
        ///
        /// </summary>
        public void InitView()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.StatisticalChart24Hour)).LoadTopView();
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            var contentView = new FrameLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(603),
            };
            bodyView.AddChidren(contentView);
            var btnTitle = new Button()
            {
                Height = Application.GetRealHeight(60),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
            };
            if(curQueryType == "room_temp")
            {
                btnTitle.Text = queryTime + "室内温度历史数据";
            }
            else
            {
                btnTitle.Text = queryTime + "室内湿度历史数据";
            }
            contentView.AddChidren(btnTitle);
            var historyDataView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealWidth(52),
                Height = Application.GetRealWidth(350),
            };
            contentView.AddChidren(historyDataView);
            brokenLine = new EchartsOption_BrokenLine();
            myEchartsView_Line = new MyEchartsViewOn()
            {
                Y = Application.GetRealWidth(10),
                Height = Application.GetRealWidth(338),
            };
            historyDataView.AddChidren(myEchartsView_Line);
#if DEBUG
            //List<string> vs = new List<string>() {
            //            "1","2","3","4","5","6","7","8","9","10","11","12","13","14"
            //        };
            //brokenLine.InitXdataText(vs);
            //brokenLine.InitYdataText("yData", new List<EnvironmentalSensorHistor>() {
            //    new EnvironmentalSensorHistor{ fieldName = "1", fieldValue= "23"  },
            //    new EnvironmentalSensorHistor{ fieldName = "2", fieldValue= "22"  },
            //    new EnvironmentalSensorHistor{ fieldName = "3", fieldValue= "-11"  },
            //    new EnvironmentalSensorHistor{ fieldName = "4", fieldValue= "21"  },
            //    new EnvironmentalSensorHistor{ fieldName = "5", fieldValue= "-41"  },
            //    new EnvironmentalSensorHistor{ fieldName = "6", fieldValue= "23"  },
            //    new EnvironmentalSensorHistor{ fieldName = "7", fieldValue= "-31"  },
            //    new EnvironmentalSensorHistor{ fieldName = "8", fieldValue= "-23"  },
            //    new EnvironmentalSensorHistor{ fieldName = "9", fieldValue= "-11"  },
            //    new EnvironmentalSensorHistor{ fieldName = "10", fieldValue= "-21"  },
            //    new EnvironmentalSensorHistor{ fieldName = "11", fieldValue= "24"  },
            //    new EnvironmentalSensorHistor{ fieldName = "12", fieldValue= "41"  },
            //    new EnvironmentalSensorHistor{ fieldName = "13", fieldValue= "32"  },
            //    new EnvironmentalSensorHistor{ fieldName = "14", fieldValue= "23"  }
            //}, "#FF9D54");
            //brokenLine.yTitle = "(℃)";
            //brokenLine.xTitle = "";
            ////if (curQueryType != "hour")
            ////{
            ////    brokenLine.xTitle = Language.StringByID(StringId.Date);
            ////}
            //var opString = brokenLine.InitOption();
            //    myEchartsView_Line.ShowWithOption(opString);
#endif
            LoadMothed_GetHistoryData();
        }
        /// <summary>
        /// 读取历史数据
        /// </summary>
        void LoadMothed_GetHistoryData()
        {
            var loadPage = new Loading()
            {
                LodingBackgroundColor = 0x88888888,
            };
            bodyView.AddChidren(loadPage);
            new System.Threading.Thread(() =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        loadPage.Start(Language.StringByID(StringId.PleaseWait));
                    });
                    var revertObj = new HttpServerRequest().GetSensorHistory("day_hour", functionId, curQueryType,time);
                    if (revertObj != null)
                    {
                        if (revertObj.Code == StateCode.SUCCESS)
                        {
                            var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
                            List<string> vs = new List<string>();
                            if (brokenLine.YvalueText == "")
                            {
                                foreach (var data in revertData)
                                {
                                    vs.Add(data.fieldName);
                                }
                                brokenLine.InitXdataText(vs);
                            }
                            //if (sr.GetAttribute("ydata") == null)
                            //{
                            //    sr.attributes.Add(new FunctionAttributes() { key = "ydata" });
                            //}
                            //sr.SetAttrState("ydata",
                            brokenLine.InitYdataText("", revertData, "#FF9D54");// + ",");
                        }
                    }
                    brokenLine.yTitle = Language.StringByID(StringId.Uint);
                    if(curQueryType == "room_temp")
                    {
                        brokenLine.yTitle += ":°C";
                    }
                    else
                    {
                        brokenLine.yTitle += ":%";
                    }
                    brokenLine.xTitle = Language.StringByID(StringId.timeMode);
                    //if (curQueryType != "hour")
                    //{
                    //    brokenLine.xTitle = Language.StringByID(StringId.Date);
                    //}
                    var opString = brokenLine.InitOption();
                    Application.RunOnMainThread(() =>
                    {
                        myEchartsView_Line.ShowWithOption(opString);
                    });
                }
                catch (Exception ex)
                {
                    MainPage.Log($"sensor history error : {ex.Message}");
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loadPage.Hide();
                    });
                }
            })
            { IsBackground = true }.Start();
        }
    }
}