clOnlineHomework.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #include "clOnlineHomework.h"
  2. #include "ui_clOnlineHomework.h"
  3. #include "CAppInfo.h"
  4. #include "clOperation.h"
  5. #include "awMsgBox.h"
  6. #include <QScrollBar>
  7. #include <QDateTime>
  8. clOnlineHomework::clOnlineHomework(QWidget *parent) :
  9. QWidget(parent),
  10. ui(new Ui::clOnlineHomework)
  11. {
  12. ui->setupUi(this);
  13. setStyleSheet(g_appInfoPtr->m_sQssStr);
  14. qRegisterMetaType<CQueryHomeworkList>("CQueryHomeworkList");
  15. connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryHomeworkList, this, &clOnlineHomework::onQueryHomeworkList);
  16. m_pObjectiveScoreTimer = std::make_shared<QTimer>();
  17. m_pObjectiveScoreTimer->setInterval(200);
  18. connect(m_pObjectiveScoreTimer.get(), &QTimer::timeout, this, [&]() {
  19. m_pObjectiveScoreTimer->stop();
  20. if (m_pObjectiveScore != nullptr)
  21. {
  22. m_pObjectiveScore.reset();
  23. }
  24. });
  25. }
  26. clOnlineHomework::~clOnlineHomework()
  27. {
  28. delete ui;
  29. }
  30. void clOnlineHomework::setUI(const int nWidth, const int nHeight)
  31. {
  32. setGeometry(0, 0, nWidth, nHeight);
  33. ui->tabw_onlineExam->setGeometry(0, 0, nWidth, nHeight);
  34. ui->tabw_onlineExam->setTabEnabled(1, false);
  35. ui->tabw_onlineExam->setTabText(0, QString::fromLocal8Bit("待考列表"));
  36. ui->tabw_onlineExam->setTabText(1, QString::fromLocal8Bit("已完成考试"));
  37. ui->vlayout_el->setContentsMargins(g_appInfoPtr->m_fRate*30, 0, g_appInfoPtr->m_fRate*30, 0);
  38. ui->vlayout_fel->setContentsMargins(g_appInfoPtr->m_fRate*30, 0, g_appInfoPtr->m_fRate*30, 0);
  39. ui->tablewt_examList->setEditTriggers(QAbstractItemView::NoEditTriggers);
  40. //整行选中的方式
  41. ui->tablewt_examList->setSelectionBehavior(QAbstractItemView::SelectRows);
  42. //设置为只能选中一行
  43. ui->tablewt_examList->setSelectionMode(QAbstractItemView::SingleSelection);
  44. //隐藏列表头
  45. ui->tablewt_examList->verticalHeader()->setVisible(false);
  46. //隐藏边框
  47. ui->tablewt_examList->setShowGrid(false);
  48. //表头不高亮显示
  49. ui->tablewt_examList->horizontalHeader()->setHighlightSections(false);
  50. //设置行数
  51. ui->tablewt_examList->setRowCount(10);
  52. //设置列数
  53. ui->tablewt_examList->setColumnCount(7);
  54. ui->tablewt_examList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
  55. ui->tablewt_examList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
  56. QStringList sHeadStr;
  57. sHeadStr << QString::fromLocal8Bit("课程") <<
  58. QString::fromLocal8Bit("层次") <<
  59. QString::fromLocal8Bit("专业") <<
  60. QString::fromLocal8Bit("考试进入时间") <<
  61. QString::fromLocal8Bit("考试时间周期") <<
  62. QString::fromLocal8Bit("剩余考试次数") <<
  63. QString::fromLocal8Bit("操作");
  64. ui->tablewt_examList->setHorizontalHeaderLabels(sHeadStr);
  65. ui->tablewt_examList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  66. ui->tablewt_examList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  67. ui->tablewt_examList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  68. ui->tablewt_examList->setColumnWidth(0, g_appInfoPtr->m_fRate*116);
  69. ui->tablewt_examList->setColumnWidth(1, g_appInfoPtr->m_fRate*56);
  70. ui->tablewt_examList->setColumnWidth(2, g_appInfoPtr->m_fRate*104);
  71. ui->tablewt_examList->setColumnWidth(3, g_appInfoPtr->m_fRate*277);
  72. ui->tablewt_examList->setColumnWidth(4, g_appInfoPtr->m_fRate*305);
  73. ui->tablewt_examList->setColumnWidth(5, g_appInfoPtr->m_fRate*102);
  74. ui->tablewt_examList->setColumnWidth(6, g_appInfoPtr->m_fRate*146);
  75. ui->tablewt_examList->horizontalHeader()->setStretchLastSection(true);
  76. ui->tablew_finishExamList->setEditTriggers(QAbstractItemView::NoEditTriggers);
  77. //整行选中的方式
  78. ui->tablew_finishExamList->setSelectionBehavior(QAbstractItemView::SelectRows);
  79. //设置为只能选中一行
  80. ui->tablew_finishExamList->setSelectionMode(QAbstractItemView::SingleSelection);
  81. //隐藏列表头
  82. ui->tablew_finishExamList->verticalHeader()->setVisible(false);
  83. //隐藏边框
  84. ui->tablew_finishExamList->setShowGrid(false);
  85. //表头不高亮显示
  86. ui->tablew_finishExamList->horizontalHeader()->setHighlightSections(false);
  87. //设置行数
  88. ui->tablew_finishExamList->setRowCount(10);
  89. //设置列数
  90. ui->tablew_finishExamList->setColumnCount(7);
  91. ui->tablew_finishExamList->setHorizontalScrollMode(QTableWidget::ScrollPerPixel);
  92. ui->tablew_finishExamList->horizontalScrollBar()->setSingleStep(g_appInfoPtr->m_fRate*5);
  93. ui->tablew_finishExamList->setHorizontalHeaderLabels(sHeadStr);
  94. ui->tablew_finishExamList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
  95. ui->tablew_finishExamList->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
  96. ui->tablew_finishExamList->verticalHeader()->setDefaultSectionSize(g_appInfoPtr->m_fRate*48);
  97. ui->tablew_finishExamList->setColumnWidth(0, g_appInfoPtr->m_fRate*116);
  98. ui->tablew_finishExamList->setColumnWidth(1, g_appInfoPtr->m_fRate*56);
  99. ui->tablew_finishExamList->setColumnWidth(2, g_appInfoPtr->m_fRate*104);
  100. ui->tablew_finishExamList->setColumnWidth(3, g_appInfoPtr->m_fRate*277);
  101. ui->tablew_finishExamList->setColumnWidth(4, g_appInfoPtr->m_fRate*305);
  102. ui->tablew_finishExamList->setColumnWidth(5, g_appInfoPtr->m_fRate*102);
  103. ui->tablew_finishExamList->setColumnWidth(6, g_appInfoPtr->m_fRate*146);
  104. ui->tablew_finishExamList->horizontalHeader()->setStretchLastSection(true);
  105. }
  106. void clOnlineHomework::showEvent(QShowEvent *)
  107. {
  108. refreshExam();
  109. }
  110. void clOnlineHomework::refreshExam()
  111. {
  112. CHttpRequestPackage hrp;
  113. hrp.sUri = "/api/ecs_oe_admin/client/exam/process/queryHomeworkList";
  114. hrp.nRequestType = RequestType::rtQueryHomeworkList;
  115. g_httpBllPtr->post(hrp);
  116. }
  117. void clOnlineHomework::onQueryHomeworkList(CQueryHomeworkList queryHomeworkList)
  118. {
  119. if (queryHomeworkList.nCode == 200)
  120. {
  121. int nSize = queryHomeworkList.vHomeworkExamList.size();
  122. ui->tablewt_examList->setRowCount(nSize);
  123. for (int i = 0; i < nSize; ++i)
  124. {
  125. CExamCourseInfo eci = queryHomeworkList.vHomeworkExamList[i];
  126. ui->tablewt_examList->setItem(i, 0, new QTableWidgetItem(eci.sCourseName));
  127. ui->tablewt_examList->setItem(i, 1, new QTableWidgetItem(eci.sCourseLevel));
  128. ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(eci.sSpecialtyName));
  129. ui->tablewt_examList->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(eci.sStartTime).arg(eci.sEndTime)));
  130. QString sWeekCycle = CWeekTransform::getWeekCycles(eci.vExamCycleWeek);
  131. QString sTimeRange = eci.sExamCycleTimeRange.join(",");
  132. QDateTime dtCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime());
  133. QDateTime dtStartTime = QDateTime::fromString(eci.sStartTime, "yyyy-MM-dd hh:mm:ss");
  134. QDateTime dtEndTime = QDateTime::fromString(eci.sEndTime, "yyyy-MM-dd hh:mm:ss");
  135. bool bIsInExamTime = dtCurrent > dtStartTime && dtCurrent < dtEndTime;
  136. QString sWeek = dtCurrent.toString("ddd");
  137. bool bIsInWeek = sWeekCycle.size() == 0 || sWeekCycle.indexOf(sWeek) >= 0;
  138. QTime tCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).time();
  139. bool bIsInTimeRange = eci.sExamCycleTimeRange.size() == 0 || CWeekTransform::isInTimeRange(tCurrent, eci.sExamCycleTimeRange);
  140. ui->tablewt_examList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("%1 %2").arg(sWeekCycle).arg(sTimeRange)));
  141. ui->tablewt_examList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount)));
  142. clOperation *clo = new clOperation(i, ui->tablewt_examList);
  143. connect(clo, &clOperation::enterExam, this, [&](CL_OPERATION_TYPE cot, int nRow){
  144. if (cot == CL_OPERATION_TYPE::cot_online_homework )
  145. {
  146. QString sWeekCycle = CWeekTransform::getWeekCycles(m_vHomeworkExamList[nRow].vExamCycleWeek);
  147. QString sTimeRange = m_vHomeworkExamList[nRow].sExamCycleTimeRange.join(",");
  148. QDateTime dtCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime());
  149. QDateTime dtStartTime = QDateTime::fromString(m_vHomeworkExamList[nRow].sStartTime, "yyyy-MM-dd hh:mm:ss");
  150. QDateTime dtEndTime = QDateTime::fromString(m_vHomeworkExamList[nRow].sEndTime, "yyyy-MM-dd hh:mm:ss");
  151. bool bIsInExamTime = dtCurrent > dtStartTime && dtCurrent < dtEndTime;
  152. QString sWeek = dtCurrent.toString("ddd");
  153. bool bIsInWeek = sWeekCycle.size() == 0 || sWeekCycle.indexOf(sWeek) >= 0;
  154. QTime tCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).time();
  155. bool bIsInTimeRange = m_vHomeworkExamList[nRow].sExamCycleTimeRange.size() == 0 || CWeekTransform::isInTimeRange(tCurrent, m_vHomeworkExamList[nRow].sExamCycleTimeRange);
  156. if(bIsInWeek && bIsInTimeRange && bIsInExamTime)
  157. {
  158. emit enterExam(cot, m_vHomeworkExamList[nRow].nExamId, m_vHomeworkExamList[nRow].nExamStudentId,
  159. m_vHomeworkExamList[nRow].sCourseCode, m_vHomeworkExamList[nRow].sCourseName);
  160. }
  161. }
  162. });
  163. connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  164. if (cot == CL_OPERATION_TYPE::cot_online_homework )
  165. {
  166. m_pObjectiveScoreTimer->stop();
  167. if (m_pObjectiveScore != nullptr &&
  168. m_pObjectiveScore->getRow() != nRow)
  169. {
  170. m_pObjectiveScore.reset();
  171. }
  172. if (m_pObjectiveScore == nullptr)
  173. {
  174. m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vHomeworkExamList[nRow].nExamStudentId), this);
  175. connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
  176. int ntableTop = ui->tabw_onlineExam->y() + g_appInfoPtr->m_fRate*70;
  177. int nTop = ntableTop + (nRow + 2)* ui->tablewt_examList->verticalHeader()->defaultSectionSize() - nHeight / 2;
  178. if (nHeight > ui->tabw_onlineExam->height())
  179. {
  180. nHeight = ui->tabw_onlineExam->height();
  181. }
  182. if (nTop < ui->tabw_onlineExam->y())
  183. {
  184. nTop = ui->tabw_onlineExam->y();
  185. }
  186. else if ((nTop + nHeight) > (ntableTop + ui->tablewt_examList->height()))
  187. {
  188. nTop = ntableTop + ui->tablewt_examList->height() - nHeight;
  189. }
  190. m_pObjectiveScore->setUI(ui->tablewt_examList->x() + ui->tablewt_examList->width() - ui->tablewt_examList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
  191. nTop, g_appInfoPtr->m_fRate * 530, nHeight);
  192. m_pObjectiveScore->show();
  193. });
  194. }
  195. }
  196. });
  197. connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  198. if (cot == CL_OPERATION_TYPE::cot_online_homework)
  199. {
  200. m_pObjectiveScoreTimer->start();
  201. }
  202. });
  203. clo->setUI(ui->tablewt_examList->columnWidth(6), ui->tablewt_examList->rowHeight(i), CL_OPERATION_TYPE::cot_online_homework);
  204. clo->setBtn1Enable(bIsInWeek && bIsInTimeRange && bIsInExamTime);
  205. clo->setBtn2Enable(eci.bIsObjScoreView);
  206. ui->tablewt_examList->setCellWidget(i, 6, clo);
  207. }
  208. m_vHomeworkExamList.swap(queryHomeworkList.vHomeworkExamList);
  209. }
  210. else
  211. {
  212. if(queryHomeworkList.sMessage.isEmpty())
  213. {
  214. ShowMsg(QString::fromLocal8Bit("获取在线作业列表失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  215. }
  216. else
  217. {
  218. ShowMsg(queryHomeworkList.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  219. }
  220. }
  221. }