clOnlineExam.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. CHttpRequestPackage hrp;
  109. hrp.sUri = "/api/ecs_oe_admin/client/exam/process/queryExamList";
  110. hrp.nRequestType = RequestType::rtQueryExamList;
  111. g_httpBllPtr->post(hrp);
  112. CHttpRequestPackage hrp1;
  113. hrp1.sUri = "/api/ecs_oe_admin/client/exam/process/queryExamEndList";
  114. hrp1.nRequestType = RequestType::rtQueryExamEndList;
  115. g_httpBllPtr->post(hrp1);
  116. }
  117. void clOnlineExam::onQueryExamList(CQueryExamList queryExamList)
  118. {
  119. if (queryExamList.nCode == 200)
  120. {
  121. qDebug() << "onQueryExamList";
  122. int nSize = queryExamList.vOnlieExamList.size();
  123. for (int i = 0; i < nSize; ++i)
  124. {
  125. CExamCourseInfo eci = queryExamList.vOnlieExamList[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. ui->tablewt_examList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("")));
  131. ui->tablewt_examList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount)));
  132. clOperation *clo = new clOperation(i, ui->tablewt_examList);
  133. clo->setUI(ui->tablewt_examList->columnWidth(6), ui->tablewt_examList->rowHeight(i), CL_OPERATION_TYPE::cot_online_exam);
  134. ui->tablewt_examList->setCellWidget(i, 6, clo);
  135. connect(clo, &clOperation::enterExam, this, [&](CL_OPERATION_TYPE cot, int nRow){
  136. if (cot == CL_OPERATION_TYPE::cot_online_exam )
  137. {
  138. emit enterExam(cot, m_vOnlieExamList[nRow].nExamId, m_vOnlieExamList[nRow].nExamStudentId);
  139. }
  140. });
  141. connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  142. if (cot == CL_OPERATION_TYPE::cot_online_exam )
  143. {
  144. m_pObjectiveScoreTimer->stop();
  145. if (m_pObjectiveScore != nullptr &&
  146. m_pObjectiveScore->getRow() != nRow)
  147. {
  148. m_pObjectiveScore.reset();
  149. }
  150. if (m_pObjectiveScore == nullptr)
  151. {
  152. m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vOnlieExamList[nRow].nExamStudentId), this);
  153. connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
  154. int ntableTop = ui->tabw_onlineExam->y() + g_appInfoPtr->m_fRate*70;
  155. int nTop = ntableTop + (nRow + 2)* ui->tablewt_examList->verticalHeader()->defaultSectionSize() - nHeight / 2;
  156. if (nTop < ui->tabw_onlineExam->y())
  157. {
  158. nTop = ui->tabw_onlineExam->y();
  159. }
  160. else if ((nTop + nHeight) > (ntableTop + ui->tablewt_examList->height()))
  161. {
  162. nTop = ntableTop + ui->tablewt_examList->height() - nHeight;
  163. }
  164. m_pObjectiveScore->setUI(ui->tablewt_examList->x() + ui->tablewt_examList->width() - ui->tablewt_examList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
  165. nTop, g_appInfoPtr->m_fRate * 530, nHeight);
  166. m_pObjectiveScore->show();
  167. });
  168. }
  169. }
  170. });
  171. connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  172. if (cot == CL_OPERATION_TYPE::cot_online_exam)
  173. {
  174. m_pObjectiveScoreTimer->start();
  175. }
  176. });
  177. }
  178. m_vOnlieExamList.swap(queryExamList.vOnlieExamList);
  179. }
  180. else
  181. {
  182. if(queryExamList.sMessage.isEmpty())
  183. {
  184. ShowMsg(QString::fromLocal8Bit("获取离线考试信息失败"), (QWidget*)(this->parent()));
  185. }
  186. else
  187. {
  188. ShowMsg(queryExamList.sMessage, (QWidget*)(this->parent()));
  189. }
  190. }
  191. }
  192. void clOnlineExam::onQueryExamEndList(CQueryExamEndList queryExamEndList)
  193. {
  194. if (queryExamEndList.nCode == 200)
  195. {
  196. int nSize = queryExamEndList.vOnlieEndExamList.size();
  197. for (int i = 0; i < nSize; ++i)
  198. {
  199. CExamCourseInfo eci = queryExamEndList.vOnlieEndExamList[i];
  200. ui->tablew_finishExamList->setItem(i, 0, new QTableWidgetItem(eci.sCourseName));
  201. ui->tablew_finishExamList->setItem(i, 1, new QTableWidgetItem(eci.sCourseLevel));
  202. ui->tablew_finishExamList->setItem(i, 2, new QTableWidgetItem(eci.sSpecialtyName));
  203. ui->tablew_finishExamList->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit("%1 ~ %2").arg(eci.sStartTime).arg(eci.sEndTime)));
  204. ui->tablew_finishExamList->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("")));
  205. ui->tablew_finishExamList->setItem(i, 5, new QTableWidgetItem(QString::number(eci.nAllowExamCount)));
  206. clOperation *clo = new clOperation(i, ui->tablew_finishExamList);
  207. clo->setUI(ui->tablew_finishExamList->columnWidth(6), ui->tablew_finishExamList->rowHeight(i), CL_OPERATION_TYPE::cot_online_finish_exam);
  208. ui->tablew_finishExamList->setCellWidget(i, 6, clo);
  209. connect(clo, &clOperation::showObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  210. if (cot == CL_OPERATION_TYPE::cot_online_finish_exam )
  211. {
  212. m_pObjectiveScoreTimer->stop();
  213. if (m_pObjectiveScore != nullptr &&
  214. m_pObjectiveScore->getRow() != nRow)
  215. {
  216. m_pObjectiveScore.reset();
  217. }
  218. if (m_pObjectiveScore == nullptr)
  219. {
  220. m_pObjectiveScore = std::make_shared<clObjectiveScore>(nRow, QString::number(m_vOnlieEndExamList[nRow].nExamStudentId), this);
  221. connect(m_pObjectiveScore.get(), &clObjectiveScore::objectiveScoreHeight, this, [&](int nRow, int nHeight) {
  222. int ntableTop = ui->tablew_finishExamList->y() + g_appInfoPtr->m_fRate*70;
  223. int nTop = ntableTop + (nRow + 2)* ui->tablew_finishExamList->verticalHeader()->defaultSectionSize() - nHeight / 2;
  224. if (nTop < ui->tablew_finishExamList->y())
  225. {
  226. nTop = ui->tablew_finishExamList->y();
  227. }
  228. else if ((nTop + nHeight) > (ntableTop + ui->tablew_finishExamList->height()))
  229. {
  230. nTop = ntableTop + ui->tablew_finishExamList->height() - nHeight;
  231. }
  232. m_pObjectiveScore->setUI(ui->tablew_finishExamList->x() + ui->tablew_finishExamList->width() - ui->tablew_finishExamList->columnWidth(6) - g_appInfoPtr->m_fRate * 530,
  233. nTop, g_appInfoPtr->m_fRate * 530, nHeight);
  234. m_pObjectiveScore->show();
  235. });
  236. }
  237. }
  238. });
  239. connect(clo, &clOperation::hideObjectiveScore, this, [&](CL_OPERATION_TYPE cot, int nRow) {
  240. if (cot == CL_OPERATION_TYPE::cot_online_finish_exam)
  241. {
  242. m_pObjectiveScoreTimer->start();
  243. }
  244. });
  245. }
  246. m_vOnlieEndExamList.swap(queryExamEndList.vOnlieEndExamList);
  247. }
  248. else
  249. {
  250. }
  251. }