|
|
@ -10,6 +10,7 @@
|
|
|
|
#include <QSqlError>
|
|
|
|
#include <QSqlError>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
#include "countdownmessagebox.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDebug>
|
|
|
@ -20,19 +21,16 @@ Widget::Widget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::Widget)
|
|
|
|
, ui(new Ui::Widget)
|
|
|
|
, m_settingDlg(new SettingWgt(this))
|
|
|
|
, m_settingDlg(new SettingWgt(this))
|
|
|
|
, m_udpDataThread(new UdpDataThread(this))
|
|
|
|
, m_udpDataThread(new UdpDataHandler(this))
|
|
|
|
, m_showSetting(false)
|
|
|
|
, m_showSetting(false)
|
|
|
|
|
|
|
|
, m_isSwitching(false)
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QString filePath = QApplication::applicationDirPath() + "/config/Config.json";
|
|
|
|
|
|
|
|
Common::GetInstance()->loadConfig(filePath);
|
|
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->setupUi(this);
|
|
|
|
initUI();
|
|
|
|
initUI();
|
|
|
|
connect(m_settingDlg, &SettingWgt::SettingFinishSig, [this](){
|
|
|
|
connect(m_settingDlg, &SettingWgt::SettingFinishSig, this, &Widget::on_pushButton_setting_clicked);
|
|
|
|
on_pushButton_setting_clicked();
|
|
|
|
connect(m_udpDataThread, &UdpDataHandler::GetDoneSig, this, &Widget::RegisterDoneSlot);
|
|
|
|
});
|
|
|
|
connect(m_udpDataThread, &UdpDataHandler::GetConnStatusSig, this, &Widget::GetConnStatusSlot);
|
|
|
|
connect(m_udpDataThread, &UdpDataThread::registerRet, this, &Widget::RegisterRetSlot);
|
|
|
|
|
|
|
|
connect(m_udpDataThread, &UdpDataThread::connectStatus, this, &Widget::ConnectStatusSlot);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget::~Widget()
|
|
|
|
Widget::~Widget()
|
|
|
@ -90,13 +88,13 @@ int Widget::startIECSProgram(const QString& workPath, const QString& snId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QProcess *process = new QProcess(this);
|
|
|
|
QProcess *process = new QProcess(this);
|
|
|
|
process->start(workPath);
|
|
|
|
process->start(workPath);
|
|
|
|
qDebug()<<"startIECSProgram:"<<snId;
|
|
|
|
|
|
|
|
if (!process->waitForStarted())
|
|
|
|
if (!process->waitForStarted())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LError("Failed to start the program with arguments:{}", process->errorString());
|
|
|
|
LError("Failed to start the program with arguments:{}", process->errorString());
|
|
|
|
return ExecIECSError;
|
|
|
|
return ExecIECSError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_udpDataThread->sendSnId(snId);
|
|
|
|
m_udpDataThread->sendSnId(snId);
|
|
|
|
|
|
|
|
m_isSwitching = false;
|
|
|
|
return NoError;
|
|
|
|
return NoError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -104,7 +102,11 @@ int Widget::checkForRepairProgram(const int mode, const QString& sn, bool& isFin
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto workModeCfg = Common::GetInstance()->getWorkModeConfigs();
|
|
|
|
auto workModeCfg = Common::GetInstance()->getWorkModeConfigs();
|
|
|
|
QDir workDir(workModeCfg[mode].workPath);
|
|
|
|
QDir workDir(workModeCfg[mode].workPath);
|
|
|
|
workDir.cdUp();
|
|
|
|
if (!workDir.cdUp())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LError("Workdir cd up failed!");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
QString dbPath = workDir.absolutePath() + "/config.db";
|
|
|
|
QString dbPath = workDir.absolutePath() + "/config.db";
|
|
|
|
return databaseQuery(dbPath, sn, isFind);
|
|
|
|
return databaseQuery(dbPath, sn, isFind);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -114,6 +116,7 @@ int Widget::databaseQuery(const QString& databasePath, const QString& deviceSn,
|
|
|
|
// 创建和打开 SQLite 数据库
|
|
|
|
// 创建和打开 SQLite 数据库
|
|
|
|
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
|
|
|
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
|
|
|
db.setDatabaseName(databasePath); // 使用传入的数据库路径
|
|
|
|
db.setDatabaseName(databasePath); // 使用传入的数据库路径
|
|
|
|
|
|
|
|
|
|
|
|
if (!db.open())
|
|
|
|
if (!db.open())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LError("Failed to open database:{}", db.lastError().text());
|
|
|
|
LError("Failed to open database:{}", db.lastError().text());
|
|
|
@ -123,38 +126,47 @@ int Widget::databaseQuery(const QString& databasePath, const QString& deviceSn,
|
|
|
|
|
|
|
|
|
|
|
|
// 创建查询对象
|
|
|
|
// 创建查询对象
|
|
|
|
QSqlQuery query(db);
|
|
|
|
QSqlQuery query(db);
|
|
|
|
|
|
|
|
|
|
|
|
// 准备 SQL 查询
|
|
|
|
// 准备 SQL 查询
|
|
|
|
query.prepare("SELECT COUNT(1) FROM history WHERE device_sn = :device_sn;");
|
|
|
|
query.prepare("SELECT COUNT(1) FROM history WHERE device_sn = :device_sn;");
|
|
|
|
query.bindValue(":device_sn", deviceSn);
|
|
|
|
query.bindValue(":device_sn", deviceSn);
|
|
|
|
|
|
|
|
|
|
|
|
// 执行查询
|
|
|
|
// 执行查询
|
|
|
|
if (!query.exec()) {
|
|
|
|
if (!query.exec()) {
|
|
|
|
LError("Failed to execute query:{}", query.lastError().text());
|
|
|
|
LError("Failed to execute query:{}", query.lastError().text());
|
|
|
|
isFind = false;
|
|
|
|
isFind = false;
|
|
|
|
db.close();
|
|
|
|
db.close();
|
|
|
|
|
|
|
|
QSqlDatabase::removeDatabase(QSqlDatabase::defaultConnection);
|
|
|
|
return DatabaseSelectError;
|
|
|
|
return DatabaseSelectError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理查询结果
|
|
|
|
// 处理查询结果
|
|
|
|
if (query.next())
|
|
|
|
if (query.next())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int count = query.value(0).toInt();
|
|
|
|
int count = query.value(0).toInt();
|
|
|
|
isFind = (count > 0);
|
|
|
|
isFind = (count > 0);
|
|
|
|
db.close();
|
|
|
|
db.close();
|
|
|
|
|
|
|
|
QSqlDatabase::removeDatabase(QSqlDatabase::defaultConnection);
|
|
|
|
return NoError;
|
|
|
|
return NoError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isFind = false;
|
|
|
|
isFind = false;
|
|
|
|
db.close();
|
|
|
|
db.close();
|
|
|
|
|
|
|
|
QSqlDatabase::removeDatabase(QSqlDatabase::defaultConnection);
|
|
|
|
return DatabaseUnknownError;
|
|
|
|
return DatabaseUnknownError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Widget::RegisterRetSlot(bool ret)
|
|
|
|
void Widget::RegisterDoneSlot(bool ret)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
qDebug()<<"11111";
|
|
|
|
ui->lineEdit_snId->setEnabled(true);
|
|
|
|
ui->lineEdit_snId->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Widget::ConnectStatusSlot(bool ret)
|
|
|
|
void Widget::GetConnStatusSlot(bool ret)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!ret)
|
|
|
|
if (!ret && !m_isSwitching)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
qDebug()<<"ret:"<<ret<<",m_isSwitching:"<<m_isSwitching;
|
|
|
|
ui->lineEdit_snId->setEnabled(true);
|
|
|
|
ui->lineEdit_snId->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -164,8 +176,8 @@ void Widget::on_pushButton_setting_clicked()
|
|
|
|
if (ui->widget_setting->isHidden())
|
|
|
|
if (ui->widget_setting->isHidden())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ui->pushButton_setting->setIcon(QIcon(":/resources/folding.png"));
|
|
|
|
ui->pushButton_setting->setIcon(QIcon(":/resources/folding.png"));
|
|
|
|
m_settingDlg->loadConfig();
|
|
|
|
|
|
|
|
ui->widget_setting->show();
|
|
|
|
ui->widget_setting->show();
|
|
|
|
|
|
|
|
m_settingDlg->loadConfig();
|
|
|
|
int currentWidth = this->width();
|
|
|
|
int currentWidth = this->width();
|
|
|
|
this->adjustSize();
|
|
|
|
this->adjustSize();
|
|
|
|
this->resize(currentWidth, this->height()); // 只保持高度变化
|
|
|
|
this->resize(currentWidth, this->height()); // 只保持高度变化
|
|
|
@ -190,9 +202,34 @@ void Widget::addLogItem(const QString &text)
|
|
|
|
ui->list_log->addItem(text); // 添加新条目
|
|
|
|
ui->list_log->addItem(text); // 添加新条目
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Widget::switchProgram()
|
|
|
|
int Widget::switchProgram(const QString snId, const int mode, const bool isRepair)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
static bool isFirstRepair = true;
|
|
|
|
|
|
|
|
if (isRepair && isFirstRepair)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
isFirstRepair = false;
|
|
|
|
|
|
|
|
CountdownMessageBox::showCountdownMessageBox(this, 3, "正在切换返修程序包!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (!isRepair)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
isFirstRepair = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
auto workModeCfgs = Common::GetInstance()->getWorkModeConfigs();
|
|
|
|
|
|
|
|
auto workModeCfg = workModeCfgs[mode];
|
|
|
|
|
|
|
|
QString workPath = isRepair ? workModeCfg.reworkPath : workModeCfg.workPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
|
|
|
|
connect(timer, &QTimer::timeout, this, [this, timer, snId, workPath]() {
|
|
|
|
|
|
|
|
if (Common::GetInstance()->getCurrentWorkMode() == -1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_isSwitching = true;
|
|
|
|
|
|
|
|
m_udpDataThread->stopClose();
|
|
|
|
|
|
|
|
timer->stop(); // 停止定时器
|
|
|
|
|
|
|
|
// 启动 IECS 程序
|
|
|
|
|
|
|
|
startIECSProgram(workPath, snId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
timer->start(1000);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -218,7 +255,7 @@ void Widget::on_lineEdit_snId_returnPressed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (productFormat.isEmpty())
|
|
|
|
if (productFormat.isEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, "警告", "当前SN与启用设值SN不匹配,请检查或重新扫码");
|
|
|
|
QMessageBox::information(this, "警告", "当前SN与启用设值SN不匹配,请检查设置或重新扫码");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui->lineEdit_snId->setEnabled(false);
|
|
|
|
ui->lineEdit_snId->setEnabled(false);
|
|
|
@ -232,8 +269,7 @@ void Widget::on_lineEdit_snId_returnPressed()
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto selectMode = selectedProducts[productFormat];
|
|
|
|
auto selectMode = selectedProducts[productFormat];
|
|
|
|
auto workModeCfgs = Common::GetInstance()->getWorkModeConfigs();
|
|
|
|
if (selectMode != currWorkMode || isRepair)
|
|
|
|
if (selectMode != currWorkMode)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 切换工作模式
|
|
|
|
// 切换工作模式
|
|
|
|
if (currWorkMode != -1)
|
|
|
|
if (currWorkMode != -1)
|
|
|
@ -242,20 +278,7 @@ void Widget::on_lineEdit_snId_returnPressed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//TODO:不相等时,m_udpDataThread发送关闭信号,等待Common单例类中的标志位变成-1后,m_udpDataThread停止发送关闭信号并启动IECS程序
|
|
|
|
//TODO:不相等时,m_udpDataThread发送关闭信号,等待Common单例类中的标志位变成-1后,m_udpDataThread停止发送关闭信号并启动IECS程序
|
|
|
|
//同时需要去IECS程序路径中查找数据库,判断是否使用返修程序
|
|
|
|
//同时需要去IECS程序路径中查找数据库,判断是否使用返修程序
|
|
|
|
auto workModeCfg = workModeCfgs[selectMode];
|
|
|
|
switchProgram(snId, selectMode, isRepair);
|
|
|
|
QString workPath = isRepair ? workModeCfg.reworkPath : workModeCfg.workPath;
|
|
|
|
|
|
|
|
qDebug()<<"workPath:"<<workPath;
|
|
|
|
|
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
|
|
|
|
connect(timer, &QTimer::timeout, this, [this, timer, snId, workPath]() {
|
|
|
|
|
|
|
|
if (Common::GetInstance()->getCurrentWorkMode() == -1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
m_udpDataThread->stopClose();
|
|
|
|
|
|
|
|
timer->stop(); // 停止定时器
|
|
|
|
|
|
|
|
// 启动 IECS 程序
|
|
|
|
|
|
|
|
startIECSProgram(workPath, snId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
timer->start(1000);
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_udpDataThread->sendSnId(snId);
|
|
|
|
m_udpDataThread->sendSnId(snId);
|
|
|
|