using 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;
///
/// 顶部区域
///
FrameLayout generalTableView;
///
/// 实时功耗
///
Button btnRealTimeData;
///
/// 实时功耗单位
///
Button btnTotalValueUint;
///
/// 总功耗
///
TextButton btnTotalValue;
///
/// 历史数据区域
///
FrameLayout diagramView;
///
/// 曲线图数据string
///
EchartsOption_BrokenLine brokenLine;
///
/// 插查询的能源列表
///
List queryList = new List();
///
/// 查询条件
/// hour、week、month
///
string curQueryType = "hour";
///
/// 能源列表区域
///
FrameLayout energyListView;
///
/// 历史数据图表
///
MyEchartsViewOn myEchartsView_Line;
Function function;
///
/// 主页
///
public SocketPage_CumulativePowerConsumption(Function function)
{
this.function = function;
bodyView = this;
}
///
///
///
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‧h",
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();
}
///
/// 加载曲线图
///
///
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();
}
///
/// 读取历史数据
///
void LoadMothed_GetHistoryData()
{
var loadPage = new Loading()
{
LodingBackgroundColor = 0x88888888,
};
diagramView.AddChidren(loadPage);
//var d = new List ();
//var dd = new List();
//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>(revertObj.Data.ToString());
List vs = new List();
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();
}
}
}