clOnlineExam.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #include "clOnlineExam.h"
  2. #include "ui_clOnlineExam.h"
  3. #include "CAppInfo.h"
  4. #include "logproc.h"
  5. #include <QScrollBar>
  6. #include "awMsgBox.h"
  7. clOnlineExam::clOnlineExam(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::clOnlineExam)
  10. {
  11. ui->setupUi(this);
  12. setStyleSheet(g_appInfoPtr->m_sQssStr);
  13. qRegisterMetaType<CQueryExamList>("CQueryExamList");
  14. connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryExamList, this, &clOnlineExam::onQueryExamList);
  15. qRegisterMetaType<CQueryExamEndList>("CQueryExamEndList");
  16. connect(g_httpBllPtr.get(), &CHttpBll::sgnQueryExamEndList, this, &clOnlineExam::onQueryExamEndList);
  17. m_pObjectiveScoreTimer = std::make_shared<QTimer>();
  18. m_pObjectiveScoreTimer->setInterval(200);
  19. connect(m_pObjectiveScoreTimer.get(), &QTimer::timeout, this, [&]() {
  20. m_pObjectiveScoreTimer->stop();
  21. if (m_pObjectiveScore != nullptr)
  22. {
  23. m_pObjectiveScore.reset();
  24. }
  25. });
  26. }
  27. clOnlineExam::~clOnlineExam()
  28. {
  29. delete ui;
  30. }
  31. void clOnlineExam::setUI(const int nWidth, const int nHeight)
  32. {
  33. setGeometry(0, 0, nWidth, nHeight);
  34. ui->tabw_onlineExam->setGeometry(0, 0, nWidth, nHeight);
  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 clOnlineExam::showEvent(QShowEvent *)
  107. {
  108. refreshExam();
  109. }
  110. void clOnlineExam::refreshExam()
  111. {
  112. CHttpRequestPackage hrp;
  113. hrp.sUri = "/api/ecs_oe_admin/client/exam/process/queryExamList";
  114. hrp.nRequestType = RequestType::rtQueryExamList;
  115. g_httpBllPtr->post(hrp);
  116. CHttpRequestPackage hrp1;
  117. hrp1.sUri = "/api/ecs_oe_admin/client/exam/process/queryExamEndList";
  118. hrp1.nRequestType = RequestType::rtQueryExamEndList;
  119. g_httpBllPtr->post(hrp1);
  120. }
  121. void clOnlineExam::onQueryExamList(CQueryExamList queryExamList)
  122. {
  123. if (queryExamList.nCode == 200)
  124. {
  125. qDebug() << "onQueryExamList";
  126. int nSize = queryExamList.vOnlieExamList.size();
  127. ui->tablewt_examList->setRowCount(nSize);
  128. for (int i = 0; i < nSize; ++i)
  129. {
  130. CExamCourseInfo eci = queryExamList.vOnlieExamList[i];
  131. ui->tablewt_examList->setItem(i, 0, new QTableWidgetItem(eci.sCourseName));
  132. ui->tablewt_examList->setItem(i, 1, new QTableWidgetItem(eci.sCourseLevel));
  133. ui->tablewt_examList->setItem(i, 2, new QTableWidgetItem(eci.sSpecialtyName));
  134. ui->tablewt_examList->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(eci.sStartTime).arg(eci.sEndTime)));
  135. QString sWeekCycle = CWeekTransform::getWeekCycles(eci.vExamCycleWeek);
  136. QString sTimeRange = eci.sExamCycleTimeRange.join(QString::fromLocal8Bit(","));
  137. QDateTime dtCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime());
  138. QDateTime dtStartTime = QDateTime::fromString(eci.sStartTime, "yyyy-MM-dd hh:mm:ss");
  139. QDateTime dtEndTime = QDateTime::fromString(eci.sEndTime, "yyyy-MM-dd hh:mm:ss");
  140. bool bIsInExamTime = dtCurrent > dtStartTime && dtCurrent < dtEndTime;
  141. QString sWeek = dtCurrent.toString("ddd");
  142. bool bIsInWeek = sWeekCycle.size() == 0 || sWeekCycle.indexOf(sWeek) >= 0;
  143. QTime tCurrent = QDateTime::fromMSecsSinceEpoch(g_appInfoPtr->serverMTime()).time();
  144. bool bIsInTimeRange = eci.sExamCycleTimeRange.size() == 0 || CWeekTransform::isInTimeRange(tCurrent, eci.sExamCycleTimeRange);
  145. ui->tablewt_examList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("%1 %2").arg(sWeekCycle).arg(sTimeRange)));
  146. ui->tablewt_examList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount)));
  147. clOperation *clo = new clOperation(i, ui->tablewt_examList);
  148. clo->setUI(ui->tablewt_examList->columnWidth(6), ui->tablewt_examList->rowHeight(i), CL_OPERATION_TYPE::cot_online_exam);
  149. clo->setBtn1Enable(bIsInWeek && bIsInTimeRange && bIsInExamTime && eci.nAllowExamCount>0);
  150. ui->tablewt_examList->setCellWidget(i, 6, clo);
  151. connect(clo, &clOperation::enterExam, this, [&](CL_OPERATION_TYPE cot, int nRow){
  152. if (cot == CL_OPERATION_TYPE::cot_online_exam )
  153. {
  154. emit enterExam(cot, m_vOnlieExamList[nRow].nExamId, m_vOnlieExamList[nRow].nExamStudentId,
  155. m_vOnlieExamList[nRow].sCourseCode, m_vOnlieExamList[nRow].sCourseName);
  156. }
  157. });
  158. connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  159. if (cot == CL_OPERATION_TYPE::cot_online_exam )
  160. {
  161. m_pObjectiveScoreTimer->stop();
  162. if (m_pObjectiveScore != nullptr &&
  163. m_pObjectiveScore->getRow() != nRow)
  164. {
  165. m_pObjectiveScore.reset();
  166. }
  167. if (m_pObjectiveScore == nullptr)
  168. {
  169. m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vOnlieExamList[nRow].nExamStudentId), this);
  170. connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
  171. int ntableTop = ui->tabw_onlineExam->y() + g_appInfoPtr->m_fRate*70;
  172. int nTop = ntableTop + (nRow + 2)* ui->tablewt_examList->verticalHeader()->defaultSectionSize() - nHeight / 2;
  173. if (nHeight > ui->tabw_onlineExam->height())
  174. {
  175. nHeight = ui->tabw_onlineExam->height();
  176. }
  177. if (nTop < ui->tabw_onlineExam->y())
  178. {
  179. nTop = ui->tabw_onlineExam->y();
  180. }
  181. else if ((nTop + nHeight) > (ntableTop + ui->tablewt_examList->height()))
  182. {
  183. nTop = ntableTop + ui->tablewt_examList->height() - nHeight;
  184. }
  185. m_pObjectiveScore->setUI(ui->tablewt_examList->x() + ui->tablewt_examList->width() - ui->tablewt_examList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
  186. nTop, g_appInfoPtr->m_fRate * 530, nHeight);
  187. m_pObjectiveScore->show();
  188. });
  189. }
  190. }
  191. });
  192. connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  193. if (cot == CL_OPERATION_TYPE::cot_online_exam)
  194. {
  195. m_pObjectiveScoreTimer->start();
  196. }
  197. });
  198. }
  199. m_vOnlieExamList.swap(queryExamList.vOnlieExamList);
  200. }
  201. else
  202. {
  203. if(queryExamList.sMessage.isEmpty())
  204. {
  205. ShowMsg(QString::fromLocal8Bit("获取在线考试信息失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  206. }
  207. else
  208. {
  209. ShowMsg(queryExamList.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  210. }
  211. }
  212. }
  213. void clOnlineExam::onQueryExamEndList(CQueryExamEndList queryExamEndList)
  214. {
  215. if (queryExamEndList.nCode == 200)
  216. {
  217. int nSize = queryExamEndList.vOnlieEndExamList.size();
  218. ui->tablew_finishExamList->setRowCount(nSize);
  219. for (int i = 0; i < nSize; ++i)
  220. {
  221. CExamCourseInfo eci = queryExamEndList.vOnlieEndExamList[i];
  222. ui->tablew_finishExamList->setItem(i, 0, new QTableWidgetItem(eci.sCourseName));
  223. ui->tablew_finishExamList->setItem(i, 1, new QTableWidgetItem(eci.sCourseLevel));
  224. ui->tablew_finishExamList->setItem(i, 2, new QTableWidgetItem(eci.sSpecialtyName));
  225. ui->tablew_finishExamList->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(eci.sStartTime).arg(eci.sEndTime)));
  226. QString sWeekCycle = CWeekTransform::getWeekCycles(eci.vExamCycleWeek);
  227. QString sTimeRange = eci.sExamCycleTimeRange.join(",");
  228. ui->tablew_finishExamList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("%1 %2").arg(sWeekCycle).arg(sTimeRange)));
  229. ui->tablew_finishExamList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount)));
  230. clOperation *clo = new clOperation(i, ui->tablew_finishExamList);
  231. clo->setUI(ui->tablew_finishExamList->columnWidth(6), ui->tablew_finishExamList->rowHeight(i), CL_OPERATION_TYPE::cot_online_finish_exam);
  232. ui->tablew_finishExamList->setCellWidget(i, 6, clo);
  233. connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  234. if (cot == CL_OPERATION_TYPE::cot_online_finish_exam )
  235. {
  236. m_pObjectiveScoreTimer->stop();
  237. if (m_pObjectiveScore != nullptr &&
  238. m_pObjectiveScore->getRow() != nRow)
  239. {
  240. m_pObjectiveScore.reset();
  241. }
  242. if (m_pObjectiveScore == nullptr)
  243. {
  244. m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vOnlieEndExamList[nRow].nExamStudentId), this);
  245. connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
  246. int ntableTop = ui->tablew_finishExamList->y() + g_appInfoPtr->m_fRate*70;
  247. int nTop = ntableTop + (nRow + 2)* ui->tablew_finishExamList->verticalHeader()->defaultSectionSize() - nHeight / 2;
  248. if (nHeight > ui->tabw_onlineExam->height())
  249. {
  250. nHeight = ui->tabw_onlineExam->height();
  251. }
  252. if (nTop < ui->tablew_finishExamList->y())
  253. {
  254. nTop = ui->tablew_finishExamList->y();
  255. }
  256. else if ((nTop + nHeight) > (ntableTop + ui->tablew_finishExamList->height()))
  257. {
  258. nTop = ntableTop + ui->tablew_finishExamList->height() - nHeight;
  259. }
  260. m_pObjectiveScore->setUI(ui->tablew_finishExamList->x() + ui->tablew_finishExamList->width() - ui->tablew_finishExamList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
  261. nTop, g_appInfoPtr->m_fRate * 530, nHeight);
  262. m_pObjectiveScore->show();
  263. });
  264. }
  265. }
  266. });
  267. connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  268. if (cot == CL_OPERATION_TYPE::cot_online_finish_exam)
  269. {
  270. m_pObjectiveScoreTimer->start();
  271. }
  272. });
  273. }
  274. m_vOnlieEndExamList.swap(queryExamEndList.vOnlieEndExamList);
  275. }
  276. else
  277. {
  278. if(queryExamEndList.sMessage.isEmpty())
  279. {
  280. ShowMsg(QString::fromLocal8Bit("获取在线考试信息失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  281. }
  282. else
  283. {
  284. ShowMsg(queryExamEndList.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  285. }
  286. }
  287. }