From 3be0abe90546f2a3a45828f5e6c8adc4517ea9e0 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期五, 14 一月 2022 13:12:38 +0800 Subject: [PATCH] Merge branch 'wxr1215' --- HDL_ON/UI/UI2/FuntionControlView/Electrical/SocketPage_CumulativePowerConsumption.cs | 404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 404 insertions(+), 0 deletions(-) diff --git a/HDL_ON/UI/UI2/FuntionControlView/Electrical/SocketPage_CumulativePowerConsumption.cs b/HDL_ON/UI/UI2/FuntionControlView/Electrical/SocketPage_CumulativePowerConsumption.cs new file mode 100644 index 0000000..c26b483 --- /dev/null +++ b/HDL_ON/UI/UI2/FuntionControlView/Electrical/SocketPage_CumulativePowerConsumption.cs @@ -0,0 +1,404 @@ +锘縰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 Shared; +namespace HDL_ON.UI +{ + public class SocketPage_CumulativePowerConsumption : FrameLayout + { + static SocketPage_CumulativePowerConsumption bodyView; + + /// <summary> + /// 椤堕儴鍖哄煙 + /// </summary> + FrameLayout generalTableView; + + /// <summary> + /// 瀹炴椂鍔熻�� + /// </summary> + Button btnRealTimeData; + /// <summary> + /// 瀹炴椂鍔熻�楀崟浣� + /// </summary> + Button btnTotalValueUint; + /// <summary> + /// 鎬诲姛鑰� + /// </summary> + TextButton btnTotalValue; + /// <summary> + /// 鍘嗗彶鏁版嵁鍖哄煙 + /// </summary> + FrameLayout diagramView; + /// <summary> + /// 鏇茬嚎鍥炬暟鎹畇tring + /// </summary> + EchartsOption_BrokenLine brokenLine; + + + /// <summary> + /// 鎻掓煡璇㈢殑鑳芥簮鍒楄〃 + /// </summary> + List<Function> queryList = new List<Function>(); + /// <summary> + /// 鏌ヨ鏉′欢 + /// hour銆亀eek銆乵onth + /// </summary> + string curQueryType = "hour"; + + + /// <summary> + /// 鑳芥簮鍒楄〃鍖哄煙 + /// </summary> + FrameLayout energyListView; + /// <summary> + /// 鍘嗗彶鏁版嵁鍥捐〃 + /// </summary> + MyEchartsViewOn myEchartsView_Line; + + + Function function; + /// <summary> + /// 涓婚〉 + /// </summary> + public SocketPage_CumulativePowerConsumption(Function function) + { + this.function = function; + bodyView = this; + } + + /// <summary> + /// + /// </summary> + public void LoadPage() + { + new TopViewDiv(bodyView, Language.StringByID(StringId.CumulativePowerConsumption)).LoadTopView(); + bodyView.BackgroundColor = CSS_Color.BackgroundColor; + + var contentView = new FrameLayout() + { + Y = Application.GetRealHeight(64), + Height = Application.GetRealHeight(603), + }; + bodyView.AddChidren(contentView); + + #region 椤堕儴view + generalTableView = new FrameLayout() + { + Gravity = Gravity.CenterHorizontal, + Y = Application.GetRealWidth(16), + Width = Application.GetRealWidth(343), + Height = Application.GetRealWidth(148),//419//148 + Radius = (uint)Application.GetRealWidth(5), + BackgroundColor = CSS_Color.MainBackgroundColor, + }; + contentView.AddChidren(generalTableView); + + btnTotalValue = new TextButton() + { + X = Application.GetRealWidth(18), + Y = Application.GetRealWidth(24), + Width = Application.GetRealWidth(18), + Height = Application.GetRealWidth(52), + TextColor = CSS_Color.FirstLevelTitleColor, + IsBold = true, + TextAlignment = TextAlignment.CenterLeft, + TextSize = 40, + Text = function.GetAttrState("total_electricity") + }; + btnTotalValue.Width = btnTotalValue.GetTextWidth(); + generalTableView.AddChidren(btnTotalValue); + + btnTotalValueUint = new Button() + { + X = btnTotalValue.Right, + Y = Application.GetRealWidth(24), + Width = Application.GetRealWidth(60), + Height = Application.GetRealWidth(28), + TextColor = CSS_Color.FirstLevelTitleColor, + TextSize = CSS_FontSize.SubheadingFontSize, + IsBold = true, + Text = "kW鈥", + TextAlignment = TextAlignment.CenterLeft, + }; + generalTableView.AddChidren(btnTotalValueUint); + + btnRealTimeData = new Button() + { + X = Application.GetRealWidth(18), + Y = btnTotalValue.Bottom, + Width = Application.GetRealWidth(209), + Height = Application.GetRealWidth(28), + TextColor = CSS_Color.TextualColor, + TextSize = CSS_FontSize.SubheadingFontSize, + TextAlignment = TextAlignment.CenterLeft, + TextID = StringId.RealTimePowerConsumption, + }; + double realTimePower = 0; + double.TryParse(function.GetAttrState("active_power"), out realTimePower); + realTimePower /= 1000; + btnRealTimeData.Text = Language.StringByID(StringId.RealTimePowerConsumption).Replace("{0}", realTimePower.ToString()); + generalTableView.AddChidren(btnRealTimeData); + + + + generalTableView.Height = Application.GetRealWidth(459); + + #endregion + + initDiagramView(); + + } + + /// <summary> + /// 鍔犺浇鏇茬嚎鍥� + /// </summary> + /// <param name="contentView"></param> + void initDiagramView() + { + brokenLine = new EchartsOption_BrokenLine(); + + + diagramView = new FrameLayout() + { + Y = Application.GetRealWidth(136), + Gravity = Gravity.CenterHorizontal, + Width = Application.GetRealWidth(343), + Height = Application.GetRealWidth(281), + BackgroundColor = CSS_Color.MainBackgroundColor, + Radius = (uint)Application.GetRealWidth(12), + BorderColor = 0x00000000, + BorderWidth = 0, + }; + generalTableView.AddChidren(diagramView); + + #region 閫夋嫨鏁版嵁鏃ユ湡鑼冨洿 + var showDataTypeView = new FrameLayout() + { + X = Application.GetRealWidth(136), + Y = Application.GetRealHeight(12), + Width = Application.GetRealWidth(144+47), + Height = Application.GetRealHeight(24), + BackgroundImagePath = "FunctionIcon/EnvironmentalScience/HistoryOpionBg1.png", + }; + diagramView.AddChidren(showDataTypeView); + + var btnShowHistroyData_Day = new Button() + { + Width = Application.GetRealWidth(48), + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.PromptingColor2, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.PromptFontSize_FirstLevel, + IsSelected = true, + TextID = StringId.day, + }; + showDataTypeView.AddChidren(btnShowHistroyData_Day); + + var btnShowHistroyData_Week = new Button() + { + X = Application.GetRealWidth(48), + Width = Application.GetRealWidth(48), + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.PromptingColor2, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.PromptFontSize_FirstLevel, + TextID = StringId.week, + }; + showDataTypeView.AddChidren(btnShowHistroyData_Week); + + var btnShowHistroyData_Month = new Button() + { + X = Application.GetRealWidth(48 * 2), + Width = Application.GetRealWidth(48), + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.PromptingColor2, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.PromptFontSize_FirstLevel, + Text = Language.StringByID(StringId.month) + }; + showDataTypeView.AddChidren(btnShowHistroyData_Month); + + var btnShowHistroyData_Year = new Button() + { + X = Application.GetRealWidth(48 * 3), + Width = Application.GetRealWidth(48), + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.PromptingColor2, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.PromptFontSize_FirstLevel, + Text = Language.StringByID(StringId.Years), + }; + showDataTypeView.AddChidren(btnShowHistroyData_Year); + + + btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) => + { + showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/HistoryOpionBg1.png"; + btnShowHistroyData_Day.IsSelected = true; + btnShowHistroyData_Month.IsSelected = false; + btnShowHistroyData_Week.IsSelected = false; + btnShowHistroyData_Year.IsSelected = false; + curQueryType = "hour"; + brokenLine.YvalueText = ""; + LoadMothed_GetHistoryData(); + }; + + btnShowHistroyData_Week.MouseUpEventHandler = (sender, e) => + { + showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/HistoryOpionBg2.png"; + btnShowHistroyData_Day.IsSelected = false; + btnShowHistroyData_Month.IsSelected = false; + btnShowHistroyData_Week.IsSelected = true; + btnShowHistroyData_Year.IsSelected = false; + curQueryType = "week"; + brokenLine.YvalueText = ""; + LoadMothed_GetHistoryData(); + }; + btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) => + { + showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/HistoryOpionBg3.png"; + btnShowHistroyData_Day.IsSelected = false; + btnShowHistroyData_Month.IsSelected = true; + btnShowHistroyData_Week.IsSelected = false; + btnShowHistroyData_Year.IsSelected = false; + curQueryType = "month"; + brokenLine.YvalueText = ""; + LoadMothed_GetHistoryData(); + }; + + btnShowHistroyData_Year.MouseUpEventHandler = (sender, e) => + { + showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/HistoryOpionBg4.png"; + btnShowHistroyData_Day.IsSelected = false; + btnShowHistroyData_Month.IsSelected = false; + btnShowHistroyData_Year.IsSelected = true; + btnShowHistroyData_Week.IsSelected = false; + curQueryType = "year_month"; + brokenLine.YvalueText = ""; + LoadMothed_GetHistoryData(); + }; + + #endregion + + var historyDataView = new FrameLayout() + { + Gravity = Gravity.CenterHorizontal, + Y = Application.GetRealWidth(52), + Height = Application.GetRealWidth(240), + }; + diagramView.AddChidren(historyDataView); + + myEchartsView_Line = new MyEchartsViewOn() + { + Y = Application.GetRealWidth(10), + Height = Application.GetRealWidth(220), + }; + historyDataView.AddChidren(myEchartsView_Line); + + LoadMothed_GetHistoryData(); + + } + + /// <summary> + /// 璇诲彇鍘嗗彶鏁版嵁 + /// </summary> + void LoadMothed_GetHistoryData() + { + var loadPage = new Loading() + { + LodingBackgroundColor = 0x88888888, + }; + diagramView.AddChidren(loadPage); + + //var d = new List<string> (); + //var dd = new List<EnvironmentalSensorHistor>(); + //Random random = new Random() ; + //for (int ii = 0; ii < 13; ii++) + //{ + // var i = random.Next(10000); + + // d.Add(i.ToString()); + // dd.Add(new EnvironmentalSensorHistor + // { + // fieldName = i.ToString(), + // fieldValue = i.ToString() + // }); + //} + //brokenLine.InitXdataText(d); + + //brokenLine.InitYdataText(function.name, dd, "#80AEFF"); + //brokenLine.yTitle = "鑳借��(kW)"; + //brokenLine.xTitle = "灏忔椂"; + //var opString = brokenLine.InitOption(); + //myEchartsView_Line.ShowWithOption(opString); + //return; + + + new System.Threading.Thread(() => + { + try + { + Application.RunOnMainThread(() => + { + loadPage.Start(Language.StringByID(StringId.PleaseWait)); + }); + + var sensorType = function.spk.Split(".")[1]; + var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, function.deviceId, "total_electricity"); + 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) + { + vs.Add(data.fieldName); + } + brokenLine.InitXdataText(vs); + } + if (function.GetAttribute("ydata") == null) + { + function.attributes.Add(new FunctionAttributes() { key = "ydata" }); + } + function.SetAttrState("ydata", brokenLine.InitYdataText(function.name, revertData, "#80AEFF") + ","); + } + } + brokenLine.yTitle = Language.StringByID(StringId.EnergyConsumption) + "(kW)"; + brokenLine.xTitle = Language.StringByID(StringId.timeMode); + if (curQueryType != "hour") + { + brokenLine.xTitle = Language.StringByID(StringId.Date); + } + var opString = brokenLine.InitOption(); + + Application.RunOnMainThread(() => + { + myEchartsView_Line.ShowWithOption(opString); + }); + } + catch (Exception ex) + { + MainPage.Log($"sensor history error : {ex.Message}"); + } + finally + { + Application.RunOnMainThread(() => + { + loadPage.Hide(); + }); + } + }) + { IsBackground = true }.Start(); + } + + } + + +} \ No newline at end of file -- Gitblit v1.8.0