#include "ExportProjectDlg.h" #include "ui_ExportProjectDlg.h" #include #include #include #include #include #include "FileUtil.h" #include #include #include #include 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 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 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; }