-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmalumno.cpp
43 lines (39 loc) · 1.39 KB
/
frmalumno.cpp
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
#include "frmalumno.h"
#include "ui_frmalumno.h"
FrmAlumno::FrmAlumno(QWidget *parent) :
QDialog(parent),
ui(new Ui::FrmAlumno)
{
ui->setupUi(this);
model=new QSqlTableModel(this);
model->setTable("alumno");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
this->alumnoIndex=-1;
}
FrmAlumno::~FrmAlumno()
{
delete ui;
}
void FrmAlumno::on_buttonBox_accepted()
{
QSqlDatabase db=QSqlDatabase::database();
try {
QSqlQuery query;
query.prepare("INSERT INTO alumno(`nombre`,`paterno`,`materno`,`nacimiento`,`sexo`,`personal_id`,`creado_por`) "
"VALUES ( :nombre, :paterno, :materno, :nacimiento, :sexo, :personal_id, :creado_por)");
query.bindValue(":nombre",ui->txtNombre->text());
query.bindValue(":paterno",ui->txtPaterno->text());
query.bindValue(":materno",ui->txtMaterno->text());
query.bindValue(":nacimiento",ui->dtpAlumnoNacimiento->date());
query.bindValue(":sexo",ui->cmbGenero->currentIndex());
int userId = qApp->property("user").toInt();
query.bindValue(":personal_id",userId);
query.bindValue(":creado_por",userId);
if(!query.exec()){
QMessageBox::critical(0, QObject::tr("Database Error"),
query.lastError().text());
}
} catch (...) {
qDebug()<<db.lastError().text();
}
}