void DataConnect::borrowInsertNew(Borrower b)
{
    QSqlDatabase mydb = QSqlDatabase::addDatabase("QSQLITE");
    mydb.setDatabaseName("data.db");
    if  (mydb.open()) {
        std::cout<<"Database is open\n";
    } else {
        std::cout<<"Database is not open\n";
    }
    QString name = QString::fromStdString(b.getName());
    QString type = QString::fromStdString(b.getType());
    QString department = QString::fromStdString(b.getDepartment());
    QString mobile = QString::fromStdString(b.getMobileNumber());
    int itemBorr = b.getItemBorr();
    int itemLate = b.getItemLate();
    QString itemString = QString::fromStdString(b.getItemString());
    int id = b.getId();

    QSqlQuery comman;
    QString exc = QString("INSERT INTO borrowers (name , type, department,")
            +QString("mobileNumber, itemBorr, itemLate ,itemString, id) VALUES ")
            +QString("('")+ name +QString("','")+type+QString("','")+department
            +QString("','")+ mobile +QString("',")+ QString::number(itemBorr) +QString(",")
            +QString::number(itemLate)+QString(",'") +itemString+ QString("',")+ QString::number(id) +QString(");");
    std::cout << exc.toStdString()<< std::endl;
    if(comman.exec(exc)) {
        std::cout <<"insert success borr!\n";
    } else {
        std::cout << "insert failure borr!\n";
    }

    mydb.close();
}
Beispiel #2
0
//
// Lend
//
void Book::Lend( const Borrower& borrower )
{
    // The book is out.
    status      = Status::Out;

    // Set the due date to now + 14 days.
    dueDate     = QDate::currentDate();
    dueDate.addDays( borrowingTime );

    // This is who borrowed it.
    borrowerID = borrower.GetID();
}
Beispiel #3
0
void MCSystem::returning(QString instanceBarcode, bool late)
{
    string borrowerID = getBorrowingRecord(instanceBarcode.toStdString(),"").second;

    MCInstance *item = getInstance(instanceBarcode.toStdString());
    Borrower *borrower = getBorrower(borrowerID);

    item->setBorrowedDate("");
    item->setBorrowingDay(0);
    item->setStatus(getStatus("","LIBRARY")->getID());

    if(late)
        borrower->setLateReturnedItems(borrower->getLateReturnedItems()+1);

    dao->updateMCInstance(instanceBarcode.toStdString(),item);
    dao->updateBorrower(borrower);

    deleteBorrowingRecord(instanceBarcode.toStdString(),borrowerID);

    dao->deleteBorrowingRecord(instanceBarcode,borrowerID.c_str());

}
Beispiel #4
0
void MCSystem::borrowing(QString instanceBarcode, QString borrowerID, int borrowingDay)
{
    MCInstance *item = getInstance(instanceBarcode.toStdString());
    Borrower *borrower = getBorrower(borrowerID.toStdString());

    time_t now = time(0);
    tm *ltm = localtime(&now);
    int month = ltm->tm_mon + 1;
    int day = ltm->tm_mday;
    int year = ltm->tm_year + 1900;

    stringstream ssMonth;
    ssMonth << month;
    stringstream ssDay;
    ssDay << day;
    stringstream ssYear;
    ssYear << year;

    string date = ssMonth.str() + "/" + ssDay.str() + "/" + ssYear.str();

    item->setBorrowedDate(date);
    item->setBorrowingDay(borrowingDay);
    item->setBorrowingTime(item->getBorrowingTime()+1);
    item->setStatus(getStatus("","BORROWED")->getID());

    borrower->setBorrowedItems(borrower->getBorrowedItems()+1);

    dao->updateMCInstance(instanceBarcode.toStdString(),item);
    dao->updateBorrower(borrower);

    pair<string,string> record = make_pair(instanceBarcode.toStdString(),borrowerID.toStdString());

    borrowingRecord->push_back(record);

    dao->addBorrowingRecord(instanceBarcode,borrowerID);
}
Beispiel #5
0
void Report::reportOverdue()
{
    std::vector <Borrower *> borrowers;
    borrowers = Service::getAllBorrowers();

    // Javascript column headers array
    QString columns = "var columns = [ "
                      "{ 'sTitle': 'ID' }, "
                      "{ 'sTitle': 'Name' }, "
                      "{ 'sTitle': 'Mobile' }, "
                      "{ 'sTitle': 'Type' }, "
                      "{ 'sTitle': 'Department' }, "
                      "{ 'sTitle': 'Overdue items' }, "
                      "];";

    // Start javascript data array
    QString data = "var data = [ ";

    // Get data for the js array
    for (int i = 0; i < borrowers.size(); ++i) {
        Borrower *borrower = borrowers.at(i);

        QString overdues = Service::getOverdueTitlesBy(borrower);

        // Skip if this borrower has no overdues
        if (overdues.isEmpty()) {
            continue;
        }

        // ID, name, mobile, borrower type, department name, overdue titles
        data.append(QString("[%1, '%2', '%3', '%4', '%5', '%6']")
                    .arg(borrower->getId())
                    .arg(borrower->getName())
                    .arg(borrower->getPhone())
                    .arg(borrower->getBorrowerType()->getName())
                    .arg(borrower->getDepartment()->getName())
                    .arg(overdues)
                   );

        if (i != borrowers.size() - 1) {
            data.append(",");
        }
    }

    // Close js data array
    data.append(" ];");
    // Specify report name
    data.append(" tableName = 'Overdue'; ");
    data.append(columns);
    generateReport(data);
}
Beispiel #6
0
void Report::reportBorrowers()
{
    std::vector <Borrower *> borrowers;
    borrowers = Service::getAllBorrowers();

    // Javascript column headers array
    QString columns = "var columns = [ "
                      "{ 'sTitle': 'ID' }, "
                      "{ 'sTitle': 'Name' }, "
                      "{ 'sTitle': 'Mobile' }, "
                      "{ 'sTitle': 'Type' }, "
                      "{ 'sTitle': 'Department' }, "
                      "{ 'sTitle': 'Items Borrowed (Past)' }, "
                      "{ 'sTitle': 'Items Borrowing' }, "
                      "];";

    // Start javascript data array
    QString data = "var data = [ ";

    // Get data for the js array
    for (int i = 0; i < borrowers.size(); ++i) {
        Borrower *borrower = borrowers.at(i);

        std::vector<int> nums
            = Service::getNumbersOfItemsBorrowedBy(borrower);

        // ID, name, mobile, borrower type, department name, items borrowed, items borrowing
        data.append(QString("[%1, '%2', '%3', '%4', '%5', '%6', '%7']")
                    .arg(borrower->getId())
                    .arg(borrower->getName())
                    .arg(borrower->getPhone())
                    .arg(borrower->getBorrowerType()->getName())
                    .arg(borrower->getDepartment()->getName())
                    .arg(QString("Borrowed %1")
                         .arg(nums[0]))
                    .arg(QString("Borrowing %1")
                         .arg(nums[1]))
                   );

        if (i != borrowers.size() - 1) {
            data.append(",");
        }
    }

    // Close js data array
    data.append(" ];");
    // Specify report name
    data.append(" tableName = 'Borrower'; ");
    data.append(columns);
    generateReport(data);
}
bool DataModel::isOverDueBorrower(Borrower b)
{
    vector<int>* ite = b.getIdItemVector();
    for (int i =0 ; i< ite->size();i++) {
        Item *item = findItemById(ite->at(i));
        if (item->getDateBorr().compare("")== 0) {

        } else {

            QString q = QString::fromStdString(item->getDateBorr());
            QDate date1 = QDate::fromString(q , "d/M/yyyy");
            QDate date2 = QDate::currentDate();

            if (date1.daysTo(date2) > 7 ) {
               return true;
            }
        }
    }
    return false;
}
Beispiel #8
0
void MultimediaCollection::addBorrower(Borrower b)
{
	borrowers.push_back(b);
	try {
		sql::Driver *driver;
		sql::Connection *con;
		sql::PreparedStatement *prepareStmt;

		driver = get_driver_instance();
		con = driver->connect("tcp://127.0.0.1:3306", "root", "dhis");
		con->setSchema("test");

		prepareStmt = con->prepareStatement(
			"INSERT INTO borrower(id, name, type, department, mobile, numborrow, numreturnlate)" 
			"VALUES (?,?,?,?,?,?,?)");
		prepareStmt->setString(1, b.getId());
		prepareStmt->setString(2, b.getName());
		prepareStmt->setString(3, b.getType());
		prepareStmt->setString(4, b.getDepartment());
		prepareStmt->setString(5, b.getMobile());
		prepareStmt->setInt(6, b.getNumItemBorrow());
		prepareStmt->setInt(7, b.getNumItemLateBorrow());

		prepareStmt->execute();

		delete prepareStmt;
		delete con;

	} catch (sql::SQLException &e) {
	  cout << "# ERR: SQLException in " << __FILE__;
	  cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
	  cout << "# ERR: " << e.what();
	  cout << " (MySQL error code: " << e.getErrorCode();
	  cout << ", SQLState: " << e.getSQLState() << " )" << endl;
	}
}
Beispiel #9
0
//
// BorrowerEntry
//
BorrowerEntry::BorrowerEntry( DatabaseManager* manager, const Borrower& borrower, QWidget *parent ) : QWidget(parent), ui(new Ui::BorrowerEntry)
{
    ui->setupUi(this);

    this->manager       = manager;
    this->borrower      = borrower;

    // Set the line edits to initial values.
    ui->idLineEdit->setText( borrower.GetID() );
    ui->nameLineEdit->setText( borrower.GetName() );
    ui->addressLineEdit->setText( borrower.GetAddress() );
    ui->feeTotalLineEdit->setText( QString::number( borrower.GetFeeTotal() ) );
    ui->feeHistoryLineEdit->setText( QString::number( borrower.GetFeeHistory() ) );

    // Set up the numbers scroll area.
    ui->scrollArea->setWidget( ui->scrollAreaWidgetContents );
    ui->scrollAreaWidgetContents->setLayout( new QVBoxLayout() );
    for( const BorrowerNumber& number : borrower.GetPhoneNumbers() )
    {
        ui->scrollAreaWidgetContents->layout()->addWidget( new PhoneNumberEntry( number, manager ) );
    }
}
Beispiel #10
0
void MultimediaCollection::enterBorrower()
{
	cout << "Enter New Borrower Process\n";
	cout << "=============================\n";

	string sInput;
	Borrower borrower;

	cout << "Borrower ID: ";
	while(getline(cin, sInput)) {
		if(sInput.empty())
			cout << "Borrower id can't be empty. Re-enter: ";
		else
		{
			if(checkBorrowerId(sInput)) {
				cout << sInput << " exists! Re-enter: ";
			}
			else {
				borrower.setId(sInput);
				break;
			}
		}
	}

	cout << "Borrower Name: ";
	while(getline(cin, sInput))
	{
		if(sInput.empty())
			cout << "Name can't be empty! Re-enter: ";
		else {
			borrower.setName(sInput);
			break;
		}
	}
	

	cout << "Borrower Type: ";
	while(getline(cin, sInput))
	{
		if(sInput.empty())
			cout << "Type can't be empty! Re-enter: ";
		else {
			borrower.setType(sInput);
			break;
		}
	}

	cout << "Borrower Department: ";
	while(getline(cin, sInput))
	{
		if(sInput.empty())
			cout << "Department can't be empty! Re-enter: ";
		else {
			borrower.setDepartment(sInput);
			break;
		}
	}

	cout << "Borrower Mobile: ";
	while(getline(cin, sInput))
	{
		if(sInput.empty())
			cout << "Phone can't be empty! Re-enter: ";
		else {
			borrower.setMobile(sInput);
			break;
		}
	}
	
	borrower.setNumItemBorrow(0);
	borrower.setNumItemLateBorrow(0);
	
	addBorrower(borrower);
	
	cout << "Entering borrower completed!\n";
}
bool Borrowers_Container::addBorrower(const Borrower & borrower){
	return (borrowers.insert(pair<unsigned int, Borrower>(borrower.getId(), borrower))).second;
}