void workerHandlingProductsMenu(Product *products, int *productCount) { int op; do { workerHandlingProductsMenuPrint(); readInt(&op, MENU_OPT_MIN, MENU_OPT_MAX, MENU_MSG_OPT); switch (op) { case 0: //exit break; case 1: cleanScreen(); addProduct(products, productCount); break; case 2: cleanScreen(); editProduct(products, productCount); break; case 3: cleanScreen(); removeProduct(products, productCount); break; case 4: cleanScreen(); listProducts(products, productCount); break; default: printf(MENU_MSG_OPT_INVALID); } } while (op != 0); }
bool Parser::sum(std::string::iterator& iter, double& val) { double localVal = 0; auto localIter = iter; // Try to evaluate at least one product in the sum if (product(localIter, localVal)) { double tempVal = 0; char oper; // Try to evaluate the sum of all products in the expression (linking them) try { while (iter != expr.end() && addProduct(localIter, tempVal, oper)) { if (oper == '+') localVal += tempVal; else localVal -= tempVal; } } // Rethrow any exception if there is one catch (std::exception& e) { throw e; } // If successful, move the original iter and expression's temp value to the sum's value val = localVal; iter = localIter; return true; } return false; }
int main(int argc, char** argv) { Product* myProduct1 = createProduct(20001, "Nexus 6P", 5000, 300, "Smartphone", 450, 100); Product* myProduct2 = createProduct(20002, "Xiaomi Mi 4", 3700, 350, "Smartphone", 374, 120); Product* myProduct3 = createProduct(20003, "iPad Pro", 6540, 500, "Tablet", 786, 322); Product* myProduct4 = createProduct(20004, "iPad", 6540, 500, "Tablet", 786, 322);; Product** products = malloc(sizeof(Product*)*4); products[0] = myProduct1; products[1] = myProduct2; products[2] = myProduct3; printf("\nTESTING: PaymentReceipt\n"); printf("\n->createPaymentReceipt"); PaymentReceipt* myReceipt = createPaymentReceipt(products,1,"15/06/2016",3); printPaymentReceipt(myReceipt); printf("\n->addProduct"); addProduct(myProduct4,myReceipt); printPaymentReceipt(myReceipt); return (EXIT_SUCCESS); }
void createProdList(FILE *fp,Prod **a,int *xpCount){ // fp is assumed to be pointing to the first production char buffer[MAXBUFFERSIZE]; initProdList(a); char *words[MAXPRODLEN]; for(int i=0;i<MAXPRODLEN;i++){ words[i]=(char *)malloc(sizeof(char)*MAXSYMLEN); } int wCount; int pCount=0; int dummyFlag; while(1){ readLine(fp,buffer,&dummyFlag); lineToWords(buffer,words,&wCount); if(wCount==0){ printf("\nWARNING EMPTY LINE\n"); } if(isEqual(words[0],"PRODEND")==1){ break; } addProduct(*a,pCount,words[0],&(words[1]),(wCount-1)); pCount++; } // for(int i=0;i<pCount;i++){ // printf("\nPRODUCTION_%d : ",pCount); // printProd(&((*a)[i])); // } for(int i=0;i<MAXPRODLEN;i++){ free(words[i]); } (*xpCount)=pCount; }
virtual void addProduct(const std::string &id, const std::string &productIdentifier, bool consumable) override { Product product; product.id = id; product.productIdentifier = productIdentifier; product.consumable = consumable; addProduct(product); }
ProductRegistry::AttributeMap & ProductRegistry::addRegion( const std::string & name) { AttributeMap &attribute_map = addProduct(name); attribute_map[ProductRegistry::PRODUCT_TYPE] = ProductRegistry::PRODUCT_TYPE_REGION; attribute_map[ProductRegistry::VERSION] = ProductRegistry::version(); return attribute_map; }
int addMenu(){ int price = 0; int quantity = 0; int result; char* type; char* model; char* manufacturer; int date; type = (char*) malloc (30*sizeof(char)); model = (char*) malloc (30*sizeof(char)); manufacturer = (char*) malloc (30*sizeof(char)); date = (char*) malloc (30*sizeof(char)); printf("Type: "); __fpurge(stdin); fgets(type,30,stdin); type = strtok(type,"\n"); printf("Model: "); __fpurge(stdin); fgets(model,30,stdin); model = strtok(model,"\n"); printf("Manufacturer: "); __fpurge(stdin); fgets(manufacturer,30,stdin); manufacturer = strtok(manufacturer,"\n"); printf("Price: "); result = scanf("%d",&price); if (!result) { printf("Price must be an int value! "); return 1; } printf("Date: "); result = scanf("%d",&date); if (!result) { printf("Date must be an int value! "); return 1; } printf("Quantity: "); result = scanf("%d",&quantity); if (!result) { printf("Quantity must be an int value! "); return 1; } addProduct(type,model,manufacturer,price,date,quantity); return 0; }
int CzMarket::LoadFromXoml(IzXomlResource* parent, bool load_children, CzXmlNode* node) { // Process market attributes CzString* public_key = NULL; CzString* simulate = NULL; if (EventsManager == NULL) EventsManager = new CzEventManager(); for (CzXmlNode::_AttribIterator it = node->attribs_begin(); it != node->attribs_end(); it++) { unsigned int name_hash = (*it)->getName().getHash(); if (name_hash == CzHashes::Name_Hash) setName((*it)->getValue().c_str()); else if (name_hash == CzHashes::Tag_Hash) setTag((*it)->getValue().c_str()); else if (name_hash == CzHashes::OnError_Hash) EventsManager->addEvent("OnError", (*it)->getValue().c_str(), true); else if (name_hash == CzHashes::OnUnavailable_Hash) EventsManager->addEvent("OnUnavailable", (*it)->getValue().c_str(), true); else if (name_hash == CzHashes::OnComplete_Hash) EventsManager->addEvent("OnComplete", (*it)->getValue().c_str(), true); else if (name_hash == CzHashes::OnBillingDisabled_Hash) EventsManager->addEvent("OnBillingDisabled", (*it)->getValue().c_str(), true); else if (name_hash == CzHashes::OnRefund_Hash) EventsManager->addEvent("OnRefund", (*it)->getValue().c_str(), true); else if (name_hash == CzHashes::AndroidPublicKey_Hash) public_key = &(*it)->getValue(); else if (name_hash == CzHashes::Simulate_Hash) simulate = &(*it)->getValue(); } CzScene* scene = NULL; if (parent != NULL && parent->getClassTypeHash() == CzHashes::Scene_Hash) scene = (CzScene*)parent; Init(public_key->c_str()); // Process products eCzDeviceType os = PLATFORM_SYS->getDeviceType(); for (CzXmlNode::_Iterator it2 = node->begin(); it2 != node->end(); ++it2) { bool valid = false; CzMarketProduct* product = new CzMarketProduct(); unsigned int name_hash = (*it2)->GetName().getHash(); if (name_hash == CzHashes::Product_Hash) { for (CzXmlNode::_AttribIterator it = (*it2)->attribs_begin(); it != (*it2)->attribs_end(); ++it) { unsigned int attrib_hash = (*it)->getName().getHash(); if (attrib_hash == CzHashes::Name_Hash) { // Search for the product CzMarketProduct* p = findProductByName((*it)->getValue().getHash()); if (p == NULL) { product->Name = (*it)->getValue(); valid = true; } else { CzDebug::Log(CZ_DEBUG_CHANNEL_WARNING, "Market - Product with this name already exists - ", (*it)->getValue().c_str(), DebugInfo.c_str()); valid = false; break; } } else if (attrib_hash == CzHashes::iOSId_Hash) { if (os == CzDeviceType_iPhone || os == CzDeviceType_iPad) product->ProductID = (*it)->getValue(); } else if (attrib_hash == CzHashes::AndroidId_Hash) { if (os == CzDeviceType_Android) product->ProductID = (*it)->getValue(); } else if (attrib_hash == CzHashes::Consumable_Hash) product->Consumable = (*it)->getValueAsBool(); else if (attrib_hash == CzHashes::Price_Hash) product->Price = (*it)->getValueAsFloat(); } } if (valid) { addProduct(product); product->Load(); } else delete product; } if (simulate != NULL) PLATFORM_MARKET->setSimulation(simulate->getHash()); if (scene != NULL) return scene->getResourceManager()->addResource(this) ? 1 : 0; else return CZ_GLOBAL_RESOURCES->getResourceManager()->addResource(this) ? 1 : 0; return 1; }
int SList::processBatch() { if(storeExistingBatch(1)) { string job; int error=0; int countT=(int)batchPro.size(); for(int i=0;i<countT;i++) { transID=batchPro.top().front(); batchPro.top().pop(); stringtoothers(batchPro.top().front(),numJobs); batchPro.top().pop(); for(int j=0;j<numJobs;j++) { job=batchPro.top().front(); //what job it is batchPro.top().pop(); if(!job.compare("DELETE")||!job.compare("SALE")||!job.compare("RESTOCK")) { temp=batchPro.top().front(); stringtoothers(temp,_barcode); batchPro.top().pop(); if(!job.compare("DELETE")) { int ind=searchBarcode(1,_barcode); if(ind) delProduct(ind); else error=1; } else if(!job.compare("SALE")) { stringtoothers(batchPro.top().front(),_qty); batchPro.top().pop(); int ind=searchBarcode(1,_barcode); if(ind) if(!specifySales(ind,_qty)) error=1; } else if(!job.compare("RESTOCK")) { stringtoothers(batchPro.top().front(),_qty); batchPro.top().pop(); int ind=searchBarcode(1,_barcode); if(ind) restock(ind,_qty); else error=1; } } else if(!job.compare("ADD")) { _name=batchPro.top().front(); batchPro.top().pop(); _cat=batchPro.top().front(); batchPro.top().pop(); temp=batchPro.top().front(); stringtoothers(temp,_barcode); if(!searchBarcode(1,_barcode)) { batchPro.top().pop(); stringtoothers(batchPro.top().front(),_price); batchPro.top().pop(); _man=batchPro.top().front(); batchPro.top().pop(); stringtoothers(batchPro.top().front(),_curunit); batchPro.top().pop(); Product p(_name,_cat,_man,_barcode,0,_curunit,_price); addProduct(size,p); } else error=1; } if(error) { errorLog.push(transID); errorLog.push(job); errorLog.push(temp); error=0; } } batchPro.pop(); } if(!errorLog.empty()) { writeErrorLog(); return 1; //cout<<"Some errors occured, please check log.txt file!"<<endl; // } return 2;//cout<<"Batch Processed!"<<endl; } else return 3; // cout<<"Please add some transactions!"<<endl; }
int SList::readFile(string fname,char type,int &time) //read from .csv or .txt file // return 1 when read successfully and -1 if not { ListNode *cur=head; ifstream readfile(fname); string temp; int index = size,num,start,end; if(readfile.good()) { start = clock(); getline(readfile,temp); stringtoothers(temp,num); if(type == ',') { getline(readfile,temp,'\n'); getline(readfile,temp,'\n'); } while(num>0) { num--; if(type!=',') getline(readfile,temp,'\n'); getline(readfile,_name,type); getline(readfile,_cat,type); getline(readfile,temp,type); stringtoothers(temp,_barcode); getline(readfile,temp,type); stringtoothers(temp,_price); getline(readfile,_man,type); getline(readfile,temp,type); stringtoothers(temp,_curunit); getline(readfile,temp,'\n'); stringtoothers(temp,_unitsold); if(type == ',') { _cat = _cat.substr(0,_cat.length()-1); _cat = _cat.substr(1,_cat.length()); _name = _name.substr(0,_name.length()-1); _name = _name.substr(1,_name.length()); _man = _man.substr(0,_man.length()-1); _man = _man.substr(1,_man.length()); } if(!searchBarcode(1,_barcode)) { Product p(_name,_cat,_man,_barcode,_unitsold,_curunit,_price); addProduct(index,p); } } head=MergeSort(head); while(tail->next!=NULL) tail=tail->next; end = clock(); // record ending time time = end - start; return 1; } else { readfile.close(); return -1; } }
void ShoppingList::addProduct(Product* product) { addProduct(product, 1); }
ImageReader::ImageHandle ImageReader::getImage(text::string_hash id) { if (hasProduct(id)) return getProduct(id); // Image is not in cache, load it. const std::string& url = text::get(id); INFO_OUT(TAG, "Loading image %s", url.c_str()); FILE* fp = fopen(url.c_str(), "rb"); if (fp == NULL) throw ResourceException("Cannot open file."); if ( !isPNGFile(fp) ) { fclose(fp); throw ResourceException("File is not PNG."); } png_structp pngStruct = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (!pngStruct) { fclose(fp); throw ResourceException("[LIBPNG] Error creating read struct."); } png_infop pngInfo = png_create_info_struct(pngStruct); if (!pngInfo) { png_destroy_read_struct(&pngStruct, nullptr, nullptr); fclose(fp); throw ResourceException("[LIBPNG] Error creating info struct."); } if ( setjmp(png_jmpbuf(pngStruct)) ) { png_destroy_read_struct(&pngStruct, &pngInfo, nullptr); fclose(fp); throw ResourceException("Error while reading file."); } png_init_io(pngStruct, fp); png_set_sig_bytes(pngStruct, pngHeaderCheckSize); // FIXME Write directly to buffer, don't copy. png_read_png(pngStruct, pngInfo, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL); struct { png_uint_32 width; png_uint_32 height; png_byte bitsPerPixel; png_byte colorType; png_size_t rowSize; } imageData; imageData.width = png_get_image_width(pngStruct, pngInfo); imageData.height = png_get_image_height(pngStruct, pngInfo); imageData.bitsPerPixel = png_get_bit_depth(pngStruct, pngInfo); imageData.colorType = png_get_color_type(pngStruct, pngInfo); imageData.rowSize = png_get_rowbytes(pngStruct, pngInfo); // FIXME Let PixelFormat decide what format is suitable. gr::PixelFormat fmt; if (imageData.colorType == PNG_COLOR_TYPE_RGBA) fmt = gr::PixelFormat::R8G8B8A8; else fmt = gr::PixelFormat::R8G8B8; unsigned char* pixels = new unsigned char[imageData.rowSize * imageData.height]; png_bytepp rowPointers = png_get_rows(pngStruct, pngInfo); for (unsigned int i = 0; i < imageData.height; i++) memcpy(pixels + (imageData.rowSize * (imageData.height - 1 - i)), rowPointers[i], imageData.rowSize); png_destroy_read_struct(&pngStruct, &pngInfo, NULL); fclose(fp); return addProduct(id, gr::Image((unsigned int) imageData.width, (unsigned int) imageData.height, fmt, 1u, pixels)); }
/** * Methode permettant de creer l'interface d'ajout * de produit au documents * @return l'interface */ QGroupBox* NewDocumentWindow::createAddProductInterface(){ QGroupBox *groupAddProduct = new QGroupBox(trUtf8("Ajout de produit"), this); QFormLayout *layoutFormAddProduct=new QFormLayout; productName=new QComboBox(this); productName->setToolTip(trUtf8("Nom du produit, description, prix")); QList<Product> listProduct= Product::getAllProduct(); if(listProduct.size()==0){ this->setDisabled(true); } for(int i=0;i<listProduct.size();i++) productName->addItem(listProduct.at(i).name+", "+listProduct.at(i).description+", "+QVariant(listProduct.at(i).price).toString()+QString(8364)); layoutFormAddProduct->addRow(trUtf8("Produit: "),productName); productQuantity=new QSpinBox(this); productQuantity->setMinimum(1); productQuantity->setMaximum(99999); layoutFormAddProduct->addRow(trUtf8("Quantité: "),productQuantity); productReduction=new QDoubleSpinBox(this); productQuantity->setMinimum(0); productQuantity->setMaximum(99999); layoutFormAddProduct->addRow(trUtf8("Remise: "),productReduction); QGroupBox *groupTypeReduction = new QGroupBox(this); fixedValue=new QRadioButton(trUtf8("Valeur fixe"),this); fixedValue->setChecked(true); percentage=new QRadioButton(trUtf8("Pourcentage"),this); QHBoxLayout *layoutRadioButton = new QHBoxLayout; layoutRadioButton->addWidget(fixedValue); layoutRadioButton->addWidget(percentage); layoutRadioButton->addStretch(); groupTypeReduction->setLayout(layoutRadioButton); layoutFormAddProduct->addRow(trUtf8("Type de reduction"),groupTypeReduction); QHBoxLayout *layoutButtonProduct=new QHBoxLayout; buttonAddProduct=new QPushButton(trUtf8("Ajouter le produit"),this); layoutButtonProduct->addWidget(buttonAddProduct); buttonRemoveProduct=new QPushButton(trUtf8("Supprimer le produit sélectionné"),this); layoutButtonProduct->addWidget(buttonRemoveProduct); layoutButtonProduct->addStretch(); layoutFormAddProduct->addRow(trUtf8("Actions: "),layoutButtonProduct); groupAddProduct->setLayout(layoutFormAddProduct); /** ******************************** **/ /** Slots **/ /** ******************************** **/ connect(buttonAddProduct, SIGNAL(clicked()), this, SLOT(addProduct())); connect(buttonRemoveProduct, SIGNAL(clicked()), this, SLOT(removeProduct())); return groupAddProduct; }