src/EditRecipe.cpp

changeset 107
bb4607e23065
parent 106
2924fb71dce9
child 108
ecfcbee4a9b2
equal deleted inserted replaced
106:2924fb71dce9 107:bb4607e23065
63 ui->st_nameEdit->setText(query.value(3).toString()); 63 ui->st_nameEdit->setText(query.value(3).toString());
64 ui->st_groupEdit->setText(query.value(4).toString()); 64 ui->st_groupEdit->setText(query.value(4).toString());
65 ui->st_guideEdit->setText(query.value(5).toString()); 65 ui->st_guideEdit->setText(query.value(5).toString());
66 ui->st_catEdit->setText(query.value(6).toString()); 66 ui->st_catEdit->setText(query.value(6).toString());
67 ui->st_catnrEdit->setText(query.value(7).toString()); 67 ui->st_catnrEdit->setText(query.value(7).toString());
68 ui->st_typeEdit->setText(s_types[query.value(8).toInt()]); 68 st_type = query.value(8).toInt();
69 ui->st_typeEdit->setText(s_types[st_type]);
69 70
70 ui->nameEdit->setText(query.value(21).toString()); 71 ui->nameEdit->setText(query.value(21).toString());
71 ui->notesEdit->setPlainText(query.value(22).toString()); 72 ui->notesEdit->setPlainText(query.value(22).toString());
72 ui->typeEdit->setCurrentIndex(query.value(23).toInt()); 73 ui->typeEdit->setCurrentIndex(query.value(23).toInt());
73 ui->batch_sizeEdit->setValue(query.value(24).toDouble()); 74 ui->batch_sizeEdit->setValue(query.value(24).toDouble());
699 return; 700 return;
700 } 701 }
701 702
702 if (this->textIsChanged) { 703 if (this->textIsChanged) {
703 if (this->recno == -1) { 704 if (this->recno == -1) {
704 query.prepare("INSERT INTO recipes SET name=:name, " 705 query.prepare("INSERT INTO recipes SET locked=:locked, st_name=:st_name, st_letter=:st_letter, "
706 "st_guide=:st_guide, st_category=:st_category, st_category_number=:st_catnr, st_type=:st_type, "
707 "st_og_min=:st_og_min, st_og_max=:st_og_max, st_fg_min=:st_fg_min, st_fg_max=:st_fg_max, "
708 "st_ibu_min=:st_ibu_min, st_ibu_max=:st_ibu_max, st_color_min=:st_color_min, st_color_max=:st_color_max, "
709 "st_carb_min=:st_carb_min, st_carb_max=:st_carb_max, st_abv_min=:st_abv_min, st_abv_max=:st_abv_max, "
710 "name=:name, notes:=notes, type=:type, batch_size=:batch_size, boil_size=:boil_size, "
711 "boil_time=:boil_time, efficiency=:efficiency, "
705 "uuid = :uuid"); 712 "uuid = :uuid");
706 } else { 713 } else {
707 query.prepare("UPDATE recipes SET name=:name " 714 query.prepare("UPDATE recipes SET locked=:locked, st_name=:st_name, st_letter=:st_letter, "
715 "st_guide=:st_guide, st_category=:st_category, st_category_number=:st_catnr, st_type=:st_type, "
716 "st_og_min=:st_og_min, st_og_max=:st_og_max, st_fg_min=:st_fg_min, st_fg_max=:st_fg_max, "
717 "st_ibu_min=:st_ibu_min, st_ibu_max=:st_ibu_max, st_color_min=:st_color_min, st_color_max=:st_color_max, "
718 "st_carb_min=:st_carb_min, st_carb_max=:st_carb_max, st_abv_min=:st_abv_min, st_abv_max=:st_abv_max, "
719 "name=:name, notes:=notes, type=:type, batch_size=:batch_size, boil_size=:boil_size, "
720 "boil_time=:boil_time, efficiency=:efficiency "
708 " WHERE record = :recno"); 721 " WHERE record = :recno");
709 } 722 }
710 //query.bindValue(":name", ui->nameEdit->text()); 723 query.bindValue(":locked", ui->lockedEdit->isChecked() ? 1:0);
711 //query.bindValue(":notes", ui->notesEdit->toPlainText()); 724 query.bindValue(":st_name", ui->st_nameEdit->text());
725 query.bindValue(":st_letter", ui->st_groupEdit->text());
726 query.bindValue(":st_guide", ui->st_guideEdit->text());
727 query.bindValue(":st_category", ui->st_catEdit->text());
728 query.bindValue(":st_catnr", st_type);
729 query.bindValue(":st_og_min", QString("%1").arg(ui->est_ogShow->minval(), 4, 'f', 3, '0'));
730 query.bindValue(":st_og_max", QString("%1").arg(ui->est_ogShow->maxval(), 4, 'f', 3, '0'));
731 query.bindValue(":st_fg_min", QString("%1").arg(ui->est_fgShow->minval(), 4, 'f', 3, '0'));
732 query.bindValue(":st_fg_max", QString("%1").arg(ui->est_fgShow->maxval(), 4, 'f', 3, '0'));
733 query.bindValue(":st_ibu_min", QString("%1").arg(ui->est_ibuShow->minval(), 4, 'f', 3, '0'));
734 query.bindValue(":st_ibu_max", QString("%1").arg(ui->est_ibuShow->maxval(), 4, 'f', 3, '0'));
735 query.bindValue(":st_color_min", QString("%1").arg(ui->est_colorShow->minval(), 4, 'f', 3, '0'));
736 query.bindValue(":st_color_max", QString("%1").arg(ui->est_colorShow->maxval(), 4, 'f', 3, '0'));
737 query.bindValue(":st_carb_min", QString("%1").arg(ui->est_carbShow->minval(), 4, 'f', 3, '0'));
738 query.bindValue(":st_carb_max", QString("%1").arg(ui->est_carbShow->maxval(), 4, 'f', 3, '0'));
739 query.bindValue(":st_abv_min", QString("%1").arg(ui->est_abvShow->minval(), 4, 'f', 3, '0'));
740 query.bindValue(":st_abv_max", QString("%1").arg(ui->est_abvShow->maxval(), 4, 'f', 3, '0'));
741 query.bindValue(":name", ui->nameEdit->text());
742 query.bindValue(":notes", ui->notesEdit->toPlainText());
743 query.bindValue(":type", ui->typeEdit->currentIndex());
744 query.bindValue(":batch_size", QString("%1").arg(ui->batch_sizeEdit->value(), 2, 'f', 1, '0'));
745 query.bindValue(":boil_size", QString("%1").arg(ui->boil_sizeEdit->value(), 2, 'f', 1, '0'));
746 query.bindValue(":boil_time", QString("%1").arg(ui->boil_timeEdit->value(), 2, 'f', 1, '0'));
747 query.bindValue(":efficiency", QString("%1").arg(ui->efficiencyEdit->value(), 2, 'f', 1, '0'));
748 query.bindValue(":est_og", QString("%1").arg(ui->est_ogEdit->value(), 4, 'f', 3, '0'));
749 query.bindValue(":est_fg", QString("%1").arg(ui->est_fgEdit->value(), 4, 'f', 3, '0'));
750 query.bindValue(":est_abv", QString("%1").arg(ui->est_abvEdit->value(), 2, 'f', 1, '0'));
751 query.bindValue(":est_color", QString("%1").arg(ui->est_colorEdit->value(), 1, 'f', 0, '0'));
752 query.bindValue(":color_method", ui->color_methodEdit->currentIndex());
753 query.bindValue(":est_ibu", QString("%1").arg(ui->est_ibuEdit->value(), 1, 'f', 0, '0'));
754 query.bindValue(":ibu_method", ui->ibu_methodEdit->currentIndex());
755 query.bindValue(":est_carb", QString("%1").arg(ui->est_carbEdit->value(), 2, 'f', 1, '0'));
756
712 if (this->recno == -1) { 757 if (this->recno == -1) {
713 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); 758 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
714 } else { 759 } else {
715 query.bindValue(":recno", this->recno); 760 query.bindValue(":recno", this->recno);
716 } 761 }
717 query.exec(); 762 qDebug() << query.lastQuery();
763 // query.exec();
718 if (query.lastError().isValid()) { 764 if (query.lastError().isValid()) {
719 qDebug() << "EditRecipe" << query.lastError(); 765 qDebug() << "EditRecipe" << query.lastError();
720 QMessageBox::warning(this, tr("Database error"), 766 QMessageBox::warning(this, tr("Database error"),
721 tr("MySQL error: %1\n%2\n%3") 767 tr("MySQL error: %1\n%2\n%3")
722 .arg(query.lastError().nativeErrorCode()) 768 .arg(query.lastError().nativeErrorCode())
786 ui->st_nameEdit->setText(query.value(1).toString()); 832 ui->st_nameEdit->setText(query.value(1).toString());
787 ui->st_catEdit->setText(query.value(2).toString()); 833 ui->st_catEdit->setText(query.value(2).toString());
788 ui->st_catnrEdit->setText(query.value(3).toString()); 834 ui->st_catnrEdit->setText(query.value(3).toString());
789 ui->st_groupEdit->setText(query.value(4).toString()); 835 ui->st_groupEdit->setText(query.value(4).toString());
790 ui->st_guideEdit->setText(query.value(5).toString()); 836 ui->st_guideEdit->setText(query.value(5).toString());
791 ui->st_typeEdit->setText(s_types[query.value(6).toInt()]); 837 st_type = query.value(6).toInt();
838 ui->st_typeEdit->setText(s_types[st_type]);
792 ui->est_ogShow->setRange(query.value(7).toDouble(), query.value(8).toDouble()); 839 ui->est_ogShow->setRange(query.value(7).toDouble(), query.value(8).toDouble());
793 ui->est_fgShow->setRange(query.value(9).toDouble(), query.value(10).toDouble()); 840 ui->est_fgShow->setRange(query.value(9).toDouble(), query.value(10).toDouble());
794 ui->est_ibuShow->setRange(query.value(11).toDouble(), query.value(12).toDouble()); 841 ui->est_ibuShow->setRange(query.value(11).toDouble(), query.value(12).toDouble());
795 ui->est_colorShow->setRange(query.value(13).toDouble(), query.value(14).toDouble()); 842 ui->est_colorShow->setRange(query.value(13).toDouble(), query.value(14).toDouble());
796 ui->est_carbShow->setRange(query.value(15).toDouble(), query.value(16).toDouble()); 843 ui->est_carbShow->setRange(query.value(15).toDouble(), query.value(16).toDouble());

mercurial