From 6d73bf6e816570291865674bef8bce8972e4de3f Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期三, 01 十二月 2021 16:32:57 +0800
Subject: [PATCH] 2021-12-01-01

---
 HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs |  119 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 63 insertions(+), 56 deletions(-)

diff --git a/HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs b/HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs
index 63622d3..b39f8be 100644
--- a/HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs
+++ b/HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs
@@ -29,13 +29,13 @@
         /// </summary>
         TextButton btnTotalValue;
         /// <summary>
+        /// 鎬诲姛鑰�-楗煎浘
+        /// </summary>
+        MyEchartsViewOn myEchartsView_Pie;
+        /// <summary>
         /// 鍘嗗彶鏁版嵁鍖哄煙
         /// </summary>
         FrameLayout diagramView;
-        /// <summary>
-        /// 鏇茬嚎鍥�
-        /// </summary>
-        MyEchartsViewOn myLineEchartsView;
         /// <summary>
         /// 鏇茬嚎鍥炬暟鎹畇tring
         /// </summary>
@@ -64,7 +64,7 @@
         /// <summary>
         /// 鍘嗗彶鏁版嵁鍥捐〃
         /// </summary>
-        MyEchartsViewOn myEchartsView;
+        MyEchartsViewOn myEchartsView_Line;
         /// <summary>
         /// 鏇茬嚎鍥炬槸鍚﹀睍寮�
         /// </summary>
@@ -83,7 +83,10 @@
         public EnergyMainPage()
         {
             bodyView = this;
-            energyList = FunctionList.List.GetEnergyList(); 
+            energyList = FunctionList.List.GetEnergyList();
+            var breaker = FunctionList.List.Functions.FindAll((obj) => obj.spk == SPK.AirSwitch);
+            var energyBreker = breaker.FindAll((obj) => obj.GetAttribute("power") != null);
+            energyList.AddRange(energyBreker);
         }
 
         /// <summary>
@@ -105,7 +108,7 @@
             generalTableView = new FrameLayout()
             {
                 Gravity = Gravity.CenterHorizontal,
-                Y = Application.GetRealHeight(16),
+                Y = Application.GetRealWidth(16),
                 Width = Application.GetRealWidth(343),
                 Height = Application.GetRealWidth(148),//419//148
                 Radius = (uint)Application.GetRealWidth(5),
@@ -154,8 +157,6 @@
             };
             generalTableView.AddChidren(btnRealTimeData);
 
-            UpdataValue();
-
 
             var echartsView = new FrameLayout()
             {
@@ -165,29 +166,23 @@
                 //Y = Application.GetRealWidth(16),
             };
             generalTableView.AddChidren(echartsView);
-            myEchartsView = new MyEchartsViewOn()
+            myEchartsView_Pie = new MyEchartsViewOn()
             {
                 Width = Application.GetRealWidth(118),
                 Height = Application.GetRealWidth(118),
             };
+            echartsView.AddChidren(myEchartsView_Pie);
 
-            echartsView.AddChidren(myEchartsView);
             Dictionary<string, string> list = new Dictionary<string, string>();
-
             foreach(var ene in energyList)
             {
                 double tt = 0;
                 double.TryParse(ene.GetAttrState(FunctionAttributeKey.TotalElectricity), out tt);
                 tt *= 100;//涔樹互100锛屽皬浜�1鏃犳硶鍔犺浇echart
-
+                tt = Math.Round(tt, 2);
                 list.Add(ene.name, tt.ToString());
             }
-
-            var echartsPie = new EchartsOption_Pie();
-            var echartRootJson = echartsPie.InitDateJson(list);
-            //var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson);
-            myEchartsView.ShowWithOption(echartRootJson);
-
+            myEchartsView_Pie.ShowWithOption(new EchartsOption_Pie().InitDateJson(list));
 
             btnDrodDown = new Button()
             {
@@ -204,6 +199,7 @@
                 showDiagramView();
             };
 
+            UpdataValue();
             #endregion
 
 
@@ -218,7 +214,11 @@
             {
                 EnergyRow(energy, energyListView, index);
                 index++;
-                DriverLayer.Control.Ins.SendReadCommand(energy);
+                new System.Threading.Thread(() =>
+                {
+                    Control.Ins.SendReadCommand(energy);
+                })
+                { IsBackground = true }.Start();
             }
 
 
@@ -231,13 +231,13 @@
         {
             if (isUnfoldOrStow)//灞曞紑
             {
-                generalTableView.Height = Application.GetRealHeight(419);
+                generalTableView.Height = Application.GetRealWidth(419);
                 btnDrodDown.Y = Application.GetRealWidth(389);
                 btnDrodDown.IsSelected = true;
             }
             else
             {
-                generalTableView.Height = Application.GetRealHeight(148);
+                generalTableView.Height = Application.GetRealWidth(148);
                 btnDrodDown.Y = Application.GetRealWidth(118);
                 btnDrodDown.IsSelected = false;
             }
@@ -256,10 +256,10 @@
 
             diagramView = new FrameLayout()
             {
-                Y = Application.GetRealHeight(136),
+                Y = Application.GetRealWidth(136),
                 Gravity = Gravity.CenterHorizontal,
                 Width = Application.GetRealWidth(343),
-                Height = Application.GetRealWidth(241),
+                Height = Application.GetRealWidth(281),
                 BackgroundColor = CSS_Color.MainBackgroundColor,
                 Radius = (uint)Application.GetRealWidth(12),
                 BorderColor = 0x00000000,
@@ -310,7 +310,7 @@
                 TextColor = CSS_Color.PromptingColor2,
                 SelectedTextColor = CSS_Color.MainColor,
                 TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
-                Text = DateTime.Now.Month.ToString() + Language.StringByID(StringId.month),
+                Text =  Language.StringByID(StringId.month),//DateTime.Now.Month.ToString() +
             };
             showDataTypeView.AddChidren(btnShowHistroyData_Month);
 
@@ -361,19 +361,17 @@
             var historyDataView = new FrameLayout()
             {
                 Gravity = Gravity.CenterHorizontal,
-                Y = Application.GetRealHeight(52),
-                //Width = Application.GetRealWidth(343 - 32),
-                Height = Application.GetRealHeight(178),
+                Y = Application.GetRealWidth(52),
+                Height = Application.GetRealWidth(190),
             };
             diagramView.AddChidren(historyDataView);
 
-            myEchartsView = new MyEchartsViewOn() {
-                Y = Application.GetRealHeight(10),
-                Height = Application.GetRealHeight(150),
+            myEchartsView_Line = new MyEchartsViewOn()
+            {
+                Y = Application.GetRealWidth(10),
+                Height = Application.GetRealWidth(180),
             };
-
-            historyDataView.AddChidren(myEchartsView);
-
+            historyDataView.AddChidren(myEchartsView_Line);
         }
 
         /// <summary>
@@ -386,13 +384,15 @@
                 brokenLine.YvalueText = "";
                 foreach (var ene in queryList)
                 {
-                    brokenLine.YvalueText += ene.GetAttrState("ydata") + ",";
+                    brokenLine.YvalueText += ene.GetAttrState("ydata");
                 }
+                var opString = brokenLine.InitOption();
 
                 Application.RunOnMainThread(() =>
                 {
-                    myEchartsView.ShowWithOption(brokenLine.InitOption());
+                    myEchartsView_Line.ShowWithOption(opString);
                 });
+
                 return;
             }
 
@@ -427,21 +427,12 @@
                                     vs.Add(data.fieldName);
                                 }
                                 brokenLine.InitXdataText(vs);
-
-                                if (sr.GetAttribute("ydata") == null)
-                                {
-                                    sr.attributes.Add(new FunctionAttributes() { key = "ydata" });
-                                }
-                                sr.SetAttrState("ydata", brokenLine.InitYdataText(sr.name, revertData, sr.GetAttrState("color")) + ",");
                             }
