#include "rayon.h"
#include <QDebug>
rayon::rayon()
{
id=0;
etat=0;
humidite=0;
luminosite=0;
temperature=0;
}
rayon::rayon(int id,int etat,int humidite,int luminosite,int temperature)
{
  this->id=id;
  this->etat=etat;
  this->humidite=humidite;
  this->luminosite=luminosite;
  this->temperature=temperature;
}


bool rayon::ajouter()
{
QSqlQuery query;
QString res= QString::number(id);
query.prepare("INSERT INTO RAYON (ID, ETAT, HUMIDITE, LUMINOSITE, TEMPERATURE) "
                    "VALUES (:id, :etat, :humidite, :luminosite, :temperature)");
query.bindValue(":id", res);
query.bindValue(":etat", etat);
query.bindValue(":humidite", humidite);
query.bindValue(":luminosite", luminosite);
query.bindValue(":temperature", temperature);

return    query.exec();
}

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

model->setQuery("select * from RAYON");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("id"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("etat"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("humidite"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("luminosite"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("temperature"));
    return model;
}

bool rayon::supprimer(int idd)
{
QSqlQuery query;
QString res= QString::number(idd);
query.prepare("Delete from RAYON where ID = :id ");
query.bindValue(":id", res);
return    query.exec();
}


bool rayon::modifier(int id, int etat, int humidite, int luminosite, int temperature)
{
    QSqlQuery query;
    QString res= QString::number(id);
    query.prepare("update rayon set etat=:etat , humidite=:humidite,luminosite=:luminosite, temperature=:temperature where id=:id");
    query.bindValue(":id", res);
    query.bindValue(":etat", etat);
    query.bindValue(":humidite", humidite);
    query.bindValue(":luminosite", luminosite);
    query.bindValue(":temperature", temperature);
    return    query.exec();

}


QSqlQueryModel *rayon::trier()
{


    QSqlQueryModel * model=new QSqlQueryModel();

    model->setQuery("select *from RAYON  ORDER BY id");
    model->setHeaderData(0, Qt::Horizontal, QObject::tr("id"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("etat"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("humidite"));
    model->setHeaderData(3, Qt::Horizontal, QObject::tr("luminosite"));
    model->setHeaderData(4, Qt::Horizontal, QObject::tr("temperature"));

    return model;
}

bool rayon::modifier_etat(int id)
{

    QSqlQuery query;
    QString res= QString::number(id);
query.prepare("update rayon set etat=:etat where id=:id");
query.bindValue(":id",res);
    query.bindValue(":etat",1);
          query.exec();
}


/*bool articler::modifier(QString nom,int prix)
{
    QSqlQuery query;
    QString res= QString(nom);
    query.prepare("update articlerayon set prix=:prix where nom=:nom");
    query.bindValue(":nom",nom);
    query.bindValue(":prix",prix);
          query.exec();
}*/






















