--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/EditSupplier.cpp Mon Feb 14 20:58:07 2022 +0100 @@ -0,0 +1,78 @@ +/** + * EditSupplier.cpp is part of bmsapp. + * + * bmsapp is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * bmsapp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "EditSupplier.h" +#include "../ui/ui_EditSupplier.h" +#include "bmsapp.h" +#include <QDebug> +#include <QtSql> + + +EditSupplier::EditSupplier(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditSupplier) +{ + QSqlQuery query; + + qDebug() << Q_FUNC_INFO << id; + ui->setupUi(this); + + if (id < 0) { + setWindowTitle( QString("BMSapp - Add new supplier")); + } else { + setWindowTitle( QString("BMSapp - Edit supplier %1").arg(id)); + query.prepare("SELECT * FROM inventory_suppliers WHERE record = :recno"); + query.bindValue(":recno", id); + query.exec(); + query.next(); + + ui->nameEdit->setText(query.value(1).toString()); + ui->addressEdit->setText(query.value(2).toString()); + ui->cityEdit->setText(query.value(3).toString()); + ui->zipEdit->setText(query.value(4).toString()); + ui->countryEdit->setText(query.value(5).toString()); + ui->webEdit->setText(query.value(6).toString()); + ui->emailEdit->setText(query.value(7).toString()); + ui->phoneEdit->setText(query.value(8).toString()); + ui->notesEdit->setText(query.value(9).toString()); + } +} + + +EditSupplier::~EditSupplier() +{ + qDebug() << Q_FUNC_INFO; + delete ui; +} + + +void EditSupplier::onOKButtonClicked() +{ + qDebug() << Q_FUNC_INFO << "Ok, check for valid data"; + + /* If there are errors in the form, show a message and do "return;" */ + + /* Save or insert the data */ + + this->close(); + this->setResult(1); +} + + +void EditSupplier::onCancelButtonClicked() +{ + qDebug() << Q_FUNC_INFO; + this->close(); + this->setResult(0); +}