コード例 #1
0
bool Windows::buildProduct(QString code){
    QString codeProduit = code.mid(code.indexOf("_")+1);//on récupére juste le code sans le tag.

    int codeInconnu = 0;

    for (int i =0; i < codeProduit.size(); i++){
        int codePos = i;
        QString codeval = codeProduit.at(i);//valeur du bit i du code
        int convert = codeval.toInt(0,36);//pour rappel on bosse en base 36.
        codeval = QString::number(convert);

        for(int p=0; p< currentProduit.getListeSection().size();p++){
            Section s = currentProduit.getListeSection().value(p);
            for(int k=0; k< s.getListeDeroul().size();k++){//listes déroulantes
                ListDeroul lD = s.getListeDeroul().value(k);
                for (int j =0; j < lD.getListCode().size();j++){
                    Code c = lD.getListCode().value(j);
                    if(c.getPos() == codePos){
                        if(c.getCodeVal() == codeval ){
                            InfoChamp i;
                            c.setActif(true);
                            i.setCode(c);

                            i.setNomChamp(lD.getName());
                            i.setValChamp(c.getChamp());


                            QList<InfoChamp> lI = s.getListInfoChamp();
                            lI.append(i);

                            s.setListeInfoChamp(lI);
                            QList<Section> lS = currentProduit.getListeSection();
                            lS.replace(p,s);
                            currentProduit.setListSection(lS);

                            codeInconnu++;

                        }

                        else if(c.getChamp() == codeval){//cas ou on les valeurs de la liste dépendent de
                            //la saisie des utilisateurs. "x"
                            InfoChamp i;

                            c.setActif(true);
                            //remplacer les "x"
                            c.setCodeVal(codeval);
                            c.setNomX(codeval);
                            for(int i = 0; i < c.getListOp().size(); i++){
                                Operation op = c.getListOp().value(i);
                                op.setQte(codeval);
                                QList<Operation> lOp = c.getListOp();
                                lOp.replace(i,op);
                                c.setListOp(lOp);
                            }
                            //

                            i.setCode(c);

                            i.setNomChamp(lD.getName());
                            i.setValChamp(c.getChamp());

                            QList<InfoChamp> lI = s.getListInfoChamp();
                            lI.append(i);

                            s.setListeInfoChamp(lI);
                            QList<Section> lS= currentProduit.getListeSection();
                            lS.replace(p,s);
                            currentProduit.setListSection(lS);

                            codeInconnu++;
                        }
                        else if(codeval == "0"){
                            codeInconnu++;
                        }
                    }
                }
            }
            for(int k=0; k< s.getOptCocher().size();k++){//listes optCocher
                OptCocher opt = s.getOptCocher().value(k);
                if(opt.getCode().getPos() == codePos){
                    if(opt.getCode().getCodeVal() == codeval){
                        InfoChamp i;
                        Code c = opt.getCode();
                        c.setActif(true);
                        i.setCode(c);

                        i.setNomChamp(c.getChamp());
                        i.setValChamp("oui");
                        QList<InfoChamp> lI = s.getListInfoChamp();
                        lI.append(i);
                        s.setListeInfoChamp(lI);
                        QList<Section> lS= currentProduit.getListeSection();
                        lS.replace(p,s);
                        currentProduit.setListSection(lS);

                        codeInconnu++;
                    }
                    else if(codeval == "0"){
                        codeInconnu++;
                    }
                }
            }

        }

        if(codeInconnu == 0){
            QMessageBox::critical(this,"Code inconnu",
                                  "Ce code est inconnu, veuillez réessayer ou re configurer le produit");
            return false;
        }
        codeInconnu = 0;
    }
    currentProduit.majRegles(0);
    return true;
}