Beispiel #1
0
bool BooksDB::saveBookStateStack(const Book &book, const std::deque<ReadingState> &stack) {
	if (!isInitialized() || book.bookId() == 0) {
		return false;
	}
	mySaveBookStateStack->setState(book.bookId(), stack);
	return executeAsTransaction(*mySaveBookStateStack);
}
Beispiel #2
0
int main() 
{
    Book* book = xlCreateBook();
    if(book) 
    {         
        Font* font = book->addFont();
        font->setName(L"Impact");
        font->setSize(36);        

        Format* format = book->addFormat();
        format->setAlignH(ALIGNH_CENTER);
        format->setBorder(BORDERSTYLE_MEDIUMDASHDOTDOT);
        format->setBorderColor(COLOR_RED);
        format->setFont(font);
	               
        Sheet* sheet = book->addSheet(L"Custom");
        if(sheet)
        {
            sheet->writeStr(2, 1, L"Format", format);
            sheet->setCol(1, 1, 25);
        }

        if(book->save(L"format.xls")) 
        {
            ::ShellExecute(NULL, L"open", L"format.xls", NULL, NULL, SW_SHOW);
        }
    }
    
    return 0;
}
Beispiel #3
0
bool BooksDB::removeBook(const Book &book) {
	if (!isInitialized() || book.bookId() == 0) {
		return false;
	}
	myDeleteBook->setFileName(book.file().path());
	return executeAsTransaction(*myDeleteBook);
}
Beispiel #4
0
/*******************************************************
**requestBook Description:
**	if the specified Book is not in the Library, return
**		"book not found"
**	if the specified Patron is not in the Library, return
**		"patron not found"
**	if the specified Book is already requested by another
**		Patron, return "book on hold by other patron"
**	update the Book's requestedBy; if the Book is on the
**		shelf, update its location to on hold; return
**		"request successful"
*******************************************************/
string Library::requestBook(std::string pID, std::string bID)
{
	//find if Book exists//
	if (getBook(bID) == NULL)
		return "Book not found.";
	
	//find if Patron exists//
	if (getPatron(pID) == NULL)
		return "Patron not found.";

	//set Book's requestedBy and/or location//
	//based on current location//
	if (getBook(bID)->getLocation() == ON_HOLD_SHELF)
		return "Book on hold by another Patron.";
	else
	{
		//initiate local pointers if Book is not already on hold//
		Patron* pPtr = getPatron(pID);
		Book* bPtr = getBook(bID);

		//set Book's requestedBy and location//
		bPtr->setRequestedBy(pPtr);
		if (bPtr->getLocation() == ON_SHELF)
		{
			bPtr->setLocation(ON_HOLD_SHELF);
		}

		//request was successful//
		return "Request successful.";
	}
}
Beispiel #5
0
 bool operator ==(const Book& other) {
     if(this->getTitle()==other.getTitle()&&this->getBookLength()
             ==other.getBookLength()) {
         return true;
     } else
         return false;
 }
