From 6830f2b949d8ab5d8e0753280c16887b65680925 Mon Sep 17 00:00:00 2001 From: Mattia Tollari Date: Thu, 27 Dec 2018 09:39:58 +0100 Subject: [PATCH] Patch level : 12.0 662 Files correlati : mr Commento : Allineata 11/12 Campo/Compass, fatta un po' di pulizia nel codice --- src/mr/mr0600.cpp | 99 ++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/src/mr/mr0600.cpp b/src/mr/mr0600.cpp index 8fcaac2c6..46968ae7a 100644 --- a/src/mr/mr0600.cpp +++ b/src/mr/mr0600.cpp @@ -215,10 +215,7 @@ TString TCampass_app::esporta(const TString& DSN, const TString& usr, const TStr // File di Log ofstream logFile; - if(dongle().year_assist() > 2121) - logFile.open("temp/Campass_log.txt"); - else - logFile.open("Campass_log.txt"); + logFile.open("Campass_log.txt", ios::out); if(!logFile.is_open()) return "Errore generazione file di Log"; @@ -365,13 +362,13 @@ bool TCampass_app::test() const // Controllo la connessione if (!sqlset.connect(DSN, usr, psw)) return false; - TRelation doc(LF_DOC),rdoc(LF_RIGHEDOC), filtro(LF_RIGHEDOC); - int items; + + TRelation doc(LF_DOC),rdoc(LF_RIGHEDOC), filtro(LF_RIGHEDOC); TString msg("Esportazione tabella "); msg << "O01A"; // Creo il filtro per la chiave del cursore TRectype filtroRDoc(rdoc.curr()); filtroRDoc.put("CODNUM", "ORP1"); TCursor curRDoc(&rdoc, "", 1, &filtroRDoc, &filtroRDoc); - items = curRDoc.items(); + const int items = curRDoc.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba int i = 0, j = 0, k = 0; @@ -422,11 +419,10 @@ bool TCampass_app::a01a(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation rilprod(LF_RILPROD), rdoc(LF_RIGHEDOC), filtro(LF_RIGHEDOC); - int items; TString msg("Esportazione tabella "); msg << "A01A"; TCursor curRilprod(&rilprod, "CODNUM = \"ORC\" && QTA > 0"); - items = curRilprod.items(); + const int items = curRilprod.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba for (curRilprod = 0; curRilprod.pos() < items && !p.is_cancelled(); ++curRilprod) @@ -490,7 +486,7 @@ bool TCampass_app::a01a(const TString id) const } } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::o01a(const TString id) const @@ -501,12 +497,11 @@ bool TCampass_app::o01a(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation doc(LF_DOC),rdoc(LF_RIGHEDOC), filtro(LF_RIGHEDOC); - int items; TString msg("Esportazione tabella "); msg << "O01A"; // Creo il filtro per la chiave del cursore TRectype filtroRDoc(rdoc.curr()); filtroRDoc.put("CODNUM", "ORP1"); TCursor curRDoc(&rdoc, "", 1, &filtroRDoc, &filtroRDoc); - items = curRDoc.items(); + const int items = curRDoc.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba for (curRDoc = 0; curRDoc.pos() < items && !p.is_cancelled(); ++curRDoc) @@ -587,7 +582,7 @@ bool TCampass_app::o01a(const TString id) const } } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::o01c(const TString id) const @@ -598,12 +593,11 @@ bool TCampass_app::o01c(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation rdoc(LF_RIGHEDOC), filtro(LF_RIGHEDOC), rdist(LF_RDIST); - int items; TString msg("Esportazione tabella "); msg << "O01C"; TRectype frdoc(rdoc.curr()); frdoc.put("CODNUM", "ORP1"); TCursor crdoc(&rdoc, "", 1, &frdoc, &frdoc); - items = crdoc.items(); + const int items = crdoc.items(); TProgress_monitor p(items, msg); for(crdoc = 0; crdoc.pos() < items; ++crdoc) { @@ -655,7 +649,7 @@ bool TCampass_app::o01c(const TString id) const } } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::o01e(const TString id) const @@ -665,11 +659,10 @@ bool TCampass_app::o01e(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation doc(LF_DOC), rdoc(LF_RIGHEDOC), filtro(LF_RIGHEDOC); - int items; TString msg("Esportazione tabella "); msg << "O01E"; TRectype filtroRDoc(rdoc.curr()); filtroRDoc.put("CODNUM", "ORP1"); TCursor curRDoc(&rdoc, "", 1, &filtroRDoc, &filtroRDoc); - items = curRDoc.items(); + const int items = curRDoc.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba for (curRDoc = 0; curRDoc.pos() < items && !p.is_cancelled(); ++curRDoc) @@ -715,7 +708,7 @@ bool TCampass_app::o01e(const TString id) const } } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::o02a(const TString CodNum, const TString id) const { @@ -724,12 +717,11 @@ bool TCampass_app::o02a(const TString CodNum, const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation doc(LF_DOC), rdoc(LF_RIGHEDOC), filtro(LF_RIGHEDOC); - int items; TString msg("Esportazione tabella "); msg << "O02A - " << CodNum; TRectype filtroRDoc(rdoc.curr()); filtroRDoc.put("CODNUM", CodNum); TCursor curRDoc(&rdoc, "", 1, &filtroRDoc, &filtroRDoc); - items = curRDoc.items(); + const int items = curRDoc.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba @@ -779,7 +771,7 @@ bool TCampass_app::o02a(const TString CodNum, const TString id) const return false; } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::o02c(const TString CodNum, const TString id) const { @@ -788,12 +780,11 @@ bool TCampass_app::o02c(const TString CodNum, const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation doc(LF_DOC), rdoc(LF_RIGHEDOC), filtro(LF_RIGHEDOC); - int items; TString msg("Esportazione tabella "); msg << "O02C - " << CodNum; // Creo il filtro per la chiave del cursore //OLD: da quel che ho capito le chiavi sono pių veloci di un filtro (come č possibile?), (ora lo so lol) TRectype filtroRDoc(rdoc.curr()); filtroRDoc.put("CODNUM", "ORP1"); TCursor curRDoc(&rdoc, "", 1, &filtroRDoc, &filtroRDoc); - items = curRDoc.items(); + const int items = curRDoc.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba @@ -839,7 +830,7 @@ bool TCampass_app::o02c(const TString CodNum, const TString id) const } } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::o03a(const TString id) const { @@ -848,12 +839,11 @@ bool TCampass_app::o03a(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation clifo(LF_CLIFO); - int items; TString msg("Esportazione tabella "); msg << "O03A"; TRectype filtro(clifo.curr()); filtro.put("TIPOCF", "C"); TCursor curClifo(&clifo, "", 1, &filtro, &filtro); - items = curClifo.items(); + const int items = curClifo.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba for (curClifo = 0; curClifo.pos() < items && !p.is_cancelled(); ++curClifo) @@ -876,7 +866,7 @@ bool TCampass_app::o03a(const TString id) const return false; } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::p01a(const TString id) const { @@ -885,11 +875,9 @@ bool TCampass_app::p01a(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation anamag(LF_ANAMAG), rdist(LF_RDIST), umart(LF_UMART); - int items; TString msg("Esportazione tabella "); msg << "P01A"; TCursor curAna(&anamag), curRDist(&rdist), curUmart(&umart); - items = curAna.items(); curRDist.items();curUmart.items(); - TString artRDist, artUmart; + const int items = curAna.items(); curRDist.items();curUmart.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba for (curAna = 0; curAna.pos() < items && !p.is_cancelled(); ++curAna) @@ -914,7 +902,7 @@ bool TCampass_app::p01a(const TString id) const *****************************************************************************/ TRectype rowRDist = curRDist.curr(); // Carico il codice attuale - artRDist = rowRDist.get("CODDIST"); + const TString artRDist = rowRDist.get("CODDIST"); // Controllo se il cursore punta allo stesso articolo // Inserisco CTART if(artRDist == rowAna.get("CODART")) @@ -942,7 +930,7 @@ bool TCampass_app::p01a(const TString id) const TRectype rowUmart = curUmart.curr(); // Carico il codice attuale - artUmart = rowUmart.get("CODART"); + TString artUmart = rowUmart.get("CODART"); // Controllo se il cursore punta allo stesso articolo, // siccome a volte possono esserci righe delle distinte senza articolo mi sposto finchč non lo trovo while(artUmart != rowAna.get("CODART")) @@ -982,7 +970,7 @@ bool TCampass_app::p01a(const TString id) const return false; } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::p01b(const TString id) const @@ -992,11 +980,10 @@ bool TCampass_app::p01b(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation anamag(LF_ANAMAG), tab(LF_TAB); - int items, itemsTab; TString msg("Esportazione tabella "); msg << "P01B"; // Anamag TCursor curAna(&anamag); - items = curAna.items(); + const int items = curAna.items(); // Tab @@ -1025,6 +1012,11 @@ bool TCampass_app::p01b(const TString id) const VALUES('" << id << "','DBS','" << toEscape(rowAna.get("CODART")) << "','MISREA','" << toEscape(cparam) << "');"; } + // Inizio a eseguire quello che ho qua + if(sqlQuery != "" && sqlset.exec(sqlQuery) != 1) + return false; + + sqlQuery.cut(0); TString anamagCod(rowAna.get("CODART")), filtroCodTab; filtroCodTab << "3" << anamagCod.sub(6,12); // Tab ******************************************************************************************************************************************************* @@ -1035,7 +1027,7 @@ bool TCampass_app::p01b(const TString id) const // Cursore TCursor curTab(&tab, "", 1, &filtroTab, &filtroTab); // Items - itemsTab = curTab.items(); + const int itemsTab = curTab.items(); if (itemsTab > 0) bool yeah = true; for (curTab = 0; curTab.pos() < itemsTab && !p.is_cancelled(); ++curTab) @@ -1043,12 +1035,17 @@ bool TCampass_app::p01b(const TString id) const TRectype rowTab = curTab.curr(); sqlQuery << "INSERT INTO P01B ( IKRUNIMP, CStr, CART, CPARAM, CPARVAL ) \ VALUES('" << id << "','DBS','" << toEscape(rowAna.get("CODART")) << "','FORING','" << rowTab.get("S0") << "');"; + + // Per ogni giro lancio una exec altrimenti rischio di sfondare il limite di caratteri + if(sqlQuery != "" && sqlset.exec(sqlQuery) != 1) + return false; + + sqlQuery.cut(0); } - if(sqlQuery != "" && sqlset.exec(sqlQuery) != 1) - return false; + return sqlset.commit() != -1; } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::p02a(const TString id) const @@ -1058,12 +1055,11 @@ bool TCampass_app::p02a(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; TRelation tab(LF_TAB); - int items; TString msg("Esportazione tabella "); msg << "P02A"; TRectype filtroTab(tab.curr()); filtroTab.put("COD", "GCA"); filtroTab.put("CODTAB", "2"); TCursor curTab(&tab, "", 1, &filtroTab, &filtroTab); - items = curTab.items(); + const int items = curTab.items(); TProgress_monitor p(items, msg); // Adesso inserisco tutta la bella roba for (curTab = 0; curTab.pos() < items && !p.is_cancelled(); ++curTab) @@ -1089,7 +1085,7 @@ bool TCampass_app::p02a(const TString id) const return false; } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::p01c(const TString id) const @@ -1099,11 +1095,10 @@ bool TCampass_app::p01c(const TString id) const if (!sqlset.connect(DSN, usr, psw)) return false; - int items; TString msg("Esportazione tabella "); msg << "P01C"; TRelation anamag(LF_ANAMAG); TCursor curAna(&anamag); - items = curAna.items(); + const int items = curAna.items(); TProgress_monitor p(items, msg); for(curAna = 0; curAna.pos() < items; ++curAna) { @@ -1144,7 +1139,7 @@ bool TCampass_app::p01c(const TString id) const } } - return sqlset.commit() == -1 ? false : true; + return sqlset.commit() != -1; } bool TCampass_app::c09a() const @@ -1162,7 +1157,7 @@ bool TCampass_app::c09a() const } // Flaggo tutti i record con l'ora di inizio, sarebbe meglio farli dopo ma chissene - TString driniQuery = "UPDATE [dbo].[RUNEXP] SET [DRINI] = CURRENT_TIMESTAMP WHERE [DRINI] IS NULL AND [CFLUSSO] = 'C09';"; + const TString driniQuery = "UPDATE [dbo].[RUNEXP] SET [DRINI] = CURRENT_TIMESTAMP WHERE [DRINI] IS NULL AND [CFLUSSO] = 'C09';"; TODBC_recordset sqlDrini("", true); if(!sqlDrini.connect(DSN, usr, psw) || sqlDrini.exec(driniQuery) < 0) @@ -1187,9 +1182,9 @@ bool TCampass_app::c09a() const if (!p.add_status()) break; - TString ccic = sqlset.get("CCIC").as_string(); - TString rcic = sqlset.get("RCIC").as_string(); - int nrev = sqlset.get("NREV").as_int(); + const TString ccic = sqlset.get("CCIC").as_string(); + const TString rcic = sqlset.get("RCIC").as_string(); + const int nrev = sqlset.get("NREV").as_int(); TRectype rec(LF_TABMOD); rec.put("MOD", "PS"); rec.put("CUST", "920"); @@ -1206,13 +1201,13 @@ bool TCampass_app::c09a() const // Aggiorno DEND // Flaggo tutti i record con l'ora di fine, sarebbe meglio farli dopo ma chissene } - TString drendQuery = "UPDATE [dbo].[RUNEXP] SET [DREND] = CURRENT_TIMESTAMP WHERE [CFLUSSO] ='C09';"; + const TString drendQuery = "UPDATE [dbo].[RUNEXP] SET [DREND] = CURRENT_TIMESTAMP WHERE [CFLUSSO] ='C09';"; if(sqlDrini.exec(drendQuery) != 1) { message_box(drendQuery); return false; } - return sqlDrini.commit() == -1 ? false : true; + return sqlDrini.commit() != -1; } void TCampass_app::main_loop()