Newer
Older
AutomaticVerification / softwareDirectory / AutoVerScheme / newcheckmethod.cpp
陈实 on 26 Mar 2024 11 KB 自动检定核查详情查看
#include "newcheckmethod.h"
#include "ui_newcheckmethod.h"
#include "checkdevice.h"
#include "qfiledialog.h"
#include "formcheckpoint.h"
#include <QMessageBox>
#include <QDebug>
#include "formcommsetting.h"
#include "formaddrsetting.h"

NewCheckMethod::NewCheckMethod(QWidget *parent,QString sId,bool bEdit) :
    QWidget(parent),
    methodId(sId),
    bEditMode(bEdit),
    ui(new Ui::NewCheckMethod)
{
    ui->setupUi(this);
    ui->tableWidget->verticalHeader()->setParent(nullptr);
    for(int i=0;i<7;i++)
        ui->tableWidget->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch);
    ui->pushButton_3->setEnabled(bEditMode);
    getMethodInfo();
}


NewCheckMethod::~NewCheckMethod()
{
    delete ui;
}

void NewCheckMethod::getMethodInfo()
{
    if(methodId!="")
    {
        programInfo = BaseCommonApi::getVerificationProgramInfo(methodId);
        ui->lineEditName->setText(programInfo.program_name);
        ui->lineEditUser->setText(programInfo.create_name);
        ui->dateEditTime->setDateTime(programInfo.create_time);
        ui->lineEditMark->setText(programInfo.remark);
        if(programInfo.img_path!="")
        {
            //QImage img(programInfo.img_path);
            //QImage scalimg = img.scaled(ui->label_11->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
            //ui->label_11->setPixmap(QPixmap::fromImage(scalimg));
            QString strStyle = "QLabel{"
                               "image:url("+programInfo.img_path+");"
                               "}";
            qDebug() << "strStyle:" << strStyle ;
            ui->label_11->setStyleSheet(strStyle);
        }
        chooseDevices(programInfo.tested_device_id,programInfo.standard_device_id);
    }
}

void NewCheckMethod::showEvent(QShowEvent *event)
{
}

void NewCheckMethod::showCheckDevice()
{
    CheckDevice *checkWindow = new CheckDevice;
    checkWindow->newCheckWnd = this;
    checkWindow->setWindowState(Qt::WindowMaximized);
    checkWindow->setWindowModality(Qt::ApplicationModal);
    checkWindow->show();
}

void NewCheckMethod::choosePicture()
{
    QString sName = QFileDialog::getOpenFileName(this,"选择图片","","Image File(*.bmp *.jpg *.jpeg *.png)");
    //第一个参数:标准文件对话框的父窗口;第二个参数:标准文件对话框的标题;第三个参数:指定默认的目录;第四个参数:文件过滤器
    //QImage img(sName);
    //int WindowW = this->width();
    //int WindowH = this->height();
    //ui->label->setGeometry(0, 0, WindowW, WindowH);
    //QImage scalimg = img.scaled(ui->label_11->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
    //ui->label_11->setPixmap(QPixmap::fromImage(scalimg));
    //ui->label_11->setPixmap(QPixmap(sName));
    QString strStyle = "QLabel{"
                       "image:url("+sName+");"
                       "}";
    //qDebug() << "strStyle:" << strStyle ;
    ui->label_11->setStyleSheet(strStyle);
    programInfo.img_path = sName;
}

void NewCheckMethod::deletePicture()
{
    ui->label_11->setStyleSheet("");
    programInfo.img_path = "";
}

void NewCheckMethod::showCheckPoint()
{
    FormCheckPoint *checkWindow = new FormCheckPoint(nullptr,checkId);
    //checkWindow.setWindowState(Qt::WindowMaximized);
    checkWindow->setWindowModality(Qt::ApplicationModal);
    checkWindow->show();
}

void NewCheckMethod::on_pushButton_3_clicked()
{
    if(!bEditMode)
        return;
    if(programInfo.id=="")
    {
        BaseCommonApi baseApi;
        qint64 id = baseApi.generateId();
        programInfo.id = QString::number(id);
        programInfo.program_name = ui->lineEditName->text();
        programInfo.create_name = ui->lineEditUser->text();
        programInfo.create_time = ui->dateEditTime->dateTime();
        programInfo.remark = ui->lineEditMark->text();
        //qDebug() << "programInfo.id" << programInfo.id ;
        if(BaseCommonApi::InsertVerificationProgramInfo(programInfo))
        {
            checkManageWnd->updateTable(true,programInfo);
            this->close();
        }else{
            QMessageBox::warning(this, "警告", "保存失败!");
        }
    }else{
        programInfo.program_name = ui->lineEditName->text();
        programInfo.create_name = ui->lineEditUser->text();
        programInfo.create_time = ui->dateEditTime->dateTime();
        programInfo.update_time = QDateTime::currentDateTime();
        programInfo.remark = ui->lineEditMark->text();
        if(BaseCommonApi::UpdateVerificationProgramInfo(programInfo))
        {
            checkManageWnd->updateTable(false,programInfo);
            this->close();
        }else{
            QMessageBox::warning(this, "警告", "保存失败!");
        }
    }
}

void NewCheckMethod::on_pushButton_4_clicked()
{
    this->close();
}
void NewCheckMethod::on_cmdButton_clicked(int type,QString id)
{
    //qDebug() << "cmd click:" << type << id ;
    FormAddrSetting *form = new FormAddrSetting(nullptr,type,id,checkId);
    form->setWindowModality(Qt::ApplicationModal);
    form->show();
}

void NewCheckMethod::on_commButton_clicked(int type,QString id)
{
    //qDebug() << "comm click:" << type << id ;
    FormCommSetting *form = new FormCommSetting(nullptr,type,id);
    form->setWindowModality(Qt::ApplicationModal);
    form->show();
}

