diff --git a/mg/mglib02.cpp b/mg/mglib02.cpp index 4234ae81e..bcc102772 100755 --- a/mg/mglib02.cpp +++ b/mg/mglib02.cpp @@ -844,18 +844,15 @@ int TCausale_magazzino::sgn(TTipo_saldomag tiposaldo) TCausale_magazzino::TCausale_magazzino(const char * codice): - TRectype(LF_TABCOM) + TRectype(LF_TABCOM) { - TTable f("%CAU"); - f.put("CODTAB",codice); - if (f.read() != NOERR) + TTable f("%CAU"); + + settab("CAU"); + put("CODTAB", codice); + if (TRectype::read(f) != NOERR) zero(); - else - *this=(TCausale_magazzino &)f.curr(); -} -TCausale_magazzino::~TCausale_magazzino() -{ -} +} // movimenti TLine_movmag ::TLine_movmag(const TLine_movmag &l) @@ -893,14 +890,11 @@ bool TMov_mag::renum() // copia la chiave dal file principale a quello delle righe void TMov_mag::set_body_key(TRectype & rowrec) { - rowrec.put("NUMREG",get("NUMREG")) ; + rowrec.put("NUMREG",get("NUMREG")); } int TMov_mag::read(TBaseisamfile& f, word op , word lockop) { - TToken_string l_key; - TLine_movmag l_data; - int res=TMultiple_rectype::read(f,op,lockop); // reset delle strutture per il controlli delle variazioni dei saldi @@ -908,11 +902,11 @@ int TMov_mag::read(TBaseisamfile& f, word op , word lockop) _annoes=get("ANNOES"); lines_to_add.destroy(); lines_to_subtract.destroy(); - for (int i=0; i0; r--) - { - TString16 codcaus(body()[r].get(RMOVMAG_CODCAUS)); - if (codcaus.blank()) - codcaus=get(RMOVMAG_CODCAUS); + for (int r = rows(); r > 0; r--) + { + TRecord_array & b = body(); + TRectype & row = b[r]; + TString16 codcaus(row.get(RMOVMAG_CODCAUS)); + if (codcaus.empty()) + codcaus=get(MOVMAG_CODCAUS); TCausale_magazzino cau(codcaus); - if (*cau.get_collegata()!='\0') + codcaus=cau.caus_collegata(); + if (codcaus.not_empty()) { // deve esserci una riga collegata - if (r < rows()-1 && body()[r+1].get(RMOVMAG_TIPORIGA)[0] != riga_automatica) + if (!b.exist(r + 1) || b[r + 1].get_char(RMOVMAG_TIPORIGA) != riga_automatica) { // manca, la inserisco - TRectype linea_auto(body()[r]); - - if (codmag_rauto(r)!=NULL) linea_auto.put(RMOVMAG_CODMAG,codmag_rauto(r)); - if (prezzo_rauto(r)!=NULL) linea_auto.put(RMOVMAG_PREZZO,prezzo_rauto(r)); - linea_auto.put(RMOVMAG_NRIG,r+1); - body().insert_row(&linea_auto); + TRectype * linea_auto = new TRectype(row); + const char * codmag = codmag_rauto(r); + if (codmag != NULL) + linea_auto->put(RMOVMAG_CODMAG, codmag); + const char * prezzo = prezzo_rauto(r); + if (prezzo != NULL) + linea_auto->put(RMOVMAG_PREZZO, prezzo); + linea_auto->put(RMOVMAG_NRIG, r+1); + linea_auto->put(RMOVMAG_TIPORIGA, (char) riga_automatica); + linea_auto->put(RMOVMAG_CODCAUS, codcaus); + b.insert_row(linea_auto); } } } // ciclo righe @@ -955,14 +957,12 @@ int TMov_mag::write(TBaseisamfile& f) const { int res; ((TMov_mag *)this)->add_automatiche(); - TToken_string l_key; - TLine_movmag l_data; - // memorizza le variazioni - for (int i=0; iline_inserted(l_key,l_data); - } + // memorizza le variazioni + + const int nrows = rows(); + + for (int i = 1; i <= nrows; i++) + ((TMov_mag *)this)->line_inserted(line2key(i), line2data(i)); if ((res=TMultiple_rectype::write(f))==NOERR ) // effettua la variazione dei saldi res=((TMov_mag *)this)->update_balances(); @@ -973,14 +973,12 @@ int TMov_mag::rewrite(TBaseisamfile& f) const { int res; ((TMov_mag *)this)->add_automatiche(); - TToken_string l_key; - TLine_movmag l_data; - // memorizza le variazioni - for (int i=0; iline_inserted(l_key,l_data); - } + // memorizza le variazioni + + const int nrows = rows(); + + for (int i = 1; i < nrows; i++) + ((TMov_mag *)this)->line_inserted(line2key(i), line2data(i)); if ((res=TMultiple_rectype::rewrite(f))==NOERR ) // effettua la variazione dei saldi res=((TMov_mag *)this)->update_balances(); @@ -1010,35 +1008,40 @@ int TMov_mag::force_update_bal() _annoes=get(MOVMAG_ANNOES); lines_to_add.destroy(); lines_to_subtract.destroy(); + // memorizza le variazioni - for (int i=0; i