From 88a83b90728f3c33f4e0ee6bd256916095267312 Mon Sep 17 00:00:00 2001 From: augusto Date: Wed, 18 Jun 1997 15:23:13 +0000 Subject: [PATCH] Correzione bug su TArticolo::read (ricorsione infinita) Inserito un oggetto TArticolo_giacenza nel movimento Metodi update_balences non piu' const git-svn-id: svn://10.65.10.50/trunk@4709 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- mg/mglib02.cpp | 51 ++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/mg/mglib02.cpp b/mg/mglib02.cpp index 4051cb256..70e55022c 100755 --- a/mg/mglib02.cpp +++ b/mg/mglib02.cpp @@ -84,19 +84,26 @@ void TArticolo::set_body_key(TRectype & rowrec) } } -int TArticolo::read(const char * cod, word op, word lockop) -{ - if (op == _isequal && lockop == _nolock &&strcmp(cod, (const char *) _codice) == 0) +int TArticolo::read(TRectype & rec, word op, word lockop) +{ + if (op == _isequal && lockop == _nolock &&strcmp(rec.get(ANAMAG_CODART), (const char *) _codice) == 0) return NOERR; - *_codice = cod; + + *_codice = rec.get(ANAMAG_CODART); - const int err = TMultiple_rectype::read(op , lockop); + const int err = TMultiple_rectype::read(rec, op , lockop); if (err != NOERR) zero(); return err; } +int TArticolo::read(const char * cod, word op, word lockop) +{ + put(ANAMAG_CODART,cod); + return read( *this, op, lockop); +} + const TString & TArticolo::descrizione(const char* lingua) const { if (lingua && *lingua) @@ -833,9 +840,9 @@ int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo) TCausale_magazzino::TCausale_magazzino(const char * codice): - TRectype(LF_TAB) + TRectype(LF_TABCOM) { - TTable f("CAU"); + TTable f("%CAU"); f.put("CODTAB",codice); if (f.read() != NOERR) zero(); @@ -911,7 +918,7 @@ int TMov_mag::remove(TBaseisamfile& f) const int res; if ((res=TMultiple_rectype::remove(f))==NOERR ) // effettua la variazione dei saldi - res=update_balances(); + res=((TMov_mag *)this)->update_balances(); return res; } @@ -928,7 +935,7 @@ int TMov_mag::write(TBaseisamfile& f) const } if ((res=TMultiple_rectype::write(f))==NOERR ) // effettua la variazione dei saldi - res=update_balances(); + res=((TMov_mag *)this)->update_balances(); return res; } @@ -945,7 +952,7 @@ int TMov_mag::rewrite(TBaseisamfile& f) const } if ((res=TMultiple_rectype::rewrite(f))==NOERR ) // effettua la variazione dei saldi - res=update_balances(); + res=((TMov_mag *)this)->update_balances(); return res; } @@ -976,7 +983,7 @@ int TMov_mag::force_update_bal() for (int i=0; iinsert_line(l_key,l_data); + insert_line(l_key,l_data); } res=update_balances(); return res; @@ -1082,7 +1089,7 @@ void TMov_mag::giac_putkey(TLocalisamfile & mag,TString16 annoes,TToken_string c // aggiorna tutti i saldi in base alle modifiche fatte. // il lock su anagrafica dovrebbe garantire il lock su tutte le // giacenze dell'articolo -int TMov_mag::update_balances() const +int TMov_mag::update_balances() { bool updated_bal=TRUE; TLocalisamfile mag(LF_MAG); @@ -1098,16 +1105,16 @@ int TMov_mag::update_balances() const TToken_string * curr_key=(TToken_string *)keys_to_add.first_item(); while (curr_key) { - TArticolo_giacenza articolo(key2field(*curr_key,"CODART")); - if (articolo.lock_and_prompt()) { + curr_art.read((const char *)key2field(*curr_key,"CODART")); + if (curr_art.lock_and_prompt()) { TLine_movmag & line_mov=(TLine_movmag &)lines_to_add[*curr_key]; - articolo.update_ultcosti(line_mov.prezzo,get_date("DATACOMP")); + curr_art.update_ultcosti(line_mov.prezzo,get_date("DATACOMP")); // lock gained giac_putkey(mag,get("ANNOES"),*curr_key); if (mag.read()!=NOERR) { // non trovato: aggiungo giac_putkey(mag,get("ANNOES"),*curr_key); - mag.put("NRIGA",1+articolo.mag(get("ANNOES")).rows()); + mag.put("NRIGA",1+curr_art.mag(get("ANNOES")).rows()); mag.write(); } // modifica questo record (e lo sblocca) @@ -1134,7 +1141,7 @@ int TMov_mag::update_balances() const } rem_key=(TToken_string *)keys_to_remove.succ_item(); } - articolo.unlock(); + curr_art.unlock(); } else { updated_bal=FALSE; } @@ -1144,15 +1151,15 @@ int TMov_mag::update_balances() const curr_key=(TToken_string *)keys_to_remove.first_item(); while (curr_key) { - TArticolo articolo(key2field(*curr_key,"CODART")); - if (articolo.lock_and_prompt()) { + curr_art.read((const char *)key2field(*curr_key,"CODART")); + if (curr_art.lock_and_prompt()) { giac_putkey(mag,_annoes,*curr_key); // modifica questo record (e lo sblocca) if (mag.read()==NOERR) { update_balances(mag.curr(),(TLine_movmag &)lines_to_subtract[*curr_key],_codcaus,-1); mag.rewrite(); } - articolo.unlock(); + curr_art.unlock(); } else { updated_bal=FALSE; } @@ -1167,7 +1174,7 @@ int TMov_mag::update_balances() const // aggiorna i saldi del record corrente // in base alla causale e alla modifica fatta (con segno + o -) -int TMov_mag::update_balances(TRectype & magrec, const TLine_movmag &l,TString16 codcaus,int rett_sign) const +int TMov_mag::update_balances(TRectype & magrec, const TLine_movmag &l,TString16 codcaus,int rett_sign) { TCausale_magazzino caus(codcaus); TLocalisamfile umart(LF_UMART); @@ -1225,7 +1232,7 @@ bool rebuild_balances(TString16 annoes, bool reset_giac) TArray used_files; used_files.add(new TLocalisamfile(LF_RMOVMAG),LF_RMOVMAG); used_files.add(new TLocalisamfile(LF_MOVMAG),LF_MOVMAG); - used_files.add(new TTable("CAU"),5); + used_files.add(new TTable("%CAU"),5); TMov_mag * m_m= new TMov_mag; // record del movimento di magazzino // relazione con un solo file (LF_MOVMAG) ma col record Head_Body