#include "modifier_parking.h"
#include "ui_modifier_parking.h"
#include"smtp.h"
#include"parking.h"
modifier_parking::modifier_parking(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::modifier_parking)
{
    ui->setupUi(this);
}

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

void modifier_parking::on_pushButton_clicked()
{
    int id= ui->lineEdit_4->text().toInt();
    int  numero=ui->lineEdit_6->text().toInt();
     QString etat= ui->lineEdit_5->text();
      bool test=tmparking.modifier(id,numero,etat);
      if(test)
      {
          Smtp* s = new Smtp( "hajmoussa2368@gmail.com", "Hm123456", "smtp.gmail.com", 465 );
          s->sendMail("hajmoussa2368@gmail.com","youssef.ghedas@esprit.tn","un parking a été modifier avec succés","Mr skander");
          notifier = new QSystemTrayIcon(this);
          notifier->setIcon(QIcon("notification.png"));
          notifier->show();
          notifier->showMessage("Succés","le parking 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_parking::on_lineEdit_4_textEdited( QString id)
{
 QSqlQuery q  ;
 q.prepare("select * from parking where id='"+id+"'");
 q.addBindValue("%"+id+"%");
  if(q.exec())
  {
      while(q.next())
      {
          ui->lineEdit_5->setText(q.value(2).toString());
          ui->lineEdit_6->setText(q.value(1).toString());
      }
  }
}
