325 this->textIsChanged = false; |
324 this->textIsChanged = false; |
326 WindowTitle(); |
325 WindowTitle(); |
327 } |
326 } |
328 |
327 |
329 |
328 |
|
329 void EditYeast::on_cloneButton_clicked() |
|
330 { |
|
331 QSqlQuery query; |
|
332 |
|
333 query.prepare("INSERT INTO inventory_yeasts SET name=:name, type=:type, form=:form, " |
|
334 "laboratory=:laboratory, product_id=:productid, min_temperature=:templo, max_temperature=:temphi, " |
|
335 "flocculation=:floc, attenuation=:att, tolerance=:tolerance, notes=:notes, best_for=:bestfor, " |
|
336 "max_reuse=:reuse, inventory=:inventory, cost=:cost, production_date=:prod, tht_date=:tht, " |
|
337 "cells=:cells, sta1=:sta1, bacteria=:bacteria, harvest_top=:harvesttop, harvest_time=:harvesttime, " |
|
338 "pitch_temperature=:pitchtemp, pofpos=:pof, short_desc=:yeastbank, gr_hl_lo=:grhllo, sg_lo=:sglo, " |
|
339 "gr_hl_hi=:grhlhi, sg_hi=:sghi, uuid = :uuid"); |
|
340 |
|
341 query.bindValue(":name", ui->nameEdit->text() + " [copy]"); |
|
342 query.bindValue(":type", ui->typeEdit->currentIndex()); |
|
343 query.bindValue(":form", ui->formEdit->currentIndex()); |
|
344 query.bindValue(":laboratory", ui->laboratoryEdit->text()); |
|
345 query.bindValue(":productid", ui->productidEdit->text()); |
|
346 query.bindValue(":templo", QString("%1").arg(ui->temploEdit->value(), 2, 'f', 1, '0')); |
|
347 query.bindValue(":temphi", QString("%1").arg(ui->temphiEdit->value(), 2, 'f', 1, '0')); |
|
348 query.bindValue(":floc", ui->flocEdit->currentIndex()); |
|
349 query.bindValue(":att", QString("%1").arg(ui->attEdit->value(), 2, 'f', 1, '0')); |
|
350 query.bindValue(":tolerance", QString("%1").arg(ui->toleranceEdit->value(), 2, 'f', 1, '0')); |
|
351 query.bindValue(":notes", ui->notesEdit->toPlainText()); |
|
352 query.bindValue(":bestfor", ui->bestforEdit->toPlainText()); |
|
353 query.bindValue(":reuse", ui->reuseEdit->value()); |
|
354 query.bindValue(":inventory", QString("%1").arg(0, 5, 'f', 4, '0')); |
|
355 query.bindValue(":cost", QString("%1").arg(ui->costEdit->value(), 3, 'f', 2, '0')); |
|
356 query.bindValue(":prod", QDate()); |
|
357 query.bindValue(":tht", QDate()); |
|
358 query.bindValue(":cells", QString("%1").arg(ui->cellsEdit->value() * 1000000000, 1, 'f', 0, '0')); |
|
359 query.bindValue(":sta1", ui->sta1Edit->isChecked() ? 1:0); |
|
360 query.bindValue(":bacteria", ui->bacteriaEdit->isChecked() ? 1:0); |
|
361 query.bindValue(":harvesttop", ui->harvesttopEdit->isChecked() ? 1:0); |
|
362 query.bindValue(":harvesttime", ui->harvesttimeEdit->value()); |
|
363 query.bindValue(":pitchtemp", QString("%1").arg(ui->pitchtempEdit->value(), 2, 'f', 1, '0')); |
|
364 query.bindValue(":pof", ui->pofEdit->isChecked() ? 1:0); |
|
365 query.bindValue(":yeastbank", ui->yeastbankEdit->text()); |
|
366 query.bindValue(":grhllo", QString("%1").arg(ui->grhlloEdit->value(), 2, 'f', 1, '0')); |
|
367 query.bindValue(":sglo", ui->sgloEdit->value()); |
|
368 query.bindValue(":grhlhi", QString("%1").arg(ui->grhlhiEdit->value(), 2, 'f', 1, '0')); |
|
369 query.bindValue(":sghi", ui->sghiEdit->value()); |
|
370 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
|
371 |
|
372 query.exec(); |
|
373 if (query.lastError().isValid()) { |
|
374 qWarning() << "EditYeast" << query.lastError(); |
|
375 QMessageBox::warning(this, tr("Database error"), |
|
376 tr("MySQL error: %1\n%2\n%3") |
|
377 .arg(query.lastError().nativeErrorCode()) |
|
378 .arg(query.lastError().driverText()) |
|
379 .arg(query.lastError().databaseText())); |
|
380 } else { |
|
381 qDebug() << "EditYeast Saved"; |
|
382 } |
|
383 } |
|
384 |
|
385 |
330 void EditYeast::on_deleteButton_clicked() |
386 void EditYeast::on_deleteButton_clicked() |
331 { |
387 { |
332 QSqlQuery query; |
388 QSqlQuery query; |
|
389 |
|
390 int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(ui->nameEdit->text()), |
|
391 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
|
392 if (rc == QMessageBox::No) |
|
393 return; |
333 |
394 |
334 query.prepare("DELETE FROM inventory_yeasts WHERE record = :recno"); |
395 query.prepare("DELETE FROM inventory_yeasts WHERE record = :recno"); |
335 query.bindValue(":recno", this->recno); |
396 query.bindValue(":recno", this->recno); |
336 query.exec(); |
397 query.exec(); |
337 if (query.lastError().isValid()) { |
398 if (query.lastError().isValid()) { |
338 qDebug() << "EditYeast" << query.lastError(); |
399 qWarning() << "EditYeast" << query.lastError(); |
339 QMessageBox::warning(this, tr("Database error"), |
400 QMessageBox::warning(this, tr("Database error"), |
340 tr("MySQL error: %1\n%2\n%3") |
401 tr("MySQL error: %1\n%2\n%3") |
341 .arg(query.lastError().nativeErrorCode()) |
402 .arg(query.lastError().nativeErrorCode()) |
342 .arg(query.lastError().driverText()) |
403 .arg(query.lastError().driverText()) |
343 .arg(query.lastError().databaseText())); |
404 .arg(query.lastError().databaseText())); |