void AddQuoteDialog::fillQuoteBilling(bool isBilling) { if (isBilling) { setWindowTitle("Nouvelle facture " + QString::number(_quote->getNumber())+ " de " + Customer(_idCustomer).getCompany()); } else { setWindowTitle("Nouveau devis " + QString::number(_quote->getNumber())+ " de "+ Customer(_idCustomer).getCompany()); } }
/*! * * @param username * @param password * @return */ QMap<QString, Customer>* Database::loginAsAdmin(QString username, QString password){ unsigned* digest = encryptPassword(password); QMap<QString, Customer>* customerMap = new QMap<QString, Customer>(); if(validateAdminLogin(username, digest)){ sqlite3_stmt* stmt; int rc = sqlite3_prepare_v2(connection, "SELECT c_name FROM ics_customers", -1, &stmt, NULL); rc = sqlite3_step(stmt); while(rc != SQLITE_DONE){ QString name = QString(static_cast<const char*>(sqlite3_column_blob(stmt, 0))); customerMap->insert(name, Customer(connection, name)); rc = sqlite3_step(stmt); } } else{ ostringstream ex; ex << "Invalid login by " << username.toStdString(); throw new InvalidLoginException(ex.str().c_str()); } return customerMap; }
void AddQuoteDialog::fillQuoteBillingCopy(bool isBilling) { if (isBilling) { setWindowTitle("Nouvelle facture " + QString::number(_quote->getNumber())+ " de " + Customer(_idCustomer).getCompany()); ui->btnDocChange->setText("Changer en devis"); ui->btnDocChange->setIcon(QIcon(":icons/img/bill_to_quote.png")); } else { setWindowTitle("Nouveau devis " + QString::number(_quote->getNumber())+ " de "+ Customer(_idCustomer).getCompany()); ui->btnDocChange->setText("Changer en facture"); ui->btnDocChange->setIcon(QIcon(":icons/img/quote_to_bill.png")); } }
/************************************************************ * ReadFile * ---------------------------------------------------------- * Returns true only if it successfully reads * Returns false if it fails to open, read or if there are no * customers in the database * ---------------------------------------------------------- * File path is set when first establishing the database *************************************************************/ bool CustomerList::ReadFile() { bool readSuccessFull; QDir dataPath = QDir::current(); QString inputData[9]; readSuccessFull = false; while(dataPath.dirName() != "Class-Project") { dataPath.cdUp(); } qDebug () << "Current dir path " << dataPath.dirName(); dataPath.cd("Database-Files"); QFile customerDataFile((dataPath.path() + "/CustomerList.txt")); // This checks if the file opens, if it does not, it will display an // error message if(customerDataFile.open(QIODevice::ReadOnly | QIODevice::Text)) { // Points Text stream to input file to read in. QTextStream inFile(&customerDataFile); while(!inFile.atEnd() && !this->isFull()) { // Data Type | TXT FILE inputData[0] = inFile.readLine(); // Customer Name | Line 1 inputData[1] = inFile.readLine(); // Address Part 1 | Line 2 inputData[2] = inFile.readLine(); // Address Part 2 | Line 3 inputData[1] = inputData[1] // Concatenate | N/A + "\n"+ inputData[2]; // addresses inputData[3] = inFile.readLine(); // Customer Interest| Line 4 inputData[4] = inFile.readLine(); // Customer Key | Line 5 inputData[5] = inFile.readLine(); // Passoword | Line 6 inputData[6] = inFile.readLine(); // Email | Line 7 inputData[7] = inFile.readLine(); // Account ID | Line 8 inputData[8] = inFile.readLine(); // Access String | Line 9 // Adds the customer to customer list this->Enqueue(Customer(inputData[0], inputData[1], inputData[3], inputData[4], inputData[5], inputData[6], inputData[7].toLong(), inputData[8])); inFile.skipWhiteSpace(); inFile.flush(); } // sets read true, flushes the Qtextstream buffer readSuccessFull = true; customerDataFile.flush(); customerDataFile.close(); } return readSuccessFull; }// **** END METHOD **** //
Customer Library::findCustomer(const std::string& customerID) { Customer foundCustomer = Customer(); for(auto& customer: customers) { if(customer.getID() == customerID) { foundCustomer = customer; } } return foundCustomer; }
void Store::readTransactions() { ifstream transactionsFile(fileNames[2]); unsigned int n; transactionsFile >> n; transactionsFile.ignore(INT64_MAX, '\n'); for (size_t i = 0; i < n; i++) { unsigned int id; Customer * customer; Date date; string productsLine, product; stringstream ss; transactionsFile >> id; transactionsFile.ignore(3); if (existsCustomer(id)) { customer = fetchCustomer(id); } else { addCustomer(Customer(id, "", Date(1, 1, 0), 0.0, false)); customer = &(*customers.rbegin()); } transactionsFile >> date; transactionsFile.ignore(3); getline(transactionsFile, productsLine); ss << productsLine; transactions.push_back(Transaction(*customer, date)); Transaction & transaction = *transactions.rbegin(); while (ss) { getline(ss, product, ','); if (existsProduct(product)) { transaction.products.push_back(fetchProduct(product)); } ss.ignore(1); } } }
/* * Loads the Customer Table */ void LoadCust(void) { long w_id; long d_id; char *name = CUSTOMER_INDEX_NAME; char *sec_name = CUSTOMER_SECONDARY_NAME; char *hist_name = HISTORY_INDEX_NAME; DB *dbp_sec; int err; if(create_db(db_env, &dbp_customer,DB_COMMON_PAGE_SIZE, 0) || open_db(dbp_customer, name, 0)) return; if(create_db(db_env, &dbp_sec, DB_COMMON_PAGE_SIZE, DB_DUP | DB_DUPSORT)) return; if((err = dbp_sec->set_bt_compare(dbp_sec, customer_secondary_comparison_func))) { db_error("DB->set_bt_compare", err); goto done; } if(open_db(dbp_sec, sec_name, 0)) return; if ((err = dbp_customer->associate(dbp_customer, 0, dbp_sec, get_customer_sec_key, 0)) != 0) { db_error("DB->associate failed: %s\n", err); goto done; } if(create_db(db_env, &dbp_history, DB_COMMON_PAGE_SIZE, 0) || open_db(dbp_history, hist_name, 0)) return; for (w_id=1L; w_id<=count_ware; w_id++) for (d_id=1L; d_id<=DIST_PER_WARE; d_id++) { if(Customer(d_id,w_id)) goto done; } done: if(dbp_customer) dbp_customer->close(dbp_customer, 0); if(dbp_sec) dbp_sec->close(dbp_sec, 0); if(dbp_history) dbp_history->close(dbp_history, 0); }
AddQuoteDialog::AddQuoteDialog(bool isBilling, int idCustomer, int id, bool copy, QWidget *parent) : QDialog(parent), _quote(0), ui(new Ui::AddQuoteDialog), _copy(copy), _idCustomer(idCustomer) { ui->setupUi(this); Gui::Utils::WindowSettings::setPositionToCenter(*this); ui->wdgContributories = new Gui::Widgets::ContributoriesWidget( QSharedPointer<Customer>(new Customer(idCustomer)), this); connect(ui->wdgContributories, SIGNAL(contributoryChanged()), this, SLOT(updateBtn())); if (id != 0) { _quote = new Billing(id); fillFields(); if (copy) { setQuoteIdNumber(0,isBilling); fillQuoteBillingCopy(isBilling); ui->dateEditQuote->setDate(QDate::currentDate()); } else { ui->btnDocChange->hide(); setWindowTitle((isBilling ? "Modifier la facture " : "Modifier le devis ")+ QString::number(getNumber())+ " de " + (Customer(idCustomer).getCompany())); } } else { _quote = new Billing(); setQuoteIdNumber(id, isBilling); ui->dateEditQuote->setDate(QDate::currentDate()); ui->btnDocChange->hide(); fillQuoteBilling(isBilling); } _quote->setIsBilling(isBilling); ui->_2->addWidget(ui->wdgContributories, 5, 0, 1, 2); emit ui->leQuoteTitle->textChanged(_quote->getTitle()); ((Gui::Widgets::ContributoriesWidget*)ui->wdgContributories)->updateUi(); }
int main() { srand ( (unsigned) time ( NULL ) ); int pid; pid = fork(); if(pid == 0){ while(1){ Producer(); printf("excute Producer\n"); sleep(1); } exit(1); } else if(pid >0){ while(1){ Customer(); printf("excute customer\n"); sleep(1); } } }
void main() { /* Print_Stmt("Calling start simulation\n"); */ StartSimulation(); /* Print_Stmt("Back from start simulation\n"); */ /* -----------------INITIALISATION -----------------------*/ /* ------------------FOOD TO BE COOKED AND FOOD READY STRUCTURE ATTRIBUTES MONITOR VARIABLES CREATION------------------- */ /* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */ /* INITIALISATION BLOCK BEGINS */ /* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */ /* --------EVERY ENTITY DOES EVERYTHING BELOW--------------------- */ /* --------------------------------------------------------------- */ /*------------------------------------------------------------ */ /* CREATE all the Locks using Syscalls */ /*------------------------------------------------------------ */ custLineLock = CreateLock("custLineLk", 10, 0); foodReadyDBLock = CreateLock("foodReadyDBLk", 13, 0); foodToBeCookedDBLock = CreateLock("fd2BCokdDBLk", 12, 0); nextTokenNumberLock = CreateLock("nextTokenNoLk", 13, 0); moneyAtRestaurantLock = CreateLock("moneyAtRestLk", 13, 0); waitToGoLock = CreateLock("waitToGoLk", 10, 0); tablesDataLock = CreateLock("tablesDataLk", 12, 0); eatInWaitingLock = CreateLock("eatInWaitingLk", 14, 0); eatInFoodWaitingLock = CreateLock("eatInFWLk", 9, 0); foodToBagLock = CreateLock("foodToBagLk", 11, 0); foodBaggedListLock = CreateLock("foodBgdListLk", 13, 0); inventoryLock = CreateLock("inventoryLk", 11, 0); managerLock = CreateLock("managerLk", 9, 0); whatToCookNextLock = CreateLock("whatToCookNextLk", 16, 0); stopSixBurgerLock = CreateLock("stop6BLk", 8, 0); stopThreeBurgerLock = CreateLock("stop3BLk", 8, 0); stopVegBurgerLock = CreateLock("stopVBLk", 8, 0); stopFriesLock = CreateLock("stopFLk", 7, 0); waiterSleepLock = CreateLock("waiterSleepLk", 13, 0); customerDataLock = CreateLock("custDataLk", 10, 0); wakeUpCookLock = CreateLock("wakeUpCookLk", 12, 0); custServedLock = CreateLock("custServedLk", 12, 0); nextWaiterIndexLock = CreateLock("nxtWtrIdxLk", 11, 0); nextCookIndexLock = CreateLock("nxtCkIdxLk", 10, 0); nextCustomerIndexLock = CreateLock("nxtCustIdxLk", 12, 0); nextOrderTakerIndexLock = CreateLock("nxtOTIdxLk", 10, 0); whatToCookFirstLock = CreateLock("what2CkFrstLk", 13, 0); cooksOnBreakCountLock = CreateLock("cksOnBrkCntLk", 13, 0); workingCookLock = CreateLock("workingCooklk", 13, 0); BagTheOrdersLock = CreateLock("BagTheOrdersLk", 14, 0); /* Create OT_COUNT number of locks, one Lock for each Ordertaker */ for(index = 1; index <= OT_COUNT; index++) orderTakerLock[index] = CreateLock("orderTakerLk", 12, index); /* --------------------------------------------------------------- */ /* Print_Stmt("after creating locks\n"); */ /*------------------------------------------------------------ */ /* Create all the Condition variables using Syscalls */ /*------------------------------------------------------------ */ custLineCV = CreateCV("custLineCV", 10, 0); tablesDataCV = CreateCV("tablesDataCV", 12, 0); eatInWaitingCV = CreateCV("eatInWaitingCV", 14, 0); eatInFoodWaitingCV = CreateCV("eatInFWtngCV", 12, 0); managerCV = CreateCV("managerCV", 9, 0); waiterSleepCV = CreateCV("waiterSleepCV", 13, 0); wakeUpCookCV = CreateCV("wakeUpCookCV", 12, 0); toGoCV = CreateCV("toGoCV", 6, 0); /* Create OT_COUNT number of Cvs, one CV for each Ordertaker */ for(index = 1; index <= OT_COUNT; index++) orderTakerCV[index] = CreateCV("orderTakerCV", 12, index); /* --------------------------------------------------------------- */ /* foodReadyData.sixBurger */ readySixBurgerMVi = CreateMV("ready6B", 7, 100, 0); /* foodReadyData.threeeBurger */ readyThreeBurgerMVi = CreateMV("ready3B", 7, 100, 0); /* foodReadyData.vegBurger */ readyVegBurgerMVi = CreateMV("ready6VB", 8, 100, 0); /* foodReadyData.fries */ readyFriesMVi = CreateMV("readyF", 6, 100, 0); /* foodToBeCookedData.sixBurger */ toBeCookedSixburgerMVi = CreateMV("toBecooked6B", 12, 0, 0); /* foodToBeCookedData.threeBurger */ toBeCookedThreeburgerMVi = CreateMV("toBecooked3B", 12, 0, 0); /* foodToBeCookedData.vegBurger */ toBeCookedVegburgerMVi = CreateMV("toBecookedVB", 12, 0, 0); /* foodToBeCookedData.fries */ toBeCookedFriesMVi = CreateMV("toBecookedF", 11, 0, 0); /*--------------------------------------------------------------------------------------------- */ /* -------- FILL IN THE CUST DATABASE WITH DEFAULT VALUES--------------------------------------- */ for(index = 1; index <= CUST_COUNT; index++) { /* custData[index].bagged */ baggedincustDBMVi[index] = CreateMV("baggedMV", 8, 0, index); /* custData[index].dineType */ dineTypeincustDBMVi[index] = CreateMV("dineTypeMV", 10, 0, index); /* custData[index].delivered */ deliveredincustDBMVi[index] = CreateMV("deliveredMV", 11, 0, index); /* baggedlist[index] */ baggedListMVi[index] = CreateMV("baggedMV", 8, 0, index); /* custData[index].myOT - initially myOT is -1 */ myOTMVi[index] = CreateMV("myOTMV", 6, -1, index); /* custData[index].ordered */ orderedincustDBMVi[index] = CreateMV("orderedMV", 9, 0, index); /* custData[index].sixBurger/threeBurger/etc. */ sixBurgerincustDBMVi[index] = CreateMV("sixBurgerMV", 11, 0, index); threeBurgerincustDBMVi[index] = CreateMV("threeBurgerMV", 13, 0, index); vegBurgerincustDBMVi[index] = CreateMV("vegBurgerMV", 11, 0, index); friesincustDBMVi[index] = CreateMV("friesMV", 7, 0, index); sodaincustDBMVi[index] = CreateMV("sodaMV", 6, 0, index); /* custData[Index].tokenNo/tableNo */ tokenNoincustDBMVi[index] = CreateMV("tokenNoMV", 9, 0, index); tableNoincustDBMVi[index] = CreateMV("tableNoMV", 9, -1, index); } /* -------------------------------------------------------------------------------- */ /* --------------------- CREATE ALL THE GLOBAL MONITOR VARIABLES ----------------- */ nextOrderTakerIndexMVi = CreateMV("nextOTIndex", 11, 1, 0); custServedMVi = CreateMV("custServed", 10, 0, 0); foodToBagMVi = CreateMV("foodToBag", 9, 0, 0); nextCustomerIndexMVi = CreateMV("nextCustIndex", 13, 1, 0); custLineLengthMVi = CreateMV("custLineLength", 14, 0, 0); managerLineLengthMVi = CreateMV("mgrLineLength", 13, 0, 0); tableAvailableMVi = CreateMV("tableAvailable", 14, 0, 0); nextTokenNumberMVi = CreateMV("nextTokenNo", 11, 0, 0); moneyAtRestaurantMVi = CreateMV("moneyAtRest", 11, 0, 0); RefillcashMVi = CreateMV("Refillcash", 10, 0, 0); broadcastedTokenNoMVi = CreateMV("bcastTokenNo", 12, 0, 0); inventoryMVi = CreateMV("inventory", 9, 100, 0); whatToCookNextMVi = CreateMV("whatToCookNext", 14, 0, 0); stopSixBurgerMVi = CreateMV("stop6B", 6, 1, 0); stopThreeBurgerMVi = CreateMV("stop3B", 6, 1, 0); stopVegBurgerMVi = CreateMV("stopVB", 6, 1, 0); stopFriesMVi = CreateMV("stopF", 5, 1, 0); /* tables[index] */ for(index = 0; index < TABLE_COUNT; index++) { tablesMVi[index] = CreateMV("tablesMV", 8, 0, index); } for(index = 1; index <= OT_COUNT; index++) { orderTakerStatusMVi[index] = CreateMV("OTstatusMV", 10, OT_BUSY, index); } /* for(index = 1; index <= 4; index++) { switch(index) { case 1: workingCooksMVi[index] = CreateMV("wkingCks6$", 9, 0, index); break; case 2: workingCooksMVi[index] = CreateMV("wkingCks3$", 9, 0, index); break; case 3: workingCooksMVi[index] = CreateMV("wkingCksV$", 9, 0, index); break; case 4: workingCooksMVi[index] = CreateMV("wkingCksF$", 9, 0, index); break; } } */ /* for(index = 1; index <= CUST_COUNT; index++) { SetMV(baggedincustDBMVi[index], 0); SetMV(deliveredincustDBMVi[index], 0); SetMV(baggedListMVi[index],0); SetMV(myOTMVi[index],0); SetMV(orderedincustDBMVi[index],0); SetMV(tokenNoincustDBMVi[index],-1); SetMV(tableNoincustDBMVi[index],-1); if (index%2 == 0) tempV = 1; else tempV = 0; SetMV(dineTypeincustDBMVi[index],tempV); SetMV(friesincustDBMVi[index],tempV); SetMV(threeBurgerincustDBMVi[index],tempV); if (index%2 == 0) tempV = 0; else tempV = 1; SetMV(vegBurgerincustDBMVi[index],tempV); SetMV(sixBurgerincustDBMVi[index],tempV); SetMV(sodaincustDBMVi[index],tempV); } */ /* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */ /* INITIALISATION BLOCK END */ /* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */ /* --------EVERY ENTITY DOES EVERYTHING ABOVE--------------------- */ /* --------------------------------------------------------------- */ /* -----------------INITIALISATION END-----------------------*/ Print_Stmt("Cust INITIALISATION END\n"); Customer(); /* ------------------------------------------------------------------------------ */ }