-                            else
+                            if (sr.GetAttribute("ydata") == null)
                             {
-                                if (sr.GetAttribute("ydata") == null)
-                                {
-                                    sr.attributes.Add(new FunctionAttributes() { key = "ydata" });
-                                }
-                                sr.SetAttrState("ydata", brokenLine.InitYdataText(sr.name, revertData, sr.GetAttrState("color"))+",");
+                                sr.attributes.Add(new FunctionAttributes() { key = "ydata" });
                             }
+                            sr.SetAttrState("ydata", brokenLine.InitYdataText(sr.name, revertData, sr.GetAttrState("color")) + ",");
                         }
                     }
                     brokenLine.yTitle = Language.StringByID(StringId.EnergyConsumption) + "(kW)";
@@ -454,7 +445,7 @@
 
                     Application.RunOnMainThread(() =>
                     {
-                        myEchartsView.ShowWithOption(opString);
+                        myEchartsView_Line.ShowWithOption(opString);
                     });
                 }
                 catch (Exception ex)
@@ -516,12 +507,13 @@
 
             row.Y = btnLine.Bottom;
             view.AddChidren(row);
+            //璁板綍闇�瑕佹洿鏂扮殑鏇存柊鎸夐挳
             listButton_value.Add(row.btnValue);
-
-            Control.Ins.SendReadCommand(energy);
         }
 
-
+        /// <summary>
+        /// 璁板綍闇�瑕佹洿鏂扮殑鏇存柊鎸夐挳
+        /// </summary>
         public List<Button> listButton_value = new List<Button>();
 
         /// <summary>
@@ -542,7 +534,7 @@
                             var newValue = updataTemp.GetAttrState(FunctionAttributeKey.Power);
                             //if (newValue != btn.Text)
                             {
-                                btn.Text = newValue;
+                                btn.Text = Math.Round(double.Parse(newValue), 2).ToString();// +"W";
                                 UpdataValue();
                             }
                         }
@@ -562,15 +554,26 @@
         {
             double totalValue = 0;
             double realtimeValue = 0;
+            Dictionary<string, string> list = new Dictionary<string, string>();//楗煎浘鏁版嵁
             foreach (var ene in bodyView.energyList)
             {
-                double power = 0;
+                double power = 0.00;
                 double.TryParse(ene.GetAttrState(FunctionAttributeKey.TotalElectricity), out power);
+                power = Math.Round(power, 2);
                 totalValue += power;
 
-                int realTimePower = 0;
-                int.TryParse(ene.GetAttrState(FunctionAttributeKey.Power), out realTimePower);
+                double realTimePower = 0;
+                double.TryParse(ene.GetAttrState(FunctionAttributeKey.Power), out realTimePower);
                 realtimeValue += realTimePower;
+                realtimeValue = Math.Round(realtimeValue, 2);
+
+                #region 楗煎浘鏁版嵁
+                double tt = 0.00;
+                double.TryParse(ene.GetAttrState(FunctionAttributeKey.TotalElectricity), out tt);
+                tt = Math.Round(tt, 2);
+                tt *= 100;//涔樹互100锛屽皬浜�1鏃犳硶鍔犺浇echart
+                list.Add(ene.name, tt.ToString());
+                #endregion
             }
             bodyView.btnTotalValue.Text = totalValue.ToString();
             realtimeValue /= 1000;
@@ -578,6 +581,9 @@
             ///鍔ㄦ�佽幏鍙栨枃鏈搴�
             bodyView.btnTotalValue.Width = bodyView.btnTotalValue.GetTextWidth() + Application.GetRealWidth(5);
             bodyView.btnTotalValueUint.X = bodyView.btnTotalValue.Right;
+            //鍒锋柊楗煎浘
+            bodyView.myEchartsView_Pie.ShowWithOption(new EchartsOption_Pie().InitDateJson(list));
+
         }
     }
 
@@ -690,6 +696,7 @@
                 Action backAction = () =>
                 {
                     btnName.Text = energy.name;
+                    btnFromFloor.Text = energy.GetRoomListName();
                 };
                 var infoView = new FunctionBaseInfoSetPage(energy, backAction);
                 MainPage.BasePageView.AddChidren(infoView);

--
Gitblit v1.8.0