Beispiel #6
0
bool operator==(const Book& a, const Book& b)
{
	// check ISBN
	int size = 4;	// size of ISBN  n-n-n-x

	for (unsigned int i = 0; i < 4; ++i)
	{
		if (a.get_ISBN_index(i) != b.get_ISBN_index(i))
			return false;
	}

	// check author
	if (a.get_author() != b.get_author())
		return false;

	// check title
	if (a.get_title() != b.get_title())
		return false;

	// check copyright date
	if (a.get_copyright() != b.get_copyright())
		return false;

	// check book stock status
	if (a.book_status() != b.book_status())
		return false;

	// all values are the same
	return true;
}
Beispiel #7
0
std::string InventoryReport::Generate() {
    ClassificationService classificationService;

    vector<Record> records;

    vector<Holding>* holdings = Catalog::Holdings();
    for (vector<Holding>::iterator it = holdings->begin();
        it != holdings->end();
        it++)
    {
        Holding holding = *it;
        Book book = classificationService.RetrieveDetails(holding.Classification());
        if (book.Type() == Book::TYPE_BOOK)
        {
            Record record(book, holding.CurrentBranch().Name(), mIsbnApi);
            records.push_back(record);
        }
    }


    sort(records.begin(), records.end());

    stringstream buffer;
    AppendHeader(buffer);
    AppendColumnHeaders(buffer);
    for (vector<Record>::iterator it = records.begin(); it != records.end();it++)
         Append(buffer, *it);
    AppendFooter(buffer);
    return buffer.str();
}
Beispiel #8
0
// Finds successor to a book
// Finds the book, gets the book with max value for the right sub-tree
Book* Library::successor(double price, Book *book) {
    Book* tmp = findBook(price, book);
    if ( tmp ) {
        return max(tmp->getRight(tmp));
    }
    return 0;
}
Beispiel #9
0
bool BooksDB::deleteFromBookList(const Book &book) {
	if (book.bookId() == 0) {
		return false;
	}
	((DBIntValue&)*myDeleteBookList->parameter("@book_id").value()) = book.bookId();
	return myDeleteBookList->execute();
}
Beispiel #10
0
void BookWrap::Each(const FunctionCallbackInfo<Value>& args) {
    Isolate* isolate = args.GetIsolate();
    HandleScope scope(isolate);

    Book* book = ObjectWrap::Unwrap<BookWrap>(args.This())->m_book;

    if (args.Length() == 1) {
        if (args[0]->IsFunction()) {
            Local<Function> fun = Local<Function>::Cast(args[0]);
            for(uint32_t i = 0; i < book->size(); ++i) {
                Local<Object> pw = PersonWrap::New(isolate, book, i);
                Local<Value> argv[1] = { pw };
                fun->Call(Null(isolate), 1, argv);
            }
            args.GetReturnValue().SetUndefined();
            return;
        }
        else {
            isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Function expected")));
            args.GetReturnValue().SetUndefined();
            return;
        }
    }
    else {
        isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "One argument expected")));
        args.GetReturnValue().SetUndefined();
        return;
            
    }
}
Beispiel #11
0
int ExportAnyData(CString filename, vector<string> &orders)
{
	Book* book = xlCreateBook();
	if(!book)
		return 0;

	for(vector<string>::iterator it = orders.begin(); it != orders.end(); it++)
	{
		CString Filename = it->c_str();
		Filename += ".xml";
		TiXmlElement *Root = getXMLRoot(Filename);
		Sheet* sheet = book->addSheet(it->c_str());
		if(!sheet)
			return 0;
		addOneSheet(sheet, Root);

		delete Root->GetDocument();
	}

	if(book->save(_T(filename.GetBuffer(0)) )) 
	{
		return 1;
	}
	else
	{
		return 0;
	}

	book->release();
}
void FormatPlugin::detectLanguage(Book &book, ZLInputStream &stream) {
	std::string language = book.language();
	if (!language.empty()) {
		return;
	}

	PluginCollection &collection = PluginCollection::Instance();
	if (language.empty()) {
		language = collection.DefaultLanguageOption.value();
	}
	if (collection.LanguageAutoDetectOption.value() && stream.open()) {
		static const int BUFSIZE = 65536;
		char *buffer = new char[BUFSIZE];
		const size_t size = stream.read(buffer, BUFSIZE);
		stream.close();
		shared_ptr<ZLLanguageDetector::LanguageInfo> info =
			ZLLanguageDetector().findInfo(buffer, size);
		delete[] buffer;
		if (!info.isNull()) {
			if (!info->Language.empty()) {
				language = info->Language;
			}
		}
	}
	book.setLanguage(language);
}
Beispiel #13
0
//Puts a book on the hold shelf, unless it is already requested.
//If checked out, note that it should go to the hold shelf
void Library::requestBook(std::string patronID, std::string bookID)
{
    Book* book = GetBook(bookID);
    Patron* patron = GetPatron(patronID);

    if(book == NULL || patron == NULL)
    {
        if(book == NULL)
        {
            std::cout << std::endl << "No such book in holdings." << std::endl;
        }
        if(patron == NULL)
        {
            std::cout << std::endl << "No such patron in records." << std::endl;
        }
        return;
    }

    if(book->getRequestedBy() == NULL)
    {
        book->setRequestedBy(patron);
        if(book->getLocation() == ON_SHELF)
        {
            book->setLocation(ON_HOLD);
        }
    }
    else
    {
        std::cout << "This book is already requested!";
    }
}
Beispiel #14
0
bool FormatPlugin::detectLanguage(Book &book, ZLInputStream &stream, const std::string &encoding, bool force) {
	std::string language = book.language();
	if (!force && !language.empty()) {
		return true;
	}

	bool detected = false;

	PluginCollection &collection = PluginCollection::Instance();
	if (collection.isLanguageAutoDetectEnabled() && stream.open()) {
		static const int BUFSIZE = 65536;
		char *buffer = new char[BUFSIZE];
		const std::size_t size = stream.read(buffer, BUFSIZE);
		stream.close();
		shared_ptr<ZLLanguageDetector::LanguageInfo> info =
			ZLLanguageDetector().findInfoForEncoding(encoding, buffer, size, -20000);
		delete[] buffer;
		if (!info.isNull()) {
			detected = true;
			if (!info->Language.empty()) {
				language = info->Language;
			}
		}
	}
	book.setLanguage(language);

	return detected;
}
Beispiel #15
0
bool BooksDB::insertIntoBookList(const Book &book) {
	if (book.bookId() == 0) {
		return false;
	}
	((DBIntValue&)*myInsertBookList->parameter("@book_id").value()) = book.bookId();
	return myInsertBookList->execute();
}
void FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream) {
	std::string language = book.language();
	std::string encoding = book.encoding();
	if (!encoding.empty() && !language.empty()) {
		return;
	}

	PluginCollection &collection = PluginCollection::Instance();
	if (language.empty()) {
		language = collection.DefaultLanguageOption.value();
	}
	if (encoding.empty()) {
		encoding = collection.DefaultEncodingOption.value();
	}
	if (collection.LanguageAutoDetectOption.value() && stream.open()) {
		static const int BUFSIZE = 65536;
		char *buffer = new char[BUFSIZE];
		const size_t size = stream.read(buffer, BUFSIZE);
		stream.close();
		shared_ptr<ZLLanguageDetector::LanguageInfo> info =
			ZLLanguageDetector().findInfo(buffer, size);
		delete[] buffer;
		if (!info.isNull()) {
			if (!info->Language.empty()) {
				language = info->Language;
			}
			encoding = info->Encoding;
			if ((encoding == "US-ASCII") || (encoding == "ISO-8859-1")) {
				encoding = "windows-1252";
			}
		}
	}
	book.setEncoding(encoding);
	book.setLanguage(language);
}
Beispiel #17
0
int main()
{
    Book book;
    book.print();

    return 0;
}
Beispiel #18
0
void BookWrap::Lookup(const v8::FunctionCallbackInfo<v8::Value>& args) {
    Isolate* isolate = args.GetIsolate();
    HandleScope scope(isolate);
    
    if (args.Length() == 1) {
        if (args[0]->IsString()) {
            const String::Utf8Value s(args[0]->ToString());
            Book* b = ObjectWrap::Unwrap<BookWrap>(args.This())->m_book;
            try {
                Person* p = b->lookup(*s);
                Local<Object> obj = PersonWrap::NewInstance();
                PersonWrap* pw = ObjectWrap::Unwrap<PersonWrap>(obj);
                pw->m_person = p;
                args.GetReturnValue().Set(obj);
            }
            catch (...) {
                isolate->ThrowException(Exception::RangeError(String::NewFromUtf8(isolate, "Not found")));
                args.GetReturnValue().SetUndefined();
            }
        }
        else {
            isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "String expected")));
            args.GetReturnValue().SetUndefined();
        }
    }
    else {
        isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "One argument expected")));
        args.GetReturnValue().SetUndefined();
    }
}
Beispiel #19
0
bool OEBPlugin::readLanguageAndEncoding(Book &book) const {
	if (book.language().empty()) {
		shared_ptr<ZLInputStream> oebStream = new OEBTextStream(opfFile(book.file()));
		detectLanguage(book, *oebStream, book.encoding());
	}
	return true;
}
Beispiel #20
0
void Index_file::Reindex_Book(const char* file_name, const char* index_name){
	lista = new vector<Keynode>;

	ifstream data_file(file_name,ios::in|ios::binary);
	if(data_file.good()){
		data_file.seekg(sizeof(HeaderBook));

		while(!data_file.eof()){
			Book book;
			data_file.read(reinterpret_cast<char*>(&book),sizeof(Book));
			if(!book.isMarked()){
				Keynode keynode(const_cast<char *>(book.getIsbn().c_str()),data_file.tellg());
				lista->push_back(keynode);
			}
		}
		sort();
	}
	data_file.close();

	ofstream index_file(index_name,ios::out|ios::binary);
	for (int i = 0; i < lista->size(); ++i)	{
		Keynode to_add = lista->at(i);
		index_file.write((char*)&to_add,sizeof(Keynode));
	}
	index_file.flush();
	index_file.close();
}
Beispiel #21
0
	 //添加图书
	 void AddBook(Book newBook)
	 {
		 cout<<"新操作:\t录入图书信息"<<endl;
		 cout<<"准备就绪..."<<endl;

		 if(newBook.GetName()=="")
		 {
			  cout<<"图书信息输入有误"<<endl<<"操作未完成"<<endl<<endl;
			  return;
		 }
		 if(aBook.size()>0)
			 for(int i=0;i<aBook.size();i++)
				 if (aBook[i].GetName()==newBook.GetName())
				 {
					 cout<<"图书已经存在"<<endl<<"操作未完成"<<endl<<endl;
					 return ;
				 }
		
		//录入图书信息:
		
		cout<<"正在录入图书信息..."<<endl;
		aBook.push_back(newBook);
		cout<<"操作完成!"<<endl<<endl;
		newBook.DisplayInfo();
	 }
