diff --git a/softwareDirectory/AutoVerScheme/formaddrsetting.cpp b/softwareDirectory/AutoVerScheme/formaddrsetting.cpp index ea066fc..99d464a 100644 --- a/softwareDirectory/AutoVerScheme/formaddrsetting.cpp +++ b/softwareDirectory/AutoVerScheme/formaddrsetting.cpp @@ -166,10 +166,6 @@ void FormAddrSetting::on_pushButton_18_clicked() { - - - - if(editIdx==-1){ //判断添加的检定项目 是否已经添加过 if(CheckItemNameList.contains(ui->comboBox->currentText())){ @@ -221,7 +217,6 @@ updateRow(rowCount,cmd); CheckItemNameList.append(cmd.belong_vername); }else{ - if(checkMode) cmdList[editIdx].belong_vername = this->ui->comboBox->currentText(); else @@ -231,7 +226,6 @@ cmdList[editIdx].update_time = QDateTime::currentDateTime(); InstructionLib cmd = cmdList[editIdx]; BaseCommonApi::UpdateInstructionLib(cmd); - updateRow(editIdx,cmd); } this->ui->stackedWidget->setCurrentIndex(0); @@ -336,7 +330,67 @@ void FormAddrSetting::on_pushButton_2_clicked() { + // 获取应用程序的根目录 + QString path = QFileDialog::getOpenFileName(this, tr("通信命令"), "", tr("Text Files (*.txt)"));; + QFile file(path); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + // 错误处理 + qDebug() << "无法打开文件:" << file.errorString(); + QString str=file.errorString(); + return; + } + for (const InstructionLib& cmd : cmdList) { + BaseCommonApi::DeleteInstructionLib(cmd.id); + } + cmdList.clear(); + QTextStream in(&file); + in.setCodec("UTF-8"); + QString line; + while (!in.atEnd()) { + line = in.readLine(); + // 使用'|'分割键和值 + QStringList list = line.split(QRegExp("\\s*\\|\\s*"), QString::KeepEmptyParts); + if(list.length()==5){ + InstructionLib cmd; + QString sName = ""; + if(iType==0){ + if(checkMode){ + cmd.verification_program_id = sId; + cmd.device_id = sId; + }else{ + QList result = BaseCommonApi::getTestedCatDevice(sId); + if(result.length()>0){ + sName = result[0].equipment_name; + } + cmd.verification_program_id = sId; + cmd.device_id = sId; + cmd.device_name = sName; + } + }else{ + QList result = BaseCommonApi::getCatDeviceInfor(sId); + if(result.length()>0){ + sName = result[0].equipment_name; + } + cmd.verification_program_id = sId; + cmd.device_id = sId; + cmd.device_name = sName; + } + BaseCommonApi baseApi; + qint64 id = baseApi.generateId(); + cmd.id = QString::number(id); + cmd.type = list[0]; + cmd.belong_vername=list[1]; + cmd.belong_checkname = list[2]; + cmd.instruct_config=list[3]; + cmd.instruct_read=list[4]; + cmd.create_time = QDateTime::currentDateTime(); + cmd.update_time = QDateTime::currentDateTime(); + BaseCommonApi::InsertInstructionLib(cmd); + } + } + file.close(); + initCmdTable(); } void FormAddrSetting::on_pushButton_clicked() @@ -351,9 +405,17 @@ void FormAddrSetting::on_ExportCmdInfo_clicked() { - QString fileName = QFileDialog::getSaveFileName(this, tr("CmdInfo"), "", tr("Text Files (*.txt)")); - if (fileName.isEmpty()) { - return; + QString fileName = QFileDialog::getSaveFileName(this, tr("通信命令"), "", tr("Text Files (*.txt)")); + if (!fileName.isEmpty()) { + QFile file(fileName); + if(file.open(QIODevice::WriteOnly| QIODevice::Text)){ + QTextStream out(&file); + out.setCodec("UTF-8"); + for (const InstructionLib& cmd : cmdList) { + QString sLine = QString("%1|%2|%3|%4|%5").arg(cmd.type).arg(cmd.belong_vername).arg(cmd.belong_checkname).arg(cmd.instruct_config).arg(cmd.instruct_read); + out << sLine << "\n"; + } + file.close(); + } } - }