ExportProjectDlg.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #include "ExportProjectDlg.h"
  2. #include "ui_ExportProjectDlg.h"
  3. #include <qcheckbox.h>
  4. #include <qgridlayout.h>
  5. #include <dbService/DBServiceSet.h>
  6. #include <dbService/UserConfigService.h>
  7. #include <dbService/EngineerService.h>
  8. #include "FileUtil.h"
  9. #include <QDebug>
  10. #include <QFileDialog>
  11. #include <QPushButton>
  12. #include <QMessageBox>
  13. ExportProjectDlg::ExportProjectDlg(QWidget *parent) : QDialog(parent), ui(new Ui::ExportProjectDlg)
  14. {
  15. ui->setupUi(this);
  16. setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
  17. this->setWindowTitle("导出工程资源包");
  18. this->setAttribute(Qt::WA_DeleteOnClose);
  19. this->resize(1000, 600);
  20. init();
  21. }
  22. void ExportProjectDlg::init()
  23. {
  24. ui->tableWidget->setFont(QFont("宋体", 12));
  25. ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
  26. ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
  27. QStringList header;
  28. header << "ID"
  29. << "工程名称"
  30. << "工程描述"
  31. << "操作";
  32. ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
  33. ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
  34. ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
  35. ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); //填充表格
  36. QHeaderView *vheader = ui->tableWidget->verticalHeader();
  37. // vheader->setHidden(true); // 隐藏行号
  38. ui->tableWidget->setColumnCount(header.count());
  39. ui->tableWidget->setHorizontalHeaderLabels(header);
  40. for (int i = 0; i < header.size(); i++) {
  41. ui->tableWidget->horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
  42. }
  43. refreshEngineerList();
  44. }
  45. void ExportProjectDlg::refreshEngineerList()
  46. {
  47. ui->tableWidget->clearContents();
  48. QList<EngineerInfo *> engineers;
  49. if (!EngineerService().QueryEngineerList(&engineers)) {
  50. qDebug() << "工程列表查询失败";
  51. return;
  52. }
  53. ui->tableWidget->setRowCount(engineers.count());
  54. QPushButton *exportPro = nullptr;
  55. QCheckBox *check = nullptr;
  56. QWidget *widget = nullptr;
  57. QGridLayout *layout = nullptr;
  58. int row = 0;
  59. foreach (auto *info, engineers) {
  60. //把查出的第一个字段放到任务名称列
  61. int id = info->engineerId;
  62. QString name = info->engineerName;
  63. widget = new QWidget;
  64. layout = new QGridLayout;
  65. check = new QCheckBox;
  66. layout->setSpacing(0);
  67. layout->setMargin(0);
  68. layout->addWidget(check);
  69. layout->setAlignment(check, Qt::AlignCenter); //居中
  70. widget->setLayout(layout);
  71. // ui->tableWidget->setCellWidget(row, 0, widget);
  72. ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(id)));
  73. ui->tableWidget->item(row, 0)->setTextAlignment(Qt::AlignCenter);
  74. ui->tableWidget->item(row, 0)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  75. ui->tableWidget->setItem(row, 1, new QTableWidgetItem(info->engineerName));
  76. ui->tableWidget->item(row, 1)->setTextAlignment(Qt::AlignCenter);
  77. ui->tableWidget->item(row, 1)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  78. ui->tableWidget->setItem(row, 2, new QTableWidgetItem(info->remark));
  79. // ui->tableWidget->item(row, 2)->setTextAlignment(Qt::AlignCenter);
  80. widget = new QWidget;
  81. layout = new QGridLayout;
  82. exportPro = new QPushButton;
  83. exportPro->setText("导出资源包");
  84. exportPro->setMaximumWidth(100);
  85. exportPro->setMinimumWidth(100);
  86. connect(exportPro, &QPushButton::clicked, [=]() { exportProject(id, name); });
  87. layout->setSpacing(0);
  88. layout->setMargin(0);
  89. layout->addWidget(exportPro);
  90. widget->setLayout(layout);
  91. ui->tableWidget->setCellWidget(row, 3, widget);
  92. row++;
  93. }
  94. qDeleteAll(engineers);
  95. engineers.clear();
  96. }
  97. void ExportProjectDlg::exportProject(int engineerId, QString name)
  98. {
  99. //判断方案是否填写完整
  100. EngineerInfo info;
  101. if (EngineerService().QueryEngineerByEngineerId(&info, engineerId)) {
  102. QString dbPath = QCoreApplication::applicationDirPath() + "/data/data.db";
  103. QString dbName = "mindData";
  104. QString remark = info.remark;
  105. if (remark == "能力与技术重要度评估") {
  106. if (info.indexSetId == -1) {
  107. QMessageBox::warning(this, "警告", "未创建能力需求体系,请创建后再导出!");
  108. return;
  109. } else {
  110. if (!EngineerService().QueryChlidNodeByPId(info.indexSetId, dbName, dbPath)) {
  111. QMessageBox::warning(this, "警告", "未创建能力需求体系,请创建后再导出!");
  112. return;
  113. }
  114. }
  115. if (info.measureFunctionId == -1) {
  116. QMessageBox::warning(this, "警告", "未创建技术措施评估体系,请创建后再导出!");
  117. return;
  118. } else {
  119. if (!EngineerService().QueryChlidNodeByPId(info.measureFunctionId, dbName, dbPath)) {
  120. QMessageBox::warning(this, "警告", "未创建技术措施评估体系,请创建后再导出!");
  121. return;
  122. }
  123. }
  124. }
  125. if (remark == ("技术方案评估")) {
  126. if (info.schemaEvalId == -1) {
  127. QMessageBox::warning(this, "警告", "未创建技术方案体系,请创建后再导出!");
  128. return;
  129. } else {
  130. if (!EngineerService().QueryChlidNodeByPId(info.schemaEvalId, dbName, dbPath)) {
  131. QMessageBox::warning(this, "警告", "未创建技术方案体系,请创建后再导出!");
  132. return;
  133. }
  134. }
  135. }
  136. if (remark == "技术方案评估,能力与技术重要度评估" || remark == "能力与技术重要度评估,技术方案评估") {
  137. if (info.schemaEvalId == -1) {
  138. QMessageBox::warning(this, "警告", "未创建技术方案体系,请创建后再导出!");
  139. return;
  140. } else {
  141. if (!EngineerService().QueryChlidNodeByPId(info.schemaEvalId, dbName, dbPath)) {
  142. QMessageBox::warning(this, "警告", "未创建技术方案体系,请创建后再导出!");
  143. return;
  144. }
  145. }
  146. if (info.indexSetId == -1) {
  147. QMessageBox::warning(this, "警告", "能力需求体系未创建,请创建后再导出!");
  148. return;
  149. } else {
  150. if (!EngineerService().QueryChlidNodeByPId(info.indexSetId, dbName, dbPath)) {
  151. QMessageBox::warning(this, "警告", "能力需求体系未创建,请创建后再导出!");
  152. return;
  153. }
  154. }
  155. if (info.measureFunctionId == -1) {
  156. QMessageBox::warning(this, "警告", "技术措施体系未创建,请创建后再导出!");
  157. return;
  158. } else {
  159. if (!EngineerService().QueryChlidNodeByPId(info.measureFunctionId, dbName, dbPath)) {
  160. QMessageBox::warning(this, "警告", "技术措施体系未创建,请创建后再导出!");
  161. return;
  162. }
  163. }
  164. }
  165. }
  166. //判断是否配置过专家
  167. QList<UserConfig *> list;
  168. if (UserConfigService().QueryUserConfigListInfoByEngineerId(&list, engineerId)) {
  169. if (list.isEmpty()) {
  170. QMessageBox::warning(this, "警告", "请先给该工程配置专家!");
  171. return;
  172. }
  173. }
  174. QFileDialog::Options options;
  175. options |= QFileDialog::DontUseNativeDialog;
  176. //文件夹路径
  177. QString srcDirPath = QFileDialog::getExistingDirectory(nullptr, "导出资源包", "/", options);
  178. if (srcDirPath.isEmpty()) {
  179. return;
  180. }
  181. srcDirPath += "/";
  182. srcDirPath += name;
  183. qDebug() << "srcDirPath---" << srcDirPath;
  184. QString sysDbPath = QCoreApplication::applicationDirPath();
  185. sysDbPath += "/data";
  186. // qDebug() << "filePath---" << sysDbPath;
  187. bool result = FileUtil().copyDirectoryFiles(srcDirPath, sysDbPath, true);
  188. // TODO 删除其他多余数据只保留选中工程
  189. if (result) {
  190. EngineerService().DeleteEngineerNotInId(engineerId, srcDirPath + "/qfd.db");
  191. }
  192. if (result) {
  193. QMessageBox::information(this, "成功", tr("导出成功"));
  194. } else {
  195. QMessageBox::warning(this, "失败", tr("导出失败"));
  196. }
  197. }
  198. ExportProjectDlg::~ExportProjectDlg()
  199. {
  200. delete ui;
  201. }