Exemple #1
0
Books BookManager::getBooksByAuthor(const std::string& author)
{
  tntdb::Statement sel = _conn.prepare(
      "select isbn, title, author, price"
      "  from book"
      " where author like :author");

  sel.set("author", '%' + author + '%');

  Books books;

  for (tntdb::Statement::const_iterator cur = sel.begin(); cur != sel.end(); ++cur)
  {
    tntdb::Row r = *cur;

    books.push_back(Book());
    Book& book = books.back();

    r[0].get(book._isbn);
    r[1].get(book._title);
    r[2].get(book._author);
    r[3].get(book._price);
  }

  return books;
}
Exemple #2
0
Books* SysType::reverBook(int bookId)
{
    QMap<int, Books*>::iterator it = this->m_BookMap.find(bookId);
    if (it != this->m_BookMap.end())
    {
        SAFE_DELETE(it.value());
        this->m_BookMap.remove(bookId);

        DaoBooks daoBook;
        Books book;
        book.setBookId(bookId);
        QVector<Books*> bookVec = daoBook.Select(&book, COND_ID);
        if (bookVec.size() > 0)
        {
            Books *pBook = bookVec.at(0);
            this->m_BookMap.insert(bookId,pBook);
            return pBook;
        } else {
            return NULL;
        }
    }
    else
    {
        QMessageBox::warning(0, "警告!", "没有此book。", "确定");
        return NULL;
    }
}
void BookCollection::addDescription(BookDescriptionPtr description) {
  if (description.isNull()) {
    return;
  }

  AuthorPtr author = description->author();
  const std::string &displayName = author->displayName();
  const std::string &sortKey = author->sortKey();

  std::map<AuthorPtr,Books>::iterator it = myCollection.begin();
  for (; it != myCollection.end(); ++it) {
    AuthorPtr author1 = (*it).first;
    if ((author1->sortKey() == sortKey) && (author1->displayName() == displayName)) {
      break;
    }
  }
  if (it != myCollection.end()) {
    (*it).second.push_back(description);
  } else {
    Books books;
    books.push_back(description);
    myCollection.insert(std::pair<AuthorPtr,Books>(author, books));
    myAuthors.push_back(author);
  }
}
int main(){
    string myTake = "y";
    string authorSearch, titleSearch;
    int programState;
    vector<Books> listOfBooks;
    Books exampleBooks;
    listOfBooks = exampleBooks.sampleBooks();
    int i;
    for(i = 0; i < 10; i++){
        exampleBooks.storeBook(listOfBooks[i]);
        cout << "hello world" << endl;
    }
    
    // Create a control system to start the book shop management system
    
    // cout << "Please press 1 continue and 0 to cancel";
    // give options the user can pick to run checks on the system
    
    // features include search ... specific book and update price
    cout << "Use the following controls to navigate through the system" << endl;
    cout << "1. SEARCH FOR BOOK >> 1" << endl ;
    cout << "2. UPDATE PRICE FOR SPECIFIC BOOK >> 2 " << endl;
    
    while(myTake == "y"){
        cout << "Enter (1) for search and (2) to update specific book price" << endl << endl;
        cin >> programState;
        switch(programState){
            case 1:
                cout << programState << endl;
                cout << "Please enter the author and the title for the book you want to search for..." << endl;
                cin >> authorSearch;
                cin >> titleSearch;
                authorSearch = findBook(listOfBooks, titleSearch, authorSearch);
                cout << authorSearch;
                break;
                
            case 2:
            int price;
            cout << "Enter the book you want to update and its update price";
            cin >> titleSearch;
            cin >> price;

             cout << "thank you your book has been updated";
                break;
        }
        
        
        cout << "press (y) if you want to continue." << endl << " Press any other key to exit program" << endl;
        cin >> myTake;
        
    }
    
    
    
};
string findBook(vector<Books> listBooks, string title,string author){
    Books specificBookSearched;
    string test;
    int i;
    
    for(i = 0; i < listBooks.size(); i++){
        if(listBooks[i].getAuthor().find(author) != string::npos){
            specificBookSearched = listBooks[i];
            test = specificBookSearched.getTitle() + "  " + specificBookSearched.getAuthor() + "  " + specificBookSearched.getPublisher();
            break;
        }
        else{
            test = "book not found";
        }
    }
    
    
    
    return test;
    
}
Exemple #6
0
void Market_maker::close_orders(Books booky){
    booky.close_books();
}
Exemple #7
0
bool BookUI::initTable(UniqueBook *uniqueBook)
{
    if (uniqueBook == NULL)
    {
        QMessageBox::warning(this, tr("错误"), tr("编辑功能出错,table初始化不成功!请检查!"), "确定");
        return false;
    }
    this->uniqueBook = uniqueBook;
    QStringList tableRowName;
    tableRowName.append("书名");
    tableRowName.append("图书编号");
    tableRowName.append("作者");
    tableRowName.append("出版社");
    tableRowName.append("图书类型");
    tableRowName.append("图书价格");
    tableRowName.append("入馆日期");
    tableRowName.append("图书数量");
    tableRowName.append("在馆数量");
    tableRowName.append("是否借出");
    tableRowName.append("读者编号");
    tableRowName.append("借出时间");
    tableRowName.append("应还时间");
    tableRowName.append("是否丢失");

    QStringList tableColumnName;
    tableColumnName.append("名字");
    tableColumnName.append("对应值");

    this->typeBox = new QComboBox();
    int index;
    QList<BookCateGory*> bookCateGoryList = SYSTYPE->getAllBookCateGory();

    Books *book = SYSTYPE->getBook(uniqueBook->getBookId());
    if (book == NULL)
    {
        QMessageBox::warning(this, tr("警告"), tr("编辑操作发生错误!"), "确定");

        return false;
    }
    int bookType = book->getCateGoryId();

    for (int i = 0; i < bookCateGoryList.size(); ++i)
    {
        typeBox->addItem(bookCateGoryList.at(i)->getCateGoryName(),
                            bookCateGoryList.at(i)->getCateGoryId());
        if (bookCateGoryList.at(i)->getCateGoryId() == bookType)
        {
            index = i;
        }
    }
    typeBox->setCurrentIndex(index);


    this->mainTable->setRowCount(tableRowName.size());
    this->mainTable->setColumnCount(tableColumnName.size());
    this->mainTable->setHorizontalHeaderLabels(tableColumnName);

    for (int i = 0; i < tableRowName.size(); ++i)
    {
        this->mainTable->setItem(i, 0, new QTableWidgetItem(tableRowName.at(i)));
    }

    this->mainTable->setItem(0, 1, new QTableWidgetItem(book->getBookName()));
    this->mainTable->setItem(1, 1, new QTableWidgetItem(uniqueBook->getBookCode()));
    this->mainTable->setItem(2, 1, new QTableWidgetItem(book->getAuthor()));
    this->mainTable->setItem(3, 1, new QTableWidgetItem(book->getPublishing()));

    this->mainTable->setCellWidget(4, 1, typeBox);
    this->mainTable->setItem(5, 1, new QTableWidgetItem(book->getPrice()));
    this->mainTable->setItem(6, 1, new QTableWidgetItem(book->getdateIN().toString("yyyy-MM-dd")));
    this->mainTable->setItem(7, 1, new QTableWidgetItem(QString::number(book->getQuantity())));
    this->mainTable->setItem(8, 1, new QTableWidgetItem(QString::number(book->getQuantityIn())));
    if (uniqueBook->getIsBorrow() == sysinclude::yesBorrow)
    {
        this->mainTable->setItem(9, 1, new QTableWidgetItem("是"));
        Borrow *borrow = SYSTYPE->getBorrowByUniqueBook(uniqueBook->getId());
        if (borrow == NULL)
        {
            QMessageBox::warning(this, tr("警告"), tr("编辑操作发生错误!请检查数据库数据"), "确定");
            return false;
        }
        User *user = SYSTYPE->getUser(borrow->getReaderId());
        this->mainTable->setItem(10, 1, new QTableWidgetItem(user->getUserCode()));
        this->mainTable->setItem(11, 1, new QTableWidgetItem(borrow->getDateBorrow().toString("yyyy-MM-dd")));
        this->mainTable->setItem(12, 1, new QTableWidgetItem(borrow->getDateReturn().toString("yyyy-MM-dd")));
        if (borrow->isLoss() == sysinclude::yesLoss)
            this->mainTable->setItem(13, 1, new QTableWidgetItem("是"));
        else
            this->mainTable->setItem(13, 1, new QTableWidgetItem("否"));
    }
    else
    {
        this->mainTable->setItem(9, 1, new QTableWidgetItem("否"));
        this->mainTable->setItem(10, 1, new QTableWidgetItem(""));
        this->mainTable->setItem(11, 1, new QTableWidgetItem(""));
        this->mainTable->setItem(12, 1, new QTableWidgetItem(""));
        this->mainTable->setItem(13, 1, new QTableWidgetItem(""));
    }

    return true;
}
Exemple #8
0
void BookUI::slotSaveEdit()
{
    this->confirnBtn->setDisabled(true);
    QVector<QString> bookInfoVec = this->getBookInfo();

    if (bookInfoVec.at(7).toInt() < bookInfoVec.at(8).toInt())
    {
        QMessageBox::warning(this, tr("警告"), tr("在馆数量大于图书数量,请仔细检查"), "确定");
        this->confirnBtn->setDisabled(false);
        return;
    }

    User *user = NULL;
    if (bookInfoVec.at(9) == "是")
    {
        QString userCode = bookInfoVec.at(10);
        user = SYSTYPE->getUserByCode(userCode);
        if (user == NULL)
        {
            QMessageBox::warning(this, tr("警告"), tr("不存在该读者,请仔细检查"), "确定");
            this->confirnBtn->setDisabled(false);
            return;
        }
    }

    Books *book = SYSTYPE->getBook(this->uniqueBook->getBookId());
    if (book == NULL)
    {
        this->confirnBtn->setDisabled(false);
        return;
    }
    book->setBookName(bookInfoVec.at(0));
    book->setAuthor(bookInfoVec.at(2));
    book->setPublishing(bookInfoVec.at(3));
    book->setCateGoryId(bookInfoVec.at(4).toInt());
    book->setPrice(bookInfoVec.at(5));
    book->setdateIN(QDate::fromString(bookInfoVec.at(6), "yyyy-MM-dd"));
    book->setQuantity(bookInfoVec.at(7).toInt());
    book->setQuantityIn(bookInfoVec.at(8).toInt());
    book->setQuantityOut(bookInfoVec.at(7).toInt() - bookInfoVec.at(8).toInt());

    this->uniqueBook->setBookCode(bookInfoVec.at(1));

    int isBorrow = this->uniqueBook->getIsBorrow();   
    Borrow *borrow = NULL;
    if (isBorrow == sysinclude::yesBorrow)
    {
        borrow= SYSTYPE->getBorrowByUniqueBook(this->uniqueBook->getId());
        if (borrow == NULL)
        {
            QMessageBox::warning(this, tr("警告"), tr("数据出错,无法保存,请关闭"), "确定");
            this->confirnBtn->setEnabled(true);
            return;
        }
    }

    if (bookInfoVec.at(9) == "是")
        this->uniqueBook->setIsBorrow(sysinclude::yesBorrow);
    else
        this->uniqueBook->setIsBorrow(sysinclude::noBorrow);

    DaoBorrow daoBorrow;
    DaoUniqueBook daoUniqueBook;
    DaoBooks daoBook;

    if (QSqlDatabase::database().driver()->hasFeature(QSqlDriver::Transactions))
    {
        if (GLobal_DB->transaction())
        {
            bool retBook = daoBook.Update(book);
            bool retUnique = daoUniqueBook.Update(uniqueBook);
            if (retBook == false || retUnique == false)
            {
                if(GLobal_DB->rollback())
                {
                    SYSTYPE->reverBook(book->getBookId());
                    SYSTYPE->reverUniqueBook(uniqueBook->getId());
                    QMessageBox::information(this, tr("提醒"), tr("更新失败!"), "确定");
                    this->confirnBtn->setDisabled(false);
                    return;
                }
            }

            bool borrowRet = false;

            if(isBorrow == sysinclude::yesBorrow)
            {
                if (bookInfoVec.at(9) == "是")
                {
                    borrow->setReaderId(user->getUserID());
                    borrow->setDateBorrow(QDate::fromString(bookInfoVec.at(11), "yyyy-MM-dd"));
                    borrow->setDateReturn(QDate::fromString(bookInfoVec.at(12), "yyyy-MM-dd"));
                    if (bookInfoVec.at(13) == "是")
                        borrow->setLoss(sysinclude::yesLoss);
                    else
                        borrow->setLoss(sysinclude::noLoss);
                    borrowRet = daoBorrow.Update(borrow);
                }
                else
                {
                    borrowRet = daoBorrow.Delete(borrow);
                }
                if (borrowRet == false)
                {
                    if(GLobal_DB->rollback())
                    {
                        SYSTYPE->reverBook(book->getBookId());
                        SYSTYPE->reverUniqueBook(uniqueBook->getId());
                        SYSTYPE->reverBorrow(borrow->getBorrowId());
                        QMessageBox::information(this, tr("提醒"), tr("更新失败!"), "确定");
                        this->confirnBtn->setDisabled(false);
                        return;
                    }
                }

            }

            else
            {
                if (bookInfoVec.at(9) == "是")
                {
                    Borrow *newBorrow = new Borrow();
                    newBorrow->setReaderId(user->getUserID());
                    newBorrow->setBookId(this->uniqueBook->getId());
                    newBorrow->setDateBorrow(QDate::fromString(bookInfoVec.at(11), "yyyy-MM-dd"));
                    newBorrow->setDateReturn(QDate::fromString(bookInfoVec.at(12), "yyyy-MM-dd"));
                    if (bookInfoVec.at(13) == "是")
                        newBorrow->setLoss(sysinclude::yesLoss);
                    else
                        newBorrow->setLoss(sysinclude::noLoss);
                    borrowRet = daoBorrow.Add(newBorrow);

                    BaseDao basedao;
                    QString tableName = "BORROW";
                    QString outFields = "ID";
                    int borrowId = basedao.getId(tableName, outFields);
                    newBorrow->setBorrowId(borrowId);

                    if (borrowRet == false)
                    {
                        GLobal_DB->rollback();
                        SYSTYPE->reverBook(book->getBookId());
                        SYSTYPE->reverUniqueBook(uniqueBook->getId());
                        QMessageBox::information(this, tr("提醒"), tr("更新失败!"), "确定");
                        this->confirnBtn->setEnabled(true);
                        return;
                    }
                    SYSTYPE->addBorrow(newBorrow->getBorrowId(), newBorrow);
                }
            }

            if (GLobal_DB->commit())
            {
                QMessageBox::information(this, tr("提醒"), tr("更新成功!"), "确定");
                this->confirnBtn->setEnabled(true);
            }
        }
    }
}
// BEGIN CUT HERE
int main(){
    Books test;
    test.run_test(-1);
    return 0;
}
int main()
{
    cout<<"Welcome to Agora Bookstore!"<<endl;
    cout<<endl;
    Books libros;
    libros.createBookTree(libros,"bookList.txt");
    bool quit = false;
    while (!quit)
    {
        string menu;
        cout<<"====== Agora ======"<<endl;
        cout<<"1. Find a book"<<endl;
        cout<<"2. View our inventory"<<endl;
        cout<<"3. Add a book to cart"<<endl;
        cout<<"4. Remove a book from cart"<<endl;
        cout<<"5. View cart"<<endl;
        cout<<"6. Add a book rating"<<endl;
        cout<<"7. Checkout"<<endl;
        cout<<"8. Quit"<<endl;
        getline(cin, menu);
        if(menu == "1")///FIND A BOOK
        {
            cout<<"Enter title:"<<endl;
            string found;
            getline(cin, found);
            libros.findBook(found);
        }
        else if(menu == "2")///VIEW INVENTORY
        {
            int c;
            c = libros.countBooksNodes();
            cout<<"Library contains "<<c<<" titles to choose from."<<endl;
            cout<<"============================"<<endl;
            libros.printBookInventory();
        }
        else if(menu == "3")///ADD BOOK
        {
            cout<<"Enter title:"<<endl;
            string bookname;
            getline(cin, bookname);
            libros.addBook(bookname);
        }
        else if(menu == "4") ///REMOVE BOOK
        {
            cout<<"Enter title:"<<endl;
            string deleted;
            getline(cin, deleted);
            libros.deleteCartNode(deleted);

        }
        else if(menu == "5") ///VIEW CART
        {
            libros.viewCart();
        }
        else if(menu == "6")///BOOK RATING
        {
            cout<<"Enter title:"<<endl;
            string rater;
            getline(cin, rater);
            libros.insertRating(rater);
        }
        else if(menu == "7")///CHECKOUT
        {
            libros.checkout();
        }
        else
        {
            quit = true;
        }
    }
cout<<"Goodbye!"<<endl;
return 0;
}