Beispiel #22
0
void DatabaseController::fillDatabase()
{
    QSqlQuery query;
    query.exec("create table books (id int primary key, "
               "title varchar(100), author varchar(100), year int)");

    QVector<Book> booksSet = Library::booksSet();
    for (int i = 0; i < booksSet.size(); i++)
    {
        if (!query.prepare("insert into books values(?, ?, ?, ?)"))
        {
            qWarning() << "Query prepare failed."
                       << _database.lastError().text();
            break;
        }

        Book book = booksSet.at(i);
        query.bindValue(0, i + 1);
        query.bindValue(1, book.title());
        query.bindValue(2, book.author());
        query.bindValue(3, book.year());

        if (!query.exec())
        {
            qWarning() << "Query exec failed."
                       << _database.lastError().text();
            break;
        }
    }
}
int main() {
	int booksCount;
	cout << "Enter number of books: ";
	cin >> booksCount;

	Book* books = new Book[booksCount];
	Book** pBook = new Book*[booksCount];

	for (int i = 0; i < booksCount; i++) {
		books[i].read();
		pBook[i] = &books[i];
	}

	double price;
	cout << "Enter price for filter:";
	cin >> price;
	cout << "\nBooks with price > " << price << "\n\n";
	for (int i = 0; i < booksCount; i++) {
		if (books[i].getPrice() >= price) {
			books[i].print();
			cout << endl;
		}
	}

	cout << "\nSorted books:\n\n";
	sort(pBook, booksCount);
	for (int i = 0; i < booksCount; i++) {
		pBook[i]->print();
		cout << endl;
	}

	char authorName[128];
	cin.get();
	cout << "Enter author name: ";
	cin.getline(authorName, 128);

	Book** filteredBookArray = new Book*[booksCount];
	int filteredBooksCount = getBooksByAuthor(authorName, filteredBookArray, books,
			booksCount);
	if (filteredBooksCount > 0) {
		cout << "Books with author " << authorName << ": ";
		printBooksArray(filteredBookArray, filteredBooksCount);
	} else {
		cout << "There is no books written by " << authorName << endl;
	}

	int code;
	cout << "Enter code for search:";
	cin >> code;

	Book* b = findByCode(code, books, booksCount);
	b->print();

	delete [] books;
	delete [] pBook;
	delete [] filteredBookArray;

	return 0;
}
    /* Add new copy to an existing book. */
    void Library::addBookCopy (BookCopy*& copy)
	{
        /* Get the book by ISBN. */
        Book* book = getBook(copy->getIsbn());

        /* Add copy for that book. */
        book->addBookCopy(copy);
    }
