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 AirSwitchP3EnergyPage : FrameLayout
{
static AirSwitchP3EnergyPage bodyView;
///
/// 总功耗-饼图
///
MyEchartsViewOn myEchartsView_Pie;
///
/// 曲线图数据string
///
EchartsOption_BrokenLine brokenLine;
///
/// 插查询的能源列表
///
List queryList = new List();
///
/// 查询条件
/// hour、week、month
///
string curQueryType = "hour";
///
/// 能源列表区域
///
FrameLayout energyListView;
///
/// 历史数据图表
///
MyEchartsViewOn myEchartsView_Line;
//5C62FE
Function device;
///
/// 主页
///
public AirSwitchP3EnergyPage(Function function)
{
bodyView = this;
device = function;
}
///
///
///
public void LoadPage()
{
new TopViewDiv(bodyView, Language.StringByID(StringId.EnergyMonitoring)).LoadTopView(0xFFF7F7F7);
bodyView.BackgroundColor = 0xFFF5F7FA;
var contentView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(667-64),
BackgroundColor = 0xFFF5F7FA,
};
bodyView.AddChidren(contentView);
contentView.AddChidren(new Button()
{
Height = Application.GetRealHeight(12),
});
brokenLine = new EchartsOption_BrokenLine();
#region 选择数据日期范围
var showDataTypeView = new FrameLayout()
{
X = Application.GetRealWidth(143),
Y = Application.GetRealHeight(12),
Width = Application.GetRealWidth(216),
Height = Application.GetRealHeight(27),
//BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png",
};
contentView.AddChidren(showDataTypeView);
var btnShowHistroyData_Day = new Button()
{
Width = Application.GetRealWidth(54),
Height = Application.GetRealHeight(27),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.PromptingColor1,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
IsSelected = true,
TextID = StringId.day,
SelectedBackgroundColor = 0x1F5C62FE,
BackgroundColor = 0x1F5C62FE,
BorderColor = CSS_Color.MainColor,
BorderWidth = 2,
};
showDataTypeView.AddChidren(btnShowHistroyData_Day);
btnShowHistroyData_Day.SetCornerWithSameRadius((uint)Application.GetRealHeight(6), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerBottomLeft);
var btnShowHistroyData_Month = new Button()
{
X = Application.GetRealWidth(54),
Width = Application.GetRealWidth(54),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.PromptingColor1,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
TextID = StringId.month,
BorderWidth = 1,
BorderColor = CSS_Color.PromptingColor1,
};
showDataTypeView.AddChidren(btnShowHistroyData_Month);
var btnShowHistroyData_Year = new Button()
{
X = Application.GetRealWidth(54 * 2),
Width = Application.GetRealWidth(54),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.PromptingColor1,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
TextID = StringId.Years,
BorderWidth = 1,
BorderColor = CSS_Color.PromptingColor1,
};
showDataTypeView.AddChidren(btnShowHistroyData_Year);
var btnShowHistroyData_Total = new Button()
{
X = Application.GetRealWidth(54 * 3),
Width = Application.GetRealWidth(54),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.PromptingColor1,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
TextID = StringId.Total,
BorderWidth = 1,
BorderColor = CSS_Color.PromptingColor1,
};
showDataTypeView.AddChidren(btnShowHistroyData_Total);
btnShowHistroyData_Day.MouseUpEventHandler = (sender, e) =>
{
//showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg1.png";
//btnShowHistroyData_Day.IsSelected = true;
//btnShowHistroyData_Year.IsSelected = false;
//btnShowHistroyData_Month.IsSelected = false;
//curQueryType = "hour";
//brokenLine.YvalueText = "";
//foreach (var enery in queryList)
//{
// LoadMothed_GetHistoryData(enery, false);
//}
};
btnShowHistroyData_Month.MouseUpEventHandler = (sender, e) =>
{
//showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg2.png";
//btnShowHistroyData_Day.IsSelected = false;
//btnShowHistroyData_Year.IsSelected = false;
//btnShowHistroyData_Month.IsSelected = true;
//curQueryType = "week";
//brokenLine.YvalueText = "";
//foreach (var enery in queryList)
//{
// LoadMothed_GetHistoryData(enery, false);
//}
};
btnShowHistroyData_Year.MouseUpEventHandler = (sender, e) =>
{
//showDataTypeView.BackgroundImagePath = "FunctionIcon/EnvironmentalScience/SensorHistoryBg3.png";
//btnShowHistroyData_Day.IsSelected = false;
//btnShowHistroyData_Year.IsSelected = true;
//btnShowHistroyData_Month.IsSelected = false;
//curQueryType = "month";
//brokenLine.YvalueText = "";
//foreach (var enery in queryList)
//{
// LoadMothed_GetHistoryData(enery, false);
//}
};
#endregion
contentView.AddChidren(new Button()
{
Height = Application.GetRealHeight(12),
});
var historyDataView = new FrameLayout()
{
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(343),
Height = Application.GetRealWidth(330),
};
contentView.AddChidren(historyDataView);
myEchartsView_Line = new MyEchartsViewOn()
{
Y = Application.GetRealWidth(10),
Height = Application.GetRealWidth(280),
};
historyDataView.AddChidren(myEchartsView_Line);
//EnergyRow(energy, energyListView, index);
new System.Threading.Thread(() =>
{
Control.Ins.SendReadCommand(device);
})
{ IsBackground = true }.Start();
}
///
/// 读取历史数据
///
void LoadMothed_GetHistoryData()
{
var loadPage = new Loading()
{
LodingBackgroundColor = 0x88888888,
};
bodyView.AddChidren(loadPage);
new System.Threading.Thread(() =>
{
try
{
Application.RunOnMainThread(() =>
{
loadPage.Start(Language.StringByID(StringId.PleaseWait));
});
var sensorType = device.spk.Split(".")[1];
var revertObj = new HttpServerRequest().GetSensorHistory(curQueryType, device.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 (device.GetAttribute("ydata") == null)
{
device.attributes.Add(new FunctionAttributes() { key = "ydata" });
}
device.SetAttrState("ydata", brokenLine.InitYdataText(device.name, revertData, device.GetAttrState("color")) + ",");
}
}
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();
}
}
}