From 4f9ea774d62989d0b3e50dd0bbdc93697895ba63 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 27 Aug 2008 09:20:30 +0000 Subject: [PATCH] Patch level : 10.0 109 Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 1208 git-svn-id: svn://10.65.10.50/trunk@17100 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- db/db0500.cpp | 478 ++++++++++++++++++++++++++++++++++++-------------- db/db0500a.h | 3 + db/db2400.cpp | 13 +- db/dblib.cpp | 11 +- db/dblib.h | 14 +- gv/gvlib.cpp | 2 - 6 files changed, 367 insertions(+), 154 deletions(-) diff --git a/db/db0500.cpp b/db/db0500.cpp index 87398f071..eb0818630 100755 --- a/db/db0500.cpp +++ b/db/db0500.cpp @@ -1,6 +1,8 @@ #include "dblib.h" #include +#include +#include #include #include #include @@ -15,33 +17,6 @@ #include "db0500a.h" -/////////////////////////////////////////////////////////// -// Funzione di richiesta stringa che andra' in libreria -/////////////////////////////////////////////////////////// - -#include - -bool copy_on_code(const char * oldcode, TString& newcode, int width = 50, const char* flags= "") -{ - int maskwidth = width+18; - if (maskwidth < 26) - maskwidth = 26; - if (maskwidth > 78) - maskwidth = 78; - - TMask m(TR("Copia codice"), 1, maskwidth, 5); - m.add_string(DLG_USER+1, 0, TR("Vecchio codice "), 1, 1, width, "D", width > 76 ? 76 : width); - m.add_string(DLG_USER, 0, TR("Nuovo codice "), 1, 2, width, flags, width > 76 ? 76 : width); - m.add_button(DLG_OK, 0, "", -12, -1, 10, 2); - m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2); - m.set(DLG_USER+1, oldcode); - m.set(DLG_USER, newcode); - bool ok = m.run() == K_ENTER; - if (ok) - newcode = m.get(DLG_USER); - return ok; -} - /////////////////////////////////////////////////////////// // TDistinta_app /////////////////////////////////////////////////////////// @@ -141,12 +116,25 @@ class TQuery_mask : public TAutomask { TDistinta_tree& _tree; TToken_string _curr; + + TCodart_livelli _livart; TCodgiac_livelli _livgiac; bool redraw_tree(TField_event e); + protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); + void create_browse1(TEdit_field& kfld, int level, short key_id) const; + bool ask_new_code(const TCodice_articolo& oldcode, TCodice_articolo& newcode) const; + + bool are_similar(const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const; + bool generate_subcode(const TCodice_articolo& oldcode, const TCodice_articolo& newcode, + const TCodice_articolo& oldsub, TCodice_articolo& newsub) const; + bool copy_article_rows(const int lfile, const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const; + bool copy_article(const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const; + bool copy_distinct(const TCodice_articolo& oldcode, const TCodice_articolo& newcode, bool recursive); + public: const TToken_string& curr() const { return _curr; } bool restart_tree(); @@ -155,6 +143,273 @@ public: virtual ~TQuery_mask() { } }; +void TQuery_mask::create_browse1(TEdit_field& kfld, int level, short key_id) const +{ + TFilename tmp; tmp.temp(); + ofstream out(tmp); + + out << "USE GCA" << endl; //usa la tabella dei livelli articolo + + const short id = key_id + level - 1; + const TString& prompt = _livart.name(level); + const TString& picture = _livart.picture(level); + out << "IN CODTAB[1,1] \"" << level << "\"" << endl; + out << "IN CODTAB[2,0] " << id << endl; + out << "DI \"" << prompt; + const int length = _livart.code_length(level); + if (length > prompt.len()) + out << '@' << length; + out << "\" CODTAB[2,0]" << endl; + out << "DI \"" << TR("Descrizione") << "@50\" S0" << endl; + out << "OU " << id << " CODTAB[2,0]" << endl; + if (level == 1) + out << "CH RE" << endl; + else + out << "CH NO" << endl; + out << "EN" << endl; + out.close(); + + TScanner scan(tmp); + while (scan.pop() != "EN") + kfld.parse_item(scan); + + xvt_fsys_removefile(tmp); +} + +bool TQuery_mask::ask_new_code(const TCodice_articolo& oldcode, TCodice_articolo& newcode) const +{ + if (newcode.blank()) + newcode = oldcode; + + const int last_level = _livart.last_level(); + const int width = last_level > 0 ? _livart.packed_length(last_level)+last_level*3+16 : 38; + TMask m(TR("Copia articolo/distinta"), 1, width, 5); + + m.add_static(DLG_NULL, 0, PR("Vecchio codice "), 1, 1); + m.add_static(DLG_NULL, 0, PR("Nuovo codice "), 1, 2); + int tab0 = 16; + + if (last_level > 0) + { + for (int i = 1; i <= last_level; i++) //cicla su tutti i livelli del codart abilitati + { + const TString& picture = _livart.picture(i); + for (int y = 0; y < 2; y++) + { + if (y == 1) + { + TString4 flags = "BU"; + if (picture[0] == '0') + flags << 'Z'; + TEdit_field& kfld = m.add_string(200+i, 0, "", tab0, y+1, picture.len(), flags); + create_browse1(kfld, i, 201); + } + else + m.add_string(100+i, 0, "", tab0, y+1, picture.len(), "D"); + } + m.set(100+i, _livart.unpack_grpcode(oldcode, i)); + m.set(200+i, _livart.unpack_grpcode(newcode, i)); + + tab0 += picture.len()+3; + } + } + else + { + m.add_string(101, 0, "", tab0, 1, 20, "D"); + m.add_string(201, 0, "", tab0, 2, 20, "U"); + m.set(101, oldcode); + m.set(201, newcode); + } + m.add_button(DLG_OK, 0, "", -12, -1, 10, 2); + m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2); + + if (m.run() == K_ENTER) + { + if (last_level > 0) + _livart.pack_maskgrpcodes(newcode, m, 201, last_level); + else + newcode = m.get(201); + } + + return newcode.full() && newcode != oldcode; +} + +bool TQuery_mask::copy_article_rows(const int lfile, const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const +{ + bool ok = true; + + // NRIGA vale per tutte le righe dei file connessi ad ANAMAG: CODCORR, DESLIN e UMART + TRecord_array um(lfile, "NRIGA"); + um.renum_key(ANAMAG_CODART, oldcode); + um.read(um.key()); + if (um.rows() > 0) + { + um.renum_key(ANAMAG_CODART, newcode); + ok = um.write() == NOERR; + + } + return ok; +} + +bool TQuery_mask::copy_article(const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const +{ + TLocalisamfile anamag(LF_ANAMAG); + anamag.put(ANAMAG_CODART, newcode); + bool ok = anamag.read() != NOERR; + if (ok) + { + anamag.put(ANAMAG_CODART, oldcode); + ok = anamag.read() == NOERR; + if (ok) + { + anamag.put(ANAMAG_CODART, newcode); + ok = anamag.write() == NOERR; + if (ok) + { + copy_article_rows(LF_CODCORR, oldcode, newcode); + copy_article_rows(LF_DESLIN, oldcode, newcode); + copy_article_rows(LF_UMART, oldcode, newcode); + } + } + } + return ok; +} + +// Confornta due codici articolo diversi e dice che sono simili +// solo se hanno una parte dei sottocodici uguali +bool TQuery_mask::are_similar(const TCodice_articolo& oldcode, + const TCodice_articolo& newcode) const +{ + const int last = _livart.last_level(); + if (last <= 1) + return false; + + int uguali = 0, diversi = 0; + for (int l = 1; l <= last; l++) + { + const TString oldstr = _livart.unpack_grpcode(oldcode, l); + if (oldstr.empty()) // Ultimo pezzo facoltativo? + break; + const TString newstr = _livart.unpack_grpcode(newcode, l); + if (oldstr == newstr) + uguali++; + else + diversi++; + } + return (diversi > 0) && (uguali > 0); // (uguali*diversi)!=0 +} + +bool TQuery_mask::generate_subcode(const TCodice_articolo& oldcode, + const TCodice_articolo& newcode, + const TCodice_articolo& oldsub, + TCodice_articolo& newsub) const +{ + newsub = oldsub; + const int last = _livart.last_level(); + for (int l = 1; l <= last; l++) + { + const TString oldstr = _livart.unpack_grpcode(oldcode, l); + if (oldstr.empty()) // Ultimo pezzo facoltativo? + break; + const TString newstr = _livart.unpack_grpcode(newcode, l); + const TString substr = _livart.unpack_grpcode(oldsub, l); + if (oldstr != newstr && oldstr == substr) + newsub.overwrite(newstr, _livart.code_start(l)-1); + } + return newsub != oldsub; +} + +bool TQuery_mask::copy_distinct(const TCodice_articolo& oldcode, + const TCodice_articolo& newcode, bool recursive) +{ + bool ok = oldcode.full() && newcode.full() && oldcode != newcode; + if (ok) + { + TLocalisamfile dist(LF_DIST); + dist.put("CODDIST", oldcode); + ok = dist.read() == NOERR; + if (ok) + { + // Se la vecchia distinta corrisponde ad un articolo di magazzino + // anche la nuova avra' il suo nuovo articolo corrispondente + const TRectype& oldartrec = cache().get(LF_ANAMAG, oldcode); + TRectype newartrec = cache().get(LF_ANAMAG, newcode); + if (!oldartrec.empty() && newartrec.empty()) + { + copy_article(oldcode, newcode); + cache().discard(LF_ANAMAG, newcode); // Annulla record vuoto in cache + newartrec = cache().get(LF_ANAMAG, newcode); + } + + dist.put("CODDIST", newcode); + if (!newartrec.empty()) + { + // Copio la descrizione dall'articolo collegato + dist.put("DESCR", newartrec.get("DESCR")); + // Determino l'unita' di misura predefinita + TToken_string umkey; + umkey << newcode << "|1"; + const TString& um = cache().get(LF_UMART, umkey, "UM"); + dist.put("UM", um); + } + else + { + dist.put("ARTPROD", " "); + const TRectype& lavrec = cache().get("LAV",newcode); + if (!lavrec.empty()) + dist.put("DESCR",lavrec.get("S0")); + } + + const int err = dist.write(); + if (err != NOERR) + { + if (err == _isreinsert) + ok = error_box(FR("La distinta '%s' e' gia' presente"), (const char*)newcode); + else + ok = error_box(FR("Errore %d durante la registrazione della distinta '%s'"), err, (const char*)newcode); + } + } + else + ok = error_box(FR("Il codice '%s' non corrisponde ad una distinta valida"), (const char*)oldcode); + } + + if (ok) + { + // copia le righe di distinta + TRecord_array rdist(LF_RDIST, "NRIG"); + rdist.renum_key("CODDIST", oldcode); + if (rdist.read(rdist.key()) == NOERR) + { + rdist.renum_key("CODDIST", newcode); + if (recursive) + { + for (int r = rdist.last_row(); r > 0; r = rdist.pred_row(r)) + { + TRectype& row = rdist.row(r, false); // Rewriteable row + const char row_type = row.get_char("TIPO"); + // Tento rigenerazione del codice solo su articoli e distinte + if (row_type == 'A' || row_type == 'D') + { + const TCodice_articolo oldsub = row.get("CODCOMP"); + TCodice_articolo newsub; + if (generate_subcode(oldcode, newcode, oldsub, newsub)) + { + row.put("CODCOMP", newsub); + if (row_type == 'A') + copy_article(oldsub, newsub); + else + copy_distinct(oldsub, newsub, recursive); + } + } + } + } + rdist.write(); + } + } + return ok; +} + + bool TQuery_mask::restart_tree() { if (!_tree.restart()) @@ -271,82 +526,31 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) if (str.not_empty()) set(F_CODICEQ, str); else - return FALSE; + return false; } break; case F_COPY: if (e == fe_button) { - const TString oldcode = get(F_CODICE); + const TCodice_articolo oldcode = get(F_CODICE); if (oldcode.blank()) error_box(TR("Selezionare un codice")); - TLocalisamfile dist(LF_DIST); - dist.put("CODDIST", oldcode); - if (dist.read() == NOERR) - { - TString newcode; - if (copy_on_code(dist.get("CODDIST"),newcode, 20, "U")) - { - if (newcode.not_empty() && newcode != oldcode) - { - dist.put("CODDIST", newcode); - const TRectype & artrec = cache().get(LF_ANAMAG,newcode); - if (!artrec.empty()) - { - dist.put("DESCR",artrec.get("DESCR")); - } else { - dist.put("ARTPROD", " "); - const TRectype & lavrec = cache().get("LAV",newcode); - if (!lavrec.empty()) - dist.put("DESCR",lavrec.get("S0")); - } - TString environment=dist.get("PARAMETRI"); - const int err = dist.write(); - if (err == NOERR) - { - // copia le righe di distinta - TRecord_array rdist(LF_RDIST, "NRIG"); - rdist.renum_key("CODDIST", oldcode); - if (rdist.read(rdist.key()) == NOERR) + else { - rdist.renum_key("CODDIST", newcode); - rdist.write(); - } - // copia le righe delle UM - TRecord_array um(LF_UMART, "NRIGA"); - um.renum_key("CODART", newcode); - int err=um.read(um.key()) ; - if (um.rows() == 0) - err = _iskeynotfound; - switch (err) - { - case _isemptyfile: - case _iskeynotfound: - um.renum_key("CODART", oldcode); - if (um.read(um.key()) == NOERR ) + TCodice_articolo newcode; + if (ask_new_code(oldcode, newcode)) { - um.renum_key("CODART", newcode); - um.write(); - } - break; - case NOERR: - dist.put("UM", um.row(1).get("UM")); - break; - } - } - else + bool recursive = are_similar(oldcode, newcode); + if (recursive) + recursive = yesno_box(TR("Si desidera riportare le modifiche al codice anche sui componenti?")); + if (copy_distinct(oldcode, newcode, recursive)) { - if (err == _isreinsert) - error_box(FR("La distinta '%s' e' gia' stata inserita"), (const char*)newcode); - else - error_box(FR("Errore %d durante la registrazione della distinta '%s'"), err, (const char*)newcode); + set(F_CODICEQ, newcode); // Passa in modifica della nuova disitinta + stop_run(K_ENTER); } } } } - else - error_box(FR("Il codice '%s' non corrisponde ad una distinta valida"), (const char*)oldcode); - } break; case F_EXPLODE: if (e == fe_button) @@ -1021,55 +1225,69 @@ bool TDistinta_mask::on_field_event(TOperable_field& o, TField_event e, long jol } break; case DLG_MOV: - if (app().has_module(MGAUT)) - { - TMask mov("db0500d"); - TMagazzini m; - - if (!m.gestmultimag()) + if (e == fe_button) + { + if (app().has_module(MGAUT)) { - mov.disable(F_CODMAG); - mov.disable(F_DESMAG); - mov.disable(F_CODDEP); - mov.disable(F_DESDEP); - } - else - if (!m.gestdep()) + TSheet_field& sf = sfield(F_SHEET); + TMov_mask mov(get(F_CODICE), &sf); + TMagazzini m; + + if (!m.gestmultimag()) { + mov.disable(F_CODMAG); + mov.disable(F_DESMAG); mov.disable(F_CODDEP); mov.disable(F_DESDEP); } - mov.set(F_CODMAG, m.standardmag()); - mov.set(F_CODDEP, m.standarddep()); - mov.set(F_PREZZOM, get(F_PREZZO)); - if (mov.run() == K_ENTER) - { - TFilename name; - - name.temp("", "ini"); - + else + if (!m.gestdep()) + { + mov.disable(F_CODDEP); + mov.disable(F_DESDEP); + } + mov.set(F_CODMAG, m.standardmag()); + mov.set(F_CODDEP, m.standarddep()); + mov.set(F_PREZZOM, get(F_PREZZO)); + if (mov.run() == K_ENTER) { - TConfig c(name); - c.set_paragraph("Transaction"); - c.set("Action", "Insert"); - c.set("Mode", "A"); - c.set_paragraph(format("%d", LF_MOVMAG)); - c.set(MOVMAG_DATAREG, mov.get(F_DATAREG)); - c.set(MOVMAG_CODCAUS, mov.get(F_CODCAUS)); - c.set_paragraph(format("%d,1", LF_RMOVMAG)); - TString8 codmag(mov.get(F_CODMAG)); + TFilename name; - codmag.rpad(3); - codmag << mov.get(F_CODDEP); - c.set(RMOVMAG_CODMAG, codmag); - c.set(RMOVMAG_CODART, get(F_CODICE)); - c.set(RMOVMAG_UM, get(F_UM)); - c.set(RMOVMAG_QUANT, mov.get(F_QUANT)); - c.set(RMOVMAG_PREZZO, mov.get(F_PREZZOM)); + name.temp("", "ini"); + + { + TConfig c(name); + c.set_paragraph("Transaction"); + c.set("Action", "Insert"); + c.set("Mode", ""); + c.set_paragraph(format("%d", LF_MOVMAG)); + c.set(MOVMAG_DATAREG, mov.get(F_DATAREG)); + c.set(MOVMAG_CODCAUS, mov.get(F_CODCAUS)); + c.set_paragraph(format("%d,1", LF_RMOVMAG)); + TString8 codmag(mov.get(F_CODMAG)); + + codmag.rpad(3); + codmag << mov.get(F_CODDEP); + c.set(RMOVMAG_CODMAG, codmag); + c.set(RMOVMAG_CODART, get(F_CODICE)); + c.set(RMOVMAG_UM, get(F_UM)); + c.set(RMOVMAG_QUANT, mov.get(F_QUANT)); + c.set(RMOVMAG_PREZZO, mov.get(F_PREZZOM)); + } + + TExternal_app app(format("mg1 -0 -i%s", (const char *)name)); + + app.run(); + const real prezzo(mov.get(F_PREZZOV)); + TLocalisamfile umart(LF_UMART); + umart.put(UMART_CODART, get(F_CODICE)); + umart.put(UMART_NRIGA, 1); + if (umart.read(_isequal, _testandlock) == NOERR) + { + umart.put(UMART_PREZZO, prezzo); + umart.rewrite(); + } } - TExternal_app app(format("mg1 -0 -i%s", (const char *)name)); - - app.run(); } } break; diff --git a/db/db0500a.h b/db/db0500a.h index 300746cf3..dd7ef86b3 100755 --- a/db/db0500a.h +++ b/db/db0500a.h @@ -103,4 +103,7 @@ #define F_PREZZOM 127 #define F_DESMAG 128 #define F_DESDEP 129 +#define F_TIPOVAL 130 +#define F_PREZZOV 131 +#define F_SCONTO 132 #endif diff --git a/db/db2400.cpp b/db/db2400.cpp index 3effd52bd..a1262bb3a 100755 --- a/db/db2400.cpp +++ b/db/db2400.cpp @@ -254,9 +254,7 @@ void TValorizzazione_mask::elabora() bf.add_line(line); } - if (pi.isfinished()) - enable(DLG_SAVEREC); - + enable(DLG_SAVEREC); vw.goto_top(); } @@ -331,12 +329,9 @@ void TValorizzazione_mask::salva() } } - if (pi.isfinished()) - { - _valori.destroy(); - _risultati.destroy(); - disable(DLG_SAVEREC); - } + _valori.destroy(); + _risultati.destroy(); + disable(DLG_SAVEREC); } bool TValorizzazione_mask::on_field_event(TOperable_field& f, TField_event e, long jolly) diff --git a/db/dblib.cpp b/db/dblib.cpp index 9f0e07bf1..9208e8445 100755 --- a/db/dblib.cpp +++ b/db/dblib.cpp @@ -1797,12 +1797,13 @@ TLavorazione *TDistinta_tree::find_labor(TRiga_esplosione *l) // TRiga_esplosione /////////////////////////////////////////////////////////// -void TRiga_esplosione::init(const TDistinta_tree& tree, bool vis_ghost, const TRectype * rec) +void TRiga_esplosione::init(const TDistinta_tree& tree, bool vis_ghost) { - TCodice_articolo art; tree.curr_code(art); art.trim(); + tree.curr_code(_comp); _comp.trim(); + tree.father_code(_dist); _dist.trim(); TCodice_um um; tree.curr_um(um); real val = tree.curr_qta(); - set(art, um, val); + set(_comp, um, val); _last_qta = tree.last_qta(vis_ghost); // Puo' sempre servire anche questa tree.curr_giaclev(_giac); _tipo = tree.curr_type(); @@ -1810,10 +1811,6 @@ void TRiga_esplosione::init(const TDistinta_tree& tree, bool vis_ghost, const TR _mat_base = FALSE; // set path and code tree.curr_id(_path); // path - if (rec != NULL) - _rdist = new TRectype(*rec); - else - _rdist = NULL; } const char * TRiga_esplosione::father(const char * types) diff --git a/db/dblib.h b/db/dblib.h index b4069115e..60a03ae8a 100755 --- a/db/dblib.h +++ b/db/dblib.h @@ -399,11 +399,12 @@ class TRiga_esplosione : public TQuantita char _tipo; bool _mat_base; real _last_qta; - TRectype * _rdist; + TCodice_articolo _comp; + TCodice_articolo _dist; protected: virtual TObject* dup() const { return new TRiga_esplosione(*this); } - void init(const TDistinta_tree& tree, bool vis_ghost = FALSE, const TRectype * rec = NULL); + void init(const TDistinta_tree& tree, bool vis_ghost = FALSE); public: const TToken_string& path() const { return _path; } @@ -420,11 +421,12 @@ public: // cerca un padre o nonno di uno dei tipi passati const char * father(const char * types=NULL); const real& last_qta() const { return _last_qta; } - const TRectype * rdist_rec() const { return _rdist;} - +t const TCodice_articolo & componente() const { return _comp; } + const TCodice_articolo & distinta() const { return _dist;} + TRiga_esplosione(); - TRiga_esplosione(const TDistinta_tree& tree, bool vis_ghost = false, const TRectype * rec = NULL); - TRiga_esplosione(const TRiga_esplosione& re); + TRiga_esplosione(const TDistinta_tree& tree, bool vis_ghost = false); + TRiga_esplosione(const TRiga_esplosione& re); virtual ~TRiga_esplosione() { if (_rdist != NULL) delete _rdist;} }; diff --git a/gv/gvlib.cpp b/gv/gvlib.cpp index 6f238af9c..1e932d1d0 100755 --- a/gv/gvlib.cpp +++ b/gv/gvlib.cpp @@ -2,8 +2,6 @@ #include #include -#include -#include #include "../cg/cg2101.h" #include "../cg/cglib02.h"