gen_interface.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "gen_interface.h"
  2. QJsonObject Gen_Interface::getInfofromDb(){
  3. QJsonObject data;
  4. QJsonArray fieldsArray;
  5. QSqlDatabase db = QSqlDatabase::database();
  6. if (!db.isOpen()) {
  7. qWarning() << "数据库未打开";
  8. return data;
  9. }
  10. // 查询 systemConfig 表
  11. QSqlQuery queryBond(db);
  12. queryBond.prepare(R"(
  13. SELECT Function, Description,setValue
  14. FROM systemConfig
  15. )");
  16. if (queryBond.exec()) {
  17. while (queryBond.next()) {
  18. QJsonObject field;
  19. field["Function"] = queryBond.value("Function").toString();
  20. field["Description"] = queryBond.value("Description").toString();
  21. field["setValue"] = queryBond.value("setValue").toInt();
  22. fieldsArray.append(field);
  23. }
  24. // qDebug() << "Fetched fields:" << fieldsArray;
  25. } else {
  26. qWarning() << "查询 systemConfig 失败:" << queryBond.lastError().text();
  27. }
  28. data["systemConfig"]=fieldsArray;
  29. // qDebug() << "Fetched data:" << data;
  30. return data;
  31. }
  32. int Gen_Interface::getLanguageValue(){
  33. int data;
  34. QJsonArray fieldsArray;
  35. QSqlDatabase db = QSqlDatabase::database();
  36. if (!db.isOpen()) {
  37. qWarning() << "数据库未打开";
  38. return -1;
  39. }
  40. // 查询 systemConfig 表
  41. QSqlQuery queryBond(db);
  42. queryBond.prepare(R"(
  43. SELECT Function, Description,setValue
  44. FROM systemConfig
  45. )");
  46. if (queryBond.exec())
  47. {
  48. while (queryBond.next())
  49. {
  50. QJsonObject field;
  51. field["Function"] = queryBond.value("Function").toString();
  52. if(field["Function"] == "language")
  53. {
  54. data = queryBond.value("setValue").toInt();
  55. return data;
  56. }
  57. }
  58. // qDebug() << "Fetched fields:" << fieldsArray;
  59. }
  60. else
  61. {
  62. qWarning() << "查询 systemConfig 失败:" << queryBond.lastError().text();
  63. }
  64. return -1;
  65. }
  66. int Gen_Interface::getThemeValue(){
  67. int data;
  68. QJsonArray fieldsArray;
  69. QSqlDatabase db = QSqlDatabase::database();
  70. if (!db.isOpen())
  71. {
  72. qWarning() << "数据库未打开";
  73. return -1;
  74. }
  75. // 查询 systemConfig 表
  76. QSqlQuery queryBond(db);
  77. queryBond.prepare(R"(
  78. SELECT Function, Description,setValue
  79. FROM systemConfig
  80. )");
  81. if (queryBond.exec())
  82. {
  83. while (queryBond.next())
  84. {
  85. QJsonObject field;
  86. field["Function"] = queryBond.value("Function").toString();
  87. if(field["Function"] == "theme")
  88. {
  89. data = queryBond.value("setValue").toInt();
  90. return data;
  91. }
  92. }
  93. // qDebug() << "Fetched fields:" << fieldsArray;
  94. }
  95. else
  96. {
  97. qWarning() << "查询 systemConfig 失败:" << queryBond.lastError().text();
  98. }
  99. return -1;
  100. }
  101. void Gen_Interface::setLanguageValue(int data){
  102. QSqlDatabase db = QSqlDatabase::database();
  103. if (!db.isOpen()) {
  104. qWarning() << "数据库未打开";
  105. }
  106. QString sql = QString("UPDATE systemConfig SET setValue = '%1' WHERE Function = 'language'").arg(data);
  107. QSqlQuery query;
  108. if (query.exec(sql)) {
  109. qDebug() << "Update successful";
  110. } else {
  111. qDebug() << "Update failed:" << query.lastError().text();
  112. }
  113. }
  114. void Gen_Interface::setThemeValue(int data){
  115. QSqlDatabase db = QSqlDatabase::database();
  116. if (!db.isOpen()) {
  117. qWarning() << "数据库未打开";
  118. }
  119. QString sql = QString("UPDATE systemConfig SET setValue = '%1' WHERE Function = 'theme'").arg(data);
  120. QSqlQuery query;
  121. if (query.exec(sql)) {
  122. qDebug() << "Update successful";
  123. } else {
  124. qDebug() << "Update failed:" << query.lastError().text();
  125. }
  126. }