#include "Frm07.h"

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

Frm07::~Frm07() {
}

void Frm07::onInit() {

}

void Frm07::createParts() {
	setMainArg(0, 0, 1024, 420);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- Panel : wMPanel4                     -----------------------------*/
	wMPanel4 = new STTPanel(p_rt, this, "wMPanel4");
	wMPanel4->setMainArg(729, 0, 294, 420, 0);
	wMPanel4->setMainStyle(0, 0x8080c0, 0xffffff, GradDir::NONE, 255, 1, 0xc0c0c0);

	/*----------------------------- Button : wMButton7                   -----------------------------*/
	wMButton7 = new STTButton(p_rt, wMPanel4, "wMButton7", 0);
	wMButton7->setMainArg(62, 219, 172, 41, false);
	wMButton7->setPressedArg("查询", 0x0, "文泉驿微米黑", 20, 0);
	wMButton7->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton7->setReleasedArg("查询", 0x0, "文泉驿微米黑", 20, 0);
	wMButton7->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton7->onEventHandler(Event::CLICKED, this, (EHandler) &Frm07::wMButton7_clk_cb);

	/*----------------------------- Button : wMButton8                   -----------------------------*/
	wMButton8 = new STTButton(p_rt, wMPanel4, "wMButton8", 0);
	wMButton8->setMainArg(62, 354, 172, 43, false);
	wMButton8->setPressedArg("导出", 0x0, "文泉驿微米黑", 20, 0);
	wMButton8->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton8->setReleasedArg("导出", 0x0, "文泉驿微米黑", 20, 0);
	wMButton8->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton8->onEventHandler(Event::CLICKED, this, (EHandler) &Frm07::wMButton8_clk_cb);

	/*----------------------------- Button : wMButton9                   -----------------------------*/
	wMButton9 = new STTButton(p_rt, wMPanel4, "wMButton9", 0);
	wMButton9->setMainArg(62, 285, 172, 46, false);
	wMButton9->setPressedArg("清除记录", 0x0, "文泉驿微米黑", 20, 0);
	wMButton9->setPressedStyle(8, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton9->setReleasedArg("清除记录", 0x0, "文泉驿微米黑", 20, 0);
	wMButton9->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton9->onEventHandler(Event::CLICKED, this, (EHandler) &Frm07::wMButton9_clk_cb);

	/*----------------------------- TextNumber : wMTextNumber1           -----------------------------*/
	wMTextNumber1 = new STTTextArea(p_rt, wMPanel4, "wMTextNumber1");
	wMTextNumber1->setMainArg(38, 118, 217, 55, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMTextNumber1->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 17, 0, 4, 4, 255);
	wMTextNumber1->setPlaceholderText("")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::DIGITAL);
	wMTextNumber1->setFont(0x0, 16, "文泉驿微米黑", 0);
	wMTextNumber1->bindData(_V("报警记录结束时间"));

	/*----------------------------- TextNumber : wMTextNumber2           -----------------------------*/
	wMTextNumber2 = new STTTextArea(p_rt, wMPanel4, "wMTextNumber2");
	wMTextNumber2->setMainArg(40, 18, 217, 55, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMTextNumber2->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 17, 0, 4, 4, 255);
	wMTextNumber2->setPlaceholderText("")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::DIGITAL);
	wMTextNumber2->setFont(0x0, 16, "文泉驿微米黑", 0);
	wMTextNumber2->bindData(_V("报警记录起始时间"));

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

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

	/*----------------------------- EventTable : wMEventTable2           -----------------------------*/
	wMEventTable2 = new STTTable(p_rt, this, "wMEventTable2");
	wMEventTable2->setMainArg(0, 0, 730, 420, "LID,序号,80;LTIME,时间,157;ENME,事件名,169;ACTN,动作,90;MEMO,说明,104;EXT1,持续时长,118", 10, false, 2);
	wMEventTable2->setHeadCellStyle(0xf0f0f0, 0xffffff, 0, 1, 0xd0d0d0, 5, 5, 0, 0, 0x0, 16, "文泉驿微米黑", 0);
	wMEventTable2->setSelCellStyle(0x1a2b3, 0xffffff, 0, 1, 0xd0d0d0, 5, 5, 0, 0, 0x0, 16, "文泉驿微米黑", 0);
	wMEventTable2->setDataCellStyle(0xffffff, 0xffffff, 0, 1, 0xd0d0d0, 5, 5, 0, 0, 0x0, 16, "文泉驿微米黑", 0);
	wMEventTable2->setDataSourceOfEvent("", "", false, 0, 99, 15, true);
	wMEventTable2->bindPageCnt(vm->get("报警记录关联总页码"));
	wMEventTable2->bindPageIndex(vm->get("报警记录关联页码"));
	wMEventTable2->setDateMode(2);

	/*----------------------------- Button : wMButton10                  -----------------------------*/
	wMButton10 = new STTButton(p_rt, this, "wMButton10", 0);
	wMButton10->setMainArg(22, 347, 129, 40, false);
	wMButton10->setPressedArg("最前页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton10->setPressedStyle(8, 255, 0x808080, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton10->setReleasedArg("最前页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton10->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton10->onEventHandler(Event::CLICKED, this, (EHandler) &Frm07::wMButton10_clk_cb);

	/*----------------------------- Button : wMButton11                  -----------------------------*/
	wMButton11 = new STTButton(p_rt, this, "wMButton11", 0);
	wMButton11->setMainArg(207, 347, 129, 40, false);
	wMButton11->setPressedArg("前一页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton11->setPressedStyle(8, 255, 0x808080, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton11->setReleasedArg("前一页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton11->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton11->onEventHandler(Event::CLICKED, this, (EHandler) &Frm07::wMButton11_clk_cb);

	/*----------------------------- Button : wMButton12                  -----------------------------*/
	wMButton12 = new STTButton(p_rt, this, "wMButton12", 0);
	wMButton12->setMainArg(403, 347, 129, 40, false);
	wMButton12->setPressedArg("后一页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton12->setPressedStyle(8, 255, 0x808080, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton12->setReleasedArg("后一页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton12->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton12->onEventHandler(Event::CLICKED, this, (EHandler) &Frm07::wMButton12_clk_cb);

	/*----------------------------- Button : wMButton13                  -----------------------------*/
	wMButton13 = new STTButton(p_rt, this, "wMButton13", 0);
	wMButton13->setMainArg(590, 347, 129, 40, false);
	wMButton13->setPressedArg("最后页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton13->setPressedStyle(8, 255, 0x808080, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton13->setReleasedArg("最后页", 0x0, "文泉驿微米黑", 16, 0);
	wMButton13->setReleasedStyle(5, 255, 0xebebeb, 0x999999, 1, 1, 0x999999, 1, 0xebebeb);
	wMButton13->onEventHandler(Event::CLICKED, this, (EHandler) &Frm07::wMButton13_clk_cb);

	/*called after widget created.*/

	return; //createParts END
}

void Frm07::onLoad() {

}

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

void Frm07::onDispose() {

}

void Frm07::wMButton10_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton10（最前页）的点击事件*/
	wMEventTable2->navFirst();
}

void Frm07::wMButton11_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton11（前一页）的点击事件*/
	wMEventTable2->navBack();
}

void Frm07::wMButton12_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton12（后一页）的点击事件*/
	wMEventTable2->navNext();
}

