void MainWindow::on_FindCustomer_clicked() { if("" == ui->FindID->text()) { QMessageBox::about(0,Title,NoCustomerID); ui->FindID->setFocus(); } else { Customer customer; customer = CM.fetchCustomer(ui->FindID->text()); if(customer.getName()!="") { ui->FindName->setText(customer.getName()); ui->FindSurname->setText(customer.getSurname()); ui->FindGroupID->setText(QString("%1").arg(customer.getGroupId())); } else { QMessageBox::about(0,Title,NoCustomerID); } ui->FindName->setFocus(); } }
void TCustomer::testName () { Customer c; c.setName (tName); QVERIFY (c.getName () == tName); }
void TCustomer::testConstructor () { Customer c (tId, tName, tSurname, tGroup); QVERIFY (c.getId () == tId && c.getName () == tName && c.getSurname () == tSurname && c.getGroupId () == tGroup); }
void Store::addCustomer(const Customer & c) { customers.push_back(c); customersIdPointer[c.getId()] = customersNamePointer[c.getName()] = &(*customers.rbegin()); if (!c.getActiveStatus()) { inactiveCustomers++; } writeCustomers(); }
void Store::readCustomers() { ifstream customersFile(fileNames[0]); Customer customer; unsigned int n; customersFile >> n; customersFile.ignore(INT64_MAX, '\n'); for (size_t i = 0; i < n; i++) { customersFile >> customer; customersFile.ignore(INT64_MAX, '\n'); customers.push_back(customer); customersIdPointer[customer.getId()] = customersNamePointer[customer.getName()] = &(*customers.rbegin()); } }
MenuResult RemoveCustomer::handle() { cout << endl; Customer* customer = readCustomerId(store); cin.clear(); cin.ignore(INT64_MAX, '\n'); cout << "\nID: " << customer->getId() << "\nName: " << customer->getName() << "\nJoin date: " << customer->getJoinDate() << "\nAmount: " << fixed << setprecision(2) << customer->getTotalCost() << endl; char c; cout << "\nAre you sure you want to remove this customer?\nInsert Y for YES or anything else to cancel: "; cin >> c; cin.clear(); cin.ignore(INT64_MAX, '\n'); c = tolower(c); if (c == 'y') { store.deleteCustomer(customer); cout << "The customer has been removed.\n"; } pause(); return CONTINUE; }
/** Runs a simple test of the functionality. * The integrity of the tree is verified after a number of simple operations: * - insert * - find * - erase * - clear */ void functionality_test() { // Validate the empty list printlist("Start"); // Inserting elements (new CustomerDefault())->setName("alfa"); printlist("insert alfa"); (new CustomerDefault())->setName("beta"); printlist("insert beta"); (new CustomerDefault())->setName("alfa1"); printlist("insert alfa1"); (new CustomerDefault())->setName("gamma"); printlist("insert gamma"); (new CustomerDefault())->setName("delta"); printlist("insert delta"); (new CustomerDefault())->setName("omega"); printlist("insert omega"); // Searching for some existing names string s("delta"); logger << "Find " << s << ": " << (Customer::find(s) ? "OK" : "NOK") << endl; s = "omega"; logger << "Find " << s << ": " << (Customer::find(s) ? "OK" : "NOK") << endl; // Searching for nonexistent name s = "hamburger"; logger << "Find " << s << ": " << (Customer::find(s) ? "OK" : "NOK") << endl; printlist("searches"); // Erasing some existing elements delete Customer::find("delta"); printlist("erase delta"); delete Customer::find("gamma"); printlist("erase gamma"); // Erasing some existing elements delete Customer::find("hamburger"); printlist("erase hamburger"); // Inserting a duplicate (new CustomerDefault())->setName("alfa2"); printlist("insert alfa2"); (new CustomerDefault())->setName("alfa4"); printlist("insert alfa4"); (new CustomerDefault())->setName("alfa x"); printlist("insert alfa x"); (new CustomerDefault())->setName("alfa y"); printlist("insert alfa y"); (new CustomerDefault())->setName("alfa z"); printlist("insert alfa z"); (new CustomerDefault())->setName("delta"); printlist("insert delta"); (new CustomerDefault())->setName("phi"); printlist("insert phi"); // Inserting an already existing element Customer * k = new CustomerDefault(); k->setName("alfa2"); logger << k->getName() << endl; printlist("duplicate insert alfa2"); delete k; // Clearing the list Customer::clear(); printlist("clear"); }