Added xml import hops

Sun, 12 Jun 2022 20:06:39 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 12 Jun 2022 20:06:39 +0200
changeset 279
8540fd0166e7
parent 278
ed562a2a4ca4
child 280
efc213beb605

Added xml import hops

src/ImportXML.cpp file | annotate | diff | comparison | revisions
src/global.h file | annotate | diff | comparison | revisions
--- a/src/ImportXML.cpp	Sun Jun 12 11:52:18 2022 +0200
+++ b/src/ImportXML.cpp	Sun Jun 12 20:06:39 2022 +0200
@@ -508,21 +508,106 @@
                      * Hop
                      */
                     total++;
+		    Hops *h = new Hops;
+		    h->h_inventory = h->h_cost = 0;
+		    h->h_notes = h->h_origin = h->h_substitutes = "";
+		    h->h_beta = h->h_hsi = h->h_humulene = h->h_caryophyllene = h->h_cohumulone = h->h_myrcene = h->h_total_oil = 0;
 
                     while (xml->readNext()) {
                         if (xml->atEnd())
                             break;
                         if ((xml->tokenType() == QXmlStreamReader::EndElement) && (xml->name() == "HOP")) {
-//                            query.exec(sql);
+			    query.prepare("INSERT INTO inventory_hops SET name=:name, alpha=:alpha, beta=:beta, "
+				"humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, "
+				"hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, "
+				"total_oil=:oil, uuid = :uuid");
+			    query.bindValue(":name", h->h_name);
+			    query.bindValue(":alpha", QString("%1").arg(h->h_alpha, 2, 'f', 1, '0'));
+			    query.bindValue(":beta", QString("%1").arg(h->h_beta, 2, 'f', 1, '0'));
+			    query.bindValue(":humulene", QString("%1").arg(h->h_humulene, 2, 'f', 1, '0'));
+			    query.bindValue(":cary", QString("%1").arg(h->h_caryophyllene, 2, 'f', 1, '0'));
+			    query.bindValue(":cohumulone", QString("%1").arg(h->h_cohumulone, 2, 'f', 1, '0'));
+			    query.bindValue(":myrcene", QString("%1").arg(h->h_myrcene, 2, 'f', 1, '0'));
+			    query.bindValue(":hsi", QString("%1").arg(h->h_hsi, 2, 'f', 1, '0'));
+			    query.bindValue(":type", h->h_type);
+			    query.bindValue(":form", h->h_form);
+			    query.bindValue(":notes", h->h_notes);
+			    query.bindValue(":origin", h->h_origin);
+			    query.bindValue(":substitutes", h->h_substitutes);
+			    query.bindValue(":oil", QString("%1").arg(h->h_total_oil, 2, 'f', 1, '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() == "ALWAYS_ON_STOCK") ||
+			    (xml->name() == "HARVEST_DATE") || (xml->name() == "DISPLAY_COST") ||
+			    (xml->name() == "COST") || (xml->name() == "INVENTORY"))) {
                             // Ignore.
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NAME")) {
+			    h->h_name = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ORIGIN")) {
+                            h->h_origin = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NOTES")) {
+                            h->h_notes = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FORM")) {
+			    QString temp = xml->readElementText();
+			    if (temp == "Plug")
+				h->h_form = 1;
+                            else if (temp == "Leaf")
+				h->h_form = 2;
+                            else if (temp == "Leaf wet")
+				h->h_form = 3;
+                            else if (temp == "Cryo")
+				h->h_form = 4;
+			    else
+				h->h_form = 0;
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ALPHA")) {
+			    h->h_alpha = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) {
+                            QString temp = xml->readElementText();
+			    if (temp == "Aroma")
+				h->h_type = 1;
+			    else if (temp == "Both")
+				h->h_type = 2;
+			    else
+				h->h_type = 0;
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE")) {
+			    QString temp = xml->readElementText();
+			    if (temp == "First wort")
+				h->h_useat = 1;
+			    else if (temp == "Boil")
+				h->h_useat = 2;
+                            else if (temp == "Aroma")
+				h->h_useat = 3;
+                            else if (temp == "Whirlpool")
+				h->h_useat = 4;
+                            else if (temp == "Dry hop")
+				h->h_useat = 5;
+			    else
+				h->h_useat = 0;
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BETA")) {
+                            h->h_beta = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HSI")) {
+                            h->h_hsi = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "SUBSTITUTES")) {
+                            h->h_substitutes = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HUMULENE")) {
+                            h->h_humulene = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && 
+			    ((xml->name() == "CARYOPHYLLENE") || (xml->name() == "CAROPHYLLENE"))) {
+                            h->h_caryophyllene = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "COHUMULONE")) {
+                            h->h_cohumulone = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MYRCENE")) {
+                            h->h_myrcene = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TOTAL_OIL")) {
+                            h->h_total_oil = xml->readElementText().toDouble();
                         } else {
                             if (xml->tokenType() == QXmlStreamReader::StartElement)
                                 qDebug() << "2  " << xml->tokenType() << xml->name();
@@ -559,8 +644,11 @@
                             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")
+			    )) {
                             // Ignore.
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NAME")) {
                         } else {
                             if (xml->tokenType() == QXmlStreamReader::StartElement)
                                 qDebug() << "2  " << xml->tokenType() << xml->name();
--- a/src/global.h	Sun Jun 12 11:52:18 2022 +0200
+++ b/src/global.h	Sun Jun 12 20:06:39 2022 +0200
@@ -86,6 +86,8 @@
 {
     QString	h_name;
     QString	h_origin;
+    QString	h_notes;
+    QString	h_substitutes;
     double	h_amount;
     double	h_cost;
     int		h_type;

mercurial