1
wei
2021-03-31 133fb9821663a8c26d99a231086209af8756e508
HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs
@@ -3,6 +3,7 @@
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using HDL_ON.UI.UI2.EchartsOption_Energy;
using Shared;
namespace HDL_ON.UI
{
@@ -100,7 +101,8 @@
                //Y = Application.GetRealWidth(16),
            };
            generalTableView.AddChidren(echartsView);
            MyEchartsViewOn myEchartsView = new MyEchartsViewOn() {
            MyEchartsViewOn myEchartsView = new MyEchartsViewOn()
            {
                Width = Application.GetRealWidth(118),
                Height = Application.GetRealWidth(118),
            };
@@ -144,11 +146,13 @@
                index++;
            }
        }
        FrameLayout diagramView;
        List<Function> queryList = new List<Function>();
        string curQueryType = "hour";
        public void ddd(FrameLayout contentView)
        void d1(FrameLayout contentView)
        {
            FrameLayout diagramView = new FrameLayout()
            diagramView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
@@ -206,6 +210,37 @@
                Text = DateTime.Now.Month.ToString() + Language.StringByID(StringId.month),
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Month);
            btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) =>
            {
                showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png";
                btnShowHistroyData_Day.IsSelected = true;
                btnShowHistroyData_Month.IsSelected = false;
                btnShowHistroyData_Week.IsSelected = false;
                curQueryType = "hour";
                d2();
            };
            btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) =>
            {
                showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg3.png";
                btnShowHistroyData_Day.IsSelected = false;
                btnShowHistroyData_Month.IsSelected = true;
                btnShowHistroyData_Week.IsSelected = false;
                curQueryType = "week";
                d2();
            };
            btnShowHistroyData_Week.MouseUpEventHandler = (sender, e) =>
            {
                showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg2.png";
                btnShowHistroyData_Day.IsSelected = false;
                btnShowHistroyData_Month.IsSelected = false;
                btnShowHistroyData_Week.IsSelected = true;
                curQueryType = "month";
                d2();
            };
            #endregion
            var historyDataView = new FrameLayout()
@@ -222,29 +257,40 @@
            historyDataView.AddChidren(myEchartsView);
        }
        void d2()
        {
            int index = 0;
            var echartRootJson = new EchartsOption_Energy();
            var seriesList = new List<EchartSeriesItem>();
            foreach (var function in queryList)
            {
                var seriesItem = d3(function, index, echartRootJson.xAxis.data);
                seriesList.Add(seriesItem);
            }
        }
        /// <summary>
        /// 查询列表
        /// </summary>
            /// <summary>
            /// 读取传感器历史数据
            /// </summary>
            void ddd2(string curQueryType,Function function,int index)
        EchartSeriesItem d3(Function function, int index, List<string> xAxisData)
            {
                var seriesList = new List<EchartSeriesItem>();
            EchartSeriesItem sItem = null;
            List<string> data = new List<string>();
                var loadPage = new Loading()
                {
                    LodingBackgroundColor = 0x88888888,
                };
                historyDataView.AddChidren(loadPage);
            diagramView.AddChidren(loadPage);
                new System.Threading.Thread(() =>
                {
                    try
                    {
                        Application.RunOnMainThread(() =>
                        {
                            loadPage.Start(Language.StringByID(StringId.PleaseWait));
                        });
                        int i = 0;
                        {
                            var sensorType = function.spk.Split(".")[0];
                            var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, function.deviceId, sensorType);
@@ -254,12 +300,12 @@
                                {
                                    var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
                                    var sItem = new EchartSeriesItem
                         sItem = new EchartSeriesItem
                                    {
                                        data = new List<int>(),
                                        lineStyle = new EchartLineStyle()
                                        {
                                            color = colorList2[i],
                                color = colorList2[index],
#if __IOS__
                                            width = 5,
#elif __ANDROID__
@@ -268,12 +314,22 @@
                                        },
                                    };
                        try
                        {
                                    foreach (var d in revertData)
                                    {
                                        echartRootJson.xAxis.data.Add(d.fieldName);
                                        echartRootJson.yAxis.data.Add(d.fieldValue);
                                if (xAxisData.Count == 0)
                                {
                                    data.Add(d.fieldName);
                                    }
                                    seriesList.Add(sItem);
                                sItem.data.Add(Convert.ToInt32(d.fieldValue));
                            }
                            xAxisData.AddRange(data);
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"revertData:{ex.Message}");
                        }
                                }
                                else
                                {
@@ -283,9 +339,6 @@
                                    });
                                }
                            }
                            i++;
                        }
                    }
                    catch (Exception ex)
                    {
@@ -298,57 +351,10 @@
                            loadPage.Hide();
                        });
                    }
                })
                { IsBackground = true }.Start();
                EchartsOption echartRootJson = new EchartsOption();
                echartRootJson.series = seriesList;
            return sItem;
#if __IOS__
                echartRootJson.xAxis.axisLabel.fontSize = 22;
                echartRootJson.yAxis.axisLabel.fontSize = 22;
#else
                    echartRootJson.xAxis.axisLabel.fontSize = 8;
                    echartRootJson.yAxis.axisLabel.fontSize = 8;
#endif
                var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson);
                myEchartsView.ShowWithOptionJsonString(echartRootJsonString);
            }
            var curQueryType = "";
            void LoadEvent_ChangeSensorHistoryShowType()
            {
                btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) =>
                {
                    showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png";
                    btnShowHistroyData_Day.IsSelected = true;
                    btnShowHistroyData_Month.IsSelected = false;
                    btnShowHistroyData_Week.IsSelected = false;
                    curQueryType = "hour";
                    LoadMothed_GetSensorHistoryData();
                };
                btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) =>
                {
                    showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg3.png";
                    btnShowHistroyData_Day.IsSelected = false;
                    btnShowHistroyData_Month.IsSelected = true;
                    btnShowHistroyData_Week.IsSelected = false;
                    curQueryType = "week";
                    LoadMothed_GetSensorHistoryData();
                };
                btnShowHistroyData_Week.MouseUpEventHandler = (sender, e) =>
                {
                    showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg2.png";
                    btnShowHistroyData_Day.IsSelected = false;
                    btnShowHistroyData_Month.IsSelected = false;
                    btnShowHistroyData_Week.IsSelected = true;
                    curQueryType = "month";
                    LoadMothed_GetSensorHistoryData();
                };
            //var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson);
            //myEchartsView.ShowWithOptionJsonString(echartRootJsonString);
            }