Exemple #1
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;
}