HomeView.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. #include "HomeView.h"
  2. #include "CreateProjWidget.h"
  3. #include "ProjectStateWidget.h"
  4. #include "ProjectManager.h"
  5. #include "QFDAlert.h"
  6. #include "QFDIcon.h"
  7. #include "ProjectListWidget.h"
  8. #include "QFDConfig.h"
  9. #include "FileUtil.h"
  10. #include <Widgets/Button.h>
  11. #include <Widgets/LineEdit.h>
  12. #include <DialogBox/Dialog.h>
  13. #include <QFileDialog>
  14. #include <QPushButton>
  15. #include <QMessageBox>
  16. #include <QBoxLayout>
  17. #include <QLabel>
  18. #include <QApplication>
  19. #include <QDebug>
  20. #include <QSettings>
  21. #include "dbService/ClassSet.h"
  22. #include "dbService/CNodeDataService.h"
  23. #include "dbService/UserService.h"
  24. #include "dbService/ClassSet.h"
  25. #include "SchemePlanManager.h"
  26. #include "dbService/SchemeProcessService.h"
  27. HomeView::HomeView(QWidget *parent) : QWidget(parent) { }
  28. void HomeView::showEvent(QShowEvent *event)
  29. {
  30. if (m_initilized == false) {
  31. initWidgets();
  32. initLayout();
  33. connectSignalsAndSlots();
  34. m_initilized = true;
  35. }
  36. QWidget::showEvent(event);
  37. if (qfReloadHomeProjectsAtShow) {
  38. loadProjects();
  39. qfReloadHomeProjectsAtShow = false;
  40. }
  41. }
  42. void HomeView::hideEvent(QHideEvent *event)
  43. {
  44. QWidget::hideEvent(event);
  45. }
  46. void HomeView::initWidgets()
  47. {
  48. m_title = new QLabel(this);
  49. m_title->setText("评估项目管理");
  50. QFont ft("Microsoft YaHei", 12);
  51. m_title->setFont(ft);
  52. m_create = new PushButton("新建", NEWFLICON(FluentIcon, ADD), this);
  53. m_create->setToolTip("新建项目");
  54. m_search = new LineEdit(this);
  55. m_search->setIsClearButtonEnabled(true);
  56. m_search->setPlaceholderText("输入项目名搜索");
  57. m_search->setMinimumWidth(300);
  58. m_filter = new PushButton("搜索 / 刷新", NEWFLICON(QFDIcon, Filter), this);
  59. m_filter->setToolTip("搜索 / 刷新项目列表");
  60. m_projListWidget = new ProjectListWidget(this);
  61. m_createProjWidget = new CreateProjWidget(this);
  62. m_totalLab = new QLabel(this);
  63. m_pageLab = new QLabel(this);
  64. m_previous = new PushButton("上一页", this);
  65. m_next = new PushButton("下一页", this);
  66. m_first = new PushButton("首页", this);
  67. m_final = new PushButton("末页", this);
  68. }
  69. void HomeView::initLayout()
  70. {
  71. // 总体布局
  72. m_layout = new QVBoxLayout(this);
  73. m_layout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
  74. m_layout->setContentsMargins(15, 10, 10, 15);
  75. m_topLayout = new QHBoxLayout();
  76. m_layout->addLayout(m_topLayout);
  77. m_layout->addWidget(m_projListWidget);
  78. m_pageLayout = new QHBoxLayout();
  79. m_layout->addLayout(m_pageLayout);
  80. // 顶部布局
  81. m_topLayout->addWidget(m_title);
  82. m_topLayout->addSpacing(15);
  83. m_topLayout->addWidget(m_create, 1, Qt::AlignLeft);
  84. m_topLayout->addWidget(m_search, 0, Qt::AlignLeft);
  85. m_topLayout->addStretch();
  86. m_topLayout->addWidget(m_filter);
  87. m_pageLayout->addWidget(m_totalLab);
  88. m_pageLayout->addStretch();
  89. m_pageLayout->addWidget(m_first);
  90. m_pageLayout->addWidget(m_previous);
  91. m_pageLayout->addWidget(m_pageLab);
  92. m_pageLayout->addWidget(m_next);
  93. m_pageLayout->addWidget(m_final);
  94. m_pageLayout->addStretch();
  95. }
  96. void HomeView::connectSignalsAndSlots()
  97. {
  98. connect(m_create, &PushButton::clicked, this, &HomeView::slotCreateProjClicked);
  99. connect(m_search, &LineEdit::textChanged, this, &HomeView::slotSearchTextChanged);
  100. connect(m_filter, &PushButton::clicked, this, &HomeView::slotFilterClicked);
  101. connect(m_createProjWidget, &CreateProjWidget::signalConfirm, this, &HomeView::slotProjInfoConfirmed);
  102. connect(m_projListWidget, &ProjectListWidget::sigOpen, this, &HomeView::slotOpenProject);
  103. connect(m_projListWidget, &ProjectListWidget::sigInfo, this, &HomeView::slotProjectInfo);
  104. connect(m_projListWidget, &ProjectListWidget::sigDelete, this, &HomeView::slotDeleteProject);
  105. connect(m_projListWidget, &ProjectListWidget::sigExport, this, &HomeView::slotExportProject);
  106. connect(m_previous, &PushButton::clicked, this, &HomeView::slotPreviousClicked);
  107. connect(m_next, &PushButton::clicked, this, &HomeView::slotNextClicked);
  108. connect(m_first, &PushButton::clicked, this, &HomeView::slotFirstClicked);
  109. connect(m_final, &PushButton::clicked, this, &HomeView::slotFinalClicked);
  110. }
  111. void HomeView::loadProjects()
  112. {
  113. qDeleteAll(m_projList);
  114. m_projList.clear();
  115. int code = ProjectManager::queryProjects(&m_projList, m_total, m_page, m_pageSize, m_search->text());
  116. if (code != QF_CODE_SUCCEEDED) {
  117. QFDAlert::showAlertWithCode(code, this);
  118. return;
  119. }
  120. m_totalLab->setText(QString("共%1条, 每页%2条").arg(m_total).arg(m_pageSize));
  121. m_pageLab->setText(QString("第 %1/%2 页").arg(m_page).arg(finalPage()));
  122. m_projListWidget->setProjects(m_projList);
  123. }
  124. int HomeView::firstPage() const
  125. {
  126. return 1;
  127. }
  128. int HomeView::finalPage() const
  129. {
  130. int p = m_total / m_pageSize + (m_total % m_pageSize > 0 ? 1 : 0);
  131. return std::max(p, firstPage());
  132. }
  133. void HomeView::slotCreateProjClicked()
  134. {
  135. if (m_createProjWidget->isVisible() == false) {
  136. m_createProjWidget->setMode(CreateProjWidget::Create);
  137. m_createProjWidget->resetInputs();
  138. m_createProjWidget->show();
  139. }
  140. }
  141. void HomeView::slotSearchTextChanged() { }
  142. void HomeView::slotFilterClicked()
  143. {
  144. m_page = firstPage();
  145. loadProjects();
  146. }
  147. /// @todo 修改或者新建项目后, 列表移到该条目
  148. void HomeView::slotProjInfoConfirmed()
  149. {
  150. int code = -1;
  151. ProjectInfo *info = m_createProjWidget->projInfo();
  152. ProjectInfo editedInfo = m_createProjWidget->editedProjInfo();
  153. if (m_createProjWidget->mode() == CreateProjWidget::Create) {
  154. code = ProjectManager::insertProject(editedInfo);
  155. } else if (m_createProjWidget->mode() == CreateProjWidget::Update) {
  156. editedInfo.id = m_createProjWidget->projInfo()->id;
  157. code = ProjectManager::updateProject(editedInfo);
  158. } else {
  159. return;
  160. }
  161. QFDAlert::showAlertWithCode(code, m_createProjWidget);
  162. if (code == QF_CODE_SUCCEEDED) {
  163. m_createProjWidget->close();
  164. m_search->clear();
  165. loadProjects();
  166. }
  167. }
  168. void HomeView::slotProjectInfo(ProjectInfo *proj)
  169. {
  170. if (m_createProjWidget->isVisible() == false) {
  171. m_createProjWidget->setMode(CreateProjWidget::Info);
  172. m_createProjWidget->setProjectInfo(proj);
  173. m_createProjWidget->show();
  174. }
  175. }
  176. void HomeView::slotOpenProject(ProjectInfo *proj)
  177. {
  178. emit sigOpenProject(proj);
  179. }
  180. void HomeView::slotDeleteProject(ProjectInfo *proj)
  181. {
  182. QString title = "删除工程 “" + proj->projectName + "” ?";
  183. MessageBox *m = new MessageBox(title, "删除后无法恢复", this);
  184. if (m->exec()) {
  185. int code = ProjectManager::deleteProject(proj->id);
  186. QFDAlert::showAlertWithCode(code, this);
  187. if (code == QF_CODE_SUCCEEDED) {
  188. // m_projList.removeOne(proj);
  189. // m_projListWidget->removeProject(proj);
  190. emit sigDeleteProject(proj);
  191. loadProjects();
  192. }
  193. }
  194. }
  195. void HomeView::slotExportProject(ProjectInfo *proj)
  196. {
  197. // 判断方案是否填写完整TODO
  198. // 判断是否配置过专家TODO
  199. QFileDialog::Options options;
  200. options |= QFileDialog::DontUseNativeDialog;
  201. // 文件夹路径
  202. QString srcDirPath = QFileDialog::getExistingDirectory(nullptr, "导出资源包", "/", options);
  203. if (srcDirPath.isEmpty()) {
  204. return;
  205. }
  206. srcDirPath += "/";
  207. srcDirPath.append(proj->projectName).append(".ini");
  208. qDebug() << "srcDirPath---" << srcDirPath;
  209. QSettings exportData("exportData.ini", QSettings::IniFormat);
  210. exportData.setIniCodec("UTF-8");
  211. // 获取到需要导出数据
  212. QString projectInfo = "";
  213. QString nodeDate = "";
  214. QString userInfo = "";
  215. QString schemeProcess = "";
  216. projectInfo.append(QString::number(proj->id))
  217. .append(",")
  218. .append(proj->projectName)
  219. .append(",")
  220. .append(proj->remark)
  221. .append(",")
  222. .append(proj->taskName)
  223. .append(",")
  224. .append(proj->estimateTime)
  225. .append(",")
  226. .append(proj->estimateObjective)
  227. .append(",")
  228. .append(proj->estimateDept)
  229. .append(",")
  230. .append(proj->estimatePerson)
  231. .append(",")
  232. .append(proj->estimateType)
  233. .append(",")
  234. .append(proj->positionalTitles)
  235. .append(",")
  236. .append(proj->createTime)
  237. .append(",")
  238. .append(proj->updateTime);
  239. // 节点
  240. QList<CNodeData> nodeList;
  241. bool nodeRet = CNodeDataService().QueryAllByProjectId(nodeList, proj->id);
  242. if (nodeRet && nodeList.size() > 0) {
  243. foreach (CNodeData node, nodeList) {
  244. QString nodeValue = QString::number(node.id)
  245. .append(",")
  246. .append(QString::number(node.projectId))
  247. .append(",")
  248. .append(QString::number(node.indexType))
  249. .append(",")
  250. .append(QString::number(node.number))
  251. .append(",")
  252. .append(QString::number(node.pNumber))
  253. .append(",")
  254. .append(node.name)
  255. .append(",")
  256. .append(node.remark)
  257. .append(",")
  258. .append(node.dimension)
  259. .append(",")
  260. .append(QString::number(node.type))
  261. .append(",")
  262. .append(QString::number(node.isEffective));
  263. nodeDate.append(nodeValue).append(";");
  264. }
  265. }
  266. // 获取人员信息
  267. QList<QFUser> userInfoList;
  268. bool retUser = UserService().QueryUserListByEngineerId(userInfoList, proj->id);
  269. if (retUser && userInfoList.size() > 0) {
  270. foreach (QFUser user, userInfoList) {
  271. QString userValue = QString::number(user.id)
  272. .append(",")
  273. .append(user.userName)
  274. .append(",")
  275. .append(user.userNo)
  276. .append(",")
  277. .append(user.password)
  278. .append(",")
  279. .append(QString::number(user.role))
  280. .append(",")
  281. .append(user.post)
  282. .append(",")
  283. .append(user.major)
  284. .append(",")
  285. .append(user.workPosition)
  286. .append(",")
  287. .append(user.educationDegree)
  288. .append(",")
  289. .append(user.phone)
  290. .append(",")
  291. .append(user.remark)
  292. .append(",")
  293. .append(user.projectId)
  294. .append(",")
  295. .append(user.writeTime)
  296. .append(",")
  297. .append(QString::number(proj->id));
  298. qDebug() << "-------------" << userValue;
  299. userInfo.append(userValue).append(";");
  300. }
  301. }
  302. // schemeProcess
  303. QList<SchemePlanManager::SchemeProcessInfo> schemeProcessList;
  304. bool retScheme = SchemeProcessService().QueryAllByProjectId(schemeProcessList, proj->id);
  305. if (retScheme && schemeProcessList.size() > 0) {
  306. qDebug() << "---------------------------" << schemeProcessList.size();
  307. foreach (SchemePlanManager::SchemeProcessInfo info, schemeProcessList) {
  308. QString schemeValue = QString::number(info.id)
  309. .append(",")
  310. .append(QString::number(info.projectId))
  311. .append(",")
  312. .append(QString::number(info.indexType))
  313. .append(",")
  314. .append(QString::number(info.step))
  315. .append(",")
  316. .append(QString::number(info.type))
  317. .append(",")
  318. .append(QString::number(info.dSource))
  319. .append(",")
  320. .append(QString::number(info.algorithm))
  321. .append(",")
  322. .append(QString::number(info.efficiencyGrades))
  323. .append(",")
  324. .append(QString::number(info.isChecked));
  325. // qDebug() << "----" << schemeProcess;
  326. schemeProcess.append(schemeValue).append(";");
  327. }
  328. }
  329. exportData.setValue("EXPORTDATA/projectInfo", projectInfo);
  330. exportData.setValue("EXPORTDATA/nodeDate", nodeDate);
  331. exportData.setValue("EXPORTDATA/userInfo", userInfo);
  332. exportData.setValue("EXPORTDATA/schemeProcess", schemeProcess);
  333. exportData.setAtomicSyncRequired(true);
  334. exportData.sync();
  335. QString sysDbPath = QCoreApplication::applicationDirPath();
  336. sysDbPath += "/exportData.ini";
  337. qDebug() << "filePath---" << sysDbPath;
  338. qDebug() << "srcDirPath---" << srcDirPath;
  339. bool result = FileUtil().copyFileToPath(sysDbPath, srcDirPath, false);
  340. if (result) {
  341. QMessageBox::information(this, "成功", tr("导出成功"));
  342. } else {
  343. QMessageBox::warning(this, "失败", tr("导出失败"));
  344. }
  345. }
  346. void HomeView::slotPreviousClicked()
  347. {
  348. m_page--;
  349. m_page = std::max(m_page, firstPage());
  350. loadProjects();
  351. }
  352. void HomeView::slotNextClicked()
  353. {
  354. m_page++;
  355. m_page = std::min(m_page, finalPage());
  356. loadProjects();
  357. }
  358. void HomeView::slotFirstClicked()
  359. {
  360. m_page = firstPage();
  361. loadProjects();
  362. }
  363. void HomeView::slotFinalClicked()
  364. {
  365. m_page = finalPage();
  366. loadProjects();
  367. }