47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
|
|
#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);
|
||
|
|
}
|