107 lines
3.4 KiB
C++
107 lines
3.4 KiB
C++
#include "kbddevimportdlg.h"
|
|
#include "../model_common/common.h"
|
|
#include <QRadioButton>
|
|
#include <QPushButton>
|
|
#include <QHBoxLayout>
|
|
#include <QVBoxLayout>
|
|
#include <QLineEdit>
|
|
#include <QLabel>
|
|
#include <QFileDialog>
|
|
#include "pub_widget/MessageBox.h"
|
|
|
|
kbdDevImportDlg::kbdDevImportDlg(QWidget *parent) : CustomDialog(parent)
|
|
{
|
|
setWindowTitle(tr("导入前置设备"));
|
|
QVBoxLayout* vLayout = new QVBoxLayout;
|
|
QHBoxLayout* hLayout = new QHBoxLayout;
|
|
|
|
m_pcsDev = new QRadioButton(tr("PCS3000设备"),this);
|
|
m_otherDev = new QRadioButton(tr("第三方设备"),this);
|
|
m_otherDev->setChecked(true);
|
|
//m_pcsDev->hide();
|
|
hLayout->addWidget(m_pcsDev);
|
|
hLayout->addWidget(m_otherDev);
|
|
hLayout->setMargin(0);
|
|
|
|
vLayout->addStretch();
|
|
vLayout->addLayout(hLayout);
|
|
vLayout->addSpacing(10);
|
|
|
|
hLayout = new QHBoxLayout;
|
|
QLabel* lable = new QLabel(tr("路径:"),this);
|
|
m_linePath = new QLineEdit(this);
|
|
QPushButton* btnOpenFile = new QPushButton(tr("选择文件"),this);
|
|
hLayout->addWidget(lable);
|
|
hLayout->addWidget(m_linePath);
|
|
hLayout->addWidget(btnOpenFile);
|
|
vLayout->addLayout(hLayout);
|
|
vLayout->addSpacing(10);
|
|
|
|
hLayout = new QHBoxLayout;
|
|
QPushButton* btnTemp = new QPushButton(tr("下载导入模板"),this);
|
|
QPushButton* btnUpdate = new QPushButton(tr("更新"),this);
|
|
QPushButton* btnOk = new QPushButton(tr("导入"),this);
|
|
hLayout->addWidget(btnTemp);
|
|
hLayout->addStretch();
|
|
hLayout->addWidget(btnUpdate);
|
|
hLayout->addWidget(btnOk);
|
|
hLayout->setMargin(0);
|
|
vLayout->addLayout(hLayout);
|
|
vLayout->addStretch();
|
|
setLayout(vLayout);
|
|
resize(370,210);
|
|
|
|
connect(btnOpenFile,&QPushButton::clicked,this,&kbdDevImportDlg::onSelectFile);
|
|
connect(btnTemp,&QPushButton::clicked,this,&kbdDevImportDlg::onDownTempFile);
|
|
connect(btnOk,&QPushButton::clicked,this,&kbdDevImportDlg::accept);
|
|
connect(btnUpdate,&QPushButton::clicked,[this](){done(2);});
|
|
}
|
|
|
|
QString kbdDevImportDlg::getFilePath()
|
|
{
|
|
return m_linePath->text();
|
|
}
|
|
|
|
void kbdDevImportDlg::onSelectFile()
|
|
{
|
|
QString strFilePath;
|
|
if(m_pcsDev->isChecked())
|
|
strFilePath = QFileDialog::getOpenFileName(this,tr("选择PSC3000导出的转发数据"),"","*.csv");
|
|
else
|
|
strFilePath = QFileDialog::getOpenFileName(this,tr("选择第三方设备文件"),"","*.xlsx");
|
|
if(!strFilePath.isEmpty())
|
|
m_linePath->setText(strFilePath);
|
|
}
|
|
|
|
void kbdDevImportDlg::onDownTempFile()
|
|
{
|
|
QString strSrcPath,strDstPath;
|
|
if(m_pcsDev->isChecked())
|
|
{
|
|
strSrcPath = Common::getStylePath()+"../templateFile/PCS3000Template.csv";
|
|
strDstPath = QFileDialog::getSaveFileName(this,tr("保存模板"),"PCS3000Template.csv","*.csv");
|
|
}
|
|
else
|
|
{
|
|
strSrcPath = Common::getStylePath()+"../templateFile/thirdPartyDevTemplate.xlsx";
|
|
strDstPath = QFileDialog::getSaveFileName(this,tr("保存模板"),"thirdPartyDevTemplate.xlsx","*.xlsx");
|
|
}
|
|
|
|
if(strDstPath.isEmpty())
|
|
return;
|
|
|
|
QFile srcFile(strSrcPath);
|
|
if(srcFile.exists())
|
|
{
|
|
if(QFile::exists(strDstPath))
|
|
QFile::remove(strDstPath);
|
|
|
|
if(srcFile.copy(strDstPath))
|
|
N_MessageBox::information(this,tr("消息"),tr("模板下载成功"));
|
|
else
|
|
N_MessageBox::information(this,tr("消息"),tr("模板下载失败"));
|
|
}
|
|
else
|
|
N_MessageBox::information(this,tr("消息"),tr("模板文件不存在"));
|
|
}
|