123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "SchemeInfoService.h"
- #include "SqlDBHelper.h"
- #include <QDebug>
- SchemeInfoService::SchemeInfoService(QObject *parent) { }
- /////////////////////方案持久化-start////////////////
- bool SchemeInfoService::AddSchemeInfoList(const QList<SchemaEval *> &schemeList)
- {
- bool ret = false;
- try {
- Transaction t(SqlDBHelper::getDatabase());
- for (int i = 0; i < schemeList.length(); i++) {
- SchemaEval *scheme = schemeList.at(i);
- InsertQuery q = t.insertInto("t_scheme_info (project_id,name,remark,value_str,score,file_path,type)");
- q.values(scheme->engineerId, scheme->name, scheme->remark, scheme->valueStr, scheme->score,
- scheme->filePath, scheme->type)
- .exec();
- t.commit();
- }
- ret = true;
- } catch (const DBException &ex) {
- qDebug() << ex.lastError.text();
- }
- return ret;
- }
- bool SchemeInfoService::DeleteSchemeByEngineerId(int engineerId)
- {
- bool ret = false;
- try {
- Transaction t(SqlDBHelper::getDatabase());
- t.deleteFrom("t_scheme_info").where("project_id = ?", engineerId);
- t.commit();
- ret = true;
- } catch (const DBException &ex) {
- qDebug() << ex.lastError.text();
- }
- return ret;
- }
- bool SchemeInfoService::QuerySchemeInfoByEngineerId(QList<SchemaEval *> *schemeList, int engineerId, int type)
- {
- QSqlDatabase db = SqlDBHelper::getDatabase();
- QSqlQuery query(db);
- bool ret = false;
- QString selectSql = QString("select id,project_id,name,remark,value_str "
- ",score,file_path,type from t_scheme_info where "
- " project_id =%1 and type = %2 ")
- .arg(QString::number(engineerId))
- .arg(type);
- // qDebug() << "sql=" << selectSql;
- if (query.exec(selectSql)) {
- while (query.next()) {
- if (query.isNull(0) == false) {
- SchemaEval *scheme = new SchemaEval();
- scheme->id = query.value(0).toInt();
- scheme->engineerId = query.value(1).toInt();
- scheme->name = query.value(2).toString();
- scheme->remark = query.value(3).toString();
- scheme->valueStr = query.value(4).toString();
- scheme->score = query.value(5).toDouble();
- scheme->filePath = query.value(6).toString();
- scheme->type = query.value(7).toInt();
- schemeList->append(scheme);
- }
- ret = true;
- }
- } else {
- qDebug() << query.lastError();
- }
- return ret;
- }
- ///////////////////////common-end/////////////////////
|