void NewCheckMethod::chooseDevices(QString checkIds, QString bizIds)
{
    programInfo.tested_device_id=checkIds;
    programInfo.standard_device_id = bizIds;
    ui->tableWidget->clearContents();
    ui->tableWidget->setRowCount(0);
    QStringList idList;
    int rowCount = 0;
    int row=0;
    checkId="";
    if(checkIds!="")
    {
        idList = checkIds.split(",");
        for(const QString& id : idList)
        {
            checkId = id;
            QList<TestedCatDevice> result = BaseCommonApi::getTestedCatDevice(id);
            if(result.length()>0){
                rowCount = ui->tableWidget->rowCount();

                ui->tableWidget->insertRow(rowCount);
                ui->tableWidget->setItem(row, 0, new QTableWidgetItem("被检设备"));
                ui->tableWidget->setItem(row, 1, new QTableWidgetItem(result[0].equipment_name)); //设置数据
                ui->tableWidget->setItem(row, 2, new QTableWidgetItem(result[0].model)); //设置数据
                ui->tableWidget->setItem(row, 3, new QTableWidgetItem(result[0].help_instruction)); //设置数据
                ui->tableWidget->setItem(row, 4, new QTableWidgetItem(result[0].manufacture_no)); //设置数据
                ui->tableWidget->setItem(row, 5, new QTableWidgetItem(result[0].manufacturer));
                QPushButton *btn_1 = new QPushButton();
                btn_1->setText(tr("设置命令"));
                btn_1->setStyleSheet("QPushButton{"
                                     "background-color:rgba(255,255,255,0);"
                                     "color:rgba(92,170,54,100);"
                                     "text-decoration:underline;"
                                     "}");
                btn_1->setCursor(Qt::PointingHandCursor);
                int type=0;
                //connect(btn_1,SIGNAL(clicked()),this,SLOT(on_cmdButton_clicked(1,id)));
                connect(btn_1, &QPushButton::clicked, this, [this,type, id]() {
                    on_cmdButton_clicked(type,id);
                });
                btn_1->setIconSize(QSize(16,16));
                btn_1->setIcon(QIcon(":/image/Index/u2324.svg"));
                QPushButton *btn_2 = new QPushButton();
                btn_2->setText(tr("设置设备接口"));
                btn_2->setStyleSheet("QPushButton{"
                                     "background-color:rgba(255,255,255,0);"
                                     "color:rgba(92,170,54,100);"
                                     "text-decoration:underline;"
                                     "}");
                btn_2->setCursor(Qt::PointingHandCursor);
                //connect(btn_2,SIGNAL(clicked()),this,SLOT(on_commButton_clicked(1,id)));
                connect(btn_2, &QPushButton::clicked, this, [this,type, id]() {
                    on_commButton_clicked(type,id);
                });
                btn_2->setIconSize(QSize(16,16));
                btn_2->setIcon(QIcon(":/image/Index/u2324.svg"));
                QWidget *tmp_widget = new QWidget();
                QHBoxLayout *tmp_layout = new QHBoxLayout(tmp_widget);
                tmp_layout->addWidget(btn_1);
                tmp_layout->addWidget(btn_2);
                tmp_layout->setMargin(0);
                ui->tableWidget->setCellWidget(row,6,tmp_widget);
                row++;
            }
        }
        idList.clear();
    }

    if(bizIds!="")
    {
        idList = bizIds.split(",");
        for(const QString& id : idList)
        {
            QList<CatDeviceInfor> result = BaseCommonApi::getCatDeviceInfor(id);
            if(result.length()>0){
                rowCount = ui->tableWidget->rowCount();

                ui->tableWidget->insertRow(rowCount);
                ui->tableWidget->setItem(row, 0, new QTableWidgetItem("标准设备"));
                ui->tableWidget->setItem(row, 1, new QTableWidgetItem(result[0].equipment_name)); //设置数据
                ui->tableWidget->setItem(row, 2, new QTableWidgetItem(result[0].model)); //设置数据
                ui->tableWidget->setItem(row, 3, new QTableWidgetItem(result[0].remark)); //设置数据
                ui->tableWidget->setItem(row, 4, new QTableWidgetItem(result[0].manufacture_no)); //设置数据
                ui->tableWidget->setItem(row, 5, new QTableWidgetItem(result[0].manufacturer));
                QPushButton *btn_1 = new QPushButton();
                btn_1->setText(tr("设置命令"));
                btn_1->setStyleSheet("QPushButton{"
                                     "background-color:rgba(255,255,255,0);"
                                     "color:rgba(92,170,54,100);"
                                     "text-decoration:underline;"
                                     "}");
                btn_1->setCursor(Qt::PointingHandCursor);
                int type=1;
                connect(btn_1, &QPushButton::clicked, this, [this,type, id]() {
                    on_cmdButton_clicked(type,id);
                });

                btn_1->setIconSize(QSize(16,16));
                btn_1->setIcon(QIcon(":/image/Index/u2324.svg"));
                QPushButton *btn_2 = new QPushButton();
                btn_2->setText(tr("设置设备接口"));
                btn_2->setStyleSheet("QPushButton{"
                                     "background-color:rgba(255,255,255,0);"
                                     "color:rgba(92,170,54,100);"
                                     "text-decoration:underline;"
                                     "}");
                btn_2->setCursor(Qt::PointingHandCursor);
                connect(btn_2, &QPushButton::clicked, this, [this,type, id]() {
                    on_commButton_clicked(type,id);
                });
                btn_2->setIconSize(QSize(16,16));
                btn_2->setIcon(QIcon(":/image/Index/u2324.svg"));
                QWidget *tmp_widget = new QWidget();
                QHBoxLayout *tmp_layout = new QHBoxLayout(tmp_widget);
                tmp_layout->addWidget(btn_1);
                tmp_layout->addWidget(btn_2);
                tmp_layout->setMargin(0);
                ui->tableWidget->setCellWidget(row,6,tmp_widget);
                row++;
            }
        }
        idList.clear();
    }
}