bool AddPatient(Patient p) { QSqlQuery query; query.exec("select * from TPatient"); query.last(); int id=query.value(0).toInt()+1; QString sql="insert into TPatient values(" +QString::number(id)+","+"'" +p.getNom()+"' , '" +p.getPrenom() +"' , '" +p.getAdresse() +"' , '" +p.getVille()+"' , '" +QString::number(p.getCP())+"' , '" +p.getCommentaire()+"' , '" +p.getTelephone()+"' , '" +p.getDateDebut().toString("yyyy-MM-dd")+"' , '" +QString::number(p.getDuree())+"' , '" +QString::number(p.getPriorite())+"')"; bool b_test=query.exec(sql); if(!b_test) { qDebug() << query.lastError().text(); qDebug() << "Insertion de données dans TPatient impossible !\n"; return false; } query.exec("select Id from TConsult"); query.last(); int idc=query.value(0).toInt()+1; for(int n=0; n<p.vIdRessource.size(); n++,idc++){ b_test=query.exec("insert into TConsult values(" +QString::number(idc)+"," +QString::number(id)+"," +QString::number(p.vIdRessource.at(n)) +")"); if(!b_test) { qDebug() << query.lastError().text(); qDebug() << "Insertion de données dans TConsult impossible !\n"; return false; } } return true; }
bool ModifierPatient(Patient p,QString id) { QSqlQuery query; QString sql="update TPatient set Nom='"+p.getNom()+"' , " +"Prenom='"+p.getPrenom() +"' , " +"Adresse='"+p.getAdresse() +"' , " +"Ville='"+p.getVille()+"' , " +"CP='"+QString::number(p.getCP())+"' , " +"Commentaire='"+p.getCommentaire()+"' , " +"Tel='"+p.getTelephone()+"' , " +"DateConsultation='"+p.getDateDebut().toString("yyyy-MM-dd")+"' , " +"DureeConsultation="+QString::number(p.getDuree())+" , " +"Priorite="+QString::number(p.getPriorite()) +" where id="+id; bool b_test= query.exec(sql); if(!b_test) { qDebug() << query.lastError().text(); qDebug() << "Modifier de données dans TPatient impossible !\n"; return false; } query.exec("delete from TConsult where IdPatient="+id); query.exec("select Id from TConsult"); query.last(); int idc=query.value(0).toInt()+1; for(int n=0; n<p.vIdRessource.size(); n++,idc++){ b_test=query.exec("insert into TConsult values(" +QString::number(idc)+"," +id+"," +QString::number(p.vIdRessource.at(n)) +")"); if(!b_test) { qDebug() << query.lastError().text(); qDebug() << "Insertion de données dans TConsult impossible !\n"; return false; } } return true; }