Files
SimpleAccount/SqlOpr.h
2026-02-27 12:29:27 +08:00

111 lines
2.3 KiB
C++

#ifndef SQL_OPR_H
#define SQL_OPR_H
#include <QSqlDatabase>
#include <cstdint>
#include <fmt/format.h>
#include <string>
#include <vector>
struct AccountRecord {
int32_t id{};
int32_t money{};
std::string payType{};
std::string dt;
std::string thing;
std::string classify;
std::string remark;
std::string additionFile{};
};
struct CommonRecord {
int32_t id{};
std::string key;
std::string value;
std::string type;
std::string mark;
};
struct RepayRecord {
int32_t id{};
int32_t accID{};
int32_t money{};
std::string dt;
std::string remark;
};
using ClassifyRecordList = std::vector<CommonRecord>;
using AccountRecordList = std::vector<AccountRecord>;
using RepayRecordList = std::vector<RepayRecord>;
class ACTSqlOpr
{
public:
ACTSqlOpr();
~ACTSqlOpr();
public:
bool OpenDb(const std::string& path);
bool GetAccountList(AccountRecordList& ret);
bool AppendAccount(AccountRecord& ret);
bool DeleteAccount(int32_t id);
bool UpdateAccount(AccountRecord& ret);
QSqlDatabase& GetDb();
const std::string& GetLastErr();
private:
bool generateDefaultTB();
private:
QSqlDatabase db_;
std::string dbPath_{};
std::string lastErr_{};
};
class ComSqlOpr
{
public:
ComSqlOpr(QSqlDatabase& db);
public:
bool GetClassifyList(ClassifyRecordList& ret);
bool GetItem(CommonRecord& ret, const std::string& key);
bool UpdateItem(CommonRecord& ret);
bool InserItem(CommonRecord& ret);
bool DeleteItem(const std::string& value);
bool CheckContent();
bool CheckClassifyExist(const std::string& value);
const std::string& GetLastErr();
private:
bool CheckAndInsert(const std::string& key, const std::string& value, const std::string& type, const std::string& mark);
private:
bool generateDefaultTB();
private:
QSqlDatabase& db_;
std::string lastErr_{};
};
class RepaySqlOpr
{
public:
RepaySqlOpr(QSqlDatabase& db);
public:
bool GetRepayResult(RepayRecordList& ret, int32_t accID);
bool InsertRepayRecord(RepayRecord& ret);
bool updateRepayRecord(RepayRecord& ret);
bool deleteRepayRecord(int32_t id);
const std::string& GetLastErr();
private:
bool generateDefaultTB();
private:
QSqlDatabase& db_;
std::string lastErr_{};
};
#endif // SQL_OPR_H