wxr
2024-07-16 cbc156bc38d8b8eae7aef60cb186ab2b52fa701f
HDL_ON/UI/UI2/FuntionControlView/Electrical/AirSwitchP3EnergyPage.cs
@@ -15,19 +15,10 @@
        static AirSwitchP3EnergyPage bodyView;
        /// <summary>
        /// 总功耗-饼图
        /// </summary>
        MyEchartsViewOn myEchartsView_Pie;
        /// <summary>
        /// 曲线图数据string
        /// </summary>
        EchartsOption_BrokenLine brokenLine;
        /// <summary>
        /// 插查询的能源列表
        /// </summary>
        List<Function> queryList = new List<Function>();
        /// <summary>
        /// 查询条件
        /// hour、week、month
@@ -35,10 +26,6 @@
        string curQueryType = "hour";
        /// <summary>
        /// 能源列表区域
        /// </summary>
        FrameLayout energyListView;
        /// <summary>
        /// 历史数据图表
        /// </summary>
@@ -69,6 +56,7 @@
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(667-64),
                BackgroundColor = 0xFFF5F7FA,
                ScrollEnabled = false,
            };
            bodyView.AddChidren(contentView);
@@ -105,6 +93,7 @@
                BackgroundColor = 0x1F5C62FE,
                BorderColor = CSS_Color.MainColor,
                BorderWidth = 2,
                Radius = 1,
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Day);
            btnShowHistroyData_Day.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerBottomLeft);
@@ -124,8 +113,11 @@
                IsSelected = false,
                BorderWidth = 1,
                BorderColor = CSS_Color.PromptingColor1,
                Radius = 1,
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Month);
            btnShowHistroyData_Month.BorderWidth = 1;
            btnShowHistroyData_Month.BorderColor = CSS_Color.PromptingColor1;
            var btnShowHistroyData_Year = new Button()
            {
@@ -141,8 +133,11 @@
                IsSelected = false,
                BorderWidth = 1,
                BorderColor = CSS_Color.PromptingColor1,
                Radius = 1,
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Year);
            btnShowHistroyData_Year.BorderWidth = 1;
            btnShowHistroyData_Year.BorderColor = CSS_Color.PromptingColor1;
            var btnShowHistroyData_Total = new Button()
            {
@@ -158,6 +153,7 @@
                IsSelected = false,
                BorderWidth = 1,
                BorderColor = CSS_Color.PromptingColor1,
                Radius = 1,
            };
            showDataTypeView.AddChidren(btnShowHistroyData_Total);
            btnShowHistroyData_Total.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerBottomRight | HDLUtils.RectCornerTopRight);
@@ -165,6 +161,10 @@
            btnShowHistroyData_Total.MouseUpEventHandler = (sender, e) =>
            {
                if(curQueryType == "total")
                {
                    return;
                }
                (sender as Button).SelectedBackgroundColor = 0x1F5C62FE;
                (sender as Button).BackgroundColor = 0x1F5C62FE;
                (sender as Button).BorderColor = CSS_Color.MainColor;
@@ -188,11 +188,20 @@
                btnShowHistroyData_Day.BorderColor = CSS_Color.PromptingColor1;
                btnShowHistroyData_Day.BackgroundColor = 0x00000000;
                btnShowHistroyData_Day.SelectedBackgroundColor = 0x00000000;
            };
#if __IOS__
                btnShowHistroyData_Day.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerBottomLeft);
                btnShowHistroyData_Total.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerBottomRight | HDLUtils.RectCornerTopRight);
#endif
            };
            btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) =>
            {
                if(curQueryType == "hour")
                {
                    return;
                }
                (sender as Button).SelectedBackgroundColor = 0x1F5C62FE;
                (sender as Button).BackgroundColor = 0x1F5C62FE;
                (sender as Button).BorderColor = CSS_Color.MainColor;
@@ -216,10 +225,22 @@
                btnShowHistroyData_Total.BorderColor = CSS_Color.PromptingColor1;
                btnShowHistroyData_Total.BackgroundColor = 0x00000000;
                btnShowHistroyData_Total.SelectedBackgroundColor = 0x00000000;
#if __IOS__
                btnShowHistroyData_Day.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerBottomLeft);
                btnShowHistroyData_Total.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerBottomRight | HDLUtils.RectCornerTopRight);
#endif
                curQueryType = "hour";
                brokenLine.YvalueText = "";
                LoadMothed_GetHistoryData();
            };
            btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) =>
            {
                if(curQueryType == "month")
                {
                    return;
                }
                (sender as Button).SelectedBackgroundColor = 0x1F5C62FE;
                (sender as Button).BackgroundColor = 0x1F5C62FE;
                (sender as Button).BorderColor = CSS_Color.MainColor;
@@ -243,10 +264,22 @@
                btnShowHistroyData_Total.BorderColor = CSS_Color.PromptingColor1;
                btnShowHistroyData_Total.BackgroundColor = 0x00000000;
                btnShowHistroyData_Total.SelectedBackgroundColor = 0x00000000;
#if __IOS__
                btnShowHistroyData_Day.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerBottomLeft);
                btnShowHistroyData_Total.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerBottomRight | HDLUtils.RectCornerTopRight);
#endif
                curQueryType = "month";
                brokenLine.YvalueText = "";
                LoadMothed_GetHistoryData();
            };
            btnShowHistroyData_Year.MouseUpEventHandler = (sender, e) =>
            {
                if(curQueryType == "year_month")
                {
                    return;
                }
                (sender as Button).SelectedBackgroundColor = 0x1F5C62FE;
                (sender as Button).BackgroundColor = 0x1F5C62FE;
                (sender as Button).BorderColor = CSS_Color.MainColor;
@@ -270,6 +303,15 @@
                btnShowHistroyData_Total.BorderColor = CSS_Color.PromptingColor1;
                btnShowHistroyData_Total.BackgroundColor = 0x00000000;
                btnShowHistroyData_Total.SelectedBackgroundColor = 0x00000000;
#if __IOS__
                btnShowHistroyData_Day.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerBottomLeft);
                btnShowHistroyData_Total.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerBottomRight | HDLUtils.RectCornerTopRight);
#endif
                curQueryType = "year_month";
                brokenLine.YvalueText = "";
                LoadMothed_GetHistoryData();
            };
            #endregion
@@ -284,6 +326,8 @@
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealWidth(330),
                Radius = (uint)Application.GetRealWidth(16),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            contentView.AddChidren(historyDataView);
