SchemeInfoService.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "SchemeInfoService.h"
  2. #include "SqlDBHelper.h"
  3. #include <QDebug>
  4. SchemeInfoService::SchemeInfoService(QObject *parent) { }
  5. /////////////////////方案持久化-start////////////////
  6. bool SchemeInfoService::AddSchemeInfoList(const QList<SchemaEval *> &schemeList)
  7. {
  8. bool ret = false;
  9. try {
  10. Transaction t(SqlDBHelper::getDatabase());
  11. for (int i = 0; i < schemeList.length(); i++) {
  12. SchemaEval *scheme = schemeList.at(i);
  13. InsertQuery q = t.insertInto("t_scheme_info (project_id,name,remark,value_str,score,file_path,type)");
  14. q.values(scheme->engineerId, scheme->name, scheme->remark, scheme->valueStr, scheme->score,
  15. scheme->filePath, scheme->type)
  16. .exec();
  17. t.commit();
  18. }
  19. ret = true;
  20. } catch (const DBException &ex) {
  21. qDebug() << ex.lastError.text();
  22. }
  23. return ret;
  24. }
  25. bool SchemeInfoService::DeleteSchemeByEngineerId(int engineerId)
  26. {
  27. bool ret = false;
  28. try {
  29. Transaction t(SqlDBHelper::getDatabase());
  30. t.deleteFrom("t_scheme_info").where("project_id = ?", engineerId);
  31. t.commit();
  32. ret = true;
  33. } catch (const DBException &ex) {
  34. qDebug() << ex.lastError.text();
  35. }
  36. return ret;
  37. }
  38. bool SchemeInfoService::QuerySchemeInfoByEngineerId(QList<SchemaEval *> *schemeList, int engineerId, int type)
  39. {
  40. QSqlDatabase db = SqlDBHelper::getDatabase();
  41. QSqlQuery query(db);
  42. bool ret = false;
  43. QString selectSql = QString("select id,project_id,name,remark,value_str "
  44. ",score,file_path,type from t_scheme_info where "
  45. " project_id =%1 and type = %2 ")
  46. .arg(QString::number(engineerId))
  47. .arg(type);
  48. // qDebug() << "sql=" << selectSql;
  49. if (query.exec(selectSql)) {
  50. while (query.next()) {
  51. if (query.isNull(0) == false) {
  52. SchemaEval *scheme = new SchemaEval();
  53. scheme->id = query.value(0).toInt();
  54. scheme->engineerId = query.value(1).toInt();
  55. scheme->name = query.value(2).toString();
  56. scheme->remark = query.value(3).toString();
  57. scheme->valueStr = query.value(4).toString();
  58. scheme->score = query.value(5).toDouble();
  59. scheme->filePath = query.value(6).toString();
  60. scheme->type = query.value(7).toInt();
  61. schemeList->append(scheme);
  62. }
  63. ret = true;
  64. }
  65. } else {
  66. qDebug() << query.lastError();
  67. }
  68. return ret;
  69. }
  70. bool SchemeInfoService::UpdateValueStrById(int id, QString valueStr)
  71. {
  72. bool ret = false;
  73. try {
  74. Transaction t(SqlDBHelper::getDatabase());
  75. t.update("t_scheme_info").set("value_str", valueStr).where("id = ?", id);
  76. t.commit();
  77. ret = true;
  78. } catch (const DBException &ex) {
  79. qDebug() << ex.lastError.text();
  80. }
  81. return ret;
  82. }
  83. ///////////////////////common-end/////////////////////