#include "HomeView.h" #include "CreateProjWidget.h" #include "ProjectStateWidget.h" #include "ProjectManager.h" #include "QFDAlert.h" #include "QFDIcon.h" #include "ProjectListWidget.h" #include "QFDConfig.h" #include "FileUtil.h" #include #include #include #include #include #include #include #include #include #include #include #include "dbService/ClassSet.h" #include "dbService/CNodeDataService.h" #include "dbService/UserService.h" #include "dbService/ClassSet.h" #include "SchemePlanManager.h" #include "dbService/SchemeProcessService.h" HomeView::HomeView(QWidget *parent) : QWidget(parent) { } void HomeView::showEvent(QShowEvent *event) { if (m_initilized == false) { initWidgets(); initLayout(); connectSignalsAndSlots(); m_initilized = true; } QWidget::showEvent(event); if (qfReloadHomeProjectsAtShow) { loadProjects(); qfReloadHomeProjectsAtShow = false; } } void HomeView::hideEvent(QHideEvent *event) { QWidget::hideEvent(event); } void HomeView::initWidgets() { m_title = new QLabel(this); m_title->setText("评估项目管理"); QFont ft("Microsoft YaHei", 12); m_title->setFont(ft); m_create = new PushButton("新建", NEWFLICON(FluentIcon, ADD), this); m_create->setToolTip("新建项目"); m_search = new LineEdit(this); m_search->setIsClearButtonEnabled(true); m_search->setPlaceholderText("输入项目名搜索"); m_search->setMinimumWidth(300); m_filter = new PushButton("搜索 / 刷新", NEWFLICON(QFDIcon, Filter), this); m_filter->setToolTip("搜索 / 刷新项目列表"); m_projListWidget = new ProjectListWidget(this); m_createProjWidget = new CreateProjWidget(this); m_totalLab = new QLabel(this); m_pageLab = new QLabel(this); m_previous = new PushButton("上一页", this); m_next = new PushButton("下一页", this); m_first = new PushButton("首页", this); m_final = new PushButton("末页", this); } void HomeView::initLayout() { // 总体布局 m_layout = new QVBoxLayout(this); m_layout->setAlignment(Qt::AlignTop | Qt::AlignLeft); m_layout->setContentsMargins(15, 10, 10, 15); m_topLayout = new QHBoxLayout(); m_layout->addLayout(m_topLayout); m_layout->addWidget(m_projListWidget); m_pageLayout = new QHBoxLayout(); m_layout->addLayout(m_pageLayout); // 顶部布局 m_topLayout->addWidget(m_title); m_topLayout->addSpacing(15); m_topLayout->addWidget(m_create, 1, Qt::AlignLeft); m_topLayout->addWidget(m_search, 0, Qt::AlignLeft); m_topLayout->addStretch(); m_topLayout->addWidget(m_filter); m_pageLayout->addWidget(m_totalLab); m_pageLayout->addStretch(); m_pageLayout->addWidget(m_first); m_pageLayout->addWidget(m_previous); m_pageLayout->addWidget(m_pageLab); m_pageLayout->addWidget(m_next); m_pageLayout->addWidget(m_final); m_pageLayout->addStretch(); } void HomeView::connectSignalsAndSlots() { connect(m_create, &PushButton::clicked, this, &HomeView::slotCreateProjClicked); connect(m_search, &LineEdit::textChanged, this, &HomeView::slotSearchTextChanged); connect(m_filter, &PushButton::clicked, this, &HomeView::slotFilterClicked); connect(m_createProjWidget, &CreateProjWidget::signalConfirm, this, &HomeView::slotProjInfoConfirmed); connect(m_projListWidget, &ProjectListWidget::sigOpen, this, &HomeView::slotOpenProject); connect(m_projListWidget, &ProjectListWidget::sigInfo, this, &HomeView::slotProjectInfo); connect(m_projListWidget, &ProjectListWidget::sigDelete, this, &HomeView::slotDeleteProject); connect(m_projListWidget, &ProjectListWidget::sigExport, this, &HomeView::slotExportProject); connect(m_previous, &PushButton::clicked, this, &HomeView::slotPreviousClicked); connect(m_next, &PushButton::clicked, this, &HomeView::slotNextClicked); connect(m_first, &PushButton::clicked, this, &HomeView::slotFirstClicked); connect(m_final, &PushButton::clicked, this, &HomeView::slotFinalClicked); } void HomeView::loadProjects() { qDeleteAll(m_projList); m_projList.clear(); int code = ProjectManager::queryProjects(&m_projList, m_total, m_page, m_pageSize, m_search->text()); if (code != QF_CODE_SUCCEEDED) { QFDAlert::showAlertWithCode(code, this); return; } m_totalLab->setText(QString("共%1条, 每页%2条").arg(m_total).arg(m_pageSize)); m_pageLab->setText(QString("第 %1/%2 页").arg(m_page).arg(finalPage())); m_projListWidget->setProjects(m_projList); } int HomeView::firstPage() const { return 1; } int HomeView::finalPage() const { int p = m_total / m_pageSize + (m_total % m_pageSize > 0 ? 1 : 0); return std::max(p, firstPage()); } void HomeView::slotCreateProjClicked() { if (m_createProjWidget->isVisible() == false) { m_createProjWidget->setMode(CreateProjWidget::Create); m_createProjWidget->resetInputs(); m_createProjWidget->show(); } } void HomeView::slotSearchTextChanged() { } void HomeView::slotFilterClicked() { m_page = firstPage(); loadProjects(); } /// @todo 修改或者新建项目后, 列表移到该条目 void HomeView::slotProjInfoConfirmed() { int code = -1; ProjectInfo *info = m_createProjWidget->projInfo(); ProjectInfo editedInfo = m_createProjWidget->editedProjInfo(); if (m_createProjWidget->mode() == CreateProjWidget::Create) { code = ProjectManager::insertProject(editedInfo); } else if (m_createProjWidget->mode() == CreateProjWidget::Update) { editedInfo.id = m_createProjWidget->projInfo()->id; code = ProjectManager::updateProject(editedInfo); } else { return; } QFDAlert::showAlertWithCode(code, m_createProjWidget); if (code == QF_CODE_SUCCEEDED) { m_createProjWidget->close(); m_search->clear(); loadProjects(); } } void HomeView::slotProjectInfo(ProjectInfo *proj) { if (m_createProjWidget->isVisible() == false) { m_createProjWidget->setMode(CreateProjWidget::Info); m_createProjWidget->setProjectInfo(proj); m_createProjWidget->show(); } } void HomeView::slotOpenProject(ProjectInfo *proj) { emit sigOpenProject(proj); } void HomeView::slotDeleteProject(ProjectInfo *proj) { QString title = "删除工程 “" + proj->projectName + "” ?"; MessageBox *m = new MessageBox(title, "删除后无法恢复", this); if (m->exec()) { int code = ProjectManager::deleteProject(proj->id); QFDAlert::showAlertWithCode(code, this); if (code == QF_CODE_SUCCEEDED) { // m_projList.removeOne(proj); // m_projListWidget->removeProject(proj); emit sigDeleteProject(proj); loadProjects(); } } } void HomeView::slotExportProject(ProjectInfo *proj) { // 判断方案是否填写完整TODO // 判断是否配置过专家TODO QFileDialog::Options options; options |= QFileDialog::DontUseNativeDialog; // 文件夹路径 QString srcDirPath = QFileDialog::getExistingDirectory(nullptr, "导出资源包", "/", options); if (srcDirPath.isEmpty()) { return; } srcDirPath += "/"; srcDirPath.append(proj->projectName).append(".ini"); qDebug() << "srcDirPath---" << srcDirPath; QSettings exportData("exportData.ini", QSettings::IniFormat); exportData.setIniCodec("UTF-8"); // 获取到需要导出数据 QString projectInfo = ""; QString nodeDate = ""; QString userInfo = ""; QString schemeProcess = ""; projectInfo.append(QString::number(proj->id)) .append(",") .append(proj->projectName) .append(",") .append(proj->remark) .append(",") .append(proj->taskName) .append(",") .append(proj->estimateTime) .append(",") .append(proj->estimateObjective) .append(",") .append(proj->estimateDept) .append(",") .append(proj->estimatePerson) .append(",") .append(proj->estimateType) .append(",") .append(proj->positionalTitles) .append(",") .append(proj->createTime) .append(",") .append(proj->updateTime); // 节点 QList nodeList; bool nodeRet = CNodeDataService().QueryAllByProjectId(nodeList, proj->id); if (nodeRet && nodeList.size() > 0) { foreach (CNodeData node, nodeList) { QString nodeValue = QString::number(node.id) .append(",") .append(QString::number(node.projectId)) .append(",") .append(QString::number(node.indexType)) .append(",") .append(QString::number(node.number)) .append(",") .append(QString::number(node.pNumber)) .append(",") .append(node.name) .append(",") .append(node.remark) .append(",") .append(node.dimension) .append(",") .append(QString::number(node.type)) .append(",") .append(QString::number(node.isEffective)); nodeDate.append(nodeValue).append(";"); } } // 获取人员信息 QList userInfoList; bool retUser = UserService().QueryUserListByEngineerId(userInfoList, proj->id); if (retUser && userInfoList.size() > 0) { foreach (QFUser user, userInfoList) { QString userValue = QString::number(user.id) .append(",") .append(user.userName) .append(",") .append(user.userNo) .append(",") .append(user.password) .append(",") .append(QString::number(user.role)) .append(",") .append(user.post) .append(",") .append(user.major) .append(",") .append(user.workPosition) .append(",") .append(user.educationDegree) .append(",") .append(user.phone) .append(",") .append(user.remark) .append(",") .append(user.projectId) .append(",") .append(user.writeTime) .append(",") .append(QString::number(proj->id)); qDebug() << "-------------" << userValue; userInfo.append(userValue).append(";"); } } // schemeProcess QList schemeProcessList; bool retScheme = SchemeProcessService().QueryAllByProjectId(schemeProcessList, proj->id); if (retScheme && schemeProcessList.size() > 0) { qDebug() << "---------------------------" << schemeProcessList.size(); foreach (SchemePlanManager::SchemeProcessInfo info, schemeProcessList) { QString schemeValue = QString::number(info.id) .append(",") .append(QString::number(info.projectId)) .append(",") .append(QString::number(info.indexType)) .append(",") .append(QString::number(info.step)) .append(",") .append(QString::number(info.type)) .append(",") .append(QString::number(info.dSource)) .append(",") .append(QString::number(info.algorithm)) .append(",") .append(QString::number(info.efficiencyGrades)) .append(",") .append(QString::number(info.isChecked)); // qDebug() << "----" << schemeProcess; schemeProcess.append(schemeValue).append(";"); } } exportData.setValue("EXPORTDATA/projectInfo", projectInfo); exportData.setValue("EXPORTDATA/nodeDate", nodeDate); exportData.setValue("EXPORTDATA/userInfo", userInfo); exportData.setValue("EXPORTDATA/schemeProcess", schemeProcess); exportData.setAtomicSyncRequired(true); exportData.sync(); QString sysDbPath = QCoreApplication::applicationDirPath(); sysDbPath += "/exportData.ini"; qDebug() << "filePath---" << sysDbPath; qDebug() << "srcDirPath---" << srcDirPath; bool result = FileUtil().copyFileToPath(sysDbPath, srcDirPath, false); if (result) { QMessageBox::information(this, "成功", tr("导出成功")); } else { QMessageBox::warning(this, "失败", tr("导出失败")); } } void HomeView::slotPreviousClicked() { m_page--; m_page = std::max(m_page, firstPage()); loadProjects(); } void HomeView::slotNextClicked() { m_page++; m_page = std::min(m_page, finalPage()); loadProjects(); } void HomeView::slotFirstClicked() { m_page = firstPage(); loadProjects(); } void HomeView::slotFinalClicked() { m_page = finalPage(); loadProjects(); }