账单记录器迁移。
This commit is contained in:
111
SqlOpr.h
Normal file
111
SqlOpr.h
Normal file
@@ -0,0 +1,111 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user