#pragma execution_character_set("utf-8")
#include "AdminWindow.h"
#include "stdafx.h"
#include "login.h"
AdminWindow::AdminWindow(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
setFixedSize(1500, 900);
this->setWindowTitle("机房预约管理系统(管理员)");
getType();
setMainPage();
ui.ordernumBox->setValidator(new QIntValidator(0, 100, this));
ui.timetableFrame->setStyleSheet("QFrame{ background: #eaeaea;border-radius: 12px;}");
ui.userFrame->setStyleSheet("QFrame{ background: #eaeaea;border-radius: 12px;}");
ui.frame_2->setStyleSheet("QFrame{ background: #eaeaea;border-radius: 12px;}");
ui.myappointFrame->setStyleSheet("QFrame{ background: #eaeaea;border-radius: 12px;}");
ui.doappointFrame->setStyleSheet("QFrame{ background: #eaeaea;border-radius: 12px;}");
timer->setInterval(5000);
//ADD();
connect(ui.logoutButton, &QPushButton::clicked, this, &AdminWindow::on_logout_clicked);
connect(ui.modifyButton, &QPushButton::clicked, this, &AdminWindow::on_modify_clicked);
connect(ui.messsubmitButton_2, &QPushButton::clicked, this, &AdminWindow::on_messsubmit_clicked);
connect(ui.passsubmitButton_2, &QPushButton::clicked, this, &AdminWindow::on_passsubmit_clicked);
connect(ui.userreturnButton_2, &QPushButton::clicked, this, &AdminWindow::on_userreturn_clicked);
connect(ui.inquiryButton, &QPushButton::clicked, this, &AdminWindow::on_inquiry_clicked);
connect(ui.permchangeButton, &QPushButton::clicked, this, &AdminWindow::on_permchange_clicked);
connect(ui.labnumberBox, static_cast<void (QComboBox::*)(int index)> (&QComboBox::currentIndexChanged), this, &AdminWindow::on_table_changed);
connect(ui.weeknumberBox, static_cast<void (QComboBox::*)(int index)> (&QComboBox::currentIndexChanged), this, &AdminWindow::on_table_changed);
connect(ui.startweekBox, static_cast<void (QComboBox::*)(int index)> (&QComboBox::currentIndexChanged), this, &AdminWindow::on_startweek_changed);
connect(ui.yesButton, &QPushButton::clicked, this, &AdminWindow::on_submit_clicked);
connect(ui.noButton, &QPushButton::clicked, this, &AdminWindow::on_clear_clicked);
connect(timer, &QTimer::timeout, this, &AdminWindow::timer_handle);
timer->start();
}
AdminWindow::~AdminWindow()
{
timer->stop();
}
void AdminWindow::setMainPage() {
ui.stackedWidget->setCurrentWidget(ui.mainPage);
ui.usernameLine->setText(QString::fromStdString(userToken->getUsername()));
ui.phoneLine->setText(QString::fromStdString(userToken->getPhone()));
ui.emailLine->setText(QString::fromStdString(userToken->getEmail()));
ui.premissionLine->setText(QString::number(userToken->getPermission()));
ui.tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//平均分配列宽
ui.tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);//平均分配行宽
ui.tableWidget->setShowGrid(false);
ui.tableWidget->setFocusPolicy(Qt::NoFocus);
ui.tableWidget->verticalHeader()->setMinimumSectionSize(60);
ui.appointTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//平均分配列宽
//ui.appointTable->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);//平均分配行宽
ui.appointTable->verticalHeader()->setDefaultSectionSize(60);
ui.appointTable->setShowGrid(false);
ui.appointTable->setFocusPolicy(Qt::NoFocus);
ui.labTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//平均分配列宽
ui.labTable->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);//平均分配行宽
ui.labTable->verticalHeader()->setMinimumSectionSize(60);
ui.labTable->setShowGrid(false);
ui.labTable->setFocusPolicy(Qt::NoFocus);
appointView();
labView();
initBoxs();
timer->start();
//showorder();
}
void AdminWindow::setUserPage() {
ui.stackedWidget->setCurrentWidget(ui.userPage);
ui.unusernameLine_2->setText(QString::fromStdString(userToken->getUsername()));
ui.newemailLine_2->setText(QString::fromStdString(userToken->getEmail()));
ui.newphoneLine_2->setText(QString::fromStdString(userToken->getPhone()));
ui.unpremisionLine_2->setText(QString::number(userToken->getPermission()));
timer->stop();
}
void AdminWindow::getType() {
char query[100];
sprintf(query, "select type_id from type_info where user_id=%d", userToken->getID());
ResultSet* res = connSQL->getMessage(query);
int count = 1;
for (; res->next(); count++) {
this->my_type[count] = res->getInt(1);
}
this->my_type[0] = count - 1;
}
void AdminWindow::appointView() {
char query[550];
ResultSet* res;
QPushButton* agree, * disagree;
QWidget* tmp_widget;
QHBoxLayout* tmp_layout;
ui.appointTable->clearContents();
ui.appointTable->setRowCount(0);
int row = 0;
int sta[3] = { 1,3,2 };
for (int i = 0; i < 3; i++) {
for (int count = 1; count <= this->my_type[0]; count++) {
sprintf(query, "select users.user_name,order_info.startweek,order_info.endweek,date_info.date_str,time_info.time_str,room_info.room_name,state_info.state_str,order_info.order_id,order_amount from order_info,date_info,room_info,state_info,time_info,users where order_info.order_room=room_info.room_id and order_info.state_id=state_info.state_id and order_info.order_date=date_info.date_id and order_info.order_time=time_info.time_id and order_info.user_id=users.user_id and room_info.room_type=%d and order_info.state_id=%d",this->my_type[count],sta[i]);
res = connSQL->getMessage(query);
for (; res->next(); row++) {
this->appoint_list[row] = res->getInt(8);
this->state_list[row] = sta[i];
ui.appointTable->insertRow(row);
ui.appointTable->setItem(row, 0, new QTableWidgetItem(QString::fromStdString(res->getString(1).c_str())));
ui.appointTable->item(row, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//元素居中
ui.appointTable->setItem(row, 1, new QTableWidgetItem(QString::number(res->getInt(2))));
ui.appointTable->item(row, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//元素居中
ui.appointTable->setItem(row, 2, new QTableWidgetItem(QString::number(res->getInt(3))));
ui.appointTable->item(row, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui.appointTable->setItem(row, 3, new QTableWidgetItem(QString::fromStdString(res->getString(4).c_str())));
ui.appointTable->item(row, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui.appointTable->setItem(row, 4, new QTableWidgetItem(QString::fromStdString(res->getString(5).c_str())));
ui.appointTable->item(row, 4)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui.appointTable->setItem(row, 5, new QTableWidgetItem(QString::number(res->getInt(9))));
ui.appointTable->item(row, 5)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui.appointTable->setItem(row, 6, new QTableWidgetItem(QString::fromStdString(res->getString(6).c_str())));
ui.appointTable->item(row, 6)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui.appointTable->setItem(row, 7, new QTableWidgetItem(QString::fromStdString(res->getString(7).c_str())));
ui.appointTable->item(row, 7)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
agree = new QPushButton();
//agree->setText("同意");
agree->setIcon(QIcon::fromTheme("folder", QIcon(":/login/select-bold.png")));
agree->setIconSize(QSize(24, 24));
agree->setStyleSheet("QPushButton{min-width:32px;max-width:32px;min-height:32px;max-height:32px;border: none; background-color:transparent;}QPushButton:hover{background-color:#dcdcdc;}QPushButton:pressed{background-color:#c5c5c5;}");
agree->setFixedSize(48, 48);
if (sta[i] == 3) {
agree->setEnabled(false);
}
disagree = new QPushButton();
//disagree->setText("拒绝");
disagree->setIcon(QIcon::fromTheme("folder", QIcon(":/login/close-bold.png")));
disagree->setIconSize(QSize(24, 24));
disagree->setStyleSheet("QPushButton{min-width:32px;max-width:32px;min-height:32px;max-height:32px;border: none; background-color:transparent;}QPushButton:hover{