blob: 87606ed45d6ab742f43a6df45b4db6b9e8b58442 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include "contraaccount.h"
#include "ui_contraaccount.h"
#include <QMessageBox>
#include <QtSql>
ContraAccount::ContraAccount(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::ContraAccount)
{
m_ui->setupUi(this);
}
ContraAccount::~ContraAccount()
{
delete m_ui;
}
void ContraAccount::on_buttonBox_accepted()
{
// some validation
if(m_ui->Name->text().isEmpty()) {
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;
}
accept();
}
int ContraAccount::save(int id)
{
QSqlQuery q;
q.prepare(id
? "UPDATE contra_accounts SET name = ?, account = ?, address = ? WHERE id = ?"
: "INSERT INTO contra_accounts (name, account, address) VALUES (?, ?, ?)"
);
q.addBindValue(m_ui->Name->text());
q.addBindValue(m_ui->Account->text());
q.addBindValue(m_ui->Address->toPlainText());
if(id)
q.addBindValue(id);
q.exec();
if(!id)
id = q.lastInsertId().toInt();
return id;
}
|