feat(production): 删除动作记录、释放料位、删除工件及订单等
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
|
||||
namespace {
|
||||
@@ -156,15 +157,17 @@ bool OrderRepository::insertOrder(Order *order, QString *error)
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery query(DatabaseManager::instance().database());
|
||||
const QSqlDatabase database = DatabaseManager::instance().database();
|
||||
const bool sqlite = DatabaseManager::instance().config().driverName == "QSQLITE";
|
||||
QSqlQuery query(database);
|
||||
query.prepare("insert into orders "
|
||||
"(no, production_no, drawing_no, batch_no, plan_num, qualified, "
|
||||
"unqualified, status, inspection_mode, start_tray_no, start_slot_no, "
|
||||
"begin_time, end_time, remark) "
|
||||
"values (:no, :production_no, :drawing_no, :batch_no, :plan_num, "
|
||||
":qualified, :unqualified, :status, :inspection_mode, "
|
||||
":start_tray_no, :start_slot_no, :begin_time, :end_time, :remark) "
|
||||
"returning id");
|
||||
":start_tray_no, :start_slot_no, :begin_time, :end_time, :remark)"
|
||||
+ (sqlite ? QString() : QString(" returning id")));
|
||||
query.bindValue(":no", order->no);
|
||||
query.bindValue(":production_no", order->productionNo);
|
||||
query.bindValue(":drawing_no", order->drawingNo);
|
||||
@@ -180,11 +183,19 @@ bool OrderRepository::insertOrder(Order *order, QString *error)
|
||||
query.bindValue(":end_time", order->endTime.isValid() ? QVariant(order->endTime) : QVariant(QVariant::DateTime));
|
||||
query.bindValue(":remark", order->remark);
|
||||
|
||||
if (!query.exec() || !query.next()) {
|
||||
if (!query.exec()) {
|
||||
setError(query, error);
|
||||
return false;
|
||||
}
|
||||
order->id = query.value(0).toInt();
|
||||
if (sqlite) {
|
||||
order->id = query.lastInsertId().toInt();
|
||||
} else {
|
||||
if (!query.next()) {
|
||||
setError(query, error);
|
||||
return false;
|
||||
}
|
||||
order->id = query.value(0).toInt();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -257,12 +268,19 @@ bool OrderRepository::removeOrder(int id, QString *error)
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery query(DatabaseManager::instance().database());
|
||||
query.prepare("delete from orders where id = :id");
|
||||
query.bindValue(":id", id);
|
||||
if (!query.exec()) {
|
||||
setError(query, error);
|
||||
return false;
|
||||
const QStringList statements = QStringList()
|
||||
<< "delete from production_state_history where order_id = :id"
|
||||
<< "delete from production_runs where order_id = :id"
|
||||
<< "delete from alarm_records where order_id = :id"
|
||||
<< "delete from orders where id = :id";
|
||||
for (const QString &statement : statements) {
|
||||
QSqlQuery query(DatabaseManager::instance().database());
|
||||
query.prepare(statement);
|
||||
query.bindValue(":id", id);
|
||||
if (!query.exec()) {
|
||||
setError(query, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user