Actualiser db.cpp
This commit is contained in:
37
db.cpp
37
db.cpp
@@ -2,31 +2,48 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
bool exportData(const std::string& filename, const std::vector<Student>& students) {
|
bool exportData(const std::string& filename, const std::vector<Student>& students, const std::string& role, const std::string& login){
|
||||||
std::ofstream file(filename);
|
std::ofstream file(filename);
|
||||||
if(!file.is_open()) return false;
|
if(!file.is_open()) return false;
|
||||||
|
|
||||||
for(auto& s : students){
|
if(role == "ADMIN" || role == "PROF"){
|
||||||
|
for(const auto& s : students){
|
||||||
file << s.nom << " " << s.notes[0] << " " << s.notes[1] << " " << s.notes[2] << "\n";
|
file << s.nom << " " << s.notes[0] << " " << s.notes[1] << " " << s.notes[2] << "\n";
|
||||||
}
|
}
|
||||||
|
} else if(role == "STUDENT"){
|
||||||
|
for(const auto& s : students){
|
||||||
|
if(s.nom == login){
|
||||||
|
file << s.nom << " " << s.notes[0] << " " << s.notes[1] << " " << s.notes[2] << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool importData(const std::string& filename, std::vector<Student>& students) {
|
bool importData(const std::string& filename, std::vector<Student>& students, const std::string& role){
|
||||||
|
if(role == "STUDENT"){
|
||||||
|
std::cout << "Import interdit pour STUDENT.\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::ifstream file(filename);
|
std::ifstream file(filename);
|
||||||
if(!file.is_open()) return false;
|
if(!file.is_open()) return false;
|
||||||
|
|
||||||
std::string nom;
|
std::string nom;
|
||||||
int n1,n2,n3;
|
int n1,n2,n3;
|
||||||
int i = 0;
|
|
||||||
while(file >> nom >> n1 >> n2 >> n3 && i < students.size()){
|
while(file >> nom >> n1 >> n2 >> n3){
|
||||||
students[i].nom = nom;
|
for(auto& s : students){
|
||||||
students[i].notes[0] = n1;
|
if(s.nom == nom){
|
||||||
students[i].notes[1] = n2;
|
s.notes[0] = n1;
|
||||||
students[i].notes[2] = n3;
|
s.notes[1] = n2;
|
||||||
i++;
|
s.notes[2] = n3;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user