PNP_PIbd-31_Rodionov_I_A_Co.../service/serviceloaddb.h
2025-01-14 21:28:06 +04:00

49 lines
1.1 KiB
C++

#ifndef SERVICELOADDB_H
#define SERVICELOADDB_H
#include <QObject>
#include <QSql>
#include <QSqlDatabase>
#include <QSqlRecord>
#include <QSqlQuery>
#include <QSqlError>
#include <QString>
#include <QDebug>
#include <QStringList>
#include <QMap>
#include <QList>
#include <QFile>
#include "models/types.h" // IWYU pragma: keep
class ServiceLoadDB : public QObject
{
Q_OBJECT
public:
explicit ServiceLoadDB(QObject *parent = nullptr);
void start();
QMap<int, Location> loadLocations();
QMap<int, Department> loadDepartments();
QMap<int, Manufacturer> loadManufacturers();
QMap<int, DeviceType> loadDeviceTypes();
QMap<int, DeviceModel> loadDeviceModels();
QMap<int, Device> loadDevices();
bool updateDevice(const Device &device);
private:
QList<DeviceStructureElement> readStructureElements(int modelId);
template <typename T>
T getValueOrDefault(const QSqlQuery &query, const QSqlRecord &record, const QString &fieldName, const T &defaultValue);
private:
QSqlDatabase _db;
QString _dbInput;
QSqlQuery _query;
QMap<int, DeviceModel> _mapDeviceModels;
};
#endif // SERVICELOADDB_H