From 5bfb959c47017825c8cf7dc8570c55b04dab694c Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期三, 09 六月 2021 16:42:11 +0800 Subject: [PATCH] Merge branch 'dev-tzy' into wxr6 --- HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs | 496 +++++++++++++++---------------------------------------- 1 files changed, 136 insertions(+), 360 deletions(-) diff --git a/HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs b/HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs index 0bccd57..e985552 100644 --- a/HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs +++ b/HDL_ON/UI/UI2/FuntionControlView/Energy/EnergyMainPage.cs @@ -1,89 +1,25 @@ 锘縰sing System; using System.Collections.Generic; using HDL_ON.DAL.Server; -using HDL_ON.DriverLayer; using HDL_ON.Entity; using HDL_ON.UI.CSS; +using HDL_ON.UI.UI2.EchartsOption_Energy; using Shared; namespace HDL_ON.UI { public class EnergyMainPage : FrameLayout { - static EnergyMainPage bodyView; - - /// <summary> - /// 椤堕儴鍖哄煙 - /// </summary> - FrameLayout generalTableView; - - /// <summary> - /// 瀹炴椂鍔熻�� - /// </summary> - Button btnRealTimeData; - /// <summary> - /// 瀹炴椂鍔熻�楀崟浣� - /// </summary> - Button btnTotalValueUint; - /// <summary> - /// 鎬诲姛鑰� - /// </summary> - TextButton btnTotalValue; - /// <summary> - /// 鍘嗗彶鏁版嵁鍖哄煙 - /// </summary> - FrameLayout diagramView; - /// <summary> - /// 鏇茬嚎鍥� - /// </summary> - MyEchartsViewOn myLineEchartsView; - /// <summary> - /// 鏇茬嚎鍥炬暟鎹畇tring - /// </summary> - EchartsOption_BrokenLine brokenLine; - /// <summary> - /// 鏇茬嚎鍥句笅鎷夋寜閽� - /// </summary> - Button btnDrodDown; - - - /// <summary> - /// 鎻掓煡璇㈢殑鑳芥簮鍒楄〃 - /// </summary> - List<Function> queryList = new List<Function>(); - /// <summary> - /// 鏌ヨ鏉′欢 - /// hour銆亀eek銆乵onth - /// </summary> - string curQueryType = "hour"; - - - /// <summary> - /// 鑳芥簮鍒楄〃鍖哄煙 - /// </summary> - FrameLayout energyListView; - /// <summary> - /// 鍘嗗彶鏁版嵁鍥捐〃 - /// </summary> - MyEchartsViewOn myEchartsView; - /// <summary> - /// 鏇茬嚎鍥炬槸鍚﹀睍寮� - /// </summary> - bool isUnfoldOrStow = false; - - List<Function> energyList = new List<Function>(); + FrameLayout bodyView; List<uint> colorList = new List<uint>(){0xFF80AEFF, 0xFFFFD154, 0xFFFF9D54, 0xFFFE6A6A, 0xFFB183C3, 0xFFADE764, 0xFFD7504B, 0xFFC6E579, 0xFFF4E001, 0xFFF0805A, 0xFF26C0C0}; List<string> colorList2 = new List<string>() { "#80AEFF", "#FFD154", "#FF9D54", "#FE6A6A", "#B183C3", "#ADE764", "#D7504B", "#C6E579", "#F4E001", "#F0805A", "#26C0C0"}; - /// <summary> - /// 涓婚〉 - /// </summary> + public EnergyMainPage() { bodyView = this; - energyList = FunctionList.List.GetEnergyList(); } /// <summary> @@ -102,18 +38,18 @@ bodyView.AddChidren(contentView); #region 椤堕儴view - generalTableView = new FrameLayout() + var generalTableView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(16), Width = Application.GetRealWidth(343), - Height = Application.GetRealWidth(148),//419//148 + Height = Application.GetRealWidth(148), Radius = (uint)Application.GetRealWidth(5), BackgroundColor = CSS_Color.MainBackgroundColor, }; contentView.AddChidren(generalTableView); - btnTotalValue = new TextButton() + TextButton btnTotalValue = new TextButton() { X = Application.GetRealWidth(18), Y = Application.GetRealWidth(24), @@ -127,7 +63,9 @@ }; generalTableView.AddChidren(btnTotalValue); - btnTotalValueUint = new Button() + btnTotalValue.Width = btnTotalValue.GetTextWidth(); + + var btnTotalValueUint = new Button() { X = btnTotalValue.Right, Y = Application.GetRealWidth(24), @@ -141,7 +79,7 @@ }; generalTableView.AddChidren(btnTotalValueUint); - btnRealTimeData = new Button() + var btnRealTimeData = new Button() { X = Application.GetRealWidth(18), Y = btnTotalValue.Bottom, @@ -153,9 +91,7 @@ TextID = StringId.RealTimePowerConsumption, }; generalTableView.AddChidren(btnRealTimeData); - - UpdataValue(); - + btnRealTimeData.Text = Language.StringByID(StringId.RealTimePowerConsumption).Replace("{0}", "0"); var echartsView = new FrameLayout() { @@ -165,7 +101,7 @@ //Y = Application.GetRealWidth(16), }; generalTableView.AddChidren(echartsView); - myEchartsView = new MyEchartsViewOn() + MyEchartsViewOn myEchartsView = new MyEchartsViewOn() { Width = Application.GetRealWidth(118), Height = Application.GetRealWidth(118), @@ -173,44 +109,34 @@ 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 - - list.Add(ene.name, tt.ToString()); - } - + list.Add("鐢靛啺绠�", "12"); + list.Add("鐢甸鎵�", "2"); + list.Add("绌鸿皟", "9"); + list.Add("娲楄。鏈�", "3"); + list.Add("鐢佃剳", "33"); var echartsPie = new EchartsOption_Pie(); var echartRootJson = echartsPie.InitDateJson(list); //var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson); myEchartsView.ShowWithOption(echartRootJson); - btnDrodDown = new Button() + var btnDrodDown = new Button() { Y = Application.GetRealWidth(118), Width = Application.GetRealWidth(343), Height = Application.GetRealWidth(30), UnSelectedImagePath = "FunctionIcon/Energy/EnergyDrodDownIcon.png", - SelectedImagePath = "FunctionIcon/Energy/EnergyDrodUpIcon.png", }; - initDiagramView(); generalTableView.AddChidren(btnDrodDown); - btnDrodDown.MouseUpEventHandler = (sender, e) => { - isUnfoldOrStow = btnDrodDown.IsSelected = !btnDrodDown.IsSelected; - showDiagramView(); - }; #endregion - energyListView = new FrameLayout() + var energyList = FunctionList.List.GetEnergyList(); + var energyListView = new FrameLayout() { Y = generalTableView.Bottom + Application.GetRealWidth(8), - Height = Application.GetRealWidth(116 * energyList.Count + 50), + Height = Application.GetRealWidth(116 * energyList.Count), }; contentView.AddChidren(energyListView); int index = 0; @@ -218,54 +144,25 @@ { EnergyRow(energy, energyListView, index); index++; - Control.Ins.SendReadCommand(energy); } - - } + FrameLayout diagramView; + List<Function> queryList = new List<Function>(); + string curQueryType = "hour"; - /// <summary> - /// - /// </summary> - void showDiagramView() + void d1(FrameLayout contentView) { - if (isUnfoldOrStow)//灞曞紑 - { - generalTableView.Height = Application.GetRealHeight(419); - btnDrodDown.Y = Application.GetRealWidth(389); - btnDrodDown.IsSelected = true; - } - else - { - generalTableView.Height = Application.GetRealHeight(148); - btnDrodDown.Y = Application.GetRealWidth(118); - btnDrodDown.IsSelected = false; - } - - energyListView.Y = generalTableView.Bottom + Application.GetRealWidth(8); - } - - /// <summary> - /// 鍔犺浇鏇茬嚎鍥� - /// </summary> - /// <param name="contentView"></param> - void initDiagramView() - { - brokenLine = new EchartsOption_BrokenLine(); - - diagramView = new FrameLayout() { - Y = Application.GetRealHeight(136), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), - Height = Application.GetRealWidth(241), + Height = Application.GetRealWidth(420), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), BorderColor = 0x00000000, BorderWidth = 0, }; - generalTableView.AddChidren(diagramView); + contentView.AddChidren(diagramView); #region 閫夋嫨鏁版嵁鏃ユ湡鑼冨洿 var showDataTypeView = new FrameLayout() @@ -322,38 +219,26 @@ btnShowHistroyData_Month.IsSelected = false; btnShowHistroyData_Week.IsSelected = false; curQueryType = "hour"; - brokenLine.YvalueText = ""; - foreach (var enery in queryList) - { - LoadMothed_GetHistoryData(enery,false); - } + 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 = "week"; - brokenLine.YvalueText = ""; - foreach (var enery in queryList) - { - LoadMothed_GetHistoryData(enery, false); - } - }; 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"; - brokenLine.YvalueText = ""; - foreach (var enery in queryList) - { - LoadMothed_GetHistoryData(enery, false); - } + d2(); }; #endregion @@ -362,115 +247,116 @@ { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(52), - //Width = Application.GetRealWidth(343 - 32), - Height = Application.GetRealHeight(178), + Width = Application.GetRealWidth(343 - 32), + Height = Application.GetRealHeight(270), }; diagramView.AddChidren(historyDataView); - myEchartsView = new MyEchartsViewOn() { - Y = Application.GetRealHeight(10), - Height = Application.GetRealHeight(150), - }; + var myEchartsView = new MyEchartsViewOn(); historyDataView.AddChidren(myEchartsView); } - /// <summary> - /// 璇诲彇鍘嗗彶鏁版嵁 - /// </summary> - void LoadMothed_GetHistoryData(Function sr,bool isDel) + void d2() { - if(isDel)//鍒犻櫎鏁版嵁鐜板疄 + int index = 0; + var echartRootJson = new EchartsOption_Energy(); + var seriesList = new List<EchartSeriesItem>(); + foreach (var function in queryList) { - brokenLine.YvalueText = ""; - foreach (var ene in queryList) - { - brokenLine.YvalueText += ene.GetAttrState("ydata") + ","; - } - - Application.RunOnMainThread(() => - { - myEchartsView.ShowWithOption(brokenLine.InitOption()); - }); - return; + 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 { - try + Application.RunOnMainThread(() => { - Application.RunOnMainThread(() => - { - loadPage.Start(Language.StringByID(StringId.PleaseWait)); - }); + loadPage.Start(Language.StringByID(StringId.PleaseWait)); + }); + var sensorType = function.spk.Split(".")[1]; + var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, function.deviceId, sensorType); - var sensorType = sr.spk.Split(".")[1]; - var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, sr.deviceId, "total_electricity"); - if (revertObj != null) + if (revertObj != null) + { + if (revertObj.Code == StateCode.SUCCESS) { - if (revertObj.Code == StateCode.SUCCESS) + var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString()); + + sItem = new EchartSeriesItem { - var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString()); - - List<string> vs = new List<string>(); - if (brokenLine.YvalueText == "") + data = new List<int>(), + lineStyle = new EchartLineStyle() { - foreach (var data in revertData) - { - vs.Add(data.fieldName); - } - brokenLine.InitXdataText(vs); + color = colorList2[index], +#if __IOS__ + width = 5, +#elif __ANDROID__ + width = 2, +#endif + }, + }; - if (sr.GetAttribute("ydata") == null) - { - sr.attributes.Add(new FunctionAttributes() { key = "ydata" }); - } - sr.SetAttrState("ydata", brokenLine.InitYdataText(sr.name, revertData, sr.GetAttrState("color")) + ","); - } - else + try + { + foreach (var d in revertData) { - if (sr.GetAttribute("ydata") == null) + if (xAxisData.Count == 0) { - sr.attributes.Add(new FunctionAttributes() { key = "ydata" }); + data.Add(d.fieldName); } - sr.SetAttrState("ydata", brokenLine.InitYdataText(sr.name, revertData, sr.GetAttrState("color"))+","); + sItem.data.Add(Convert.ToInt32(d.fieldValue)); } + xAxisData.AddRange(data); + } + catch (Exception ex) + { + MainPage.Log($"revertData:{ex.Message}"); } } - brokenLine.yTitle = Language.StringByID(StringId.EnergyConsumption) + "(kW)"; - brokenLine.xTitle = Language.StringByID(StringId.timeMode); - if(curQueryType != "hour") + else { - brokenLine.xTitle = Language.StringByID(StringId.Date); + Application.RunOnMainThread(() => + { + IMessageCommon.Current.ShowErrorInfoAlter("", true, 2, Language.StringByID(StringId.GetSensorHistoryFailed), false); + }); } - var opString = brokenLine.InitOption(); + } + } + catch (Exception ex) + { + MainPage.Log($"sensor history error : {ex.Message}"); + } + finally + { + Application.RunOnMainThread(() => + { + loadPage.Hide(); + }); + } + return sItem; - Application.RunOnMainThread(() => - { - myEchartsView.ShowWithOption(opString); - }); - } - catch (Exception ex) - { - MainPage.Log($"sensor history error : {ex.Message}"); - } - finally - { - Application.RunOnMainThread(() => - { - loadPage.Hide(); - }); - } - }) - { IsBackground = true }.Start(); + //var echartRootJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(echartRootJson); + //myEchartsView.ShowWithOptionJsonString(echartRootJsonString); } + /// <summary> /// @@ -484,119 +370,16 @@ }; view.AddChidren(btnLine); - //瀹氫箟浠h〃鑹� - energy.attributes.Add(new FunctionAttributes() { key = "color", state = colorList2[index] }); - - var row = new EnergyRow(energy, colorList[index]); - - row.SetHistory_Action = (isAdd) => + var row = new FrameLayout() { - if (isAdd) - { - if(!isUnfoldOrStow)//濡傛灉鏇茬嚎鍥炬病鏈夊姞杞藉嚭鏉ワ紝鍒欒嚜鍔ㄥ姞杞藉嚭鏉� - { - isUnfoldOrStow = true; - showDiagramView(); - } - queryList.Add(row.function); - LoadMothed_GetHistoryData(row.function, false); - } - else - { - queryList.Remove(row.function); - LoadMothed_GetHistoryData(row.function, true); - if (queryList.Count == 0)//濡傛灉鏌ヨ鍒楄〃涓�0锛岃嚜鍔ㄦ敹璧锋洸绾垮浘 - { - isUnfoldOrStow = false; - showDiagramView(); - } - } + Y = btnLine.Bottom, + Gravity = Gravity.CenterHorizontal, + Width = Application.GetRealWidth(343), + Height = Application.GetRealWidth(100), + Radius = (uint)Application.GetRealWidth(12), + BackgroundColor = CSS_Color.MainBackgroundColor, }; - - - row.Y = btnLine.Bottom; view.AddChidren(row); - listButton_value.Add(row.btnValue); - - Control.Ins.SendReadCommand(energy); - } - - - public List<Button> listButton_value = new List<Button>(); - - /// <summary> - /// 鏇存柊鍔熻兘鐘舵�� - /// </summary> - public static void UpdataStatus(Function updataTemp) - { - Application.RunOnMainThread(() => - { - try - { - if (bodyView == null) - return; - foreach (var btn in bodyView.listButton_value) - { - if (btn.Tag.ToString() == updataTemp.sid) - { - var newValue = updataTemp.GetAttrState(FunctionAttributeKey.Power); - //if (newValue != btn.Text) - { - btn.Text = newValue; - UpdataValue(); - } - } - } - } - catch (Exception ex) - { - MainPage.Log($"{bodyView.GetType().Name } UpdataStates error : {ex.Message}"); - } - }); - } - - /// <summary> - /// 鏇存柊鏁版嵁 - /// </summary> - static void UpdataValue() - { - double totalValue = 0; - double realtimeValue = 0; - foreach (var ene in bodyView.energyList) - { - double power = 0; - double.TryParse(ene.GetAttrState(FunctionAttributeKey.TotalElectricity), out power); - totalValue += power; - - int realTimePower = 0; - int.TryParse(ene.GetAttrState(FunctionAttributeKey.Power), out realTimePower); - realtimeValue += realTimePower; - } - bodyView.btnTotalValue.Text = totalValue.ToString(); - realtimeValue /= 1000; - bodyView.btnRealTimeData.Text = Language.StringByID(StringId.RealTimePowerConsumption).Replace("{0}", realtimeValue.ToString()); - ///鍔ㄦ�佽幏鍙栨枃鏈搴� - bodyView.btnTotalValue.Width = bodyView.btnTotalValue.GetTextWidth() + Application.GetRealWidth(5); - bodyView.btnTotalValueUint.X = bodyView.btnTotalValue.Right; - } - } - - - public class EnergyRow : FrameLayout - { - public Button btnValue; - Button btnShowData; - public Function function; - public Action<bool> SetHistory_Action; - public EnergyRow(Function energy, uint color) - { - function = energy; - Gravity = Gravity.CenterHorizontal; - Width = Application.GetRealWidth(343); - Height = Application.GetRealWidth(100); - Radius = (uint)Application.GetRealWidth(12); - BackgroundColor = CSS_Color.MainBackgroundColor; - Tag = energy.sid; var btnColorTip = new Button() { @@ -604,13 +387,13 @@ Y = Application.GetRealWidth(16), Width = Application.GetRealWidth(12), Height = Application.GetRealWidth(12), - BackgroundColor = color + BackgroundColor = colorList[index], }; - AddChidren(btnColorTip); + row.AddChidren(btnColorTip); var btnName = new Button() { - X = Application.GetRealWidth(28), + X = Application.GetRealWidth(8 + 10 + 32), Y = Application.GetRealHeight(10), Width = Application.GetRealWidth(200), Height = Application.GetRealHeight(24), @@ -619,11 +402,11 @@ TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.TextFontSize, }; - AddChidren(btnName); + row.AddChidren(btnName); var btnFromFloor = new Button() { - X = Application.GetRealWidth(28), + X = Application.GetRealWidth(8 + 10 + 32), Y = Application.GetRealHeight(10 + 24), Width = Application.GetRealWidth(200), Height = Application.GetRealHeight(18), @@ -632,9 +415,9 @@ TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, }; - AddChidren(btnFromFloor); + row.AddChidren(btnFromFloor); - btnValue = new Button() + var btnValue = new Button() { X = Application.GetRealWidth(28), Y = Application.GetRealWidth(57), @@ -643,11 +426,9 @@ TextAlignment = TextAlignment.CenterLeft, TextSize = CSS_FontSize.HeadlineFontSize, TextColor = CSS_Color.FirstLevelTitleColor, - Text = energy.GetAttrState(FunctionAttributeKey.Power), - Tag = energy.sid, - IsBold = true, + Text = "---" }; - AddChidren(btnValue); + row.AddChidren(btnValue); var btnSetting = new Button() @@ -658,9 +439,9 @@ Height = Application.GetMinRealAverage(32), UnSelectedImagePath = "Public/FuncInfoSetIcon.png", }; - AddChidren(btnSetting); + row.AddChidren(btnSetting); - var btnSeltSensorValue = new Button() + Button btnSeltSensorValue = new Button() { X = Application.GetRealWidth(16), Y = Application.GetRealWidth(47), @@ -671,8 +452,9 @@ IsBold = true, TextSize = CSS_FontSize.HeadlineFontSize, }; - AddChidren(btnSeltSensorValue); + row.AddChidren(btnSeltSensorValue); + Button btnShowData; btnShowData = new Button() { X = Application.GetRealWidth(291), @@ -681,16 +463,15 @@ Height = Application.GetMinRealAverage(32), UnSelectedImagePath = "FunctionIcon/EnvironmentalScience/DiagramIcon.png", SelectedImagePath = "FunctionIcon/EnvironmentalScience/DiagramIconOn.png", - IsSelected = false, + IsSelected = true, }; - AddChidren(btnShowData); + row.AddChidren(btnShowData); btnSetting.MouseUpEventHandler = (sender, e) => { Action backAction = () => { btnName.Text = energy.name; - btnFromFloor.Text = energy.GetRoomListName(); }; var infoView = new FunctionBaseInfoSetPage(energy, backAction); MainPage.BasePageView.AddChidren(infoView); @@ -698,11 +479,6 @@ MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; - btnShowData.MouseUpEventHandler = (sender, e) => { - btnShowData.IsSelected = !btnShowData.IsSelected; - SetHistory_Action(btnShowData.IsSelected); - }; } - } } \ No newline at end of file -- Gitblit v1.8.0