summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-09-19 17:24:47 +0200
committerYorhel <git@yorhel.nl>2009-09-19 17:24:47 +0200
commit53e433db6da39c99049984ad8cd767bbab1d8acf (patch)
tree239bc09fbdc6921a77041259b2603e468803c412
parentf98086b625473f8d2dab5369aeed87f55193e503 (diff)
Added checks for duplicate contra accounts + VACUUM on startup
-rw-r--r--contraaccount.cpp21
-rw-r--r--contraaccount.h1
-rw-r--r--geld.cpp3
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");
}