#include "parking_f.h"
#include <QSqlQuery>
parking_f::parking_f()
{
  numero=0;
  etat=0;
  id=0;
}

parking_f::parking_f(int numero,int etat,int id)
{
  this->numero=numero;
    this->etat=etat;
    this->id=id;
}
int parking_f::get_numero(){return  numero;}
int parking_f::get_etat(){return  etat;}
int parking_f::get_id(){return id;}
bool parking_f::ajouter()
{
QSqlQuery query;
QString res= QString::number(numero);
query.prepare("INSERT INTO etudiant (numero, etat) "
                    "VALUES (:numero, :etat)");
query.bindValue(":numero", res);
query.bindValue(":etat", etat);
query.bindValue(":id", id);

return    query.exec();
}

QSqlQueryModel * parking_f::afficher()
{QSqlQueryModel * model= new QSqlQueryModel();

model->setQuery("select * from parking_f");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("numero"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("etat "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("id"));
    return model;
}

bool parking_f::supprimer(int numero)
{
QSqlQuery query;
QString res= QString::number(numero);
query.prepare("Delete from parking_f where numero = :numero ");
query.bindValue(":numero",numero);
return    query.exec();
}

bool parking_f::modifier(int numero ,int etat, int id)
{
     QSqlQuery query;
     QString res= QString::number(numero);
 query.prepare("update etudiant set etat=:etat where numero=:numero ");
 query.bindValue(":numero",numero);
     query.bindValue(":etat",etat);
     query.bindValue(":id",id);
           query.exec();
}

QSqlQueryModel *parking_f::trier()
{


    QSqlQueryModel * model=new QSqlQueryModel();

    model->setQuery("select *from etudiant  ORDER BY numero");
    model->setHeaderData(0,Qt::Horizontal,QObject::tr("numero"));
    model->setHeaderData(1,Qt::Horizontal,QObject::tr("etat"));
     model->setHeaderData(2,Qt::Horizontal,QObject::tr("id"));

    return model;
}
