#include <iostream> #include <iomanip> #include <vector> #include <string> #include <fstream> #include <QCoreApplication> #include "ProdDbAccess.h" #include "BulkDbAccess.h" #include "toolbox.cpp" using namespace std; bool checkDuplicates(vector<string> serials); bool validateWithDB(vector<string> serials); int main(int argc, char* argv[]) { if ( argc > 2 ) { cerr << "ERROR: Too many parameters! Please only provide the name of a text file containing the serials needed." << endl; exit(1); } std::string fileName = ""; if ( argc == 2) fileName = string(argv[1]); else fileName = "serials.dat"; vector<string> apdSerials = loadSerialsFromFileName(fileName); if (apdSerials.size() != 30) { if (apdSerials.size() < 30) cerr << "There are less than 30 APDs in this file. This might indicate an error. Do you want to continue?" << std::endl; else cerr << "There are more than 30 APDs in this file. There can only be up to 30 APDs in one batch. Do you want to continue?" << std::endl; std::string answer; cin >> answer; if (answer != "yes" && answer != "y") return 1; } if (!checkDuplicates(apdSerials)) { cerr << "At least one APD was found at least twice. Since an APD can't be in two slots at once, this serial file is invalid and will not be checked against the database." << std::endl; return 1; } if (!validateWithDB(apdSerials)) { cerr << "At least one APD was naughty!" << endl; return 1; } cerr << "Santa will visit all of these APDs." << endl; return 0; } bool checkDuplicates(vector<string> serials) { bool result = true; for (auto outerIterator = serials.begin(); outerIterator != serials.end(); outerIterator++) { for (auto innerIterator = outerIterator; innerIterator != serials.end(); innerIterator++) { if (innerIterator != outerIterator && *innerIterator == *outerIterator) { result = false; cerr << "Serial " << *innerIterator << " appears at least twice!" << std::endl; } } } return result; } bool validateWithDB(vector<string> serials) { AbsDbAccess* _dba = suitedDbAccess(serials.size()); bool result = true; for (auto iterator = serials.begin(); iterator != serials.end(); iterator++) { if (_dba->apdAvailable(stoul(*iterator))) { cout << "Serial " << *iterator << " is good!" << endl; } else { cerr << "Serial " << *iterator << " was not found or is not available! ERROR!" << endl; result = false; } } return result; }