94 |
94 |
95 if (id >= 0) { |
95 if (id >= 0) { |
96 query.prepare("SELECT * FROM recipes WHERE record = :recno"); |
96 query.prepare("SELECT * FROM recipes WHERE record = :recno"); |
97 query.bindValue(":recno", id); |
97 query.bindValue(":recno", id); |
98 query.exec(); |
98 query.exec(); |
99 query.next(); |
99 query.first(); |
|
100 |
|
101 QSqlRecord rec = query.record(); |
|
102 for (int i = 0; i < rec.count(); i++) |
|
103 qDebug() << i << rec.fieldName(i) << query.value(i); |
100 |
104 |
101 recipe->record = query.value(0).toInt(); |
105 recipe->record = query.value(0).toInt(); |
102 recipe->uuid = query.value(1).toString(); |
106 recipe->uuid = query.value(1).toString(); |
103 recipe->locked = query.value(2).toInt() ? true:false; |
107 recipe->locked = query.value(2).toInt() ? true:false; |
104 recipe->st_name = query.value(3).toString(); |
108 recipe->st_name = query.value(3).toString(); |
297 if (parseError.error != QJsonParseError::NoError) { |
301 if (parseError.error != QJsonParseError::NoError) { |
298 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
302 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
299 } else if (yeasts.isArray()) { |
303 } else if (yeasts.isArray()) { |
300 for (int i = 0; i < yeasts.array().size(); i++) { |
304 for (int i = 0; i < yeasts.array().size(); i++) { |
301 QJsonObject obj = yeasts.array().at(i).toObject(); |
305 QJsonObject obj = yeasts.array().at(i).toObject(); |
302 qDebug() << i << obj; |
306 //qDebug() << i << obj; |
303 Yeasts y; |
307 Yeasts y; |
304 /* First some defaults for newer fields. */ |
308 /* First some defaults for newer fields. */ |
305 y.y_tolerance = y.y_harvest_time = y.y_pitch_temperature = y.y_zymocide = 0; |
309 y.y_tolerance = y.y_harvest_time = y.y_pitch_temperature = y.y_zymocide = 0; |
306 y.y_sta1 = y.y_bacteria = y.y_harvest_top = y.y_pofpos = false; |
310 y.y_sta1 = y.y_bacteria = y.y_harvest_top = y.y_pofpos = false; |
307 y.y_gr_hl_lo = 50; |
311 y.y_gr_hl_lo = 50; |
334 y.y_sg_lo = obj["y_sg_lo"].toDouble(); |
338 y.y_sg_lo = obj["y_sg_lo"].toDouble(); |
335 y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt(); |
339 y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt(); |
336 y.y_sg_hi = obj["y_sg_hi"].toDouble(); |
340 y.y_sg_hi = obj["y_sg_hi"].toDouble(); |
337 y.y_cost = obj["y_cost"].toDouble(); |
341 y.y_cost = obj["y_cost"].toDouble(); |
338 |
342 |
339 if (y.y_tolerance == 0) { // More and better tests? |
343 if (y.y_tolerance == 0 || y.y_cells == 0) { // More and better tests? |
340 /* |
344 /* |
341 * Possible data upgrade needed. |
345 * Possible data upgrade needed. |
342 */ |
346 */ |
343 query.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature," |
347 yquery.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature," |
344 "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi " |
348 "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi " |
345 "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id"); |
349 "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id"); |
346 query.bindValue(":name", y.y_name); |
350 yquery.bindValue(":name", y.y_name); |
347 query.bindValue(":laboratory", y.y_laboratory); |
351 yquery.bindValue(":laboratory", y.y_laboratory); |
348 query.bindValue(":product_id", y.y_product_id); |
352 yquery.bindValue(":product_id", y.y_product_id); |
349 query.exec(); |
353 yquery.exec(); |
350 if (query.first()) { |
354 if (yquery.first()) { |
351 y.y_tolerance = query.value(0).toDouble(); |
355 y.y_tolerance = yquery.value(0).toDouble(); |
352 y.y_cells = query.value(1).toDouble(); |
356 y.y_cells = yquery.value(1).toDouble(); |
353 y.y_sta1 = query.value(2).toInt() ? true:false; |
357 y.y_sta1 = yquery.value(2).toInt() ? true:false; |
354 y.y_bacteria = query.value(3).toInt() ? true:false; |
358 y.y_bacteria = yquery.value(3).toInt() ? true:false; |
355 y.y_harvest_top = query.value(4).toInt() ? true:false; |
359 y.y_harvest_top = yquery.value(4).toInt() ? true:false; |
356 y.y_harvest_time = query.value(5).toInt(); |
360 y.y_harvest_time = yquery.value(5).toInt(); |
357 y.y_pitch_temperature = query.value(6).toDouble(); |
361 y.y_pitch_temperature = yquery.value(6).toDouble(); |
358 y.y_pofpos = query.value(7).toInt() ? true:false; |
362 y.y_pofpos = yquery.value(7).toInt() ? true:false; |
359 y.y_zymocide = query.value(8).toInt(); |
363 y.y_zymocide = yquery.value(8).toInt(); |
360 y.y_gr_hl_lo = query.value(9).toInt(); |
364 y.y_gr_hl_lo = yquery.value(9).toInt(); |
361 y.y_sg_lo = query.value(10).toDouble(); |
365 y.y_sg_lo = yquery.value(10).toDouble(); |
362 y.y_gr_hl_hi = query.value(11).toInt(); |
366 y.y_gr_hl_hi = yquery.value(11).toInt(); |
363 y.y_sg_hi = query.value(12).toDouble(); |
367 y.y_sg_hi = yquery.value(12).toDouble(); |
364 } else { |
368 } else { |
365 qDebug() << y.y_name << y.y_product_id << "not found for upgrade"; |
369 qDebug() << y.y_name << y.y_product_id << "not found for upgrade"; |
366 } |
370 } |
367 } |
371 } |
368 recipe->yeasts.append(y); |
372 recipe->yeasts.append(y); |
371 } |
375 } |
372 } else { |
376 } else { |
373 qDebug() << "empty yeasts"; |
377 qDebug() << "empty yeasts"; |
374 } |
378 } |
375 |
379 |
376 qDebug() << query.value(88).toString(); |
380 const auto& ma_json = query.value("json_mashs").toString().trimmed(); |
377 const auto& ma_json = query.value(88).toString(); |
|
378 if (!ma_json.trimmed().isEmpty()) { |
381 if (!ma_json.trimmed().isEmpty()) { |
379 const auto& formattedJson = QString("%1").arg(ma_json); |
382 const auto& formattedJson = QString("%1").arg(ma_json); |
380 QJsonDocument mashs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
383 QJsonDocument mashs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
381 if (parseError.error != QJsonParseError::NoError) { |
384 if (parseError.error != QJsonParseError::NoError) { |
382 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
385 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
1058 qDebug() << "mashs_Json" << i << obj; |
1062 qDebug() << "mashs_Json" << i << obj; |
1059 array.append(obj); /* Append this object */ |
1063 array.append(obj); /* Append this object */ |
1060 } |
1064 } |
1061 QJsonDocument doc; |
1065 QJsonDocument doc; |
1062 doc.setArray(array); |
1066 doc.setArray(array); |
1063 // qDebug() << doc.toJson(QJsonDocument::Compact); |
1067 qDebug() << doc.toJson(QJsonDocument::Compact); |
1064 query.bindValue(":json_mashs", doc.toJson(QJsonDocument::Compact)); |
1068 query.bindValue(":json_mashs", doc.toJson(QJsonDocument::Compact)); |
1065 } |
1069 } |
1066 |
1070 |
1067 if (this->recno == -1) { |
1071 if (this->recno == -1) { |
1068 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
1072 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |