92 ui->beerstyleEdit->addItem(query.value(0).toString()+" "+query.value(1).toString()+" "+query.value(2).toString()); |
92 ui->beerstyleEdit->addItem(query.value(0).toString()+" "+query.value(1).toString()+" "+query.value(2).toString()); |
93 query.next(); |
93 query.next(); |
94 } |
94 } |
95 |
95 |
96 if (id >= 0) { |
96 if (id >= 0) { |
97 query.prepare("SELECT * FROM recipes WHERE record = :recno"); |
97 if (! DB_recipe::load(recipe, this, id)) |
98 query.bindValue(":recno", id); |
98 return; |
99 query.exec(); |
|
100 if (! query.first()) { |
|
101 qDebug() << "EditRecipe seek error record" << id; |
|
102 QMessageBox::warning(this, tr("Database error"), tr("MySQL error: record %1 not found").arg(id)); |
|
103 this->done(QDialog::Rejected); // At this stage, this doesn't work because the dialog is not yet visible. |
|
104 return; |
|
105 } |
|
106 |
|
107 QSqlRecord rec = query.record(); |
|
108 for (int i = 0; i < rec.count(); i++) |
|
109 qDebug() << i << rec.fieldName(i) << query.value(i); |
|
110 |
|
111 recipe->record = query.value(0).toInt(); |
|
112 recipe->uuid = query.value(1).toString(); |
|
113 recipe->locked = query.value(2).toInt() ? true:false; |
|
114 recipe->st_name = query.value(3).toString(); |
|
115 recipe->st_letter = query.value(4).toString(); |
|
116 recipe->st_guide = query.value(5).toString(); |
|
117 recipe->st_category = query.value(6).toString(); |
|
118 recipe->st_category_number = query.value(7).toInt(); |
|
119 recipe->st_type = query.value(8).toInt(); |
|
120 recipe->st_og_min = query.value(9).toDouble(); |
|
121 recipe->st_og_max = query.value(10).toDouble(); |
|
122 recipe->st_fg_min = query.value(11).toDouble(); |
|
123 recipe->st_fg_max = query.value(12).toDouble(); |
|
124 recipe->st_ibu_min = query.value(13).toDouble(); |
|
125 recipe->st_ibu_max = query.value(14).toDouble(); |
|
126 recipe->st_color_min = query.value(15).toDouble(); |
|
127 recipe->st_color_max = query.value(16).toDouble(); |
|
128 recipe->st_carb_min = query.value(17).toDouble(); |
|
129 recipe->st_carb_max = query.value(18).toDouble(); |
|
130 recipe->st_abv_min = query.value(19).toDouble(); |
|
131 recipe->st_abv_max = query.value(20).toDouble(); |
|
132 recipe->name = query.value(21).toString(); |
|
133 recipe->notes = query.value(22).toString(); |
|
134 recipe->type = query.value(23).toInt(); |
|
135 recipe->batch_size = query.value(24).toDouble(); |
|
136 recipe->boil_size = query.value(25).toDouble(); |
|
137 recipe->boil_time = query.value(26).toDouble(); |
|
138 recipe->efficiency = query.value(27).toDouble(); |
|
139 recipe->est_og = query.value(28).toDouble(); |
|
140 recipe->est_fg = query.value(29).toDouble(); |
|
141 recipe->est_abv = query.value(30).toDouble(); |
|
142 recipe->est_color = query.value(31).toDouble(); |
|
143 recipe->color_method = query.value(32).toInt(); |
|
144 recipe->est_ibu = query.value(33).toDouble(); |
|
145 recipe->ibu_method = query.value(34).toInt(); |
|
146 recipe->est_carb = query.value(35).toDouble(); |
|
147 |
|
148 recipe->sparge_temp = query.value(36).toDouble(); |
|
149 recipe->sparge_ph = query.value(37).toDouble(); |
|
150 recipe->sparge_volume = query.value(38).toDouble(); |
|
151 recipe->sparge_source = query.value(39).toInt(); |
|
152 recipe->sparge_acid_type = query.value(40).toInt(); |
|
153 recipe->sparge_acid_perc = query.value(41).toDouble(); |
|
154 recipe->sparge_acid_amount = query.value(42).toDouble(); |
|
155 recipe->mash_ph = query.value(43).toDouble(); |
|
156 recipe->mash_name = query.value(44).toString(); |
|
157 recipe->calc_acid = query.value(45).toInt() ? true:false; |
|
158 |
|
159 recipe->w1_name = query.value(46).toString(); |
|
160 recipe->w1_amount = query.value(47).toDouble(); |
|
161 recipe->w1_calcium = query.value(48).toDouble(); |
|
162 recipe->w1_sulfate = query.value(49).toDouble(); |
|
163 recipe->w1_chloride = query.value(50).toDouble(); |
|
164 recipe->w1_sodium = query.value(51).toDouble(); |
|
165 recipe->w1_magnesium = query.value(52).toDouble(); |
|
166 recipe->w1_total_alkalinity = query.value(53).toDouble(); |
|
167 recipe->w1_ph = query.value(54).toDouble(); |
|
168 recipe->w1_cost = query.value(55).toDouble(); |
|
169 recipe->w2_name = query.value(56).toString(); |
|
170 recipe->w2_amount = query.value(57).toDouble(); |
|
171 recipe->w2_calcium = query.value(58).toDouble(); |
|
172 recipe->w2_sulfate = query.value(59).toDouble(); |
|
173 recipe->w2_chloride = query.value(60).toDouble(); |
|
174 recipe->w2_sodium = query.value(61).toDouble(); |
|
175 recipe->w2_magnesium = query.value(62).toDouble(); |
|
176 recipe->w2_total_alkalinity = query.value(63).toDouble(); |
|
177 recipe->w2_ph = query.value(64).toDouble(); |
|
178 recipe->w2_cost = query.value(65).toDouble(); |
|
179 recipe->wg_amount = query.value(66).toDouble(); |
|
180 recipe->wg_calcium = query.value(67).toDouble(); |
|
181 recipe->wg_sulfate = query.value(68).toDouble(); |
|
182 recipe->wg_chloride = query.value(69).toDouble(); |
|
183 recipe->wg_sodium = query.value(70).toDouble(); |
|
184 recipe->wg_magnesium = query.value(71).toDouble(); |
|
185 recipe->wg_total_alkalinity = query.value(72).toDouble(); |
|
186 recipe->wg_ph = query.value(73).toDouble(); |
|
187 recipe->wb_calcium = query.value(74).toDouble(); |
|
188 recipe->wb_sulfate = query.value(75).toDouble(); |
|
189 recipe->wb_chloride = query.value(76).toDouble(); |
|
190 recipe->wb_sodium = query.value(77).toDouble(); |
|
191 recipe->wb_magnesium = query.value(78).toDouble(); |
|
192 recipe->wb_total_alkalinity = query.value(79).toDouble(); |
|
193 recipe->wb_ph = query.value(80).toDouble(); |
|
194 recipe->wa_acid_name = query.value(81).toInt(); |
|
195 recipe->wa_acid_perc = query.value(82).toDouble(); |
|
196 recipe->wa_base_name = query.value(83).toInt(); |
|
197 |
|
198 QJsonParseError parseError; |
|
199 const auto& f_json = query.value(84).toString(); |
|
200 if (!f_json.trimmed().isEmpty()) { |
|
201 const auto& formattedJson = QString("%1").arg(f_json); |
|
202 QJsonDocument fermentables = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
203 if (parseError.error != QJsonParseError::NoError) { |
|
204 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
|
205 } else if (fermentables.isArray()) { |
|
206 double percentcheck = 0; |
|
207 for (int i = 0; i < fermentables.array().size(); i++) { |
|
208 QJsonObject obj = fermentables.array().at(i).toObject(); |
|
209 //qDebug() << i << obj; |
|
210 Fermentables f; |
|
211 f.f_name = obj["f_name"].toString(); |
|
212 f.f_origin = obj["f_origin"].toString(); |
|
213 f.f_supplier = obj["f_supplier"].toString(); |
|
214 f.f_amount = obj["f_amount"].toDouble(); |
|
215 f.f_cost = obj["f_cost"].toDouble(); |
|
216 f.f_type = obj["f_type"].toInt(); |
|
217 f.f_yield = obj["f_yield"].toDouble(); |
|
218 f.f_color = obj["f_color"].toDouble(); |
|
219 f.f_coarse_fine_diff = obj["f_coarse_fine_diff"].toDouble(); |
|
220 f.f_moisture = obj["f_moisture"].toDouble(); |
|
221 f.f_diastatic_power = obj["f_diastatic_power"].toDouble(); |
|
222 f.f_protein = obj["f_protein"].toDouble(); |
|
223 f.f_dissolved_protein = obj["f_dissolved_protein"].toDouble(); |
|
224 f.f_max_in_batch = obj["f_max_in_batch"].toDouble(); |
|
225 f.f_graintype = obj["f_graintype"].toInt(); |
|
226 f.f_added = obj["f_added"].toInt(); |
|
227 f.f_recommend_mash = obj["f_recommend_mash"].toInt() ? true:false; |
|
228 f.f_add_after_boil = obj["f_add_after_boil"].toInt() ? true:false; |
|
229 f.f_adjust_to_total_100 = obj["f_adjust_to_total_100"].toInt() ? true:false; |
|
230 f.f_percentage = obj["f_percentage"].toDouble(); |
|
231 f.f_di_ph = obj["f_di_ph"].toDouble(); |
|
232 f.f_acid_to_ph_57 = obj["f_acid_to_ph_57"].toDouble(); |
|
233 if (f.f_adjust_to_total_100) |
|
234 recipe->fermentables_use100 = true; |
|
235 percentcheck += f.f_percentage; |
|
236 recipe->fermentables.append(f); |
|
237 } |
|
238 qDebug() << "fermentables" << recipe->fermentables.size() << percentcheck; |
|
239 if (percentcheck == 0) { |
|
240 /* Missing percentages, fix it. */ |
|
241 double total = 0; |
|
242 for (int i = 0; i < recipe->fermentables.size(); i++) { |
|
243 if (recipe->fermentables.at(i).f_added < 4) |
|
244 total += recipe->fermentables.at(i).f_amount; |
|
245 } |
|
246 for (int i = 0; i < recipe->fermentables.size(); i++) { |
|
247 if (recipe->fermentables.at(i).f_added < 4) |
|
248 recipe->fermentables[i].f_percentage = round((recipe->fermentables.at(i).f_amount / total) * 10000.0) / 100.0; |
|
249 } |
|
250 qDebug() << " fixed missing percentages"; |
|
251 is_changed(); |
|
252 } |
|
253 } |
|
254 } else { |
|
255 qDebug() << "empty fermentables"; |
|
256 } |
|
257 |
|
258 const auto& h_json = query.value(85).toString(); |
|
259 if (!h_json.trimmed().isEmpty()) { |
|
260 const auto& formattedJson = QString("%1").arg(h_json); |
|
261 QJsonDocument hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
262 if (parseError.error != QJsonParseError::NoError) { |
|
263 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset; |
|
264 } else if (hops.isArray()) { |
|
265 for (int i = 0; i < hops.array().size(); i++) { |
|
266 QJsonObject obj = hops.array().at(i).toObject(); |
|
267 //qDebug() << i << obj; |
|
268 Hops h; |
|
269 h.h_name = obj["h_name"].toString(); |
|
270 h.h_origin = obj["h_origin"].toString(); |
|
271 h.h_amount = obj["h_amount"].toDouble(); |
|
272 h.h_cost = obj["h_cost"].toDouble(); |
|
273 h.h_type = obj["h_type"].toInt(); |
|
274 h.h_form = obj["h_form"].toInt(); |
|
275 h.h_useat = obj["h_useat"].toInt(); |
|
276 h.h_time = obj["h_time"].toInt(); |
|
277 h.h_alpha = obj["h_alpha"].toDouble(); |
|
278 h.h_beta = obj["h_beta"].toDouble(); |
|
279 h.h_hsi = obj["h_hsi"].toDouble(); |
|
280 h.h_humulene = obj["h_humulene"].toDouble(); |
|
281 h.h_caryophyllene = obj["h_caryophyllene"].toDouble(); |
|
282 h.h_cohumulone = obj["h_cohumulone"].toDouble(); |
|
283 h.h_myrcene = obj["h_myrcene"].toDouble(); |
|
284 h.h_total_oil = obj["h_total_oil"].toDouble(); |
|
285 recipe->hops.append(h); |
|
286 } |
|
287 qDebug() << "hops" << recipe->hops.size(); |
|
288 } |
|
289 } else { |
|
290 qDebug() << "empty hops"; |
|
291 } |
|
292 |
|
293 const auto& m_json = query.value(86).toString(); |
|
294 if (!m_json.trimmed().isEmpty()) { |
|
295 const auto& formattedJson = QString("%1").arg(m_json); |
|
296 QJsonDocument miscs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
297 if (parseError.error != QJsonParseError::NoError) { |
|
298 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset; |
|
299 } else if (miscs.isArray()) { |
|
300 for (int i = 0; i < miscs.array().size(); i++) { |
|
301 QJsonObject obj = miscs.array().at(i).toObject(); |
|
302 //qDebug() << i << obj; |
|
303 Miscs m; |
|
304 m.m_name = obj["m_name"].toString(); |
|
305 m.m_amount = obj["m_amount"].toDouble(); |
|
306 m.m_type = obj["m_type"].toInt(); |
|
307 m.m_use_use = obj["m_use_use"].toInt(); |
|
308 m.m_time = obj["m_time"].toDouble(); |
|
309 m.m_amount_is_weight = obj["m_amount_is_weight"].toInt() ? true:false; |
|
310 m.m_cost = obj["m_cost"].toDouble(); |
|
311 recipe->miscs.append(m); |
|
312 } |
|
313 qDebug() << "miscs" << recipe->miscs.size(); |
|
314 } |
|
315 } else { |
|
316 qDebug() << "empty miscs"; |
|
317 } |
|
318 |
|
319 const auto& y_json = query.value(87).toString(); |
|
320 if (!y_json.trimmed().isEmpty()) { |
|
321 const auto& formattedJson = QString("%1").arg(y_json); |
|
322 QJsonDocument yeasts = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
323 if (parseError.error != QJsonParseError::NoError) { |
|
324 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
|
325 } else if (yeasts.isArray()) { |
|
326 for (int i = 0; i < yeasts.array().size(); i++) { |
|
327 QJsonObject obj = yeasts.array().at(i).toObject(); |
|
328 //qDebug() << i << obj; |
|
329 Yeasts y; |
|
330 /* First some defaults for newer fields. */ |
|
331 y.y_tolerance = y.y_harvest_time = y.y_pitch_temperature = y.y_zymocide = 0; |
|
332 y.y_sta1 = y.y_bacteria = y.y_harvest_top = y.y_pofpos = false; |
|
333 y.y_gr_hl_lo = 50; |
|
334 y.y_sg_lo = 1.04; |
|
335 y.y_gr_hl_hi = 80; |
|
336 y.y_sg_hi = 1.08; |
|
337 /* Now get what we have got */ |
|
338 y.y_name = obj["y_name"].toString(); |
|
339 y.y_laboratory = obj["y_laboratory"].toString(); |
|
340 y.y_product_id = obj["y_product_id"].toString(); |
|
341 y.y_amount = obj["y_amount"].toDouble(); |
|
342 y.y_type = obj["y_type"].toInt(); |
|
343 y.y_form = obj["y_form"].toInt(); |
|
344 y.y_min_temperature = obj["y_min_temperature"].toDouble(); |
|
345 y.y_max_temperature = obj["y_max_temperature"].toDouble(); |
|
346 y.y_flocculation = obj["y_flocculation"].toInt(); |
|
347 y.y_attenuation = obj["y_attenuation"].toDouble(); |
|
348 y.y_cells = obj["y_cells"].toDouble(); |
|
349 y.y_tolerance = obj["y_tolerance"].toDouble(); |
|
350 y.y_inventory = obj["y_inventory"].toDouble(); |
|
351 y.y_use = obj["y_use"].toInt(); |
|
352 y.y_sta1 = obj["y_sta1"].toInt() ? true:false; |
|
353 y.y_bacteria = obj["y_bacteria"].toInt() ? true:false; |
|
354 y.y_harvest_top = obj["y_harvest_top"].toInt() ? true:false; |
|
355 y.y_harvest_time = obj["y_harvest_time"].toInt(); |
|
356 y.y_pitch_temperature = obj["y_pitch_temperature"].toDouble(); |
|
357 y.y_pofpos = obj["y_pofpos"].toInt() ? true:false; |
|
358 y.y_zymocide = obj["y_zymocide"].toInt(); |
|
359 y.y_gr_hl_lo = obj["y_gr_hl_lo"].toInt(); |
|
360 y.y_sg_lo = obj["y_sg_lo"].toDouble(); |
|
361 y.y_gr_hl_hi = obj["y_gr_hl_hi"].toInt(); |
|
362 y.y_sg_hi = obj["y_sg_hi"].toDouble(); |
|
363 y.y_cost = obj["y_cost"].toDouble(); |
|
364 |
|
365 if (y.y_tolerance == 0 || y.y_cells == 0) { // More and better tests? |
|
366 /* |
|
367 * Possible data upgrade needed. |
|
368 */ |
|
369 yquery.prepare("SELECT tolerance,cells,sta1,bacteria,harvest_top,harvest_time,pitch_temperature," |
|
370 "pofpos,zymocide,gr_hl_lo,sg_lo,gr_hl_hi,sg_hi " |
|
371 "FROM inventory_yeasts WHERE name=:name AND laboratory=:laboratory AND product_id=:product_id"); |
|
372 yquery.bindValue(":name", y.y_name); |
|
373 yquery.bindValue(":laboratory", y.y_laboratory); |
|
374 yquery.bindValue(":product_id", y.y_product_id); |
|
375 yquery.exec(); |
|
376 if (yquery.first()) { |
|
377 y.y_tolerance = yquery.value(0).toDouble(); |
|
378 y.y_cells = yquery.value(1).toDouble(); |
|
379 y.y_sta1 = yquery.value(2).toInt() ? true:false; |
|
380 y.y_bacteria = yquery.value(3).toInt() ? true:false; |
|
381 y.y_harvest_top = yquery.value(4).toInt() ? true:false; |
|
382 y.y_harvest_time = yquery.value(5).toInt(); |
|
383 y.y_pitch_temperature = yquery.value(6).toDouble(); |
|
384 y.y_pofpos = yquery.value(7).toInt() ? true:false; |
|
385 y.y_zymocide = yquery.value(8).toInt(); |
|
386 y.y_gr_hl_lo = yquery.value(9).toInt(); |
|
387 y.y_sg_lo = yquery.value(10).toDouble(); |
|
388 y.y_gr_hl_hi = yquery.value(11).toInt(); |
|
389 y.y_sg_hi = yquery.value(12).toDouble(); |
|
390 } else { |
|
391 qDebug() << y.y_name << y.y_product_id << "not found for upgrade"; |
|
392 } |
|
393 } |
|
394 recipe->yeasts.append(y); |
|
395 } |
|
396 qDebug() << "yeasts" << recipe->yeasts.size(); |
|
397 } |
|
398 } else { |
|
399 qDebug() << "empty yeasts"; |
|
400 } |
|
401 |
|
402 const auto& ma_json = query.value("json_mashs").toString().trimmed(); |
|
403 if (!ma_json.trimmed().isEmpty()) { |
|
404 const auto& formattedJson = QString("%1").arg(ma_json); |
|
405 QJsonDocument mashs = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); |
|
406 if (parseError.error != QJsonParseError::NoError) { |
|
407 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; |
|
408 } else if (mashs.isArray()) { |
|
409 for (int i = 0; i < mashs.array().size(); i++) { |
|
410 QJsonObject obj = mashs.array().at(i).toObject(); |
|
411 qDebug() << i << obj; |
|
412 Mashs m; |
|
413 m.step_name = obj["step_name"].toString(); |
|
414 m.step_type = obj["step_type"].toInt(); |
|
415 m.step_volume = obj["step_volume"].toDouble(); |
|
416 m.step_infuse_amount = obj["step_infuse_amount"].toDouble(); |
|
417 m.step_infuse_temp = obj["step_infuse_temp"].toDouble(); |
|
418 m.step_temp = obj["step_temp"].toDouble(); |
|
419 m.step_time = obj["step_time"].toDouble(); |
|
420 m.ramp_time = obj["ramp_time"].toDouble(); |
|
421 m.end_temp = obj["end_temp"].toDouble(); |
|
422 m.step_wg_ratio = obj["step_wg_ratio"].toDouble(); |
|
423 recipe->mashs.append(m); |
|
424 } |
|
425 } |
|
426 } else { |
|
427 qDebug() << "empty mashs"; |
|
428 } |
|
429 qDebug() << "mashs" << recipe->mashs.size(); |
|
430 |
|
431 } else { |
99 } else { |
432 /* Set some defaults */ |
100 /* Set some defaults */ |
|
101 recipe->record = -1; |
433 recipe->locked = false; |
102 recipe->locked = false; |
434 recipe->st_name = ""; |
103 recipe->st_name = ""; |
435 recipe->st_letter = ""; |
104 recipe->st_letter = ""; |
436 recipe->st_guide = ""; |
105 recipe->st_guide = ""; |
437 recipe->st_category = ""; |
106 recipe->st_category = ""; |
801 QMessageBox::warning(this, tr("Edit Recipe"), tr("No beerstyle selected.")); |
470 QMessageBox::warning(this, tr("Edit Recipe"), tr("No beerstyle selected.")); |
802 return; |
471 return; |
803 } |
472 } |
804 |
473 |
805 if (this->textIsChanged) { |
474 if (this->textIsChanged) { |
806 if (this->recno == -1) { |
475 recipe->record = this->recno; |
807 query.prepare("INSERT INTO recipes SET locked=:locked, st_name=:st_name, st_letter=:st_letter, " |
476 if (DB_recipe::save(recipe, this)) { |
808 "st_guide=:st_guide, st_category=:st_category, st_category_number=:st_catnr, st_type=:st_type, " |
477 /* |
809 "st_og_min=:st_og_min, st_og_max=:st_og_max, st_fg_min=:st_fg_min, st_fg_max=:st_fg_max, " |
478 * If this was a new record, update the global recno. |
810 "st_ibu_min=:st_ibu_min, st_ibu_max=:st_ibu_max, st_color_min=:st_color_min, st_color_max=:st_color_max, " |
479 */ |
811 "st_carb_min=:st_carb_min, st_carb_max=:st_carb_max, st_abv_min=:st_abv_min, st_abv_max=:st_abv_max, " |
480 this->recno = recipe->record; |
812 "name=:name, notes=:notes, type=:type, batch_size=:batch_size, boil_size=:boil_size, " |
|
813 "boil_time=:boil_time, efficiency=:efficiency, est_og=:est_og, est_fg=:est_fg, est_abv=:est_abv, " |
|
814 "est_color=:est_color, color_method=:color_method, est_ibu=:est_ibu, ibu_method=:ibu_method, " |
|
815 "est_carb=:est_carb, sparge_temp=:sparge_temp, sparge_ph=:sparge_ph, " |
|
816 "sparge_volume=:sparge_volume, sparge_source=:sparge_source, sparge_acid_type=:sparge_acid_type, " |
|
817 "sparge_acid_perc=:sparge_acid_perc, sparge_acid_amount=:sparge_acid_amount, mash_ph=:mash_ph, " |
|
818 "mash_name=:mash_name, calc_acid=:calc_acid, " |
|
819 "w1_name=:w1_name, w1_amount=:w1_amount, w1_calcium=:w1_calcium, w1_sulfate=:w1_sulfate, " |
|
820 "w1_chloride=:w1_chloride, w1_sodium=:w1_sodium, w1_magnesium=:w1_magnesium, " |
|
821 "w1_total_alkalinity=:w1_total_alkalinity, w1_ph=:w1_ph, w1_cost=:w1_cost, " |
|
822 "w2_name=:w2_name, w2_amount=:w2_amount, w2_calcium=:w2_calcium, w2_sulfate=:w2_sulfate, " |
|
823 "w2_chloride=:w2_chloride, w2_sodium=:w2_sodium, w2_magnesium=:w2_magnesium, " |
|
824 "w2_total_alkalinity=:w2_total_alkalinity, w2_ph=:w2_ph, w2_cost=:w2_cost, " |
|
825 "wg_amount=:wg_amount, wg_calcium=:wg_calcium, wg_sulfate=:wg_sulfate, " |
|
826 "wg_chloride=:wg_chloride, wg_sodium=:wg_sodium, wg_magnesium=:wg_magnesium, " |
|
827 "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, " |
|
828 "wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, " |
|
829 "wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, " |
|
830 "wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, " |
|
831 "json_fermentables=:json_fermentables, json_hops=:json_hops, json_miscs=:json_miscs, " |
|
832 "json_yeasts=:json_yeasts, json_mashs=:json_mashs, uuid=:uuid"); |
|
833 } else { |
|
834 query.prepare("UPDATE recipes SET locked=:locked, st_name=:st_name, st_letter=:st_letter, " |
|
835 "st_guide=:st_guide, st_category=:st_category, st_category_number=:st_catnr, st_type=:st_type, " |
|
836 "st_og_min=:st_og_min, st_og_max=:st_og_max, st_fg_min=:st_fg_min, st_fg_max=:st_fg_max, " |
|
837 "st_ibu_min=:st_ibu_min, st_ibu_max=:st_ibu_max, st_color_min=:st_color_min, st_color_max=:st_color_max, " |
|
838 "st_carb_min=:st_carb_min, st_carb_max=:st_carb_max, st_abv_min=:st_abv_min, st_abv_max=:st_abv_max, " |
|
839 "name=:name, notes=:notes, type=:type, batch_size=:batch_size, boil_size=:boil_size, " |
|
840 "boil_time=:boil_time, efficiency=:efficiency, est_og=:est_og, est_fg=:est_fg, est_abv=:est_abv, " |
|
841 "est_color=:est_color, color_method=:color_method, est_ibu=:est_ibu, ibu_method=:ibu_method, " |
|
842 "est_carb=:est_carb, sparge_temp=:sparge_temp, sparge_ph=:sparge_ph, " |
|
843 "sparge_volume=:sparge_volume, sparge_source=:sparge_source, sparge_acid_type=:sparge_acid_type, " |
|
844 "sparge_acid_perc=:sparge_acid_perc, sparge_acid_amount=:sparge_acid_amount, mash_ph=:mash_ph, " |
|
845 "mash_name=:mash_name, calc_acid=:calc_acid, " |
|
846 "w1_name=:w1_name, w1_amount=:w1_amount, w1_calcium=:w1_calcium, w1_sulfate=:w1_sulfate, " |
|
847 "w1_chloride=:w1_chloride, w1_sodium=:w1_sodium, w1_magnesium=:w1_magnesium, " |
|
848 "w1_total_alkalinity=:w1_total_alkalinity, w1_ph=:w1_ph, w1_cost=:w1_cost, " |
|
849 "w2_name=:w2_name, w2_amount=:w2_amount, w2_calcium=:w2_calcium, w2_sulfate=:w2_sulfate, " |
|
850 "w2_chloride=:w2_chloride, w2_sodium=:w2_sodium, w2_magnesium=:w2_magnesium, " |
|
851 "w2_total_alkalinity=:w2_total_alkalinity, w2_ph=:w2_ph, w2_cost=:w2_cost, " |
|
852 "wg_amount=:wg_amount, wg_calcium=:wg_calcium, wg_sulfate=:wg_sulfate, " |
|
853 "wg_chloride=:wg_chloride, wg_sodium=:wg_sodium, wg_magnesium=:wg_magnesium, " |
|
854 "wg_total_alkalinity=:wg_total_alkalinity, wg_ph=:wg_ph, " |
|
855 "wb_calcium=:wb_calcium, wb_sulfate=:wb_sulfate, wb_chloride=:wb_chloride, wb_sodium=:wb_sodium, " |
|
856 "wb_magnesium=:wb_magnesium, wb_total_alkalinity=:wb_total_alkalinity, wb_ph=:wb_ph, " |
|
857 "wa_acid_name=:wa_acid_name, wa_acid_perc=:wa_acid_perc, wa_base_name=:wa_base_name, " |
|
858 "json_fermentables=:json_fermentables, json_hops=:json_hops, json_miscs=:json_miscs, " |
|
859 "json_yeasts=:json_yeasts, json_mashs=:json_mashs WHERE record = :recno"); |
|
860 } |
|
861 query.bindValue(":locked", recipe->locked ? 1:0); |
|
862 query.bindValue(":st_name", recipe->st_name); |
|
863 query.bindValue(":st_letter", recipe->st_letter); |
|
864 query.bindValue(":st_guide", recipe->st_guide); |
|
865 query.bindValue(":st_category", recipe->st_category); |
|
866 query.bindValue(":st_catnr", recipe->st_category_number); |
|
867 query.bindValue(":st_type", recipe->st_type); |
|
868 query.bindValue(":st_og_min", round(recipe->st_og_min * 1000) / 1000); |
|
869 query.bindValue(":st_og_max", round(recipe->st_og_max * 1000) / 1000); |
|
870 query.bindValue(":st_fg_min", round(recipe->st_fg_min * 1000) / 1000); |
|
871 query.bindValue(":st_fg_max", round(recipe->st_fg_max * 1000) / 1000); |
|
872 query.bindValue(":st_ibu_min", round(recipe->st_ibu_min * 10) / 10); |
|
873 query.bindValue(":st_ibu_max", round(recipe->st_ibu_max * 10) / 10); |
|
874 query.bindValue(":st_color_min", round(recipe->st_color_min * 10) / 10); |
|
875 query.bindValue(":st_color_max", round(recipe->st_color_max * 10) / 10); |
|
876 query.bindValue(":st_carb_min", round(recipe->st_carb_min * 10) / 10); |
|
877 query.bindValue(":st_carb_max", round(recipe->st_carb_max * 10) / 10); |
|
878 query.bindValue(":st_abv_min", round(recipe->st_abv_min * 10) / 10); |
|
879 query.bindValue(":st_abv_max", round(recipe->st_abv_max * 10) / 10); |
|
880 query.bindValue(":name", recipe->name); |
|
881 query.bindValue(":notes", recipe->notes); |
|
882 query.bindValue(":type", recipe->type); |
|
883 query.bindValue(":batch_size", round(recipe->batch_size * 10) / 10); |
|
884 query.bindValue(":boil_size", round(recipe->boil_size * 10) / 10); |
|
885 query.bindValue(":boil_time", round(recipe->boil_time * 10) / 10); |
|
886 query.bindValue(":efficiency", round(recipe->efficiency * 10) / 10); |
|
887 query.bindValue(":est_og", round(recipe->est_og * 1000) / 1000); |
|
888 query.bindValue(":est_fg", round(recipe->est_fg * 1000) / 1000); |
|
889 query.bindValue(":est_abv", round(recipe->est_abv * 10) / 10); |
|
890 query.bindValue(":est_color", round(recipe->est_color * 10) / 10); |
|
891 query.bindValue(":color_method", recipe->color_method); |
|
892 query.bindValue(":est_ibu", round(recipe->est_ibu * 10) / 10); |
|
893 query.bindValue(":ibu_method", recipe->ibu_method); |
|
894 query.bindValue(":est_carb", round(recipe->est_carb * 10) / 10); |
|
895 query.bindValue(":sparge_temp", round(recipe->sparge_temp * 10) / 10); |
|
896 query.bindValue(":sparge_ph", round(recipe->sparge_ph * 100) / 100); |
|
897 query.bindValue(":sparge_volume", round(recipe->sparge_volume * 10) / 10); |
|
898 query.bindValue(":sparge_source", recipe->sparge_source); |
|
899 query.bindValue(":sparge_acid_type", recipe->sparge_acid_type); |
|
900 query.bindValue(":sparge_acid_perc", round(recipe->sparge_acid_perc * 10) / 10); |
|
901 query.bindValue(":sparge_acid_amount", round(recipe->sparge_acid_amount * 100000) / 100000); |
|
902 query.bindValue(":mash_ph", round(recipe->mash_ph * 100) / 100); |
|
903 query.bindValue(":mash_name", recipe->mash_name); |
|
904 query.bindValue(":calc_acid", recipe->calc_acid ?1:0); |
|
905 query.bindValue(":w1_name", recipe->w1_name); |
|
906 query.bindValue(":w1_amount", round(recipe->w1_amount * 10) / 10); |
|
907 query.bindValue(":w1_calcium", round(recipe->w1_calcium * 100000) / 100000); |
|
908 query.bindValue(":w1_sulfate", round(recipe->w1_sulfate * 100000) / 100000); |
|
909 query.bindValue(":w1_chloride", round(recipe->w1_chloride * 100000) / 100000); |
|
910 query.bindValue(":w1_sodium", round(recipe->w1_sodium * 100000) / 100000); |
|
911 query.bindValue(":w1_magnesium", round(recipe->w1_magnesium * 100000) / 100000); |
|
912 query.bindValue(":w1_total_alkalinity", round(recipe->w1_total_alkalinity * 100000) / 100000); |
|
913 query.bindValue(":w1_ph", round(recipe->w1_ph * 100) / 100); |
|
914 query.bindValue(":w1_cost", round(recipe->w1_cost * 100) / 100); |
|
915 query.bindValue(":w2_name", recipe->w2_name); |
|
916 query.bindValue(":w2_amount", round(recipe->w2_amount * 10) / 10); |
|
917 query.bindValue(":w2_calcium", round(recipe->w2_calcium * 100000) / 100000); |
|
918 query.bindValue(":w2_sulfate", round(recipe->w2_sulfate * 100000) / 100000); |
|
919 query.bindValue(":w2_chloride", round(recipe->w2_chloride * 100000) / 100000); |
|
920 query.bindValue(":w2_sodium", round(recipe->w2_sodium * 100000) / 100000); |
|
921 query.bindValue(":w2_magnesium", round(recipe->w2_magnesium * 100000) / 100000); |
|
922 query.bindValue(":w2_total_alkalinity", round(recipe->w2_total_alkalinity * 100000) / 100000); |
|
923 query.bindValue(":w2_ph", round(recipe->w2_ph * 100) / 100); |
|
924 query.bindValue(":w2_cost", round(recipe->w2_cost * 100) / 100); |
|
925 query.bindValue(":wg_amount", round(recipe->wg_amount * 10) / 10); |
|
926 query.bindValue(":wg_calcium", round(recipe->wg_calcium * 100000) / 100000); |
|
927 query.bindValue(":wg_sulfate", round(recipe->wg_sulfate * 100000) / 100000); |
|
928 query.bindValue(":wg_chloride", round(recipe->wg_chloride * 100000) / 100000); |
|
929 query.bindValue(":wg_sodium", round(recipe->wg_sodium * 100000) / 100000); |
|
930 query.bindValue(":wg_magnesium", round(recipe->wg_magnesium * 100000) / 100000); |
|
931 query.bindValue(":wg_total_alkalinity", round(recipe->wg_total_alkalinity * 100000) / 100000); |
|
932 query.bindValue(":wg_ph", round(recipe->wg_ph * 100) / 100); |
|
933 query.bindValue(":wb_calcium", round(recipe->wb_calcium * 100000) / 100000); |
|
934 query.bindValue(":wb_sulfate", round(recipe->wb_sulfate * 100000) / 100000); |
|
935 query.bindValue(":wb_chloride", round(recipe->wb_chloride * 100000) / 100000); |
|
936 query.bindValue(":wb_sodium", round(recipe->wb_sodium * 100000) / 100000); |
|
937 query.bindValue(":wb_magnesium", round(recipe->wb_magnesium * 100000) / 100000); |
|
938 query.bindValue(":wb_total_alkalinity", round(recipe->wb_total_alkalinity * 100000) / 100000); |
|
939 query.bindValue(":wb_ph", round(recipe->wb_ph * 100) / 100); |
|
940 query.bindValue(":wa_acid_name", recipe->wa_acid_name); |
|
941 query.bindValue(":wa_acid_perc", round(recipe->wa_acid_perc * 10) / 10); |
|
942 query.bindValue(":wa_base_name", recipe->wa_base_name); |
|
943 |
|
944 if (recipe->fermentables.size() == 0) { |
|
945 query.bindValue(":json_fermentables", "[]"); |
|
946 } else { |
|
947 QJsonArray array; |
|
948 for (int i = 0; i < recipe->fermentables.size(); i++) { |
|
949 QJsonObject obj; |
|
950 obj.insert("f_name", recipe->fermentables.at(i).f_name); |
|
951 obj.insert("f_origin", recipe->fermentables.at(i).f_origin); |
|
952 obj.insert("f_supplier", recipe->fermentables.at(i).f_supplier); |
|
953 obj.insert("f_amount", round(recipe->fermentables.at(i).f_amount * 10000) / 10000); |
|
954 obj.insert("f_cost", round(recipe->fermentables.at(i).f_cost * 1000) / 1000); |
|
955 obj.insert("f_type", recipe->fermentables.at(i).f_type); |
|
956 obj.insert("f_yield", round(recipe->fermentables.at(i).f_yield * 10) / 10); |
|
957 obj.insert("f_color", round(recipe->fermentables.at(i).f_color * 10) / 10); |
|
958 obj.insert("f_coarse_fine_diff", round(recipe->fermentables.at(i).f_coarse_fine_diff * 10) / 10); |
|
959 obj.insert("f_moisture", round(recipe->fermentables.at(i).f_moisture * 10) / 10); |
|
960 obj.insert("f_diastatic_power", round(recipe->fermentables.at(i).f_diastatic_power * 100000) / 100000); |
|
961 obj.insert("f_protein", round(recipe->fermentables.at(i).f_protein * 10) / 10); |
|
962 obj.insert("f_dissolved_protein", round(recipe->fermentables.at(i).f_dissolved_protein * 10) / 10); |
|
963 obj.insert("f_max_in_batch", recipe->fermentables.at(i).f_max_in_batch); |
|
964 obj.insert("f_graintype", recipe->fermentables.at(i).f_graintype); |
|
965 obj.insert("f_added", recipe->fermentables.at(i).f_added); |
|
966 obj.insert("f_recommend_mash", recipe->fermentables.at(i).f_recommend_mash ? 1:0); |
|
967 obj.insert("f_add_after_boil", recipe->fermentables.at(i).f_add_after_boil ? 1:0); |
|
968 obj.insert("f_adjust_to_total_100", recipe->fermentables.at(i).f_adjust_to_total_100 ? 1:0); |
|
969 obj.insert("f_percentage", round(recipe->fermentables.at(i).f_percentage * 10) / 10); |
|
970 obj.insert("f_di_ph", round(recipe->fermentables.at(i).f_di_ph * 100000) / 100000); |
|
971 obj.insert("f_acid_to_ph_57", round(recipe->fermentables.at(i).f_acid_to_ph_57 * 100000) / 100000); |
|
972 qDebug() << "fermentables_Json" << i << obj; |
|
973 array.append(obj); /* Append this object */ |
|
974 } |
|
975 QJsonDocument doc; |
|
976 doc.setArray(array); |
|
977 // qDebug() << doc.toJson(QJsonDocument::Compact); |
|
978 query.bindValue(":json_fermentables", doc.toJson(QJsonDocument::Compact)); |
|
979 } |
|
980 |
|
981 if (recipe->hops.size() == 0) { |
|
982 query.bindValue(":json_hops", "[]"); |
|
983 } else { |
|
984 QJsonArray array; |
|
985 for (int i = 0; i < recipe->hops.size(); i++) { |
|
986 QJsonObject obj; |
|
987 obj.insert("h_name", recipe->hops.at(i).h_name); |
|
988 obj.insert("h_origin", recipe->hops.at(i).h_origin); |
|
989 obj.insert("h_amount", round(recipe->hops.at(i).h_amount * 10000) / 10000); |
|
990 obj.insert("h_cost", round(recipe->hops.at(i).h_cost * 100) / 100); |
|
991 obj.insert("h_type", recipe->hops.at(i).h_type); |
|
992 obj.insert("h_form", recipe->hops.at(i).h_form); |
|
993 obj.insert("h_useat", recipe->hops.at(i).h_useat); |
|
994 obj.insert("h_time", round(recipe->hops.at(i).h_time)); |
|
995 obj.insert("h_alpha", round(recipe->hops.at(i).h_alpha * 100) / 100); |
|
996 obj.insert("h_beta", round(recipe->hops.at(i).h_beta * 100) / 100); |
|
997 obj.insert("h_hsi", round(recipe->hops.at(i).h_hsi * 100) / 100); |
|
998 obj.insert("h_humulene", round(recipe->hops.at(i).h_humulene * 100) / 100); |
|
999 obj.insert("h_caryophyllene", round(recipe->hops.at(i).h_caryophyllene * 100) / 100); |
|
1000 obj.insert("h_cohumulone", round(recipe->hops.at(i).h_cohumulone * 100) / 100); |
|
1001 obj.insert("h_myrcene", round(recipe->hops.at(i).h_myrcene * 100) / 100); |
|
1002 obj.insert("h_total_oil", round(recipe->hops.at(i).h_total_oil * 100) / 100); |
|
1003 qDebug() << "hops_Json" << i << obj; |
|
1004 array.append(obj); /* Append this object */ |
|
1005 } |
|
1006 QJsonDocument doc; |
|
1007 doc.setArray(array); |
|
1008 query.bindValue(":json_hops", doc.toJson(QJsonDocument::Compact)); |
|
1009 } |
481 } |
1010 |
|
1011 if (recipe->miscs.size() == 0) { |
|
1012 query.bindValue(":json_miscs", "[]"); |
|
1013 } else { |
|
1014 QJsonArray array; |
|
1015 for (int i = 0; i < recipe->miscs.size(); i++) { |
|
1016 QJsonObject obj; |
|
1017 obj.insert("m_name", recipe->miscs.at(i).m_name); |
|
1018 obj.insert("m_amount", round(recipe->miscs.at(i).m_amount * 10000) / 10000); |
|
1019 obj.insert("m_type", recipe->miscs.at(i).m_type); |
|
1020 obj.insert("m_use_use", recipe->miscs.at(i).m_use_use); |
|
1021 obj.insert("m_time", round(recipe->miscs.at(i).m_time)); |
|
1022 obj.insert("m_amount_is_weight", recipe->miscs.at(i).m_amount_is_weight ? 1:0); |
|
1023 obj.insert("m_cost", round(recipe->miscs.at(i).m_cost * 10000) / 10000); |
|
1024 qDebug() << "miscs_Json" << i << obj; |
|
1025 array.append(obj); /* Append this object */ |
|
1026 } |
|
1027 QJsonDocument doc; |
|
1028 doc.setArray(array); |
|
1029 // qDebug() << doc.toJson(QJsonDocument::Compact); |
|
1030 query.bindValue(":json_miscs", doc.toJson(QJsonDocument::Compact)); |
|
1031 } |
|
1032 |
|
1033 if (recipe->yeasts.size() == 0) { |
|
1034 query.bindValue(":json_yeasts", "[]"); |
|
1035 } else { |
|
1036 QJsonArray array; |
|
1037 for (int i = 0; i < recipe->yeasts.size(); i++) { |
|
1038 QJsonObject obj; |
|
1039 obj.insert("y_name", recipe->yeasts.at(i).y_name); |
|
1040 obj.insert("y_laboratory", recipe->yeasts.at(i).y_laboratory); |
|
1041 obj.insert("y_product_id", recipe->yeasts.at(i).y_product_id); |
|
1042 obj.insert("y_amount", round(recipe->yeasts.at(i).y_amount * 10000) / 10000); |
|
1043 obj.insert("y_type", recipe->yeasts.at(i).y_type); |
|
1044 obj.insert("y_form", recipe->yeasts.at(i).y_form); |
|
1045 obj.insert("y_min_temperature", round(recipe->yeasts.at(i).y_min_temperature * 10) / 10); |
|
1046 obj.insert("y_max_temperature", round(recipe->yeasts.at(i).y_max_temperature * 10) / 10); |
|
1047 obj.insert("y_flocculation", recipe->yeasts.at(i).y_flocculation); |
|
1048 obj.insert("y_attenuation", round(recipe->yeasts.at(i).y_attenuation * 10) / 10); |
|
1049 obj.insert("y_cells", recipe->yeasts.at(i).y_cells); |
|
1050 obj.insert("y_tolerance", round(recipe->yeasts.at(i).y_tolerance * 10) / 10); |
|
1051 obj.insert("y_inventory", round(recipe->yeasts.at(i).y_inventory * 10000) / 10000); |
|
1052 obj.insert("y_use", recipe->yeasts.at(i).y_use); |
|
1053 obj.insert("y_sta1", recipe->yeasts.at(i).y_sta1 ? 1:0); |
|
1054 obj.insert("y_bacteria", recipe->yeasts.at(i).y_bacteria ? 1:0); |
|
1055 obj.insert("y_harvest_top", recipe->yeasts.at(i).y_harvest_top ? 1:0); |
|
1056 obj.insert("y_harvest_time", recipe->yeasts.at(i).y_harvest_time); |
|
1057 obj.insert("y_pitch_temperature", round(recipe->yeasts.at(i).y_pitch_temperature * 10) / 10); |
|
1058 obj.insert("y_pofpos", recipe->yeasts.at(i).y_pofpos ? 1:0); |
|
1059 obj.insert("y_zymocide", recipe->yeasts.at(i).y_zymocide); |
|
1060 obj.insert("y_gr_hl_lo", recipe->yeasts.at(i).y_gr_hl_lo); |
|
1061 obj.insert("y_sg_lo", round(recipe->yeasts.at(i).y_sg_lo * 1000) / 1000); |
|
1062 obj.insert("y_gr_hl_hi", recipe->yeasts.at(i).y_gr_hl_hi); |
|
1063 obj.insert("y_sg_hi", round(recipe->yeasts.at(i).y_sg_hi * 1000) / 1000); |
|
1064 obj.insert("y_cost", round(recipe->yeasts.at(i).y_cost * 1000) / 1000); |
|
1065 qDebug() << "yeasts_Json" << i << obj; |
|
1066 array.append(obj); /* Append this object */ |
|
1067 } |
|
1068 QJsonDocument doc; |
|
1069 doc.setArray(array); |
|
1070 // qDebug() << doc.toJson(QJsonDocument::Compact); |
|
1071 query.bindValue(":json_yeasts", doc.toJson(QJsonDocument::Compact)); |
|
1072 } |
|
1073 |
|
1074 if (recipe->mashs.size() == 0) { |
|
1075 query.bindValue(":json_mashs", "[]"); |
|
1076 qDebug() << "Saved empty mashs"; |
|
1077 } else { |
|
1078 QJsonArray array; |
|
1079 for (int i = 0; i < recipe->mashs.size(); i++) { |
|
1080 QJsonObject obj; |
|
1081 obj.insert("step_name", recipe->mashs.at(i).step_name); |
|
1082 obj.insert("step_type", recipe->mashs.at(i).step_type); |
|
1083 obj.insert("step_volume", round(recipe->mashs.at(i).step_volume * 100) / 100); |
|
1084 obj.insert("step_infuse_amount", round(recipe->mashs.at(i).step_infuse_amount * 100) / 100); |
|
1085 obj.insert("step_infuse_temp", round(recipe->mashs.at(i).step_infuse_temp * 100) / 100); |
|
1086 obj.insert("step_temp", round(recipe->mashs.at(i).step_temp * 100) / 100); |
|
1087 obj.insert("step_time", round(recipe->mashs.at(i).step_time * 100) / 100); |
|
1088 obj.insert("ramp_time", round(recipe->mashs.at(i).ramp_time * 100) / 100); |
|
1089 obj.insert("end_temp", round(recipe->mashs.at(i).end_temp * 100) / 100); |
|
1090 obj.insert("step_wg_ratio", round(recipe->mashs.at(i).step_wg_ratio * 100) / 100); |
|
1091 qDebug() << "mashs_Json" << i << obj; |
|
1092 array.append(obj); /* Append this object */ |
|
1093 } |
|
1094 QJsonDocument doc; |
|
1095 doc.setArray(array); |
|
1096 qDebug() << doc.toJson(QJsonDocument::Compact); |
|
1097 query.bindValue(":json_mashs", doc.toJson(QJsonDocument::Compact)); |
|
1098 } |
|
1099 |
|
1100 if (this->recno == -1) { |
|
1101 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
|
1102 } else { |
|
1103 query.bindValue(":recno", this->recno); |
|
1104 } |
|
1105 query.exec(); |
|
1106 qDebug() << query.lastQuery(); |
|
1107 if (query.lastError().isValid()) { |
|
1108 qDebug() << "EditRecipe" << query.lastError(); |
|
1109 QMessageBox::warning(this, tr("Database error"), |
|
1110 tr("MySQL error: %1\n%2\n%3") |
|
1111 .arg(query.lastError().nativeErrorCode()) |
|
1112 .arg(query.lastError().driverText()) |
|
1113 .arg(query.lastError().databaseText())); |
|
1114 } else { |
|
1115 /* |
|
1116 * If this was a new recipe, find out what record number we |
|
1117 * have got and set it. So when the user saves this record |
|
1118 * again, it will be updated instead of inserting a new copy. |
|
1119 */ |
|
1120 if (this->recno < 0) { |
|
1121 QVariant id = query.lastInsertId(); |
|
1122 this->recno = recipe->record = id.toInt(); |
|
1123 qDebug() << "EditRecipe Inserted record" << this->recno; |
|
1124 } else { |
|
1125 qDebug() << "EditRecipe Updated record" << this->recno; |
|
1126 } |
|
1127 } |
|
1128 } |
482 } |
1129 |
483 |
1130 ui->saveButton->setEnabled(false); |
484 ui->saveButton->setEnabled(false); |
1131 this->textIsChanged = false; |
485 this->textIsChanged = false; |
1132 WindowTitle(); |
486 WindowTitle(); |