222 this->textIsChanged = false; |
222 this->textIsChanged = false; |
223 WindowTitle(); |
223 WindowTitle(); |
224 } |
224 } |
225 |
225 |
226 |
226 |
|
227 void EditHop::on_cloneButton_clicked() |
|
228 { |
|
229 QSqlQuery query; |
|
230 |
|
231 QString sql = "INSERT INTO inventory_hops SET name=:name, alpha=:alpha, beta=:beta, " |
|
232 "humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, " |
|
233 "hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, " |
|
234 "always_on_stock=:always, inventory=:inventory, cost=:cost, production_date=:prod, " |
|
235 "tht_date=:tht, total_oil=:oil, utilisation=:utilisation, bu_factor=:bu_factor, uuid=:uuid"; |
|
236 |
|
237 query.prepare(sql); |
|
238 query.bindValue(":name", ui->nameEdit->text() + " [copy]"); |
|
239 query.bindValue(":alpha", QString("%1").arg(ui->alphaEdit->value(), 2, 'f', 1, '0')); |
|
240 query.bindValue(":beta", QString("%1").arg(ui->betaEdit->value(), 2, 'f', 1, '0')); |
|
241 query.bindValue(":humulene", QString("%1").arg(ui->humuleneEdit->value(), 2, 'f', 1, '0')); |
|
242 query.bindValue(":cary", QString("%1").arg(ui->caryEdit->value(), 2, 'f', 1, '0')); |
|
243 query.bindValue(":cohumulone", QString("%1").arg(ui->cohumuloneEdit->value(), 2, 'f', 1, '0')); |
|
244 query.bindValue(":myrcene", QString("%1").arg(ui->myrceneEdit->value(), 2, 'f', 1, '0')); |
|
245 query.bindValue(":hsi", QString("%1").arg(ui->hsiEdit->value(), 2, 'f', 1, '0')); |
|
246 query.bindValue(":type", ui->typeEdit->currentIndex()); |
|
247 query.bindValue(":form", ui->formEdit->currentIndex()); |
|
248 query.bindValue(":notes", ui->notesEdit->toPlainText()); |
|
249 query.bindValue(":origin", ui->originEdit->text()); |
|
250 query.bindValue(":substitutes", ui->substitutesEdit->text()); |
|
251 query.bindValue(":always", ui->alwaysEdit->isChecked() ? 1:0); |
|
252 query.bindValue(":inventory", QString("%1").arg(0, 5, 'f', 4, '0')); |
|
253 query.bindValue(":cost", QString("%1").arg(ui->costEdit->value(), 3, 'f', 2, '0')); |
|
254 /* Uses https://www.qtcentre.org/threads/17295-How-to-put-empty-value-in-QDateEdit */ |
|
255 query.bindValue(":prod", QDate()); |
|
256 query.bindValue(":tht", QDate()); |
|
257 query.bindValue(":oil", QString("%1").arg(ui->oilEdit->value(), 2, 'f', 1, '0')); |
|
258 query.bindValue(":utilisation", QString("%1").arg(ui->utilisationEdit->value(), 2, 'f', 1, '0')); |
|
259 query.bindValue(":bu_factor", QString("%1").arg(ui->bufactorEdit->value(), 2, 'f', 1, '0')); |
|
260 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
|
261 query.exec(); |
|
262 if (query.lastError().isValid()) { |
|
263 qDebug() << "EditHop" << query.lastError(); |
|
264 QMessageBox::warning(this, tr("Database error"), |
|
265 tr("MySQL error: %1\n%2\n%3") |
|
266 .arg(query.lastError().nativeErrorCode()) |
|
267 .arg(query.lastError().driverText()) |
|
268 .arg(query.lastError().databaseText())); |
|
269 } else { |
|
270 qDebug() << "EditHop Saved"; |
|
271 } |
|
272 |
|
273 } |
|
274 |
|
275 |
227 void EditHop::on_deleteButton_clicked() |
276 void EditHop::on_deleteButton_clicked() |
228 { |
277 { |
229 QSqlQuery query; |
278 QSqlQuery query; |
230 |
279 |
231 query.prepare("DELETE FROM inventory_hops WHERE record = :recno"); |
280 query.prepare("DELETE FROM inventory_hops WHERE record = :recno"); |