wei
2021-04-01 ccdff82fac4bcc1067ec806ade5ae897f1214f4d
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
{
@@ -15,7 +16,7 @@
        List<string> colorList2 = new List<string>() {
                                        "#80AEFF", "#FFD154", "#FF9D54", "#FE6A6A", "#B183C3", "#ADE764",
                                        "#D7504B", "#C6E579", "#F4E001", "#F0805A", "#26C0C0"};
        public EnergyMainPage()
        {
            bodyView = this;
@@ -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),
            };
@@ -134,21 +136,23 @@
            var energyListView = new FrameLayout()
            {
                Y = generalTableView.Bottom + Application.GetRealWidth(8),
                Height = Application.GetRealWidth(116 * energyList.Count) ,
                Height = Application.GetRealWidth(116 * energyList.Count),
            };
            contentView.AddChidren(energyListView);
            int index = 0;
            foreach(var energy in energyList)
            foreach (var energy in energyList)
            {
                EnergyRow(energy, energyListView, index);
                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,134 +257,105 @@
            historyDataView.AddChidren(myEchartsView);
        }
            /// <summary>
            /// 读取传感器历史数据
            /// </summary>
            void ddd2(string curQueryType,Function function,int index)
        void d2()
        {
            int index = 0;
            var echartRootJson = new EchartsOption_Energy();
            var seriesList = new List<EchartSeriesItem>();
            foreach (var function in queryList)
            {
                var seriesList = new List<EchartSeriesItem>();
                var loadPage = new Loading()
                {
                    LodingBackgroundColor = 0x88888888,
                };
                historyDataView.AddChidren(loadPage);
                var seriesItem = d3(function, index, echartRootJson.xAxis.data);
                seriesList.Add(seriesItem);
            }
        }
        /// <summary>
        /// 查询列表
        /// </summary>
        /// <summary>
        /// 读取传感器历史数据
        /// </summary>
        EchartSeriesItem d3(Function function, int index, List<string> xAxisData)
        {
            EchartSeriesItem sItem = null;
            List<string> data = new List<string>();
            var loadPage = new Loading()
            {
                LodingBackgroundColor = 0x88888888,
            };
            diagramView.AddChidren(loadPage);
                new System.Threading.Thread(() =>
            try
            {
                Application.RunOnMainThread(() =>
                {
                    try
                    loadPage.Start(Language.StringByID(StringId.PleaseWait));
                });
                var sensorType = function.spk.Split(".")[0];
                var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, function.deviceId, sensorType);
                if (revertObj != null)
                {
                    if (revertObj.Code == StateCode.SUCCESS)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            loadPage.Start(Language.StringByID(StringId.PleaseWait));
                        });
                        int i = 0;
                        var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
                         sItem = new EchartSeriesItem
                        {
                            var sensorType = function.spk.Split(".")[0];
                            var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, function.deviceId, sensorType);
                            if (revertObj != null)
                            data = new List<int>(),
                            lineStyle = new EchartLineStyle()
                            {
                                if (revertObj.Code == StateCode.SUCCESS)
                                {
                                    var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
                                    var sItem = new EchartSeriesItem
                                    {
                                        data = new List<int>(),
                                        lineStyle = new EchartLineStyle()
                                        {
                                            color = colorList2[i],
                                color = colorList2[index],
#if __IOS__
                                            width = 5,
                                width = 5,
#elif __ANDROID__
                                        width = 2,
#endif
                                        },
                                    };
                            },
                        };
                                    foreach (var d in revertData)
                                    {
                                        echartRootJson.xAxis.data.Add(d.fieldName);
                                        echartRootJson.yAxis.data.Add(d.fieldValue);
                                    }
                                    seriesList.Add(sItem);
                                }
                                else
                        try
                        {
                            foreach (var d in revertData)
                            {
                                if (xAxisData.Count == 0)
                                {
                                    Application.RunOnMainThread(() =>
                                    {
                                        IMessageCommon.Current.ShowErrorInfoAlter("", true, 2, Language.StringByID(StringId.GetSensorHistoryFailed), false);
                                    });
                                    data.Add(d.fieldName);
                                }
                                sItem.data.Add(Convert.ToInt32(d.fieldValue));
                            }
                            i++;
                            xAxisData.AddRange(data);
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"revertData:{ex.Message}");
                        }
                    }
                    catch (Exception ex)
                    {
                        MainPage.Log($"sensor history error : {ex.Message}");
                    }
                    finally
                    else
                    {
                        Application.RunOnMainThread(() =>
                        {
                            loadPage.Hide();
                            IMessageCommon.Current.ShowErrorInfoAlter("", true, 2, Language.StringByID(StringId.GetSensorHistoryFailed), false);
                        });
                    }
                })
                { IsBackground = true }.Start();
                EchartsOption echartRootJson = new EchartsOption();
                echartRootJson.series = seriesList;
#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()
            catch (Exception ex)
            {
                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();
                };
                MainPage.Log($"sensor history error : {ex.Message}");
            }
            finally
            {
                Application.RunOnMainThread(() =>
                {
                    loadPage.Hide();
                });
            }
            return sItem;
            //var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson);
            //myEchartsView.ShowWithOptionJsonString(echartRootJsonString);
        }
        /// <summary>
@@ -475,4 +481,4 @@
        }
    }
}
}