#include <QtGui>
#include <QtCore>
#include <QtSql>

#include "explication.h"

explic::explic(){
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setWindowFlags(Qt::WindowStaysOnTopHint);

connect(pushButton,SIGNAL(pressed()),this,SLOT(fonctioncreetable()));
connect(pushButton_2,SIGNAL(pressed()),qApp,SLOT(closeAllWindows()));
}

void explic::fonctioncreetable(){
QSqlDatabase db = QSqlDatabase::database();
QString requete;
requete = "CREATE TABLE Alarmes (ID_Primkey BIGINT(20) NOT NULL AUTO_INCREMENT,"
			    	  "TextAlarme LONGTEXT COLLATE utf8_unicode_ci NULL,"
			          "Alarm_Date DATETIME NULL,"
			          "Alarm_AlarmDate DATETIME NULL,"
				  "Nom VARCHAR(50) COLLATE utf8_unicode_ci NULL,"
				  "Prenom VARCHAR(50) COLLATE utf8_unicode_ci NULL,"
			          "Alarm_IDDos VARCHAR(36) NULL,"
  				  "Alarm_valid BOOL NULL,"
				  "Alarm_utilisateur VARCHAR(30) COLLATE utf8_unicode_ci NULL,"
				  "PRIMARY KEY(ID_Primkey));";
QSqlQuery query(db);
query.exec(requete);
QStringList listetables;
listetables = db.tables(QSql::Tables);
int i=0;
while(listetables[i]== "Alarmes"){
	if(i < listetables.size()){
	i++;
		}
	else{
	QMessageBox::critical(0,QObject::tr("erreur"),QObject::trUtf8("la table Alarmes n'a pas pu être installée"),QMessageBox::Ok);
		}
	}
QMessageBox msg;
msg.setText(trUtf8("La table Alarmes a été installée,\nvous devez relancer le logiciel."));
msg.addButton(tr("Fermer"),QMessageBox::DestructiveRole);
msg.exec();

emit close();
	
}
