src/EditSupplier.cpp

Mon, 14 Feb 2022 20:58:07 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 14 Feb 2022 20:58:07 +0100
changeset 10
8aa2bd9ba9e8
child 11
c9cdc15d3caf
permissions
-rw-r--r--

Added the EditSupplier popup window. It is now ready to validate the form data.

/**
 * 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);
}

mercurial