123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- #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 <Widgets/Button.h>
- #include <Widgets/LineEdit.h>
- #include <DialogBox/Dialog.h>
- #include <QFileDialog>
- #include <QPushButton>
- #include <QMessageBox>
- #include <QBoxLayout>
- #include <QLabel>
- #include <QApplication>
- #include <QDebug>
- #include <QSettings>
- #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<CNodeData> 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<QFUser> 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<SchemePlanManager::SchemeProcessInfo> 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();
- }
|