System zleceń - kopia
This commit is contained in:
46
zlecenie.cpp
Normal file
46
zlecenie.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "zlecenie.h"
|
||||
|
||||
Zlecenie::Zlecenie(int id, std::string nazwa, std::string opis, std::string przypisany)
|
||||
: id(id), nazwa(nazwa), opis(opis), przypisany(przypisany) {}
|
||||
|
||||
int Zlecenie::GetId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
std::string Zlecenie::GetNazwa() const {
|
||||
return nazwa;
|
||||
}
|
||||
|
||||
std::string Zlecenie::GetOpis() const {
|
||||
return opis;
|
||||
}
|
||||
|
||||
std::string Zlecenie::GetPrzypisany() const {
|
||||
return przypisany;
|
||||
}
|
||||
|
||||
void Zlecenie::saveToFile(std::ofstream& outFile) const {
|
||||
outFile << id << '\n';
|
||||
outFile << nazwa << '\n';
|
||||
outFile << opis << '\n';
|
||||
outFile << przypisany << '\n';
|
||||
}
|
||||
|
||||
Zlecenie Zlecenie::loadFromFile(std::ifstream& sourcefile) {
|
||||
std::string nazwa, opis, przypisany;
|
||||
int id;
|
||||
if (!(sourcefile >> id)) {
|
||||
throw std::runtime_error("Nieudany odczyt ID");
|
||||
}
|
||||
sourcefile.ignore(); // Ignoruj znak nowej linii po ID
|
||||
if (!std::getline(sourcefile, nazwa)) {
|
||||
throw std::runtime_error("Nieudany odczyt nazwy");
|
||||
}
|
||||
if (!std::getline(sourcefile, opis)) {
|
||||
throw std::runtime_error("Nieudany odczyt opisu");
|
||||
}
|
||||
if (!std::getline(sourcefile, przypisany)) {
|
||||
throw std::runtime_error("Nieudany odczyt przypisanego użytkownika");
|
||||
}
|
||||
return Zlecenie(id, nazwa, opis, przypisany);
|
||||
}
|
||||
Reference in New Issue
Block a user