Beispiel #25
0
bool TxtPlugin::readLanguageAndEncoding(Book &book) const {
	shared_ptr<ZLInputStream> stream = book.file().inputStream();
	if (stream.isNull()) {
		return false;
	}
	detectEncodingAndLanguage(book, *stream);
	return !book.encoding().empty();
}
Beispiel #26
0
void Library::printBooks() {
  //Avoid signed to unsigned int error. 
  int intBookListSize = bookList.size();
	for (int i = 0; i < intBookListSize; i++) {
		Book book = bookList.at(i);
		cout << book.toString() << endl;
	}
}
Beispiel #27
0
// Finds predecessor to a book
// Finds the book, gets the book with max value for the left sub-tree
Book* Library::predecessor(double price, Book *book)
{
    Book* tmp = findBook(price, book);
    if ( tmp ) {
        return max(tmp->getLeft(tmp));
    }
    return 0;
}
Beispiel #28
0
bool BooksDB::setStackPos(const Book &book, int stackPos) {
	if (book.bookId() == 0) {
		return false;
	}
	((DBIntValue&)*mySetStackPos->parameter("@book_id").value()) = book.bookId();
	((DBIntValue&)*mySetStackPos->parameter("@stack_pos").value()) = stackPos;
	return mySetStackPos->execute();
}
Beispiel #29
0
void book_author_search()
{
	cout << "Enter the book's author:" << endl;
	string name;
	cin.clear();
	cin.ignore(numeric_limits<streamsize>::max(), '\n');
	getline(cin, name);
	Category *tmp1 = beginning;
	Book *tmp;
	vector <Book *> list;

	system("CLS");
	cout << "Searching..." << endl;

	int i = 0;

	while (tmp1 != NULL)
	{
		tmp = tmp1->getHead();

		while (tmp != NULL)
		{
			if (iequals(tmp->getAuthor(), name))
			{
				list.push_back(tmp);
				i++;
				cout << "Result no." << i << endl;
				tmp->print();
			}
			tmp = tmp->getNext();
		}
		tmp1 = tmp1->getNext();
	}

	if (i == 0)
	{
		system("CLS");
		cout << "No such ID was found." << endl;
		cout << "Please try again" << endl;
	}

	else
	{
		cout << "Which of the results do you want to manage? (enter a number)" << endl;

		stahp();
		int ch;
		cin >> ch;
		ch--;
		if (ch > 49 || list[ch] == NULL)
		{
			cout << "Invalid response. Please start again." << endl;
		}

		else
			book_menu(list[ch]);
	}
}
Beispiel #30
0
bool PluckerPlugin::readMetaInfo(Book &book) const {
	shared_ptr<ZLInputStream> stream = new PluckerTextStream(book.file());
	detectEncodingAndLanguage(book, *stream);
	if (book.encoding().empty()) {
		return false;
	}

	return true;
}