src/EditProductTab6.cpp

changeset 483
eb0a5f132ea9
parent 482
e13763ec829f
child 484
ebf7ef31da35
equal deleted inserted replaced
482:e13763ec829f 483:eb0a5f132ea9
588 double vpm = 1.00; 588 double vpm = 1.00;
589 double max = 100; 589 double max = 100;
590 590
591 for (int i = 0; i < product->yeasts.size(); i++) { 591 for (int i = 0; i < product->yeasts.size(); i++) {
592 if (product->yeasts.at(i).use == YEAST_USE_PRIMARY) { 592 if (product->yeasts.at(i).use == YEAST_USE_PRIMARY) {
593 if (product->yeasts.at(i).form == YEAST_FORMS_LIQUID) { 593 qDebug() << "calcViability()" << i << product->yeasts.at(i).yp_uuid << product->yeasts.at(i).yp_package;
594 if (! product->yeasts.at(i).yp_uuid.isNull() && (product->yeasts.at(i).yp_uuid.length() == 36)) {
595 qDebug() << " valid package vpm:" << product->yeasts.at(i).yp_viability << product->yeasts.at(i).yp_max;
596 vpm = product->yeasts.at(i).yp_viability;
597 max = product->yeasts.at(i).yp_max;
598 } else if (product->yeasts.at(i).form == YEAST_FORMS_LIQUID) { // Fallback to hardcoded values.
594 vpm = 0.80; 599 vpm = 0.80;
595 max = 97; 600 max = 97;
596 if (product->yeasts.at(i).laboratory == "White Labs") { // PurePitch 601 if (product->yeasts.at(i).laboratory == "White Labs") { // PurePitch
597 /* 602 /*
598 * Purepitch 6th month viability point 80,8%. 603 * Purepitch 6th month viability point 80,8%.
952 calcYeast(); 957 calcYeast();
953 is_changed(); 958 is_changed();
954 } 959 }
955 960
956 961
962 void EditProduct::yeast_load_packages(QString laboratory, int form)
963 {
964 QSqlQuery query;
965
966 /*
967 * Clear package and rebuild package select table.
968 */
969 this->ypackageEdit->setCurrentIndex(-1);
970 this->ypackageEdit->clear();
971 this->ypackageEdit->addItem(""); // Start with empty value
972 query.prepare("SELECT * FROM inventory_yeastpack WHERE laboratory=:laboratory AND form=:form AND valid='1' ORDER BY laboratory,package");
973 query.bindValue(":laboratory", laboratory);
974 query.bindValue(":form", form);
975 qDebug() << " search" << laboratory << form;
976 query.exec();
977 while (query.next()) {
978 this->ypackageEdit->addItem(query.value("laboratory").toString()+" - "+query.value("package").toString());
979 qDebug() << " add package" << query.value("laboratory").toString() << query.value("package").toString();
980 }
981 }
982
983
984 void EditProduct::yeast_package_changed(int val)
985 {
986 QSqlQuery query;
987 int index = 0;
988
989 #ifdef DEBUG_YEAST
990 qDebug() << "yeast_package_changed()" << product->yeasts_row << val;
991 #endif
992
993 /*
994 * Scan the packages for result number 'val'
995 */
996 query.prepare("SELECT * FROM inventory_yeastpack WHERE laboratory=:laboratory AND form=:form AND valid='1' ORDER BY laboratory,package");
997 query.bindValue(":laboratory", product->yeasts.at(product->yeasts_row).laboratory);
998 query.bindValue(":form", product->yeasts.at(product->yeasts_row).form);
999 qDebug() << " search" << product->yeasts.at(product->yeasts_row).laboratory << product->yeasts.at(product->yeasts_row).form;
1000 query.exec();
1001 while (query.next()) {
1002 index++;
1003 if (index == val) {
1004 qDebug() << " result" << index << query.value("package").toString();
1005 product->yeasts[product->yeasts_row].yp_uuid = query.value("uuid").toString();
1006 product->yeasts[product->yeasts_row].yp_package = query.value("package").toString();
1007 product->yeasts[product->yeasts_row].yp_cells = query.value("cells").toDouble();
1008 product->yeasts[product->yeasts_row].yp_viability = query.value("viability").toDouble();
1009 product->yeasts[product->yeasts_row].yp_max = query.value("max").toInt();
1010 product->yeasts[product->yeasts_row].yp_size = query.value("size").toDouble();
1011 is_changed();
1012 return;
1013 }
1014 }
1015 if (! product->yeasts[product->yeasts_row].yp_uuid.isNull()) {
1016 /*
1017 * Clear package
1018 */
1019 product->yeasts[product->yeasts_row].yp_uuid = QString();
1020 product->yeasts[product->yeasts_row].yp_package = QString();
1021 product->yeasts[product->yeasts_row].yp_cells = product->yeasts[product->yeasts_row].cells;
1022 product->yeasts[product->yeasts_row].yp_viability = 0.99;
1023 product->yeasts[product->yeasts_row].yp_max = 100;
1024 product->yeasts[product->yeasts_row].yp_size = 0.01;
1025 is_changed();
1026 qDebug() << " cleared old yp_xxx data";
1027 }
1028 qDebug() << " result not found";
1029 }
1030
1031
957 void EditProduct::yeast_select_changed(int val) 1032 void EditProduct::yeast_select_changed(int val)
958 { 1033 {
959 QSqlQuery query, query1; 1034 QSqlQuery query;
960 bool instock = yinstockEdit->isChecked(); 1035 bool instock = yinstockEdit->isChecked();
961 QString w; 1036 QString w;
962 QTableWidgetItem *item; 1037 QTableWidgetItem *item;
963 int oldform = product->yeasts.at(product->yeasts_row).form; 1038 int oldform = product->yeasts.at(product->yeasts_row).form;
964 1039
1050 } 1125 }
1051 1126
1052 /* 1127 /*
1053 * Clear package and rebuild package select table. 1128 * Clear package and rebuild package select table.
1054 */ 1129 */
1055 this->ypackageEdit->setCurrentIndex(-1); 1130 yeast_load_packages(query.value("laboratory").toString(), query.value("form").toInt());
1056 this->ypackageEdit->clear();
1057 this->ypackageEdit->addItem(""); // Start with empty value
1058 query1.prepare("SELECT * FROM inventory_yeastpack WHERE laboratory=:laboratory AND form=:form AND valid='1' ORDER BY laboratory,package");
1059 query1.bindValue(":laboratory", query.value("laboratory").toString());
1060 query1.bindValue(":form", query.value("form").toInt());
1061 qDebug() << " search" << query.value("laboratory").toString() << query.value("form").toInt();
1062 query1.exec();
1063 while (query1.next()) {
1064 this->ypackageEdit->addItem(query1.value("laboratory").toString()+" - "+query1.value("package").toString());
1065 qDebug() << " add package" << query1.value("laboratory").toString() << query1.value("package").toString();
1066 }
1067 1131
1068 ui->yeastsTable->setItem(product->yeasts_row, 0, new QTableWidgetItem(product->yeasts.at(product->yeasts_row).name)); 1132 ui->yeastsTable->setItem(product->yeasts_row, 0, new QTableWidgetItem(product->yeasts.at(product->yeasts_row).name));
1069 ui->yeastsTable->setItem(product->yeasts_row, 1, new QTableWidgetItem(product->yeasts.at(product->yeasts_row).laboratory)); 1133 ui->yeastsTable->setItem(product->yeasts_row, 1, new QTableWidgetItem(product->yeasts.at(product->yeasts_row).laboratory));
1070 ui->yeastsTable->setItem(product->yeasts_row, 2, new QTableWidgetItem(product->yeasts.at(product->yeasts_row).product_id)); 1134 ui->yeastsTable->setItem(product->yeasts_row, 2, new QTableWidgetItem(product->yeasts.at(product->yeasts_row).product_id));
1071 1135
1296 useatEdit->addItem(tr("Tertiary")); 1360 useatEdit->addItem(tr("Tertiary"));
1297 useatEdit->addItem(tr("Bottle")); 1361 useatEdit->addItem(tr("Bottle"));
1298 useatEdit->setCurrentIndex(product->yeasts.at(product->yeasts_row).use); 1362 useatEdit->setCurrentIndex(product->yeasts.at(product->yeasts_row).use);
1299 1363
1300 yeast_instock_changed(true); 1364 yeast_instock_changed(true);
1365 yeast_load_packages(product->yeasts.at(product->yeasts_row).laboratory, product->yeasts.at(product->yeasts_row).form);
1366
1367 int index = -1;
1368 if (! product->yeasts.at(product->yeasts_row).yp_uuid.isNull() && (product->yeasts.at(product->yeasts_row).yp_uuid.length() == 36)) {
1369 query.prepare("SELECT * FROM inventory_yeastpack WHERE laboratory=:laboratory AND form=:form AND valid='1' ORDER BY laboratory,package");
1370 query.bindValue(":laboratory", product->yeasts.at(product->yeasts_row).laboratory);
1371 query.bindValue(":form", product->yeasts.at(product->yeasts_row).form);
1372 qDebug() << " search" << product->yeasts.at(product->yeasts_row).laboratory << product->yeasts.at(product->yeasts_row).form;
1373 query.exec();
1374 while (query.next()) {
1375 index++;
1376 if (query.value("uuid").toString() == product->yeasts.at(product->yeasts_row).yp_uuid)
1377 break;
1378 }
1379 qDebug() << " result" << index << (query.value("uuid").toString() == product->yeasts.at(product->yeasts_row).yp_uuid);
1380 }
1301 1381
1302 connect(yselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::yeast_select_changed); 1382 connect(yselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::yeast_select_changed);
1383 connect(ypackageEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::yeast_package_changed);
1303 connect(yamountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::yeast_amount_changed); 1384 connect(yamountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::yeast_amount_changed);
1304 connect(useatEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::yeast_useat_changed); 1385 connect(useatEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditProduct::yeast_useat_changed);
1305 connect(yinstockEdit, &QCheckBox::stateChanged, this, &EditProduct::yeast_instock_changed); 1386 connect(yinstockEdit, &QCheckBox::stateChanged, this, &EditProduct::yeast_instock_changed);
1306 connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); 1387 connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
1307 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); 1388 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
1316 } else { 1397 } else {
1317 1398
1318 } 1399 }
1319 1400
1320 disconnect(yselectEdit, nullptr, nullptr, nullptr); 1401 disconnect(yselectEdit, nullptr, nullptr, nullptr);
1402 disconnect(ypackageEdit, nullptr, nullptr, nullptr);
1321 disconnect(yamountEdit, nullptr, nullptr, nullptr); 1403 disconnect(yamountEdit, nullptr, nullptr, nullptr);
1322 disconnect(useatEdit, nullptr, nullptr, nullptr); 1404 disconnect(useatEdit, nullptr, nullptr, nullptr);
1323 disconnect(yinstockEdit, nullptr, nullptr, nullptr); 1405 disconnect(yinstockEdit, nullptr, nullptr, nullptr);
1324 disconnect(buttonBox, nullptr, nullptr, nullptr); 1406 disconnect(buttonBox, nullptr, nullptr, nullptr);
1325 1407

mercurial