clOnlineExam.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. clo->setBtn2Enable(eci.bIsObjScoreView);
  151. ui->tablewt_examList->setCellWidget(i, 6, clo);
  152. connect(clo, &clOperation::enterExam, this, [&](CL_OPERATION_TYPE cot, int nRow){
  153. if (cot == CL_OPERATION_TYPE::cot_online_exam )
  154. {
  155. emit enterExam(cot, m_vOnlieExamList[nRow].nExamId, m_vOnlieExamList[nRow].nExamStudentId,
  156. m_vOnlieExamList[nRow].sCourseCode, m_vOnlieExamList[nRow].sCourseName);
  157. }
  158. });
  159. connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  160. if (cot == CL_OPERATION_TYPE::cot_online_exam )
  161. {
  162. m_pObjectiveScoreTimer->stop();
  163. if (m_pObjectiveScore != nullptr &&
  164. m_pObjectiveScore->getRow() != nRow)
  165. {
  166. m_pObjectiveScore.reset();
  167. }
  168. if (m_pObjectiveScore == nullptr)
  169. {
  170. m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vOnlieExamList[nRow].nExamStudentId), this);
  171. connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
  172. int ntableTop = ui->tabw_onlineExam->y() + g_appInfoPtr->m_fRate*70;
  173. int nTop = ntableTop + (nRow + 2)* ui->tablewt_examList->verticalHeader()->defaultSectionSize() - nHeight / 2;
  174. if (nHeight > ui->tabw_onlineExam->height())
  175. {
  176. nHeight = ui->tabw_onlineExam->height();
  177. }
  178. if (nTop < ui->tabw_onlineExam->y())
  179. {
  180. nTop = ui->tabw_onlineExam->y();
  181. }
  182. else if ((nTop + nHeight) > (ntableTop + ui->tablewt_examList->height()))
  183. {
  184. nTop = ntableTop + ui->tablewt_examList->height() - nHeight;
  185. }
  186. m_pObjectiveScore->setUI(ui->tablewt_examList->x() + ui->tablewt_examList->width() - ui->tablewt_examList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
  187. nTop, g_appInfoPtr->m_fRate * 530, nHeight);
  188. m_pObjectiveScore->show();
  189. });
  190. }
  191. }
  192. });
  193. connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  194. if (cot == CL_OPERATION_TYPE::cot_online_exam)
  195. {
  196. m_pObjectiveScoreTimer->start();
  197. }
  198. });
  199. }
  200. m_vOnlieExamList.swap(queryExamList.vOnlieExamList);
  201. }
  202. else
  203. {
  204. if(queryExamList.sMessage.isEmpty())
  205. {
  206. ShowMsg(QString::fromLocal8Bit("获取在线考试信息失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  207. }
  208. else
  209. {
  210. ShowMsg(queryExamList.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  211. }
  212. }
  213. }
  214. void clOnlineExam::onQueryExamEndList(CQueryExamEndList queryExamEndList)
  215. {
  216. if (queryExamEndList.nCode == 200)
  217. {
  218. int nSize = queryExamEndList.vOnlieEndExamList.size();
  219. ui->tablew_finishExamList->setRowCount(nSize);
  220. for (int i = 0; i < nSize; ++i)
  221. {
  222. CExamCourseInfo eci = queryExamEndList.vOnlieEndExamList[i];
  223. ui->tablew_finishExamList->setItem(i, 0, new QTableWidgetItem(eci.sCourseName));
  224. ui->tablew_finishExamList->setItem(i, 1, new QTableWidgetItem(eci.sCourseLevel));
  225. ui->tablew_finishExamList->setItem(i, 2, new QTableWidgetItem(eci.sSpecialtyName));
  226. ui->tablew_finishExamList->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(eci.sStartTime).arg(eci.sEndTime)));
  227. QString sWeekCycle = CWeekTransform::getWeekCycles(eci.vExamCycleWeek);
  228. QString sTimeRange = eci.sExamCycleTimeRange.join(",");
  229. ui->tablew_finishExamList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("%1 %2").arg(sWeekCycle).arg(sTimeRange)));
  230. ui->tablew_finishExamList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount)));
  231. clOperation *clo = new clOperation(i, ui->tablew_finishExamList);
  232. clo->setUI(ui->tablew_finishExamList->columnWidth(6), ui->tablew_finishExamList->rowHeight(i), CL_OPERATION_TYPE::cot_online_finish_exam);
  233. clo->setBtn1Enable(eci.bIsObjScoreView);
  234. ui->tablew_finishExamList->setCellWidget(i, 6, clo);
  235. connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  236. if (cot == CL_OPERATION_TYPE::cot_online_finish_exam )
  237. {
  238. m_pObjectiveScoreTimer->stop();
  239. if (m_pObjectiveScore != nullptr &&
  240. m_pObjectiveScore->getRow() != nRow)
  241. {
  242. m_pObjectiveScore.reset();
  243. }
  244. if (m_pObjectiveScore == nullptr)
  245. {
  246. m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vOnlieEndExamList[nRow].nExamStudentId), this);
  247. connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
  248. int ntableTop = ui->tablew_finishExamList->y() + g_appInfoPtr->m_fRate*70;
  249. int nTop = ntableTop + (nRow + 2)* ui->tablew_finishExamList->verticalHeader()->defaultSectionSize() - nHeight / 2;
  250. if (nHeight > ui->tabw_onlineExam->height())
  251. {
  252. nHeight = ui->tabw_onlineExam->height();
  253. }
  254. if (nTop < ui->tablew_finishExamList->y())
  255. {
  256. nTop = ui->tablew_finishExamList->y();
  257. }
  258. else if ((nTop + nHeight) > (ntableTop + ui->tablew_finishExamList->height()))
  259. {
  260. nTop = ntableTop + ui->tablew_finishExamList->height() - nHeight;
  261. }
  262. m_pObjectiveScore->setUI(ui->tablew_finishExamList->x() + ui->tablew_finishExamList->width() - ui->tablew_finishExamList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
  263. nTop, g_appInfoPtr->m_fRate * 530, nHeight);
  264. m_pObjectiveScore->show();
  265. });
  266. }
  267. }
  268. });
  269. connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  270. if (cot == CL_OPERATION_TYPE::cot_online_finish_exam)
  271. {
  272. m_pObjectiveScoreTimer->start();
  273. }
  274. });
  275. }
  276. m_vOnlieEndExamList.swap(queryExamEndList.vOnlieEndExamList);
  277. }
  278. else
  279. {
  280. if(queryExamEndList.sMessage.isEmpty())
  281. {
  282. ShowMsg(QString::fromLocal8Bit("获取在线考试信息失败"), (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  283. }
  284. else
  285. {
  286. ShowMsg(queryExamEndList.sMessage, (QWidget*)(this->parent()), MSG_ICON_TYPE::mit_error);
  287. }
  288. }
  289. }