#include "QWStatistics.h" #include "app/Application.h" #include "app/AppData.h" #include "app/Station.h" #include "database/DAO.h" QWStatistics::QWStatistics(QWidget* parent) : MyWidget(parent) { comboxStation = make_shared(this); comboxStation->setGeometry(10, 10, 200, 28); comboxStation->setStyleSheet(QSS_BTN_COMBOX.c_str()); QStringList listStation; listStation << "所有"; for (auto item: Application::data().mapStation) { listStation << item.second->name.c_str(); } comboxStation->addItems(listStation); QStringList headerTextList; headerTextList << "日期" << "日充电\n电量" << "日放电\n电量" << "日充电\n电量(尖)" << "日充电\n电量(峰)" << "日充电\n电量(平)" << "日充电\n电量(谷)" << "日放电\n电量(尖)" << "日放电\n电量(峰)" << "日放电\n电量(平)" << "日放电\n电量(谷)" << "日充电\n费用" << "日放电\n费用" << "日收益" ; //<< "总充电\n电量" << "总放电\n电量" //<< "总充电\n电量(尖)" << "总充电\n电量(峰)" << "总充电\n电量(平)" << "总充电\n电量(谷)" //<< "总放电\n电量(尖)" << "总放电\n电量(峰)" << "总放电\n电量(平)" << "总放电\n电量(谷)"; table = MyQUI::TableWidget(this, 10, 50, 1190, 800); table->horizontalHeader()->setDefaultSectionSize(80); // 设置为水平表头 table->setColumnCount(headerTextList.size()); table->setHorizontalHeaderLabels(headerTextList); table->setColumnWidth(0, 120); btnRefresh = make_shared("刷新", this); btnRefresh->setGeometry(220, 10, 60, 30); //btnRefresh->setStyleSheet(); connect(comboxStation.get(), &QComboBox::currentIndexChanged, this, &QWStatistics::onCurrentIndexChanged); connect(btnRefresh.get(), &QPushButton::clicked, this, &QWStatistics::onCurrentIndexChanged); } QWStatistics::~QWStatistics() { } void QWStatistics::onCurrentIndexChanged(int index) { auto& appdata = Application::data(); string stationName = comboxStation->itemText(index).toStdString(); if (stationName == "所有") { } else { auto station = appdata.getStationByName(stationName); if (station) { string sql = "SELECT * FROM stat_total_day std WHERE station_id='" + std::to_string(station->stationId) + "' ORDER BY dt DESC LIMIT 100;"; vector result; DAO::exec(NULL, sql, result); table->clearContents(); table->setRowCount(0); for (int i = 0; i