@@ -294,12 +338,241 @@
            };
            historyDataView.AddChidren(myEchartsView_Line);
            //EnergyRow(energy, energyListView, index);
            new System.Threading.Thread(() =>
                {
                    Control.Ins.SendReadCommand(device);
                })
                { IsBackground = true }.Start();
            var btnTip = new Button()
            {
                Y = Application.GetRealWidth(289),
                Height = Application.GetRealHeight(41),
                Width = Application.GetRealWidth(300),
                TextAlignment = TextAlignment.Center,
                Gravity = Gravity.CenterHorizontal,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextID = StringId.AirSwitchP3HistroyTip1,
            };
            historyDataView.AddChidren(btnTip);
            LoadMothed_GetHistoryData();
            #region A
            contentView.AddChidren(new Button()
            {
                Height = Application.GetRealHeight(12),
            });
            var viewa = new FrameLayout()
            {
                Gravity  = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(52),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
            };
            contentView.AddChidren(viewa);
            Button btnRighta = new Button()
            {
                X = Application.GetRealWidth(321),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/Right.png",
            };
            viewa.AddChidren(btnRighta);
            Button btnTitlea = new Button()
            {
                X = Application.GetRealWidth(16),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.TextFontSize,
                TextColor= 0xFF000000,
                Width = Application.GetRealWidth(300),
                TextID = StringId.RealTimeElectricityConsumptionDataOfPhaseA
            };
            viewa.AddChidren(btnTitlea);
            #endregion
            #region B
            contentView.AddChidren(new Button()
            {
                Height = Application.GetRealHeight(12),
            });
            var viewb = new FrameLayout()
            {
                Gravity  = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(52),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
            };
            contentView.AddChidren(viewb);
            Button btnRightb = new Button()
            {
                X = Application.GetRealWidth(321),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/Right.png",
            };
            viewb.AddChidren(btnRightb);
            Button btnTitleb = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(300),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = 0xFF000000,
                TextID = StringId.RealTimeElectricityConsumptionDataOfPhaseB,
            };
            viewb.AddChidren(btnTitleb);
            #endregion
            #region C
            contentView.AddChidren(new Button()
            {
                Height = Application.GetRealHeight(12),
            });
            var viewc = new FrameLayout()
            {
                Gravity  = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(52),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
            };
            contentView.AddChidren(viewc);
            Button btnRightc = new Button()
            {
                X = Application.GetRealWidth(321),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/Right.png",
            };
            viewc.AddChidren(btnRightc);
            Button btnTitlec = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(300),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = 0xFF000000,
                TextID = StringId.RealTimeElectricityConsumptionDataOfPhaseC,
            };
            viewc.AddChidren(btnTitlec);
            #endregion
            btnTitlea.MouseUpEventHandler = (sender, e) => {
                var skipView = new AirSwitchP3SubloopEnergyPage(device,FunctionAttributeKey.ElectricityA);
                MainPage.BasePageView.AddChidren(skipView);
                skipView.LoadPage(StringId.RealTimeElectricityConsumptionDataOfPhaseA);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            btnTitleb.MouseUpEventHandler = (sender, e) => {
                var skipView = new AirSwitchP3SubloopEnergyPage(device, FunctionAttributeKey.ElectricityB);
                MainPage.BasePageView.AddChidren(skipView);
                skipView.LoadPage(StringId.RealTimeElectricityConsumptionDataOfPhaseB);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            btnTitlec.MouseUpEventHandler = (sender, e) => {
                var skipView = new AirSwitchP3SubloopEnergyPage(device, FunctionAttributeKey.ElectricityC);
                MainPage.BasePageView.AddChidren(skipView);
                skipView.LoadPage(StringId.RealTimeElectricityConsumptionDataOfPhaseC);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            #region 总用电量
            var totalElectricityView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealWidth(183),
                Radius = (uint)Application.GetRealWidth(16),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            //historyDataView.AddChidren(totalElectricityView);
            var btnTotalElectricity = new Button()
            {
                Width = Application.GetRealWidth(300),
                Height = Application.GetRealHeight(55),
                X = Application.GetRealWidth(14),
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextColor = 0xFF030D1C,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = StringId.TotalPowerAndUnit,
            };
            totalElectricityView.AddChidren(btnTotalElectricity);
            double totalNumber = 0.00;
            double.TryParse(device.GetAttrState(FunctionAttributeKey.TotalElectricity), out totalNumber);
            var btnTotalNumber = new Button()
            {
                Y = Application.GetRealHeight(27),
                Gravity = Gravity.CenterHorizontal,
                Height = Application.GetRealHeight(167),
                TextSize = 49,
                TextColor = 0xFF030D1C,
                TextAlignment = TextAlignment.Center,
                Text = totalNumber.ToString("F2"),
            };
            totalElectricityView.AddChidren(btnTotalNumber);
            btnShowHistroyData_Day.MouseUpEventHandler += (sender, e) => {
                totalElectricityView.RemoveFromParent();
                historyDataView.AddChidren(myEchartsView_Line);
                //viewa.Visible = true;
                //viewb.Visible = true;
                //viewc.Visible = true;
                btnTip.TextID = StringId.AirSwitchP3HistroyTip1;
                historyDataView.Height = Application.GetRealWidth(330);
            };
            btnShowHistroyData_Month.MouseUpEventHandler += (sender, e) => {
                totalElectricityView.RemoveFromParent();
                historyDataView.AddChidren(myEchartsView_Line);
                //viewa.Visible = true;
                //viewb.Visible = true;
                //viewc.Visible = true;
                btnTip.TextID = StringId.AirSwitchP3HistroyTip2;
                historyDataView.Height = Application.GetRealWidth(330);
            };
            btnShowHistroyData_Year.MouseUpEventHandler += (sender, e) => {
                totalElectricityView.RemoveFromParent();
                historyDataView.AddChidren(myEchartsView_Line);
                //viewa.Visible = false;
                //viewb.Visible = false;
                //viewc.Visible = false;
                btnTip.TextID = StringId.AirSwitchP3HistroyTip3;
                historyDataView.Height = Application.GetRealWidth(330);
            };
            btnShowHistroyData_Total.MouseUpEventHandler += (sender, e) => {
                myEchartsView_Line.RemoveFromParent();
                historyDataView.AddChidren(totalElectricityView);
                //viewa.Visible = false;
                //viewb.Visible = false;
                //viewc.Visible = false;
                historyDataView.Height = Application.GetRealHeight(184);
            };
            #endregion
        }
@@ -329,37 +602,73 @@
                    });
                    var sensorType = device.spk.Split(".")[1];
                    var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, device.deviceId, "total_electricity");
                    var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, device.deviceId, FunctionAttributeKey.TotalElectricity);
                    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)
