153 } else { |
152 } else { |
154 query.bindValue(":recno", recno); |
153 query.bindValue(":recno", recno); |
155 } |
154 } |
156 query.exec(); |
155 query.exec(); |
157 if (query.lastError().isValid()) { |
156 if (query.lastError().isValid()) { |
158 qDebug() << "EditWater" << query.lastError(); |
157 qWarning() << "EditWater" << query.lastError(); |
159 QMessageBox::warning(this, tr("Database error"), |
158 QMessageBox::warning(this, tr("Database error"), |
160 tr("MySQL error: %1\n%2\n%3") |
159 tr("MySQL error: %1\n%2\n%3") |
161 .arg(query.lastError().nativeErrorCode()) |
160 .arg(query.lastError().nativeErrorCode()) |
162 .arg(query.lastError().driverText()) |
161 .arg(query.lastError().driverText()) |
163 .arg(query.lastError().databaseText())); |
162 .arg(query.lastError().databaseText())); |
170 this->textIsChanged = false; |
169 this->textIsChanged = false; |
171 WindowTitle(); |
170 WindowTitle(); |
172 } |
171 } |
173 |
172 |
174 |
173 |
|
174 void EditWater::on_cloneButton_clicked() |
|
175 { |
|
176 QSqlQuery query; |
|
177 |
|
178 query.prepare("INSERT INTO inventory_waters SET name=:name, unlimited_stock=:unlimited, calcium=:ca, " |
|
179 "bicarbonate=:hco, sulfate=:so4, chloride=:cl, sodium=:na, magnesium=:mg, ph=:ph, notes=:notes, " |
|
180 "total_alkalinity=:alkalinity, inventory=:inventory, cost=:cost, nitrate=:no, uuid = :uuid"); |
|
181 |
|
182 query.bindValue(":name", ui->nameEdit->text() + " [copy]"); |
|
183 query.bindValue(":unlimited", ui->unlimitedEdit->isChecked() ? 1:0); |
|
184 query.bindValue(":ca", round(calcium * 1000) / 1000); |
|
185 query.bindValue(":hco", round(bicarbonate * 1000) / 1000); |
|
186 query.bindValue(":so4", round(sulfate * 1000) / 1000); |
|
187 query.bindValue(":cl", round(chloride * 1000) / 1000); |
|
188 query.bindValue(":na", round(sodium * 1000) / 1000); |
|
189 query.bindValue(":mg", round(magnesium * 1000) / 1000); |
|
190 query.bindValue(":ph", round(ph * 1000) / 1000); |
|
191 query.bindValue(":notes", ui->notesEdit->toPlainText()); |
|
192 query.bindValue(":alkalinity", round(total_alkalinity * 1000) / 1000); |
|
193 query.bindValue(":inventory", QString("%1").arg(0, 2, 'f', 1, '0')); |
|
194 query.bindValue(":cost", QString("%1").arg(ui->costEdit->value(), 6, 'f', 5, '0')); |
|
195 query.bindValue(":no", round(nitrate * 1000) / 1000); |
|
196 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
|
197 |
|
198 query.exec(); |
|
199 if (query.lastError().isValid()) { |
|
200 qWarning() << "EditWater" << query.lastError(); |
|
201 QMessageBox::warning(this, tr("Database error"), |
|
202 tr("MySQL error: %1\n%2\n%3") |
|
203 .arg(query.lastError().nativeErrorCode()) |
|
204 .arg(query.lastError().driverText()) |
|
205 .arg(query.lastError().databaseText())); |
|
206 } else { |
|
207 qDebug() << "EditWater Saved"; |
|
208 } |
|
209 } |
|
210 |
|
211 |
175 void EditWater::on_deleteButton_clicked() |
212 void EditWater::on_deleteButton_clicked() |
176 { |
213 { |
177 QSqlQuery query; |
214 QSqlQuery query; |
|
215 |
|
216 int rc = QMessageBox::warning(this, tr("Delete water"), tr("Delete %1").arg(ui->nameEdit->text()), |
|
217 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
|
218 if (rc == QMessageBox::No) |
|
219 return; |
178 |
220 |
179 query.prepare("DELETE FROM inventory_waters WHERE record = :recno"); |
221 query.prepare("DELETE FROM inventory_waters WHERE record = :recno"); |
180 query.bindValue(":recno", this->recno); |
222 query.bindValue(":recno", this->recno); |
181 query.exec(); |
223 query.exec(); |
182 if (query.lastError().isValid()) { |
224 if (query.lastError().isValid()) { |
183 qDebug() << "EditWater" << query.lastError(); |
225 qWarning() << "EditWater" << query.lastError(); |
184 QMessageBox::warning(this, tr("Database error"), |
226 QMessageBox::warning(this, tr("Database error"), |
185 tr("MySQL error: %1\n%2\n%3") |
227 tr("MySQL error: %1\n%2\n%3") |
186 .arg(query.lastError().nativeErrorCode()) |
228 .arg(query.lastError().nativeErrorCode()) |
187 .arg(query.lastError().driverText()) |
229 .arg(query.lastError().driverText()) |
188 .arg(query.lastError().databaseText())); |
230 .arg(query.lastError().databaseText())); |