49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#include "db.h"
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
bool exportData(const std::string& filename, const std::vector<Student>& students, const std::string& role, const std::string& login){
|
|
std::ofstream file(filename);
|
|
if(!file.is_open()) return false;
|
|
|
|
if(role == "ADMIN" || role == "PROF"){
|
|
for(const auto& s : students){
|
|
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();
|
|
return true;
|
|
}
|
|
|
|
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);
|
|
if(!file.is_open()) return false;
|
|
|
|
std::string nom;
|
|
int n1,n2,n3;
|
|
|
|
while(file >> nom >> n1 >> n2 >> n3){
|
|
for(auto& s : students){
|
|
if(s.nom == nom){
|
|
s.notes[0] = n1;
|
|
s.notes[1] = n2;
|
|
s.notes[2] = n3;
|
|
}
|
|
}
|
|
}
|
|
|
|
file.close();
|
|
return true;
|
|
} |