Added import yeasts

Mon, 13 Jun 2022 21:01:19 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 13 Jun 2022 21:01:19 +0200
changeset 285
f66df13aee7f
parent 284
33bb98c33e6a
child 286
18a7e8d67fc5

Added import yeasts

src/ImportXML.cpp file | annotate | diff | comparison | revisions
src/global.h file | annotate | diff | comparison | revisions
--- a/src/ImportXML.cpp	Mon Jun 13 17:34:51 2022 +0200
+++ b/src/ImportXML.cpp	Mon Jun 13 21:01:19 2022 +0200
@@ -722,21 +722,118 @@
                      * Yeast
                      */
                     total++;
+		    Yeasts *y = new Yeasts();
+		    y->laboratory = y->product_id = y->best_for = y->notes = y->short_desc = "";
+		    y->max_reuse = 10;
+		    y->min_temperature = 18;
+		    y->max_temperature = 22;
+		    y->attenuation = 77;
 
                     while (xml->readNext()) {
                         if (xml->atEnd())
                             break;
                         if ((xml->tokenType() == QXmlStreamReader::EndElement) && (xml->name() == "YEAST")) {
-//                            query.exec(sql);
+			    query.prepare("INSERT INTO inventory_yeasts SET name=:name, type=:type, form=:form, "
+				"laboratory=:laboratory, product_id=:productid, min_temperature=:templo, max_temperature=:temphi, "
+				"flocculation=:floc, attenuation=:att, notes=:notes, best_for=:bestfor, "
+				"max_reuse=:reuse, short_desc='', uuid = :uuid");
+			    query.bindValue(":name", y->name);
+			    query.bindValue(":type", y->type);
+			    query.bindValue(":form", y->form);
+			    query.bindValue(":laboratory", y->laboratory);
+			    query.bindValue(":productid", y->product_id);
+			    query.bindValue(":templo", QString("%1").arg(y->min_temperature, 2, 'f', 1, '0'));
+			    query.bindValue(":temphi", QString("%1").arg(y->max_temperature, 2, 'f', 1, '0'));
+			    query.bindValue(":floc", y->flocculation);
+			    query.bindValue(":att", QString("%1").arg(y->attenuation, 2, 'f', 1, '0'));
+			    query.bindValue(":notes", y->notes);
+			    query.bindValue(":bestfor", y->best_for);
+			    query.bindValue(":reuse", y->max_reuse);
+			    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() == "TIMES_CULTURED") ||
+			    (xml->name() == "DISP_MIN_TEMP") || (xml->name() == "DISP_MAX_TEMP") ||
+			    (xml->name() == "CULTURE_DATE") || (xml->name() == "STARTER_TYPE") ||
+			    (xml->name() == "STARTER_MADE") || (xml->name() == "STARTER_VOLUME") ||
+			    (xml->name() == "OG_STARTER") || (xml->name() == "TIME_AERATED") ||
+			    (xml->name() == "ZINC_ADDED") || (xml->name() == "AMOUNT_ZINC") ||
+			    (xml->name() == "AMOUNT_EXTRACT") || (xml->name() == "COST_EXTRACT") ||
+			    (xml->name() == "ALWAYS_ON_STOCK") || (xml->name() == "DISPLAY_AMOUNT") ||
+			    (xml->name() == "AMOUNT") || (xml->name() == "DISPLAY_AMOUNT") ||
+			    (xml->name() == "AMOUNT_IS_WEIGHT") || (xml->name() == "ADD_TO_SECONDARY") ||
+			    (xml->name() == "COST") || (xml->name() == "DISPLAY_COST") ||
+			    (xml->name() == "TEMP") || (xml->name() == "INVENTORY"))) {
                             // Ignore.
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NAME")) {
+			    y->name = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "LABORATORY")) {
+                            y->laboratory = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "PRODUCT_ID")) {
+                            y->product_id = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NOTES")) {
+                            y->notes = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BEST_FOR")) {
+                            y->best_for = xml->readElementText();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) {
+                            QString temp = xml->readElementText();
+			    if (temp == "Ale")
+				y->type = 1;
+			    else if (temp == "Wheat")
+				y->type = 2;
+                            else if (temp == "Wine")
+				y->type = 3;
+                            else if (temp == "Champagne")
+				y->type = 4;
+                            else if (temp == "Brett")
+				y->type = 5;
+                            else if (temp == "Kveik")
+				y->type = 6;
+                            else if (temp == "Hybrid")
+				y->type = 7;
+			    else
+				y->type = 0;
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FORM")) {
+                            QString temp = xml->readElementText();
+                            if (temp == "Dry")
+                                y->form = 1;
+			    else if (temp == "Slant")
+				y->form = 2;
+                            else if (temp == "Culture")
+				y->form = 3;
+                            else if (temp == "Frozen")
+				y->form = 4;
+                            else if (temp == "Bottle")
+				y->form = 5;
+                            else if (temp == "Dried")
+				y->form = 6;
+			    else
+				y->form = 0;
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FLOCCULATION")) {
+                            QString temp = xml->readElementText();
+                            if (temp == "Medium")
+                                y->flocculation = 1;
+			    else if (temp == "High")
+	    			y->flocculation = 1;
+                            else if (temp == "Very high")
+				y->flocculation = 3;
+			    else
+				y->flocculation = 0;			    
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MIN_TEMPERATURE")) {
+			    y->min_temperature = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MAX_TEMPERATURE")) {
+                            y->max_temperature = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ATTENUATION")) {
+                            y->attenuation = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MAX_REUSE")) {
+			    y->max_reuse = xml->readElementText().toInt();
                         } else {
                             if (xml->tokenType() == QXmlStreamReader::StartElement)
                                 qDebug() << "2  " << xml->tokenType() << xml->name();
--- a/src/global.h	Mon Jun 13 17:34:51 2022 +0200
+++ b/src/global.h	Mon Jun 13 21:01:19 2022 +0200
@@ -132,12 +132,16 @@
     QString	name;
     QString	laboratory;
     QString	product_id;
+    QString	notes;
+    QString	best_for;
+    QString	short_desc;
     double	amount;
     int		type;
     int		form;
     double	min_temperature;
     double	max_temperature;
     int		flocculation;
+    int		max_reuse;
     double	attenuation;
     double	cells;
     double	tolerance;

mercurial