# HG changeset patch # User Michiel Broek # Date 1655192371 -7200 # Node ID 18a7e8d67fc58bec4e7de3a756ea8c51506de695 # Parent f66df13aee7f48d4a7bd4790ecad26883bb38825 Added import waters diff -r f66df13aee7f -r 18a7e8d67fc5 src/ImportXML.cpp --- a/src/ImportXML.cpp Mon Jun 13 21:01:19 2022 +0200 +++ b/src/ImportXML.cpp Tue Jun 14 09:39:31 2022 +0200 @@ -857,21 +857,65 @@ * Water */ total++; + Waters *w = new Waters(); + w->notes = ""; + w->ph = 7.0; while (xml->readNext()) { if (xml->atEnd()) break; if ((xml->tokenType() == QXmlStreamReader::EndElement) && (xml->name() == "WATER")) { -// query.exec(sql); + query.prepare("INSERT INTO inventory_waters SET name=:name, unlimited_stock=:unlimited, calcium=:ca, " + "bicarbonate=:hco, sulfate=:so4, chloride=:cl, sodium=:na, magnesium=:mg, ph=:ph, notes=:notes, " + "total_alkalinity=:alkalinity, nitrate=:no, uuid = :uuid"); + query.bindValue(":name", w->name); + query.bindValue(":unlimited", w->unlimited_stock ? 1:0); + query.bindValue(":ca", QString("%1").arg(w->calcium, 4, 'f', 3, '0')); + query.bindValue(":hco", QString("%1").arg(w->bicarbonate, 4, 'f', 3, '0')); + query.bindValue(":so4", QString("%1").arg(w->sulfate, 4, 'f', 3, '0')); + query.bindValue(":cl", QString("%1").arg(w->chloride, 4, 'f', 3, '0')); + query.bindValue(":na", QString("%1").arg(w->sodium, 4, 'f', 3, '0')); + query.bindValue(":mg", QString("%1").arg(w->magnesium, 4, 'f', 3, '0')); + query.bindValue(":ph", QString("%1").arg(w->ph, 4, 'f', 3, '0')); + query.bindValue(":notes", w->notes); + query.bindValue(":alkalinity", QString("%1").arg(w->total_alkalinity, 4, 'f', 3, '0')); + query.bindValue(":no", QString("%1").arg(w->nitrate, 4, 'f', 3, '0')); + query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); + query.exec(); if (query.lastError().isValid()) { -// qWarning() << sql << query.lastError(); + qWarning() << query.lastError(); errors++; } ui->progressBar->setValue(round(100 * xml->characterOffset() / fsize)); break; } - if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "VERSION")) { + if ((xml->tokenType() == QXmlStreamReader::StartElement) && ( + (xml->name() == "VERSION") || (xml->name() == "DEFAULT_WATER") || + (xml->name() == "ALWAYS_ON_STOCK") || (xml->name() == "AMOUNT") || + (xml->name() == "DISPLAY_AMOUNT"))) { // Ignore. + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NAME")) { + w->name = xml->readElementText(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NOTES")) { + w->notes = xml->readElementText(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "xUNLIMITED_STOCK")) { + w->unlimited_stock = (xml->readElementText() == "TRUE") ? true:false; + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "CALCIUM")) { + w->calcium = xml->readElementText().toDouble(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BICARBONATE")) { + w->bicarbonate = xml->readElementText().toDouble(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TOTAL_ALKALINITY")) { + w->total_alkalinity = xml->readElementText().toDouble(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "SULFATE")) { + w->sulfate = xml->readElementText().toDouble(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "CHLORIDE")) { + w->chloride = xml->readElementText().toDouble(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "SODIUM")) { + w->sodium = xml->readElementText().toDouble(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MAGNESIUM")) { + w->magnesium = xml->readElementText().toDouble(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "PH")) { + w->ph = xml->readElementText().toDouble(); } else { if (xml->tokenType() == QXmlStreamReader::StartElement) qDebug() << "2 " << xml->tokenType() << xml->name(); diff -r f66df13aee7f -r 18a7e8d67fc5 src/global.h --- a/src/global.h Mon Jun 13 21:01:19 2022 +0200 +++ b/src/global.h Tue Jun 14 09:39:31 2022 +0200 @@ -180,6 +180,26 @@ }; +struct Waters +{ + QString name; + QString notes; + bool unlimited_stock; + double calcium; + double bicarbonate; + double total_alkalinity; + double sulfate; + double chloride; + double sodium; + double magnesium; + double nitrate; + double ph; + double cost; + double inventory; + bool avail; +}; + + struct Splits { QString name; ///< Name of split part