123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- #include "clOnlineHomework.h"
- #include "ui_clOnlineHomework.h"
- #include "CAppInfo.h"
- #include "clOperation.h"
- #include "awMsgBox.h"
- #include <QScrollBar>
- #include <QDateTime>
- clOnlineHomework::clOnlineHomework(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::clOnlineHomework)
- {
- ui->setupUi(this);
- setStyleSheet(g_appInfoPtr->m_sQssStr);
- qRegisterMetaType<CQueryHomeworkList>("CQueryHomeworkList");
- connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryHomeworkList, this, &clOnlineHomework::onQueryHomeworkList);
- m_pObjectiveScoreTimer = std::make_shared<QTimer>();
- m_pObjectiveScoreTimer->setInterval(200);
- connect(m_pObjectiveScoreTimer.get(), &QTimer::timeout, this, [&]() {
- m_pObjectiveScoreTimer->stop();
- if (m_pObjectiveScore != nullptr)
- {
- m_pObjectiveScore.reset();
- }
- });
- }
- clOnlineHomework::~clOnlineHomework()
- {
- delete ui;
- }
- void clOnlineHomework::setUI(const int nWidth, const int nHeight)
- {
- setGeometry(0, 0, nWidth, nHeight);
- ui->tabw_onlineExam->setGeometry(0, 0, nWidth, nHeight);
- ui->tabw_onlineExam->setTabEnabled(1, false);
- ui->tabw_onlineExam->setTabText(0, QString::fromLocal8Bit("待考列表"));
- ui->tabw_onlineExam->setTabText(1, QString::fromLocal8Bit("已完成考试"));
- ui->vlayout_el->setContentsMargins(g_appInfoPtr->m_fRate*30, 0, g_appInfoPtr->m_fRate*30, 0);
- ui->vlayout_fel->setContentsMargins(g_appInfoPtr->m_fRate*30, 0, g_appInfoPtr->m_fRate*30, 0);
- ui->tablewt_examList->setEditTriggers(QAbstractItemView::NoEditTriggers);
- //整行选中的方式
- ui->tablewt_examList->setSelectionBehavior(QAbstractItemView::SelectRows);
- //设置为只能选中一行
- ui->tablewt_examList->setSelectionMode(QAbstractItemView::SingleSelection);
- //隐藏列表头
- ui->tablewt_examList->verticalHeader()->setVisible(false);
- //隐藏边框
- ui->tablewt_examList->setShowGrid(false);
- //表头不高亮显示
- ui->tablewt_examList->horizontalHeader()->setHighlightSections(false);
- //设置行数
- ui->tablewt_examList->setRowCount(10);
- //设置列数
- ui->tablewt_examList->setColumnCount(7);
- ui->tablewt_examList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
- ui->tablewt_examList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
- QStringList sHeadStr;
- sHeadStr << QString::fromLocal8Bit("课程") <<
- QString::fromLocal8Bit("层次") <<
- QString::fromLocal8Bit("专业") <<
- QString::fromLocal8Bit("考试进入时间") <<
- QString::fromLocal8Bit("考试时间周期") <<
- QString::fromLocal8Bit("剩余考试次数") <<
- QString::fromLocal8Bit("操作");
- ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr);
- ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
- ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
- ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
- ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*116);
- ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*56);
- ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*104);
- ui->tablewt_examList->setColumnWidth(3, g_appInfoPtr->m_fRate*277);
- ui->tablewt_examList->setColumnWidth(4, g_appInfoPtr->m_fRate*305);
- ui->tablewt_examList->setColumnWidth(5, g_appInfoPtr->m_fRate*102);
- ui->tablewt_examList->setColumnWidth(6, g_appInfoPtr->m_fRate*146);
- ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true);
- ui->tablew_finishExamList->setEditTriggers(QAbstractItemView::NoEditTriggers);
- //整行选中的方式
- ui->tablew_finishExamList->setSelectionBehavior(QAbstractItemView::SelectRows);
- //设置为只能选中一行
- ui->tablew_finishExamList->setSelectionMode(QAbstractItemView::SingleSelection);
- //隐藏列表头
- ui->tablew_finishExamList->verticalHeader()->setVisible(false);
- //隐藏边框
- ui->tablew_finishExamList->setShowGrid(false);
- //表头不高亮显示
- ui->tablew_finishExamList->horizontalHeader()->setHighlightSections(false);
- //设置行数
- ui->tablew_finishExamList->setRowCount(10);
- //设置列数
- ui->tablew_finishExamList->setColumnCount(7);
- ui->tablew_finishExamList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
- ui->tablew_finishExamList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
- ui->tablew_finishExamList->setHorizontalHeaderLabels(sHeadStr);
- ui->tablew_finishExamList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
- ui->tablew_finishExamList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
- ui->tablew_finishExamList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
- ui->tablew_finishExamList->setColumnWidth(0, g_appInfoPtr->m_fRate*116);
- ui->tablew_finishExamList->setColumnWidth(1, g_appInfoPtr->m_fRate*56);
- ui->tablew_finishExamList->setColumnWidth(2, g_appInfoPtr->m_fRate*104);
- ui->tablew_finishExamList->setColumnWidth(3, g_appInfoPtr->m_fRate*277);
- ui->tablew_finishExamList->setColumnWidth(4, g_appInfoPtr->m_fRate*305);
- ui->tablew_finishExamList->setColumnWidth(5, g_appInfoPtr->m_fRate*102);
- ui->tablew_finishExamList->setColumnWidth(6, g_appInfoPtr->m_fRate*146);
- ui->tablew_finishExamList->horizontalHeader()->setStretchLastSection(true);
- }
- void clOnlineHomework::showEvent(QShowEvent *)
- {
- refreshExam();
- }
- void clOnlineHomework::refreshExam()
- {
- CHttpRequestPackage hrp;
- hrp.sUri = "/api/ecs_oe_admin/client/exam/process/queryHomeworkList";
- hrp.nRequestType = RequestType::rtQueryHomeworkList;
- g_httpBllPtr->post(hrp);
- }
- void clOnlineHomework::onQueryHomeworkList(CQueryHomeworkList queryHomeworkList)
- {
- if (queryHomeworkList.nCode == 200)
- {
- int nSize = queryHomeworkList.vHomeworkExamList.size();
- ui->tablewt_examList->setRowCount(nSize);
- for (int i = 0; i < nSize; ++i)
- {
- CExamCourseInfo eci = queryHomeworkList.vHomeworkExamList[i];
- ui->tablewt_examList->setItem(i, 0, new QTableWidgetItem(eci.sCourseName));
- ui->tablewt_examList->setItem(i, 1, new QTableWidgetItem(eci.sCourseLevel));
- ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(eci.sSpecialtyName));
- ui->tablewt_examList->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(eci.sStartTime).arg(eci.sEndTime)));
- QString sWeekCycle = CWeekTransform::getWeekCycles(eci.vExamCycleWeek);
- QString sTimeRange = eci.sExamCycleTimeRange.join(",");
- QDateTime dtCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime());
- QDateTime dtStartTime = QDateTime::fromString(eci.sStartTime, "yyyy-MM-dd hh:mm:ss");
- QDateTime dtEndTime = QDateTime::fromString(eci.sEndTime, "yyyy-MM-dd hh:mm:ss");
- bool bIsInExamTime = dtCurrent > dtStartTime && dtCurrent < dtEndTime;
- QString sWeek = dtCurrent.toString("ddd");
- bool bIsInWeek = sWeekCycle.size() == 0 || sWeekCycle.indexOf(sWeek) >= 0;
- QTime tCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).time();
- bool bIsInTimeRange = eci.sExamCycleTimeRange.size() == 0 || CWeekTransform::isInTimeRange(tCurrent, eci.sExamCycleTimeRange);
- ui->tablewt_examList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("%1 %2").arg(sWeekCycle).arg(sTimeRange)));
- ui->tablewt_examList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount)));
- clOperation *clo = new clOperation(i, ui->tablewt_examList);
-
- connect(clo, &clOperation::enterExam, this, [&](CL_OPERATION_TYPE cot, int nRow){
- if (cot == CL_OPERATION_TYPE::cot_online_homework )
- {
- QString sWeekCycle = CWeekTransform::getWeekCycles(m_vHomeworkExamList[nRow].vExamCycleWeek);
- QString sTimeRange = m_vHomeworkExamList[nRow].sExamCycleTimeRange.join(",");
- QDateTime dtCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime());
- QDateTime dtStartTime = QDateTime::fromString(m_vHomeworkExamList[nRow].sStartTime, "yyyy-MM-dd hh:mm:ss");
- QDateTime dtEndTime = QDateTime::fromString(m_vHomeworkExamList[nRow].sEndTime, "yyyy-MM-dd hh:mm:ss");
- bool bIsInExamTime = dtCurrent > dtStartTime && dtCurrent < dtEndTime;
- QString sWeek = dtCurrent.toString("ddd");
- bool bIsInWeek = sWeekCycle.size() == 0 || sWeekCycle.indexOf(sWeek) >= 0;
- QTime tCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).time();
- bool bIsInTimeRange = m_vHomeworkExamList[nRow].sExamCycleTimeRange.size() == 0 || CWeekTransform::isInTimeRange(tCurrent, m_vHomeworkExamList[nRow].sExamCycleTimeRange);
- if(bIsInWeek && bIsInTimeRange && bIsInExamTime)
- {
- emit enterExam(cot, m_vHomeworkExamList[nRow].nExamId, m_vHomeworkExamList[nRow].nExamStudentId,
- m_vHomeworkExamList[nRow].sCourseCode, m_vHomeworkExamList[nRow].sCourseName);
- }
- }
- });
- connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
- if (cot == CL_OPERATION_TYPE::cot_online_homework )
- {
- m_pObjectiveScoreTimer->stop();
- if (m_pObjectiveScore != nullptr &&
- m_pObjectiveScore->getRow() != nRow)
- {
- m_pObjectiveScore.reset();
- }
- if (m_pObjectiveScore == nullptr)
- {
- m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vHomeworkExamList[nRow].nExamStudentId), this);
- connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
- int ntableTop = ui->tabw_onlineExam->y() + g_appInfoPtr->m_fRate*70;
- int nTop = ntableTop + (nRow + 2)* ui->tablewt_examList->verticalHeader()->defaultSectionSize() - nHeight / 2;
- if (nHeight > ui->tabw_onlineExam->height())
- {
- nHeight = ui->tabw_onlineExam->height();
- }
- if (nTop < ui->tabw_onlineExam->y())
- {
- nTop = ui->tabw_onlineExam->y();
- }
- else if ((nTop + nHeight) > (ntableTop + ui->tablewt_examList->height()))
- {
- nTop = ntableTop + ui->tablewt_examList->height() - nHeight;
- }
- m_pObjectiveScore->setUI(ui->tablewt_examList->x() + ui->tablewt_examList->width() - ui->tablewt_examList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
- nTop, g_appInfoPtr->m_fRate * 530, nHeight);
- m_pObjectiveScore->show();
- });
- }
- }
- });
- connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
- if (cot == CL_OPERATION_TYPE::cot_online_homework)
- {
- m_pObjectiveScoreTimer->start();
- }
- });
- clo->setUI(ui->tablewt_examList->columnWidth(6), ui->tablewt_examList->rowHeight(i), CL_OPERATION_TYPE::cot_online_homework);
- clo->setBtn1Enable(bIsInWeek && bIsInTimeRange && bIsInExamTime);
- clo->setBtn2Enable(eci.bIsObjScoreView);
- ui->tablewt_examList->setCellWidget(i, 6, clo);
- }
- m_vHomeworkExamList.swap(queryHomeworkList.vHomeworkExamList);
- }
- else
- {
- if(queryHomeworkList.sMessage.isEmpty())
- {
- ShowMsg(QString::fromLocal8Bit("获取在线作业列表失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
- }
- else
- {
- ShowMsg(queryHomeworkList.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
- }
- }
- }
|