void Frm07::wMButton13_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton13（最后页）的点击事件*/
	wMEventTable2->navLast();
}

// 从这里开始下面的三个方法为报警时间的方法 并非为报警记录的方法
void Frm07::wMButton8_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton8（导出）的点击事件*/
	int startDate=0,endDate=0;
	vm->getInt("报警记录起始时间", startDate);
	vm->getInt("报警记录结束时间", endDate);

	// 这里选择导出全部
	EventMgr::getInstance(p_rt)->exportCSV();
}

void Frm07::wMButton9_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton9（清除记录）的点击事件*/
	int startDate=0,endDate=0;
	vm->getInt("报警记录起始时间", startDate);
	vm->getInt("报警记录结束时间", endDate);

	if (startDate == 0 || endDate == 0){
		EventMgr::getInstance(p_rt)->deleteDB();
	}else{
		// 删除指定日期数据
		EventMgr::getInstance(p_rt)->deleteDB(startDate, endDate);
	}
	TTableView* tv = (TTableView*)wMEventTable2->getData();
    tv->drawData(true);
}

void Frm07::wMButton7_clk_cb(uint16_t code, LvEvent e) {
	/*wMButton7（查询）的点击事件*/
	int startDate=0,endDate=0;
	vm->getInt("报警记录起始时间", startDate);
	vm->getInt("报警记录结束时间", endDate);
	wMEventTable2->setDataSourceOfEvent(to_string(startDate), to_string(endDate), false, 0, 99, 15, false);
}
