123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- #include "ExportProjectDlg.h"
- #include "ui_ExportProjectDlg.h"
- #include <qcheckbox.h>
- #include <qgridlayout.h>
- #include <dbService/DBServiceSet.h>
- #include <dbService/UserConfigService.h>
- #include <dbService/EngineerService.h>
- #include "FileUtil.h"
- #include <QDebug>
- #include <QFileDialog>
- #include <QPushButton>
- #include <QMessageBox>
- ExportProjectDlg::ExportProjectDlg(QWidget *parent) : QDialog(parent), ui(new Ui::ExportProjectDlg)
- {
- ui->setupUi(this);
- setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
- this->setWindowTitle("导出工程资源包");
- this->setAttribute(Qt::WA_DeleteOnClose);
- this->resize(1000, 600);
- init();
- }
- void ExportProjectDlg::init()
- {
- ui->tableWidget->setFont(QFont("宋体", 12));
- ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
- ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
- QStringList header;
- header << "ID"
- << "工程名称"
- << "工程描述"
- << "操作";
- ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
- ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
- ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
- ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); //填充表格
- QHeaderView *vheader = ui->tableWidget->verticalHeader();
- // vheader->setHidden(true); // 隐藏行号
- ui->tableWidget->setColumnCount(header.count());
- ui->tableWidget->setHorizontalHeaderLabels(header);
- for (int i = 0; i < header.size(); i++) {
- ui->tableWidget->horizontalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
- }
- refreshEngineerList();
- }
- void ExportProjectDlg::refreshEngineerList()
- {
- ui->tableWidget->clearContents();
- QList<EngineerInfo *> engineers;
- if (!EngineerService().QueryEngineerList(&engineers)) {
- qDebug() << "工程列表查询失败";
- return;
- }
- ui->tableWidget->setRowCount(engineers.count());
- QPushButton *exportPro = nullptr;
- QCheckBox *check = nullptr;
- QWidget *widget = nullptr;
- QGridLayout *layout = nullptr;
- int row = 0;
- foreach (auto *info, engineers) {
- //把查出的第一个字段放到任务名称列
- int id = info->engineerId;
- QString name = info->engineerName;
- widget = new QWidget;
- layout = new QGridLayout;
- check = new QCheckBox;
- layout->setSpacing(0);
- layout->setMargin(0);
- layout->addWidget(check);
- layout->setAlignment(check, Qt::AlignCenter); //居中
- widget->setLayout(layout);
- // ui->tableWidget->setCellWidget(row, 0, widget);
- ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(id)));
- ui->tableWidget->item(row, 0)->setTextAlignment(Qt::AlignCenter);
- ui->tableWidget->item(row, 0)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
- ui->tableWidget->setItem(row, 1, new QTableWidgetItem(info->engineerName));
- ui->tableWidget->item(row, 1)->setTextAlignment(Qt::AlignCenter);
- ui->tableWidget->item(row, 1)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
- ui->tableWidget->setItem(row, 2, new QTableWidgetItem(info->remark));
- // ui->tableWidget->item(row, 2)->setTextAlignment(Qt::AlignCenter);
- widget = new QWidget;
- layout = new QGridLayout;
- exportPro = new QPushButton;
- exportPro->setText("导出资源包");
- exportPro->setMaximumWidth(100);
- exportPro->setMinimumWidth(100);
- connect(exportPro, &QPushButton::clicked, [=]() { exportProject(id, name); });
- layout->setSpacing(0);
- layout->setMargin(0);
- layout->addWidget(exportPro);
- widget->setLayout(layout);
- ui->tableWidget->setCellWidget(row, 3, widget);
- row++;
- }
- qDeleteAll(engineers);
- engineers.clear();
- }
- void ExportProjectDlg::exportProject(int engineerId, QString name)
- {
- //判断方案是否填写完整
- EngineerInfo info;
- if (EngineerService().QueryEngineerByEngineerId(&info, engineerId)) {
- QString dbPath = QCoreApplication::applicationDirPath() + "/data/data.db";
- QString dbName = "mindData";
- QString remark = info.remark;
- if (remark == "能力与技术重要度评估") {
- if (info.indexSetId == -1) {
- QMessageBox::warning(this, "警告", "未创建能力需求体系,请创建后再导出!");
- return;
- } else {
- if (!EngineerService().QueryChlidNodeByPId(info.indexSetId, dbName, dbPath)) {
- QMessageBox::warning(this, "警告", "未创建能力需求体系,请创建后再导出!");
- return;
- }
- }
- if (info.measureFunctionId == -1) {
- QMessageBox::warning(this, "警告", "未创建技术措施评估体系,请创建后再导出!");
- return;
- } else {
- if (!EngineerService().QueryChlidNodeByPId(info.measureFunctionId, dbName, dbPath)) {
- QMessageBox::warning(this, "警告", "未创建技术措施评估体系,请创建后再导出!");
- return;
- }
- }
- }
- if (remark == ("技术方案评估")) {
- if (info.schemaEvalId == -1) {
- QMessageBox::warning(this, "警告", "未创建技术方案体系,请创建后再导出!");
- return;
- } else {
- if (!EngineerService().QueryChlidNodeByPId(info.schemaEvalId, dbName, dbPath)) {
- QMessageBox::warning(this, "警告", "未创建技术方案体系,请创建后再导出!");
- return;
- }
- }
- }
- if (remark == "技术方案评估,能力与技术重要度评估" || remark == "能力与技术重要度评估,技术方案评估") {
- if (info.schemaEvalId == -1) {
- QMessageBox::warning(this, "警告", "未创建技术方案体系,请创建后再导出!");
- return;
- } else {
- if (!EngineerService().QueryChlidNodeByPId(info.schemaEvalId, dbName, dbPath)) {
- QMessageBox::warning(this, "警告", "未创建技术方案体系,请创建后再导出!");
- return;
- }
- }
- if (info.indexSetId == -1) {
- QMessageBox::warning(this, "警告", "能力需求体系未创建,请创建后再导出!");
- return;
- } else {
- if (!EngineerService().QueryChlidNodeByPId(info.indexSetId, dbName, dbPath)) {
- QMessageBox::warning(this, "警告", "能力需求体系未创建,请创建后再导出!");
- return;
- }
- }
- if (info.measureFunctionId == -1) {
- QMessageBox::warning(this, "警告", "技术措施体系未创建,请创建后再导出!");
- return;
- } else {
- if (!EngineerService().QueryChlidNodeByPId(info.measureFunctionId, dbName, dbPath)) {
- QMessageBox::warning(this, "警告", "技术措施体系未创建,请创建后再导出!");
- return;
- }
- }
- }
- }
- //判断是否配置过专家
- QList<UserConfig *> list;
- if (UserConfigService().QueryUserConfigListInfoByEngineerId(&list, engineerId)) {
- if (list.isEmpty()) {
- QMessageBox::warning(this, "警告", "请先给该工程配置专家!");
- return;
- }
- }
- QFileDialog::Options options;
- options |= QFileDialog::DontUseNativeDialog;
- //文件夹路径
- QString srcDirPath = QFileDialog::getExistingDirectory(nullptr, "导出资源包", "/", options);
- if (srcDirPath.isEmpty()) {
- return;
- }
- srcDirPath += "/";
- srcDirPath += name;
- qDebug() << "srcDirPath---" << srcDirPath;
- QString sysDbPath = QCoreApplication::applicationDirPath();
- sysDbPath += "/data";
- // qDebug() << "filePath---" << sysDbPath;
- bool result = FileUtil().copyDirectoryFiles(srcDirPath, sysDbPath, true);
- // TODO 删除其他多余数据只保留选中工程
- if (result) {
- EngineerService().DeleteEngineerNotInId(engineerId, srcDirPath + "/qfd.db");
- }
- if (result) {
- QMessageBox::information(this, "成功", tr("导出成功"));
- } else {
- QMessageBox::warning(this, "失败", tr("导出失败"));
- }
- }
- ExportProjectDlg::~ExportProjectDlg()
- {
- delete ui;
- }
|