|
@@ -0,0 +1,64 @@
|
|
|
+#include "GradeIndexInfoService.h"
|
|
|
+#include "SqlDBHelper.h"
|
|
|
+#include <QDebug>
|
|
|
+GradeIndexInfoService::GradeIndexInfoService(QObject *parent) { }
|
|
|
+
|
|
|
+bool GradeIndexInfoService::QueryGradeIndexInfoByProjectId(GradeIndexInfo *gradeIndexInfo, int projectId)
|
|
|
+{
|
|
|
+
|
|
|
+ QSqlDatabase db = SqlDBHelper::getDatabase();
|
|
|
+ QSqlQuery query(db);
|
|
|
+ bool ret = false;
|
|
|
+ QString selectSql = QString("SELECT id, project_id,grade_name,grade_value FROM "
|
|
|
+ "t_grade_index_info WHERE project_id = %1")
|
|
|
+ .arg(projectId);
|
|
|
+ if (query.exec(selectSql)) {
|
|
|
+ if (query.next()) {
|
|
|
+ if (query.isNull(0) == false) {
|
|
|
+ gradeIndexInfo->id = query.value(0).toInt();
|
|
|
+ gradeIndexInfo->projectId = query.value(1).toInt();
|
|
|
+ gradeIndexInfo->gradeIndexName = query.value(2).toString();
|
|
|
+ gradeIndexInfo->gradeIndexValue = query.value(3).toString();
|
|
|
+ }
|
|
|
+ ret = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ qDebug() << query.lastError();
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+int GradeIndexInfoService::AddGradeIndexInfo(const GradeIndexInfo &gradeIndexInfo)
|
|
|
+{
|
|
|
+ int ret = -1;
|
|
|
+ try {
|
|
|
+ Transaction t(SqlDBHelper::getDatabase());
|
|
|
+ InsertQuery query = t.insertInto("t_grade_index_info(`project_id`, `grade_index_name`, `grade_index_value`)");
|
|
|
+ NonQueryResult result =
|
|
|
+ query.values(gradeIndexInfo.projectId, gradeIndexInfo.gradeIndexName, gradeIndexInfo.gradeIndexValue)
|
|
|
+ .exec();
|
|
|
+ t.commit();
|
|
|
+ ret = result.lastInsertId().toInt();
|
|
|
+ } catch (const DBException &ex) {
|
|
|
+ qDebug() << ex.lastError.text();
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+bool GradeIndexInfoService::UpdateGradeIndexInfo(const GradeIndexInfo &gradeIndexInfo)
|
|
|
+{
|
|
|
+
|
|
|
+ bool ret = false;
|
|
|
+ try {
|
|
|
+ Transaction t(SqlDBHelper::getDatabase());
|
|
|
+ t.update("t_grade_index_info")
|
|
|
+ .set("grade_index_name", gradeIndexInfo.gradeIndexName)
|
|
|
+ .set("grade_index_value", gradeIndexInfo.gradeIndexValue)
|
|
|
+ .where("id = ?", gradeIndexInfo.id);
|
|
|
+ t.commit();
|
|
|
+ ret = true;
|
|
|
+ } catch (const DBException &ex) {
|
|
|
+ qDebug() << ex.lastError.text();
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+}
|