#include "Frm13.h"

Frm13::Frm13(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm13::~Frm13() {
}

void Frm13::onInit() {

}

void Frm13::createParts() {
	setMainArg(0, 0, 800, 420);
	setMainStyle(0, 0xffffff, 0xffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- HistoryTrend : wMHistoryTrend1       -----------------------------*/
	wMHistoryTrend1 = new STTHistoryTrend(p_rt, this, "wMHistoryTrend1");
	wMHistoryTrend1->setMainArg(0, 33, 799, 268, 1, 301, 4, 5, 12, "文泉驿微米黑", 0x0, 0);
	wMHistoryTrend1->setMainStyle(0, 0xffffff, 0xffffff, 0, 0, 0xc0c0c0, 0, 0x0, 50, 50, 20, 50);
	wMHistoryTrend1->setFractionLen(0, 0, 0);
	wMHistoryTrend1->setXAxis(0, 0, 7, 1, true, "\n\n\n\n\n\n\n");
	wMHistoryTrend1->setYAxis(0, 0, 6, 1, true, "100\n80\n60\n40\n20\n0", 0, 100);
	wMHistoryTrend1->setY2Axis(0, 0, 2, 1, true, "\n", 0, 100);
	wMHistoryTrend1->setChartBgStyle(0, 0xf0f0f0, 0xffffff, 0, 1, 0xc0c0c0, 2, 2, 1, 0xc0c0c0, 5, 0);
	wMHistoryTrend1->setTickStyle(1, 0xc0c0c0);
	wMHistoryTrend1->hideSeries(wMHistoryTrend1->setAddSeries(0, 0x808080, NULL, 0, 100), true);
	wMHistoryTrend1->hideSeries(wMHistoryTrend1->setAddSeries(0, 0xff, NULL, 0, 100), true);
	wMHistoryTrend1->hideSeries(wMHistoryTrend1->setAddSeries(0, 0xffff, NULL, 0, 100), true);
	wMHistoryTrend1->hideSeries(wMHistoryTrend1->setAddSeries(0, 0x808080, NULL, 0, 100), false);
	wMHistoryTrend1->hideSeries(wMHistoryTrend1->setAddSeries(0, 0xff00, NULL, 0, 100), true);
	wMHistoryTrend1->hideSeries(wMHistoryTrend1->setAddSeries(0, 0xffc400, NULL, 0, 100), true);
	wMHistoryTrend1->hideSeries(wMHistoryTrend1->setAddSeries(0, 0xff0000, NULL, 0, 100), true);
	wMHistoryTrend1->setDataSource("1", "", false, "样气压力;载气压力;CO2浓度;可燃气体浓度;进样压力;环境温度;环境湿度", "{\"m\":\"0\",\"mv\":\"\",\"xu\":\"63\",\"xs\":\"12\",\"xsu\":\"2\",\"xsv\":\"\",\"y2n\":\"\",\"y2m\":\"\"}");
	wMHistoryTrend1->bindHistoryDate(vm->get("CO2历史曲线日期"));

	/*----------------------------- Button : wMButton4                   -----------------------------*/
	wMButton4 = new STTButton(p_rt, this, "wMButton4", 0);
	wMButton4->setMainArg(225, 306, 129, 40, false);
	wMButton4->setPressedArg("左移", 0x0, "文泉驿微米黑", 16, 0);
	wMButton4->setPressedStyle(8, 255, 0x808080, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton4->setReleasedArg("左移", 0x0, "文泉驿微米黑", 16, 0);
	wMButton4->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton4->onEventHandler(Event::CLICKED, this, (EHandler) &Frm13::wMButton4_clk_cb);

	/*----------------------------- Button : wMButton5                   -----------------------------*/
	wMButton5 = new STTButton(p_rt, this, "wMButton5", 0);
	wMButton5->setMainArg(428, 307, 129, 40, false);
	wMButton5->setPressedArg("右移", 0x0, "文泉驿微米黑", 16, 0);
	wMButton5->setPressedStyle(8, 255, 0x808080, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton5->setReleasedArg("右移", 0x0, "文泉驿微米黑", 16, 0);
	wMButton5->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton5->onEventHandler(Event::CLICKED, this, (EHandler) &Frm13::wMButton5_clk_cb);

	/*----------------------------- TextNumber : wMTextNumber3           -----------------------------*/
	wMTextNumber3 = new STTTextArea(p_rt, this, "wMTextNumber3");
	wMTextNumber3->setMainArg(109, 363, 203, 41, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMTextNumber3->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 10, 0, 4, 4, 255);
	wMTextNumber3->setPlaceholderText("")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::DIGITAL);
	wMTextNumber3->setFont(0x0, 16, "文泉驿微米黑", 0);
	wMTextNumber3->bindData(_V("CO2历史曲线起始时间"));

	/*----------------------------- Label : wMLabel1                     -----------------------------*/
	wMLabel1 = new STTLabel(p_rt, this, "wMLabel1");
	wMLabel1->setMainArg(8, 364, 102, 39, "起始时间", TextAlign::LEFT, LabelLongMode::CLIP, 30);
	wMLabel1->setFonts(0x0, 25, "文泉驿微米黑", 0);
	wMLabel1->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel1->setFormatText(TextAlign::LEFT, LabelLongMode::CLIP, 30);

	/*----------------------------- TextNumber : wMTextNumber4           -----------------------------*/
	wMTextNumber4 = new STTTextArea(p_rt, this, "wMTextNumber4");
	wMTextNumber4->setMainArg(422, 363, 194, 41, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMTextNumber4->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 10, 0, 4, 4, 255);
	wMTextNumber4->setPlaceholderText("")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::DIGITAL);
	wMTextNumber4->setFont(0x0, 16, "文泉驿微米黑", 0);
	wMTextNumber4->bindData(_V("CO2历史曲线结束时间"));

	/*----------------------------- Label : wMLabel2                     -----------------------------*/
	wMLabel2 = new STTLabel(p_rt, this, "wMLabel2");
	wMLabel2->setMainArg(321, 364, 102, 39, "结束时间", TextAlign::LEFT, LabelLongMode::CLIP, 30);
	wMLabel2->setFonts(0x0, 25, "文泉驿微米黑", 0);
	wMLabel2->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel2->setFormatText(TextAlign::LEFT, LabelLongMode::CLIP, 30);

	/*----------------------------- Button : wMButton7                   -----------------------------*/
	wMButton7 = new STTButton(p_rt, this, "wMButton7", 0);
	wMButton7->setMainArg(632, 364, 129, 40, false);
	wMButton7->setPressedArg("查询", 0x0, "文泉驿微米黑", 16, 0);
	wMButton7->setPressedStyle(8, 255, 0x808080, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton7->setReleasedArg("查询", 0x0, "文泉驿微米黑", 16, 0);
	wMButton7->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton7->onEventHandler(Event::CLICKED, this, (EHandler) &Frm13::wMButton7_clk_cb);

	/*----------------------------- Label : wMLabel3                     -----------------------------*/
	wMLabel3 = new STTLabel(p_rt, this, "wMLabel3");
	wMLabel3->setMainArg(323, 8, 154, 38, "CO2历史曲线", TextAlign::LEFT, LabelLongMode::CLIP, 30);
	wMLabel3->setFonts(0x0, 25, "文泉驿微米黑", 0);
	wMLabel3->setMainStyle(0, 0xffffff, 0xffffff, GradDir::NONE, 0, 0x0, 0);
	wMLabel3->setFormatText(TextAlign::LEFT, LabelLongMode::CLIP, 30);

	/*called after widget created.*/

	return; //createParts END
}

void Frm13::onLoad() {

}

bool Frm13::onClosing() {
	return true;
}

void Frm13::onDispose() {

}

void Frm13::wMButton4_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton4（左移）的点击事件*/
	wMHistoryTrend1->navBack();
}

void Frm13::wMButton5_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton5（右移）的点击事件*/
	wMHistoryTrend1->navNext();
}

void Frm13::wMButton7_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton7（查询）的点击事件*/
	// 需要对日期进行限制。。
	int startDate=0,endDate=0;
	vm->getInt("CO2历史曲线起始时间", startDate);
	vm->getInt("CO2历史曲线结束时间", endDate);
	// 间隔的时间长度
	int internval = endDate-startDate;
	string start = to_string(startDate);
	// 获取起始日期的年 月 日
    int year = std::stoi(start.substr(0, 4));
    int month = std::stoi(start.substr(4, 2));
    int day = std::stoi(start.substr(6, 2));

	wMHistoryTrend1->navTo(year, month, day, 0, 0, 0, true, internval);
}
