while(qry.next())
{
model->setQuery(qry);
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("ID"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Name"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Depart"));
model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("Car Reg"));
model
->setHeaderData
(4, Qt
::Horizontal,
QObject::tr("Srt Date"));
model
->setHeaderData
(5, Qt
::Horizontal,
QObject::tr("End Date"));
model
->setHeaderData
(6, Qt
::Horizontal,
QObject::tr("Contact"));
model
->setHeaderData
(7, Qt
::Horizontal,
QObject::tr("Photo"));
ui->tableView_staffLog->setModel(model);
}
connect(ui->tableView_staffLog, SIGNAL(pressed(const QModelIndex&)), this,
SLOT(on_tableView_staffLog_clicked(const QModelIndex&)));
}
void ControlPanel::on_tableView_staffLog_clicked(const QModelIndex& index)
{
int emp_id = tableModel->data(tableModel->index(index.row(),0), Qt::DisplayRole).toInt();
employeedetails = EmployeeDetails::instance(emp_id, index.row(), this);
connect( employeedetails, SIGNAL(employeeDeleted(int)), this, SLOT(deleteEmployee(int)) );
employeedetails->show();
}
while(qry.next())
{
QSqlQueryModel *model = new QSqlQueryModel(ui->tableView_staffLog);
model->setQuery(qry);
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Depart"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Car Reg"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Srt Date"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("End Date"));
model->setHeaderData(6, Qt::Horizontal, QObject::tr("Contact"));
model->setHeaderData(7, Qt::Horizontal, QObject::tr("Photo"));
ui->tableView_staffLog->setModel(model);
}
connect(ui->tableView_staffLog, SIGNAL(pressed(const QModelIndex&)), this,
SLOT(on_tableView_staffLog_clicked(const QModelIndex&)));
}
void ControlPanel::on_tableView_staffLog_clicked(const QModelIndex& index)
{
const QAbstractItemModel* tableModel = ui->tableView_staffLog->model();
int emp_id = tableModel->data(tableModel->index(index.row(),0), Qt::DisplayRole).toInt();
employeedetails = EmployeeDetails::instance(emp_id, index.row(), this);
connect( employeedetails, SIGNAL(employeeDeleted(int)), this, SLOT(deleteEmployee(int)) );
employeedetails->show();
}
To copy to clipboard, switch view to plain text mode
query.prepare("UPDATE employee SET is_hidden = '1' WHERE emp_id = (:emp_id)");
query.bindValue(":emp_id", emp_id);
success = query.exec();
if(!success)
{
qDebug() << "removeEmployee error: "
<< query.lastError();
}
else
{
if( tableRow >= 0 )
emit employeeDeleted(tableRow);
this->close();
}
query.prepare("UPDATE employee SET is_hidden = '1' WHERE emp_id = (:emp_id)");
query.bindValue(":emp_id", emp_id);
success = query.exec();
if(!success)
{
qDebug() << "removeEmployee error: "
<< query.lastError();
}
else
{
if( tableRow >= 0 )
emit employeeDeleted(tableRow);
this->close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks