WidgetModificacion
::WidgetModificacion(QWidget *parent,
int tipo_tabla
) : ui(new Ui::WidgetModificacion)
{
ui->setupUi(this);
this->tipo_tabla = tipo_tabla;
if (db.isOpen ()){
switch (tipo_tabla){
case 0:
model->setTable ("TABLE_PRODUCTOS");
break;
case 1:
model->setTable ("TABLE_CLIENTES");
break;
}
model->setSort (1, Qt::AscendingOrder);
model->select ();
while (model->canFetchMore()) model->fetchMore();
this->ui->tableView->setModel (model);
QStyledItemDelegate *display = new NumberRepresentation(this);
ui->tableView->setItemDelegateForColumn (0, display);
ui->tableView->setItemDelegateForColumn (4, display);
ui->tableView->setColumnWidth(1,250);
connect (this
->model,
SIGNAL(beforeUpdate
(int,
QSqlRecord &)),
this,
SLOT (actualizar_fecha
(int,
QSqlRecord &)));
}
else{
QMessageBox::critical(0, qApp
->tr
("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"Llamar a Agus.\n\n"
}
}
WidgetModificacion::~WidgetModificacion()
{
delete ui;
}
void WidgetModificacion::on_cerrar_clicked()
{
emit finaliza_modificacion
(QString (":ImagesMilk/Iconos/uvacopa.png"));
this->db.close ();
this->close ();
}
void WidgetModificacion
::actualizar_fecha (int row,
QSqlRecord & record
){ if (tipo_tabla == 0){
query->prepare ("UPDATE TABLE_PRODUCTOS SET fecha_modificacion = SYSDATE WHERE id_codigo_barra = :value");
query->bindValue (":value", this->ui->tableView->model ()->data (this->ui->tableView->model ()->index (row, 0)).toString ());
query->exec ();
//while (model->canFetchMore()) model->fetchMore();
//this->ui->tableView->setModel (model);
}
}
WidgetModificacion::WidgetModificacion(QWidget *parent, int tipo_tabla) :
QWidget(parent),
ui(new Ui::WidgetModificacion)
{
ui->setupUi(this);
this->tipo_tabla = tipo_tabla;
db = QSqlDatabase::database ("app_db");
if (db.isOpen ()){
model = new QSqlTableModel (this, db);
switch (tipo_tabla){
case 0:
model->setTable ("TABLE_PRODUCTOS");
break;
case 1:
model->setTable ("TABLE_CLIENTES");
break;
}
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->setSort (1, Qt::AscendingOrder);
model->select ();
while (model->canFetchMore()) model->fetchMore();
this->ui->tableView->setModel (model);
QStyledItemDelegate *display = new NumberRepresentation(this);
ui->tableView->setItemDelegateForColumn (0, display);
ui->tableView->setItemDelegateForColumn (4, display);
ui->tableView->setColumnWidth(1,250);
connect (this->model, SIGNAL(beforeUpdate (int, QSqlRecord &)), this, SLOT (actualizar_fecha (int, QSqlRecord &)));
}
else{
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"Llamar a Agus.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
}
WidgetModificacion::~WidgetModificacion()
{
delete ui;
}
void WidgetModificacion::on_cerrar_clicked()
{
emit finaliza_modificacion (QString (":ImagesMilk/Iconos/uvacopa.png"));
this->db.close ();
this->close ();
}
void WidgetModificacion::actualizar_fecha (int row, QSqlRecord & record){
if (tipo_tabla == 0){
QSqlQuery *query = new QSqlQuery (db);
query->prepare ("UPDATE TABLE_PRODUCTOS SET fecha_modificacion = SYSDATE WHERE id_codigo_barra = :value");
query->bindValue (":value", this->ui->tableView->model ()->data (this->ui->tableView->model ()->index (row, 0)).toString ());
query->exec ();
//while (model->canFetchMore()) model->fetchMore();
//this->ui->tableView->setModel (model);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks