#include "kbddevimportdlg.h" #include "../model_common/common.h" #include #include #include #include #include #include #include #include #include kbdDevImportDlg::kbdDevImportDlg(QWidget *parent) : QDialog(parent) { setWindowTitle(tr("导入前置设备")); QVBoxLayout* vLayout = new QVBoxLayout; QHBoxLayout* hLayout = new QHBoxLayout; m_modelTypeGroupbox= new QGroupBox(tr("模板类型"),this); m_pcsDev = new QRadioButton(tr("PCS3000设备")); m_otherDev = new QRadioButton(tr("第三方设备")); m_pcsDev->setChecked(true); QHBoxLayout* hLayout1 = new QHBoxLayout; hLayout1->addWidget(m_pcsDev); hLayout1->addWidget(m_otherDev); hLayout1->setMargin(10); m_modelTypeGroupbox->setLayout(hLayout1); hLayout->addWidget(m_modelTypeGroupbox); 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); QPushButton* btnTemp = new QPushButton(tr("下载导入模板"),this); QPushButton* btnUpdate = new QPushButton(tr("更新设备"),this); QPushButton* btnOk = new QPushButton(tr("导入设备"),this); QPushButton* btnAddSub = new QPushButton(tr("增删设备点"),this); hLayout = new QHBoxLayout; hLayout->setMargin(0); hLayout->addWidget(btnOk); hLayout->addWidget(btnUpdate); hLayout->addWidget(btnAddSub); vLayout->addLayout(hLayout); vLayout->addSpacing(20); QVBoxLayout* vLayoutmpt = new QVBoxLayout; lable = new QLabel(tr("备注:"),this); vLayoutmpt->addWidget(lable); lable = new QLabel(tr("1 导入设备:导入通道设备及点数据,必须是之前未添加设备"),this); vLayoutmpt->addWidget(lable); lable = new QLabel(tr("2 更新设备:更新已存在设备点属性信息,不能添加设备及设备点"),this); vLayoutmpt->addWidget(lable); lable = new QLabel(tr("3 增删设备点:对已有设备点进行增加或删除,不会修改现有设备点属性"),this); vLayoutmpt->addWidget(lable); vLayout->addLayout(vLayoutmpt); hLayout = new QHBoxLayout; hLayout->addWidget(btnTemp); vLayout->addLayout(hLayout); 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);}); connect(btnAddSub,&QPushButton::clicked,[this](){done(3);}); } 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)) QMessageBox::information(this,tr("消息"),tr("模板下载成功")); else QMessageBox::information(this,tr("消息"),tr("模板下载失败")); } else QMessageBox::information(this,tr("消息"),tr("模板文件不存在")); }