Introduce `BankSettingsWindow` for managing bank data, added `EditBankDialog` for editing bank details, and created reusable `PaddedItemDelegate` for list padding. Refactor DAO to support fetching multiple applications by device ID for improved data handling. Adjust existing components to integrate new bank-related features.
121 lines
3.8 KiB
C++
121 lines
3.8 KiB
C++
#include <QSqlQuery>
|
|
#include <QSqlError>
|
|
#include <QVariant>
|
|
#include "ApplicationDAO.h"
|
|
#include "DatabaseManager.h"
|
|
#include "db/ApplicationInfo.h"
|
|
|
|
bool ApplicationDAO::upsertApplication(const ApplicationInfo &info) {
|
|
QSqlQuery query(DatabaseManager::instance().database());
|
|
|
|
query.prepare(R"(
|
|
INSERT INTO applications (id, device_id, pin_code, name, package, status, comment, image)
|
|
VALUES (:id, :device_id, :pin_code, :name, :package, :status, :comment, :image)
|
|
ON CONFLICT(device_id, name)
|
|
DO UPDATE SET
|
|
device_id = excluded.device_id,
|
|
pin_code = excluded.pin_code,
|
|
name = excluded.name,
|
|
package = excluded.package,
|
|
status = excluded.status,
|
|
comment = excluded.comment,
|
|
image = excluded.image
|
|
)");
|
|
|
|
query.bindValue(":id", info.id);
|
|
query.bindValue(":device_id", info.deviceId);
|
|
query.bindValue(":pin_code", info.pinCode);
|
|
query.bindValue(":name", info.name);
|
|
query.bindValue(":package", info.package);
|
|
query.bindValue(":status", info.status);
|
|
query.bindValue(":comment", info.comment);
|
|
query.bindValue(":image", info.image);
|
|
|
|
if (!query.exec()) {
|
|
qWarning() << "Ошибка при вставке/обновлении application:" << query.lastError().text();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ApplicationDAO::updatePinCode(const QString &appId, const QString &pinCode) {
|
|
QSqlQuery query(DatabaseManager::instance().database());
|
|
|
|
query.prepare(R"(
|
|
UPDATE applications
|
|
SET pin_code = :pin_code
|
|
WHERE id = :id
|
|
)");
|
|
|
|
query.bindValue(":pin_code", pinCode);
|
|
query.bindValue(":id", appId);
|
|
|
|
if (!query.exec()) {
|
|
qWarning() << "Ошибка при обновлении PIN-кода приложения:" << query.lastError().text();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
ApplicationInfo parseApplication(const QSqlQuery &query) {
|
|
ApplicationInfo app;
|
|
app.id = query.value("id").toString();
|
|
app.deviceId = query.value("device_id").toString();
|
|
app.pinCode = query.value("pin_code").toString();
|
|
app.name = query.value("name").toString();
|
|
app.package = query.value("package").toString();
|
|
app.status = query.value("status").toString();
|
|
app.comment = query.value("comment").toString();
|
|
app.image = query.value("image").toByteArray();
|
|
return app;
|
|
}
|
|
|
|
ApplicationInfo ApplicationDAO::getApplication(const QString &deviceId, const QString &appName) {
|
|
QSqlQuery query(DatabaseManager::instance().database());
|
|
|
|
query.prepare(R"(
|
|
SELECT id, device_id, pin_code, name, package, status, comment, image
|
|
FROM applications
|
|
WHERE device_id = :device_id AND name = :name
|
|
LIMIT 1
|
|
)");
|
|
|
|
query.bindValue(":device_id", deviceId);
|
|
query.bindValue(":name", appName);
|
|
|
|
if (!query.exec()) {
|
|
qWarning() << "Ошибка при получении приложений по deviceId:" << query.lastError().text();
|
|
return {};
|
|
}
|
|
|
|
while (query.next()) {
|
|
return parseApplication(query);
|
|
}
|
|
return {};
|
|
}
|
|
|
|
QList<ApplicationInfo> ApplicationDAO::getApplicationsByDeviceId(const QString &deviceId) {
|
|
QSqlQuery query(DatabaseManager::instance().database());
|
|
QList<ApplicationInfo> list;
|
|
query.prepare(R"(
|
|
SELECT id, device_id, pin_code, name, package, status, comment, image
|
|
FROM applications
|
|
WHERE device_id = :device_id
|
|
)");
|
|
|
|
query.bindValue(":device_id", deviceId);
|
|
|
|
if (!query.exec()) {
|
|
qWarning() << "Ошибка при получении приложений по deviceId:" << query.lastError().text();
|
|
return {};
|
|
}
|
|
|
|
while (query.next()) {
|
|
list.append(parseApplication(query));
|
|
}
|
|
|
|
return list;
|
|
}
|