using System;
|
using System.Collections.Generic;
|
using HDL_ON.DAL.Server;
|
using HDL_ON.Entity;
|
using HDL_ON.Stan;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON.UI
|
{
|
public class CacWeekHistoryPage : FrameLayout
|
{
|
|
CacWeekHistoryPage bodyView;
|
HorizontalScrolViewLayout dateHorView;
|
Function device;
|
/// <summary>
|
/// 数据显示类型
|
/// room_temp 温度
|
/// room_humidity 湿度
|
/// </summary>
|
string showType;
|
Dictionary<string, double> dataDic = new Dictionary<string, double>();
|
public CacWeekHistoryPage(Function device,string type)
|
{
|
bodyView = this;
|
this.device = device;
|
showType = type;
|
BackgroundColor = CSS_Color.BackgroundColor;
|
}
|
|
public void InitView()
|
{
|
if (showType == "room_temp")
|
{
|
new TopViewDiv(bodyView, Language.StringByID(StringId.Temp)).LoadTopView();
|
}
|
else
|
{
|
new TopViewDiv(bodyView, Language.StringByID(StringId.Humidity)).LoadTopView();
|
}
|
|
|
|
InitContentView();
|
}
|
|
|
private void InitContentView()
|
{
|
FrameLayout contentView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(80),
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealHeight(482),
|
BackgroundColor = CSS_Color.MainBackgroundColor,
|
Radius = (uint)Application.GetRealWidth(5)
|
};
|
bodyView.AddChidren(contentView);
|
|
Button btnTitle = new Button()
|
{
|
Height = Application.GetRealHeight(60),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
TextAlignment = TextAlignment.Center,
|
};
|
if (showType == "room_temp")
|
{
|
btnTitle.Text = "最近7天每天平均室内温度统计图";
|
}
|
else
|
{
|
btnTitle.Text = "最近7天每天平均室内湿度统计图";
|
}
|
contentView.AddChidren(btnTitle);
|
|
FrameLayout dataView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(39),
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(293),
|
Height = Application.GetRealHeight(345 + 30),
|
};
|
contentView.AddChidren(dataView);
|
|
Button btnUnit = new Button()
|
{
|
Height = Application.GetRealHeight(15 + 30),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = 0xFF43425D,
|
TextSize = 8,
|
};
|
if (showType == "room_temp")
|
{
|
btnUnit.Text = Language.StringByID(StringId.Uint) + ":℃";
|
}
|
else
|
{
|
btnUnit.Text = Language.StringByID(StringId.Uint) + "%";
|
}
|
dataView.AddChidren(btnUnit);
|
|
#if DEBUG
|
//dataDic.Add("0201", 49);
|
//dataDic.Add("0202", 20);
|
//dataDic.Add("0203", 10);
|
//dataDic.Add("0204", 49);
|
//dataDic.Add("0205", 20);
|
//dataDic.Add("0206", 20);
|
//dataDic.Add("0207", 48);
|
|
//dataDic.Add("0201", -20);
|
//dataDic.Add("0202", -20);
|
//dataDic.Add("0203", -20);
|
//dataDic.Add("0204", -48);
|
//dataDic.Add("0205", -20);
|
//dataDic.Add("0206", -20);
|
//dataDic.Add("0207", -20);
|
#endif
|
|
DataItemView dataShowView = new DataItemView("0",360);
|
//dataShowView.Height = Application.GetRealHeight(360);
|
dataShowView.Y = Application.GetRealHeight(30);
|
|
List<string> items = new List<string>()
|
{
|
"100","90","80","70","60","50","40","30","20","10","0"
|
};
|
if (showType == "room_temp")
|
{
|
items = new List<string>()
|
{
|
"50","40","30","20","10","0","-10","-20","-30","-40","-50"
|
};
|
}
|
int index = 0;
|
foreach (var item in items)
|
{
|
DataItemView dataItemView;
|
if (item == "0" )
|
{
|
dataItemView = dataShowView;
|
index++;
|
}
|
else
|
{
|
dataItemView = new DataItemView(item,30);
|
dataItemView.Y = ++index * Application.GetRealHeight(30) + Application.GetRealHeight(15);
|
}
|
dataItemView.InitView(showType == "room_temp");
|
dataView.AddChidren(dataItemView);
|
}
|
dateHorView = new HorizontalScrolViewLayout()
|
{
|
X = Application.GetRealWidth(48),
|
Y = dataView.Bottom,// - Application.GetRealHeight(19),
|
Width = Application.GetRealWidth(267),
|
Height = Application.GetRealHeight(26),
|
};
|
contentView.AddChidren(dateHorView);
|
|
Button btnTip = new Button()
|
{
|
Y = contentView.Bottom + Application.GetRealHeight(28),
|
Height = Application.GetRealHeight(20),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
|
TextAlignment = TextAlignment.Center,
|
Text = "*可通过点击柱形图查看当天24小时温度统计"
|
};
|
bodyView.AddChidren(btnTip);
|
|
|
new System.Threading.Thread(() =>
|
{
|
|
var revertObj = new HttpServerRequest().GetSensorHistory("week", device.deviceId, showType);
|
if (revertObj.Code == StateCode.SUCCESS)
|
{
|
var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
|
foreach (var reObj in revertData)
|
{
|
double value = 0;
|
try
|
{
|
value = Convert.ToDouble(reObj.fieldValue);
|
}
|
catch { }
|
dataDic.Add(reObj.time, value);
|
}
|
Application.RunOnMainThread(() =>
|
{
|
RefrshDataView(dataDic, dataShowView);
|
RefreshXtext();
|
});
|
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
void RefreshXtext()
|
{
|
dateHorView.RemoveAll();
|
|
foreach (var dic in dataDic)
|
{
|
FrameLayout dateView = new FrameLayout()
|
{
|
Width = Application.GetRealWidth(39),
|
Height = Application.GetRealHeight(26),
|
};
|
dateHorView.AddChidren(dateView);
|
|
Button btnLineh = new Button()
|
{
|
Width = 1,
|
Height = Application.GetRealHeight(4),
|
Gravity = Gravity.CenterHorizontal,
|
BackgroundColor = 0xFFDBDBDB
|
};
|
dateView.AddChidren(btnLineh);
|
|
Button btnDate = new Button()
|
{
|
Y = Application.GetRealHeight(12),
|
Height = Application.GetRealHeight(14),
|
TextColor = 0xFF43425D,
|
TextSize = 10,
|
Text = dic.Key,
|
};
|
try
|
{
|
string[] strs = dic.Key.Split(@"/");
|
btnDate.Text = strs[1] + "/" + strs[2];
|
}
|
catch { }
|
dateView.AddChidren(btnDate);
|
}
|
|
}
|
|
|
void RefrshDataView(Dictionary<string,double> dataDic, FrameLayout dataShowView)
|
{
|
int valueIndex = 0;
|
foreach (var data in dataDic)
|
{
|
ColumnarView cv = new ColumnarView(device.deviceId,showType, data.Key, data.Value);
|
cv.X = Application.GetRealWidth(valueIndex * 38 + 25);
|
cv.InitView();
|
dataShowView.AddChidren(cv);
|
cv.Clicker();
|
|
|
valueIndex++;
|
}
|
}
|
|
|
|
}
|
|
class DataItemView : FrameLayout
|
{
|
string value;
|
Button btnLine;
|
int height;
|
public DataItemView(string value,int height)
|
{
|
this.value = value;
|
Width = Application.GetRealWidth(293);
|
this.height = height;
|
Height = Application.GetRealHeight(height);
|
}
|
|
public void InitView(bool isTemp) {
|
|
Button btnValue = new Button()
|
{
|
Width = Application.GetRealWidth(18),
|
Height = Application.GetRealHeight(30),
|
TextAlignment = TextAlignment.CenterRight,
|
TextColor = 0xFF43425D,
|
TextSize = 8,
|
Text = value
|
};
|
AddChidren(btnValue);
|
|
btnLine = new Button()
|
{
|
X = Application.GetRealWidth(26),
|
Width = Application.GetRealWidth(267),
|
Height = 1,
|
BackgroundColor = CSS_Color.DividingLineColor,
|
};
|
if (isTemp)
|
{
|
btnLine.Gravity = Gravity.CenterVertical;
|
btnValue.Gravity = Gravity.CenterVertical;
|
}
|
else
|
{
|
if (height == 360)
|
{
|
btnValue.Y = Application.GetRealHeight(height - 45);
|
}
|
else
|
{
|
btnLine.Gravity = Gravity.CenterVertical;
|
}
|
btnLine.Y = Application.GetRealHeight(height - 30);
|
}
|
AddChidren(btnLine);
|
|
|
|
|
|
}
|
|
}
|
|
class ColumnarView : VerticalScrolViewLayout
|
{
|
string functionId;
|
string time;
|
string type;
|
double value;
|
string valueText;
|
/// <summary>
|
/// 方向:向上、向下
|
/// </summary>
|
bool isUpward;
|
Button btnValue;
|
Button btnValueText;
|
|
|
public ColumnarView(string functionId,string type, string key, double value)
|
{
|
this.functionId = functionId;
|
this.type = type;
|
time = key;
|
this.isUpward = value >= 0;
|
valueText = value.ToString();
|
if (isUpward)
|
{
|
this.value = value;
|
}
|
else
|
{
|
this.value = value * -1;
|
}
|
Width = Application.GetRealWidth(39);
|
Height = Application.GetRealHeight((int)(value * 3 + 30));
|
}
|
|
public void InitView()
|
{
|
int yValue = 0;
|
btnValue = new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Height = Application.GetRealHeight((int)(value * 3)),
|
Width = Application.GetRealWidth(16),
|
BackgroundColor = 0xFFFF9D54,
|
};
|
|
btnValueText = new Button()
|
{
|
Height = Application.GetRealHeight(30),
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextColor = 0xFF43425D,
|
Text = valueText,
|
};
|
if(type == "room_temp")
|
{
|
btnValueText.Text += "℃";
|
if (isUpward)
|
{
|
yValue = (int)(150 - value * 3);
|
yValue = yValue > 0 ? yValue : 0;
|
Y = Application.GetRealHeight(yValue+1);
|
AddChidren(btnValueText);
|
AddChidren(btnValue);
|
}
|
else
|
{
|
Y = Application.GetRealHeight(180);
|
AddChidren(btnValue);
|
AddChidren(btnValueText);
|
}
|
}
|
else
|
{
|
yValue = (int)(360 -30- 30 - value * 3);
|
Y = Application.GetRealHeight(yValue+1);
|
AddChidren(btnValueText);
|
AddChidren(btnValue);
|
btnValueText.Text += "%";
|
}
|
}
|
|
public void Clicker()
|
{
|
btnValue.MouseUpEventHandler = (sender, e) =>
|
{
|
var page = new CacDayHistoryPage(functionId,type, time);
|
MainPage.BasePageView.AddChidren(page);
|
page.InitView();
|
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
|
};
|
btnValueText.MouseUpEventHandler = (sender, e) =>
|
{
|
var page = new CacDayHistoryPage(functionId,type, time);
|
MainPage.BasePageView.AddChidren(page);
|
page.InitView();
|
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
|
};
|
}
|
}
|
}
|