From 53e433db6da39c99049984ad8cd767bbab1d8acf Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sat, 19 Sep 2009 17:24:47 +0200 Subject: Added checks for duplicate contra accounts + VACUUM on startup --- contraaccount.cpp | 21 ++++++++++++++++++++- contraaccount.h | 1 + geld.cpp | 3 ++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/contraaccount.cpp b/contraaccount.cpp index 86ce9b8..acd952d 100644 --- a/contraaccount.cpp +++ b/contraaccount.cpp @@ -9,6 +9,7 @@ ContraAccount::ContraAccount(QWidget *parent) : { m_ui->setupUi(this); m_ui->Name->setFocus(); + itemId = 0; } ContraAccount::~ContraAccount() @@ -20,13 +21,30 @@ void ContraAccount::on_buttonBox_accepted() { // some validation if(m_ui->Name->text().isEmpty()) { - QMessageBox::critical(this, "Form validation error", "Name field is required"); + QMessageBox::critical(this, "Form validation error", "Name field is required."); return; } if(m_ui->Account->text().isEmpty()) { QMessageBox::critical(this, "Form validation error", "You know, without an account number, a contra account isn't really an account..."); return; } + QSqlQuery q; + q.prepare("SELECT 1 FROM contra_accounts WHERE id <> ? AND lower(name) = lower(?)"); + q.addBindValue(itemId); + q.addBindValue(m_ui->Name->text()); + q.exec(); + if(q.next()) { + QMessageBox::critical(this, "Form validation error", "A contra account with that name already exists."); + return; + } + q.prepare("SELECT 1 FROM contra_accounts WHERE id <> ? AND lower(account) = lower(?)"); + q.addBindValue(itemId); + q.addBindValue(m_ui->Account->text()); + q.exec(); + if(q.next()) { + QMessageBox::critical(this, "Form validation error", "A contra account with that number already exists."); + return; + } accept(); } @@ -40,6 +58,7 @@ void ContraAccount::load(int id) m_ui->Name->setText(q.value(0).toString()); m_ui->Account->setText(q.value(1).toString()); m_ui->Address->setPlainText(q.value(2).toString()); + itemId = id; } int ContraAccount::save(int id) diff --git a/contraaccount.h b/contraaccount.h index 76d8513..17d1397 100644 --- a/contraaccount.h +++ b/contraaccount.h @@ -17,6 +17,7 @@ public: private: Ui::ContraAccount *m_ui; + int itemId; private slots: void on_buttonBox_accepted(); diff --git a/geld.cpp b/geld.cpp index 1482a5a..01f57a1 100644 --- a/geld.cpp +++ b/geld.cpp @@ -59,7 +59,7 @@ Geld::Geld(QWidget *parent) connect(ui->tableContra, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(editContra())); connect(ui->actionContraDelete, SIGNAL(triggered()), this, SLOT(deleteContra())); - ui->statusBar->showMessage(QString("Opened database file %1").arg(f), 0); + ui->statusBar->showMessage(QString("Opened database file %1").arg(f), 5000); } @@ -94,6 +94,7 @@ void Geld::initDB(QString file) "description TEXT" ")" ); + q.exec("VACCUM"); } -- cgit v1.2.3