#include "modifier_chariot.h"
#include "ui_modifier_chariot.h"
#include"chariot.h"
modifier_chariot::modifier_chariot(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::modifier_chariot)
{
    ui->setupUi(this);
}

modifier_chariot::~modifier_chariot()
{
    delete ui;
}


void modifier_chariot::on_pushButton_clicked()
{
    int id= ui->lineEdit->text().toInt();
    int    etat=ui->lineEdit_2->text().toInt();
     QString couleur= ui->lineEdit_3->text();
      bool test=tmpchariot.modifier(id,etat,couleur);
      if(test)
      {
          //Smtp* s = new Smtp( "hajmoussa2368@gmail.com", "Hm123456", "smtp.gmail.com", 465 );
          //s->sendMail("hajmoussa2368@gmail.com","youssef.ghedas@esprit.tn","une caisse a été modifier avec succés","Mr youssef");
          notifier = new QSystemTrayIcon(this);
          notifier->setIcon(QIcon("notification.png"));
          notifier->show();
          notifier->showMessage("Succés","l'article a été modifier avec succés",QSystemTrayIcon::Warning,10000);
          hide();


      }
      else
      {
          notifier = new QSystemTrayIcon(this);
          notifier->setIcon(QIcon("notification.png"));
          notifier->show();
          notifier->showMessage("Echec!","L'article n'a pas pu etre modifié",QSystemTrayIcon::Warning,10000);
      }

}


void modifier_chariot::on_lineEdit_textEdited( QString id)
{
    QSqlQuery q  ;
    q.prepare("select * from chariot where id='"+id+"'");
    q.addBindValue("%"+id+"%");
     if(q.exec())
     {
         while(q.next())
         {
             ui->lineEdit_3->setText(q.value(2).toString());
             ui->lineEdit_2->setText(q.value(1).toString());
         }
     }
}
