void CmdInterface::onDelRecord(PhoneBook & pb) { long index=-1; Record tmp; println("Input the record's index to delete(0 to cancel):"); if ((index = getNumber()) != 0) { if (tmp = pb.searchByIndex(index)) { println("The record is: "); show(tmp); println("Are you sure to delete it? (y/n)"); if (getConfirmed()) { pb.delRecord(index); cout << "Record successfully deleted.\n"; } else println("Canceled"); } else println("Index not found!"); } else println("Canceled"); }
void CmdInterface::onEditRecord(PhoneBook & pb) { long index = -1; Record tmp; println("Input the record's index to Edit(0 to cancel):"); if ((index = getNumber()) != 0) { if (tmp = pb.searchByIndex(index)) { println("The record is: "); show(tmp); edit_menu(); char cmd; do{ cmd = getCommand(); switch (cmd) { case '1': println("Input the new name:"); tmp.setName(getLine()); println("Name successfully modified."); break; case '2': println("Input the new phone:"); tmp.setPhone(getLine()); println("Phone successfully modified."); break; case '3': println("Input the new address:"); tmp.setAddr(getLine()); println("Address successfully modified."); break; case '0': println("Finish Modification."); break; default : println("Error Command!"); break; } edit_menu(); }while (cmd != '0'); pb.setRecord(index, tmp); cout << "Record #" << index << " successfully modified." << endl; } else println("Index not found!"); } else println("Canceled"); }
void CmdInterface::onSearchRecord(PhoneBook & pb) { println("(1)Search index (2)Search name (3)Search phone"); char cmd; cmd = getCommand(); switch(cmd) { case '1': long index; println("Input the index to search:"); if ((index = getNumber()) != 0) { Record tmp; if (tmp = pb.searchByIndex(index)) { show(tmp); } else println("Index not found!"); } else println("Canceled"); break; case '2': println("Input the name to search:"); show(pb.searchByName(getLine())); break; case '3': println("Input the phone to search:"); show(pb.searchByPhone(getLine())); break; case '0': println("Canceled"); break; default : println("Error command."); break; } }