#ifndef DATABASEUTILS_H
#define DATABASEUTILS_H

#include <QtSql/QSqlQuery>
#include <QtSql/QSqlError>
#include <QtSql/QSqlDatabase>
#include <QFile>
#include <QDate>
#include <QDebug>
#include <QtSql/QSqlRecord>

namespace DatabaseUtils
{
    extern QSqlDatabase db;

    bool init_Database();
    bool closeDatabase();
    bool insert_ResData(const QString &chexing, const QString &sm_num, const QString &hot_num, double value, const QString &detect, const QString &state, const QString &flag, const QString &name);
    int delete_ResData(int id);
    bool update_ResData(int id, const QString &chexing, const QString &sm_num, const QString &hot_num, double value, const QString &detect, const QString &state, const QString &flag, const QString &name);
    QList<QVariantMap> read_ResData();
    int getResTotalRows();
    QVector<QVariantList> getData(int limit, int offset);
    QVector<QVariantList> getAllData();
    bool insertTestData(int numRows);
    bool insert_Info_t(const QString &column, const QVariant &value);
    bool delete_Info_t();
    bool update_Info_t(const QString &column, const QVariant &value);
    QVariant read_Info_t(const QString &column);
    QMap<QString, QVariant> read_all_Info_t();

    QList<QVariantList> getLastFiveDailyDataSkippingToday();
    bool insertOrUpdateDailyData(int daily_inspection_count, int manual_inspection_count, int qualified, int over_limit, int under_limit, double max_value, double min_value, double qualification_rate);
    QString get_today_daliy_t(int &daily_cnt, int &daily_cnt_manual,
                              int &daily_qualified_cnt, int &daily_cnt_over,
                              int &daily_cnt_down, double &daily_cnt_max,
                              double &daily_cnt_min);
    bool updateLastDate();

}

#endif // DATABASEUTILS_H