#if DEBUG
                            if (revertData == null || revertData.Count == 0) {
                                List<string> vs = new List<string>() {
                                    "1","2","3","4",
                                    "5","6","7","8",
                                    "9","10","11","12",
                                    //"13","14","15","16",
                                    //"17","18","19","20",
                                    //"21","22","23","24",
                                };
                                    brokenLine.InitXdataText(vs);
                                revertData = new List<EnvironmentalSensorHistor>()
                                {
                                    vs.Add(data.fieldName);
                                    new EnvironmentalSensorHistor{ fieldValue = "100"},
                                    new EnvironmentalSensorHistor{ fieldValue = "200"},
                                    new EnvironmentalSensorHistor{ fieldValue = "300"},
                                    new EnvironmentalSensorHistor{ fieldValue = "400"},
                                    new EnvironmentalSensorHistor{ fieldValue = "500"},
                                    new EnvironmentalSensorHistor{ fieldValue = "400"},
                                    new EnvironmentalSensorHistor{ fieldValue = "100"},
                                    new EnvironmentalSensorHistor{ fieldValue = "200"},
                                    new EnvironmentalSensorHistor{ fieldValue = "300"},
                                    new EnvironmentalSensorHistor{ fieldValue = "400"},
                                    new EnvironmentalSensorHistor{ fieldValue = "500"},
                                    new EnvironmentalSensorHistor{ fieldValue = "400"},
                                };
                                if (device.GetAttribute("ydata") == null)
                                {
                                    device.attributes.Add(new FunctionAttributes() { key = "ydata" });
                                }
                                brokenLine.InitXdataText(vs);
                            }
                            if (device.GetAttribute("ydata") == null)
                                device.SetAttrState("ydata", brokenLine.InitYdataText2(device.name, revertData, "#5C62FE", curQueryType == "year_month") + ", ");
                        }
                        else
#endif
                            {
                                device.attributes.Add(new FunctionAttributes() { key = "ydata" });
                                List<string> vs = new List<string>();
                                if (brokenLine.YvalueText == "")
                                {
                                    foreach (var data in revertData)
                                    {
                                        vs.Add(data.fieldName);
                                    }
                                    brokenLine.InitXdataText(vs);
                                }
                                if (device.GetAttribute("ydata") == null)
                                {
                                    device.attributes.Add(new FunctionAttributes() { key = "ydata" });
                                }
                                device.SetAttrState("ydata", brokenLine.InitYdataText2(device.name, revertData, "#5C62FE", curQueryType == "year_month") + ", ");
                            }
                            device.SetAttrState("ydata", brokenLine.InitYdataText(device.name, revertData, device.GetAttrState("color")) + ",");
                        }
                    }
                    brokenLine.yTitle = Language.StringByID(StringId.EnergyConsumption) + "(kW)";
                    brokenLine.yTitle = Language.StringByID(StringId.Uint) + "(KW·h)";
                    brokenLine.xTitle = Language.StringByID(StringId.timeMode);
                    if (curQueryType != "hour")
                    {
                        brokenLine.xTitle = Language.StringByID(StringId.Date);
                    }
                    var opString = brokenLine.InitOption();
                    var opString = brokenLine.InitOption(100, curQueryType == "year_month");
                    Application.RunOnMainThread(() =>
                    {
                        myEchartsView_Line.ShowWithOption(opString);