114090d2fb
Files correlati : Ricompilazione Demo : [ ] Commento : aggiunto il controllo sul dninst git-svn-id: svn://10.65.10.50/trunk@19985 c028cbd2-c16b-5b4b-a496-9718f37d4682
869 lines
27 KiB
C++
Executable File
869 lines
27 KiB
C++
Executable File
#include <automask.h>
|
||
#include <defmask.h>
|
||
#include <dongle.h>
|
||
#include <progind.h>
|
||
#include <recarray.h>
|
||
#include <recset.h>
|
||
#include <relapp.h>
|
||
|
||
#include "../mg/anamag.h"
|
||
#include "../mg/codcorr.h"
|
||
#include "../mg/umart.h"
|
||
#include "condv.h"
|
||
#include "rcondv.h"
|
||
|
||
#include "ve2500a.h"
|
||
#include "ve2500b.h"
|
||
|
||
////////////////////////////////////////////////////////////////////
|
||
// MASCHERA SECONDARIA DI GENERAZIONE LISTINO
|
||
////////////////////////////////////////////////////////////////////
|
||
class TGestione_listini_semplice_mask_genera: public TAutomask
|
||
{
|
||
|
||
TMask* _main_mask; //puntatore maschera principale
|
||
|
||
protected:
|
||
int find_art_in_sheet(const char tipo, const TString& cod, const TString& um, const int nscagl) const;
|
||
void copia_listino();
|
||
void crea_da_anamag();
|
||
|
||
public:
|
||
void crea_listino();
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
TGestione_listini_semplice_mask_genera(TMask* main_mask);
|
||
};
|
||
|
||
|
||
bool TGestione_listini_semplice_mask_genera::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
TGestione_listini_semplice_mask_genera::TGestione_listini_semplice_mask_genera(TMask* main_mask)
|
||
: TAutomask("ve2500b"), _main_mask(main_mask)
|
||
{
|
||
const bool gesliscv = ini_get_bool(CONFIG_DITTA, "ve", "GESLISCV");
|
||
enable(FB_CATVEN, gesliscv);
|
||
enable(FB_DESVEN, gesliscv);
|
||
}
|
||
|
||
// COPIA LISTINO
|
||
//----------------------------------------------------------------------------------------------------------------------
|
||
//metodo che restituisce l'indice della riga dello sheet che contiene
|
||
//la coppia tipo-articolo desiderata (-1 se non lo trova)
|
||
int TGestione_listini_semplice_mask_genera::find_art_in_sheet(const char tipo, const TString& cod,
|
||
const TString& um, const int nscagl) const
|
||
{
|
||
TSheet_field& s = _main_mask->sfield(FA_RIGHE);
|
||
int i = -1;
|
||
FOR_EACH_SHEET_ROW(s, r, row)
|
||
{
|
||
const char tiporiga = row->get_char(0);
|
||
const TString& codart = row->get(1);
|
||
TString4 umis = row->get(4);
|
||
umis.trim();
|
||
const int numscagl = row->get_int(5);
|
||
if (tipo == tiporiga && cod == codart && um == umis && nscagl == numscagl)
|
||
{
|
||
i = r;
|
||
break;
|
||
}
|
||
}
|
||
return i;
|
||
}
|
||
|
||
//metodo per la copia da un listino esistente
|
||
void TGestione_listini_semplice_mask_genera::copia_listino()
|
||
{
|
||
//parametri listino origine
|
||
const TString& ori_catven = get(FB_CATVEN);
|
||
const TString& ori_codlis = get(FB_COD);
|
||
const real ricarico = get_real(FB_RICARICO);
|
||
|
||
//vanno fuori dall'if(get_bool(FB_COPIATESTA)) perch<63> rec_ori_testata serve in seguito! (che schifo!)
|
||
TToken_string key;
|
||
key.add("L");
|
||
key.add(ori_catven);
|
||
key.add("");
|
||
key.add("");
|
||
key.add(ori_codlis);
|
||
const TRectype& rec_ori_testata = cache().get(LF_CONDV, key);
|
||
|
||
//TESTATA
|
||
//se richiesto mette nei campi della maschera principale i dati di testata
|
||
if (get_bool(FB_COPIATESTA))
|
||
{
|
||
//magico metodino per scrivere sui campi della maschera principale (testata nuovo listino) i dati della testata..
|
||
//..del listino originale (senza usare una lunghissima serie di set su ogni campo!)
|
||
FOR_EACH_MASK_FIELD((*_main_mask), i, f)
|
||
{
|
||
const TFieldref* fld_file = f->field();
|
||
if (fld_file != NULL && !f->in_key(0) && f->enabled() && f->empty())
|
||
f->set(fld_file->read(rec_ori_testata));
|
||
}
|
||
}
|
||
|
||
//RIGHE
|
||
//prende il recordset delle righe del listino origine e lo mette sullo sheet
|
||
TString query;
|
||
query << "USE RCONDV\n";
|
||
query << "FROM TIPO=L CATVEN=#CATVEN COD=#COD\n";
|
||
query << "TO TIPO=L CATVEN=#CATVEN COD=#COD\n";
|
||
|
||
TISAM_recordset righe_listino(query);
|
||
righe_listino.set_var("#CATVEN", ori_catven);
|
||
righe_listino.set_var("#COD", ori_codlis);
|
||
|
||
const long righe_listino_items = righe_listino.items();
|
||
TProgind pi(righe_listino_items, TR("Copia righe listino origine..."), true, true);
|
||
|
||
//sheet righe listino da riempire nella maschera principale
|
||
TSheet_field& sf_righe = _main_mask->sfield(FA_RIGHE);
|
||
TMask& msk = sf_righe.sheet_mask();
|
||
|
||
//record corrente del recordset (non const perch<63> la modifica eventualmente causa ricarico)
|
||
TRectype& riga_corrente = righe_listino.cursor()->curr();
|
||
TString80 val;
|
||
|
||
//alcune date utili nelle righe; prese qui perch<63> vengono dalla testata o dalla maschera e sono poi riportate..
|
||
//..nelle righe
|
||
TDate data_ult_aum = _main_mask->get_date(FA_VALINI);
|
||
if (!data_ult_aum.ok())
|
||
data_ult_aum = TDate(TODAY);
|
||
TDate data_prz_storico = rec_ori_testata.get_date(CONDV_VALIN);
|
||
if (!data_prz_storico.ok())
|
||
data_prz_storico = data_ult_aum - 1L;
|
||
|
||
//scorre tutte le righe listino del recordset e le sbatte nello sheet della maschera principale
|
||
for (bool ok = righe_listino.move_first(); ok; ok = righe_listino.move_next())
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
//controlla che il record non esista per caso gi<67> nel listino di destinazione (caso della copia listino in pi<70>..
|
||
//..fasi separate: un lavoro da mica normali!). Prende quindi la chiave di riga e cerca nello sheet...
|
||
const char tiporiga = riga_corrente.get_char(RCONDV_TIPORIGA);
|
||
const TString& codice = riga_corrente.get(RCONDV_CODRIGA);
|
||
const TString& um = riga_corrente.get(RCONDV_UM);
|
||
const int nscagl = riga_corrente.get_int(RCONDV_NSCAGL);
|
||
//se il record non esiste pu<70> aggiungerlo allo sheet
|
||
if (find_art_in_sheet(tiporiga, codice, um, nscagl) < 0)
|
||
{
|
||
TToken_string& row = sf_righe.row(-1);
|
||
//per ogni campo della maschera setta all'interno del record corrente di file
|
||
//il valore di quei campi che hanno un field
|
||
FOR_EACH_MASK_FIELD(msk, i, f)
|
||
{
|
||
const TFieldref* fr = f->field();
|
||
if (fr != NULL)
|
||
{
|
||
val = fr->read(riga_corrente);
|
||
if (fr->name() == RCONDV_PREZZO && !ricarico.is_zero()) //gestione del ricarico sul listino
|
||
{
|
||
const real old_prezzo = riga_corrente.get_real(RCONDV_PREZZO);
|
||
const real new_prezzo = old_prezzo * (1 + ricarico / CENTO);
|
||
val = new_prezzo.string();
|
||
//aggiorna i campi direttamente sul record, in modo che quando saranno incontrati successivamente,...
|
||
//..saranno gi<67> a posto senza dover rifare tutti i ragionamenti sul ricarico
|
||
riga_corrente.put(RCONDV_DATAULTAUM, data_ult_aum);
|
||
riga_corrente.put(RCONDV_PRZSTO, old_prezzo);
|
||
riga_corrente.put(RCONDV_DATAPRZSTO, data_prz_storico);
|
||
}
|
||
row.add(val, sf_righe.cid2index(f->dlg()));
|
||
}
|
||
}
|
||
//forza una check_row
|
||
sf_righe.check_row(sf_righe.items()-1, 3);
|
||
}
|
||
}
|
||
sf_righe.force_update();
|
||
}
|
||
|
||
|
||
//CREA DA ANAGRAFICA ARTICOLI
|
||
//----------------------------------------------------------------------------------------------------------------------
|
||
void TGestione_listini_semplice_mask_genera::crea_da_anamag()
|
||
{
|
||
//prende i dati dalla maschera per crearsi una query di generazione righe sheet
|
||
TString query;
|
||
query << "USE ANAMAG\n";
|
||
//incasinatissima SELECT
|
||
TString select;
|
||
|
||
//<2F> stato selezionato il gruppo/sottogruppo merceologico?
|
||
TString8 grmerc;
|
||
if (!field(FB_GRMERC).empty())
|
||
{
|
||
grmerc.format("%-3s%-2s", (const char*)get(FB_GRMERC),(const char*)get(FB_SOTGRMERC));
|
||
grmerc.rtrim();
|
||
select << "(GRMERC=#GRMERC)";
|
||
}
|
||
//<2F> stato selezionato il raggruppamento fiscale?
|
||
const TString& raggfis = get(FB_RAGFIS);
|
||
if (raggfis.full())
|
||
{
|
||
if (select.full())
|
||
select << "&&";
|
||
select << "(RAGGFIS=#RAGGFIS)";
|
||
}
|
||
if (select.full())
|
||
query << "SELECT " << select << "\n";
|
||
|
||
//parte FROM/TO comune
|
||
query << "FROM CODART=#DACODART\n";
|
||
query << "TO CODART=#ACODART\n";
|
||
|
||
TISAM_recordset recset(query);
|
||
recset.set_var("#DACODART", get(FB_DACODART));
|
||
recset.set_var("#ACODART", get(FB_ACODART));
|
||
if (grmerc.full())
|
||
recset.set_var("#GRMERC", grmerc);
|
||
if (raggfis.full())
|
||
recset.set_var("#RAGGFIS", raggfis);
|
||
|
||
const long recset_items = recset.items();
|
||
TProgind pi(recset_items, TR("Importazione righe da anagrafica..."), true, true);
|
||
|
||
//fase riempimento sheet maschera principale
|
||
TSheet_field& sf_righe = _main_mask->sfield(FA_RIGHE);
|
||
|
||
//attenzione! ci possono essere articoli presenti pi<70> volte in UMART con diverse unit<69> di misura: li mette tutti
|
||
const bool gest_um = _main_mask->get_bool(FA_GESTUM);
|
||
TRecord_array arr_art_um(LF_UMART, UMART_NRIGA);
|
||
//la gestione omaggi (misteriosamente definita gestsco) attiva l'iva
|
||
const bool gest_sco = _main_mask->get_bool(FA_GESTSCO);
|
||
|
||
//per ogni riga del recordset va ad aggiornare lo sheet sulla maschera (aggiunge la riga)
|
||
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
|
||
const TString& codart = recset.get("CODART").as_string();
|
||
TRectype* key = new TRectype(LF_UMART);
|
||
key->put(UMART_CODART, codart);
|
||
arr_art_um.read(key);
|
||
const int num_um = gest_um ? arr_art_um.rows() : 1;
|
||
//se ci sono pi<70> unit<69> di misura per lo stesso codart ci sono tanti record quante um
|
||
for (int u = 1; u <= num_um; u++)
|
||
{
|
||
TToken_string& row = sf_righe.row(-1);
|
||
row.add('A', 0);
|
||
row.add(codart, 1);
|
||
row.add(recset.get("DESCR").as_string(), 2);
|
||
const TRectype& rec_umart = arr_art_um.row(u);
|
||
row.add(rec_umart.get(UMART_PREZZO), 3);
|
||
//se attivata gestione unit<69> di misura...
|
||
if (gest_um)
|
||
row.add(rec_umart.get(UMART_UM), 4);
|
||
|
||
row.add(recset.get("SCONTO").as_string(), 7);
|
||
if (gest_sco)
|
||
{
|
||
const TString& codiva = recset.get("CODIVA").as_string();
|
||
if (codiva.full())
|
||
{
|
||
row.add("X", 8);
|
||
row.add(codiva, 9);
|
||
}
|
||
}
|
||
|
||
row.add(recset.get("PERCPROVV").as_string(), 18);
|
||
}
|
||
} //for(bool ok=...
|
||
sf_righe.force_update();
|
||
}
|
||
|
||
|
||
// GESTIONE COPIA/GENERA IN AUTOMATICO
|
||
//------------------------------------
|
||
void TGestione_listini_semplice_mask_genera::crea_listino()
|
||
{
|
||
//per prima cosa controlla se deve copiare da un listino esistente o generare da nuovo
|
||
const int f_tipo_gen = get_int(FB_SELECT);
|
||
switch (f_tipo_gen)
|
||
{
|
||
case 1:
|
||
copia_listino();
|
||
break;
|
||
case 2:
|
||
crea_da_anamag();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
////////////////////////////////////////////////////////////////////
|
||
// MASCHERA PRINCIPALE DI GESTIONE LISTINO (quella con lo sheet)
|
||
////////////////////////////////////////////////////////////////////
|
||
class TGestione_listini_semplice_mask: public TAutomask
|
||
{
|
||
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
public:
|
||
int find_art(TSheet_field& s, const char tipo, const TString& art, const int tranne = -1) const;
|
||
int guess_art(TSheet_field& s, const char tipo, const TString& art, const int column) const;
|
||
TGestione_listini_semplice_mask();
|
||
|
||
};
|
||
|
||
|
||
TGestione_listini_semplice_mask::TGestione_listini_semplice_mask() : TAutomask("ve2500a")
|
||
{
|
||
//in base alla cervellotica configurazione impostata dall'utonto abilita/disabilita campi
|
||
const bool gesliscv = ini_get_bool(CONFIG_DITTA, "ve", "GESLISCV");
|
||
enable(FA_L_CATVEN, gesliscv);
|
||
enable(FA_L_DESVEN, gesliscv);
|
||
//attenzione!!! il campo CATVEN <20> in chiave 1! per disabilitarlo ci vuole questo trucco!
|
||
if (!gesliscv)
|
||
efield(FA_L_CATVEN).reset_key(1);
|
||
}
|
||
|
||
//metodo per la ricerca al volo di un articolo (serve per posizionare il cursore sullo sheet in tempo reale..
|
||
//..mentre si digita il codice articolo nel campo di ricerca
|
||
int TGestione_listini_semplice_mask::guess_art(TSheet_field& s, const char tipo, const TString& art,
|
||
const int column) const
|
||
{
|
||
int i = -1;
|
||
FOR_EACH_SHEET_ROW(s, r, row)
|
||
{
|
||
const char tiporiga = row->get_char(0);
|
||
const TString& cod = row->get(column);
|
||
if (tipo == tiporiga && cod.starts_with(art, true))
|
||
{
|
||
i = r;
|
||
break;
|
||
}
|
||
}
|
||
return i;
|
||
}
|
||
|
||
//metodo che restituisce l'indice della riga dello sheet che contiene
|
||
//la coppia tipo-articolo desiderata (-1 se non lo trova)
|
||
int TGestione_listini_semplice_mask::find_art(TSheet_field& s, const char tipo, const TString& art,
|
||
const int tranne) const
|
||
{
|
||
int i = -1;
|
||
//tranne serve per evitare una riga specifica;di default <20> posto =-1 perch<63> non si usa
|
||
FOR_EACH_SHEET_ROW(s, r, row)
|
||
{
|
||
if (r != tranne)
|
||
{
|
||
const char tiporiga = row->get_char(0);
|
||
const char* codart = row->get(1);
|
||
|
||
if (tipo == tiporiga && art == codart)
|
||
{
|
||
i = r;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
return i;
|
||
}
|
||
|
||
|
||
bool TGestione_listini_semplice_mask::on_field_event(TOperable_field &o, TField_event e, long jolly)
|
||
{
|
||
switch(o.dlg())
|
||
{
|
||
case FA_CODRIGA_A:
|
||
case FA_CODRIGA_G:
|
||
case FA_CODRIGA_S:
|
||
case FA_CODRIGA_R:
|
||
//ricerca della riga listino attraverso codice nello sheet usando il campo di ricerca
|
||
if (e == fe_edit || e == fe_modify)
|
||
{
|
||
const char tiporiga = get(FA_TIPORIGA)[0];
|
||
const TString& codriga = ((TEditable_field&)o).get_window_data();
|
||
TSheet_field& sf_righe = sfield(FA_RIGHE);
|
||
const long riga = guess_art(sf_righe, tiporiga, codriga, 1);
|
||
if (riga >= 0 && riga != sf_righe.selected())
|
||
{
|
||
sf_righe.select(riga, true);
|
||
const short f_descr = o.dlg() + 1;
|
||
const char* descr = sf_righe.cell(riga, 2);
|
||
set(f_descr, descr);
|
||
}
|
||
}
|
||
break;
|
||
case FA_DESRIGA_A:
|
||
case FA_DESRIGA_G:
|
||
case FA_DESRIGA_S:
|
||
case FA_DESRIGA_R:
|
||
//ricerca della riga listino attraverso descrizione nello sheet usando il campo di ricerca
|
||
if (!o.empty() && e == fe_edit)
|
||
{
|
||
const char tiporiga = get(FA_TIPORIGA)[0];
|
||
const TString& desriga = ((TEditable_field&)o).get_window_data();
|
||
TSheet_field& sf_righe = sfield(FA_RIGHE);
|
||
const long riga = guess_art(sf_righe, tiporiga, desriga, 2);
|
||
if (riga >= 0)
|
||
{
|
||
sf_righe.select(riga, true);
|
||
const short f_cod = o.dlg() - 1;
|
||
const char* cod = sf_righe.cell(riga, 1);
|
||
set(f_cod, cod);
|
||
}
|
||
}
|
||
break;
|
||
//se abilita la gestione scaglioni nello sheet devono comparire le colonne NSCAGL e QLIM
|
||
case FA_GESTSCAGL:
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
TSheet_field& sf_righe = sfield(FA_RIGHE);
|
||
const bool gest_scagl = o.get().full();
|
||
sf_righe.enable_column(S_NSCAGL, gest_scagl);
|
||
sf_righe.enable_column(S_QLIM, gest_scagl);
|
||
|
||
sf_righe.force_update();
|
||
}
|
||
break;
|
||
//stesso giochetto per UM
|
||
case FA_GESTUM:
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
TSheet_field& sf_righe = sfield(FA_RIGHE);
|
||
const bool gest_um = o.get().full();
|
||
sf_righe.enable_column(S_UM, gest_um);
|
||
|
||
sf_righe.force_update();
|
||
}
|
||
break;
|
||
//e anche per i campi omaggio
|
||
case FA_GESTSCO:
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
TSheet_field& sf_righe = sfield(FA_RIGHE);
|
||
const bool gest_sco = o.get().full();
|
||
sf_righe.enable_column(S_ADDIVA, gest_sco);
|
||
sf_righe.enable_column(S_CODIVA, gest_sco);
|
||
sf_righe.enable_column(S_QOM, gest_sco);
|
||
sf_righe.enable_column(S_QBASE, gest_sco);
|
||
sf_righe.enable_column(S_CODARTOM, gest_sco);
|
||
sf_righe.enable_column(S_UMOM, gest_sco);
|
||
sf_righe.enable_column(S_PROMAGGIO, gest_sco);
|
||
|
||
sf_righe.force_update();
|
||
}
|
||
break;
|
||
//controllo della unicit<69> del tiporiga+codriga nello sheet
|
||
case FA_RIGHE:
|
||
if (e == se_notify_modify)
|
||
{
|
||
TSheet_field& sf_righe = sfield(FA_RIGHE);
|
||
TToken_string& riga = sf_righe.row(jolly);
|
||
const char tipo = riga.get_char(0);
|
||
const TString& art = riga.get(1);
|
||
const long found_riga = find_art(sf_righe, tipo, art, jolly);
|
||
if (found_riga >= 0)
|
||
return error_box(TR("Non <20> possibile inserire lo stesso articolo pi<70> di una volta!"));
|
||
}
|
||
if (e == se_enter)
|
||
{
|
||
TSheet_field& sf_righe = sfield(FA_RIGHE);
|
||
TToken_string& riga = sf_righe.row(jolly);
|
||
const char tipo = riga.get_char(0);
|
||
const TString& art = riga.get(1);
|
||
|
||
if (get(FA_TIPO)[0] != tipo)
|
||
set(FA_TIPO, tipo, 0x1); //0x1 perch<63> ha dei message e non degli output
|
||
|
||
switch (tipo)
|
||
{
|
||
case 'A':
|
||
if (art.full() && get(FA_CODRIGA_A) != art)
|
||
{
|
||
//deve scriversi nel campo di ricerca; 0x2 serve x far funzionare le output del campo stesso
|
||
set(FA_CODRIGA_A, art, 0x2);
|
||
}
|
||
break;
|
||
case 'G':
|
||
if (art.full() && get(FA_CODRIGA_G) != art)
|
||
{
|
||
set(FA_CODRIGA_G, art, 0x2);
|
||
}
|
||
break;
|
||
case 'S':
|
||
if (art.full() && get(FA_CODRIGA_S) != art)
|
||
{
|
||
set(FA_CODRIGA_S, art, 0x2);
|
||
}
|
||
break;
|
||
case 'R':
|
||
if (art.full() && get(FA_CODRIGA_R) != art)
|
||
{
|
||
set(FA_CODRIGA_R, art, 0x2);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
case DLG_GRMERC:
|
||
if (e == fe_button)
|
||
{
|
||
TISAM_recordset gmc_recset("USE GMC");
|
||
|
||
//TCursor_sheet cs(gmc_recset.cursor(), "CODTAB|S0", TR("Gruppi merceologici"), HR("Gr.Merc.|Descrizione@50"), 0, 0, win());
|
||
TToken_string siblings;
|
||
TBrowse_sheet cs (gmc_recset.cursor(), "CODTAB|S0", TR("Gruppi merceologici"), HR("Gr.Merc.|Descrizione@50"), 0,
|
||
efield(FA_GRMERC_A), siblings);
|
||
if (cs.run() == K_ENTER)
|
||
{
|
||
TLocalisamfile anamag(LF_ANAMAG);
|
||
anamag.put(ANAMAG_CODART, get(FA_CODRIGA_A));
|
||
int err = anamag.read();
|
||
if (err == NOERR)
|
||
{
|
||
TToken_string& row = cs.row(cs.selected());
|
||
const TString& grmerc = row.get(0);
|
||
anamag.put(ANAMAG_GRMERC, grmerc);
|
||
anamag.rewrite();
|
||
|
||
set(FA_GRMERC_A, grmerc, 0x2);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case DLG_CREA: //copia / generazione listino
|
||
if (e == fe_button)
|
||
{
|
||
TGestione_listini_semplice_mask_genera mask_gen(this); //gli passa la maschera principale
|
||
if (mask_gen.run() == K_ENTER)
|
||
mask_gen.crea_listino();
|
||
}
|
||
break;
|
||
case DLG_COMPATTA: //eliminazione delle righe con articoli inesistenti!
|
||
if (e == fe_button)
|
||
{
|
||
TSheet_field& sf_righe = sfield(FA_RIGHE);
|
||
FOR_EACH_SHEET_ROW_BACK(sf_righe, r, row) //deve andare all'indietro per minimizzare il riordino righe
|
||
{
|
||
if (row->get_char(2) <= ' ') //le righe senza descrizione sono sbagliate (<28> obbligatoria per articoli ecc.)
|
||
{
|
||
bool kill_row = true;
|
||
if (row->get_char(0) == 'A') //solo se <20> un articolo tenta di recuperarlo con il codice alternativo..(mah?)
|
||
{
|
||
TLocalisamfile file_codcorr(LF_CODCORR);
|
||
file_codcorr.setkey(2);
|
||
file_codcorr.put(CODCORR_CODARTALT, row->get(1));
|
||
int err = file_codcorr.read();
|
||
//se miracolosamente trova il record con il vecchio codart come codartalt...
|
||
if (err == NOERR)
|
||
{
|
||
const TString& new_codart = file_codcorr.get(CODCORR_CODART); //il nuovo codart c'<27> x' <20> in key 1
|
||
const TString& new_descr = cache().get(LF_ANAMAG, new_codart, ANAMAG_DESCR);
|
||
if (!new_descr.blank())
|
||
{
|
||
row->add(new_codart, 1);
|
||
row->add(new_descr, 2);
|
||
kill_row = false;
|
||
}
|
||
}
|
||
} //if(row->get_char(0)..
|
||
if (kill_row)
|
||
sf_righe.destroy(r, false);
|
||
}
|
||
}
|
||
sf_righe.force_update();
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////////
|
||
// APPLICAZIONE
|
||
///////////////////////////////////////////////////////////////
|
||
class TGestione_listini_semplice : public TRelation_application
|
||
{
|
||
TGestione_listini_semplice_mask *_mask;
|
||
TRelation* _rel;
|
||
|
||
private:
|
||
void save_rows();
|
||
TString build_query() const;
|
||
|
||
protected:
|
||
virtual bool user_create();
|
||
virtual bool user_destroy();
|
||
virtual TMask *get_mask(int) { return _mask; }
|
||
virtual bool changing_mask(int) { return false; }
|
||
virtual void init_query_mode(TMask& m);
|
||
virtual void init_insert_mode(TMask& m);
|
||
virtual void init_modify_mode(TMask& m);
|
||
|
||
virtual bool protected_record(TRectype& rec);
|
||
|
||
virtual int read(TMask& m);
|
||
virtual int write(const TMask& m);
|
||
virtual int rewrite(const TMask& m);
|
||
virtual bool remove();
|
||
|
||
const TString& find_descr(TToken_string& row);
|
||
|
||
public:
|
||
virtual TRelation *get_relation() const { return _rel; }
|
||
|
||
TGestione_listini_semplice() { _rel = NULL; _mask = NULL;}
|
||
virtual ~TGestione_listini_semplice() {}
|
||
};
|
||
|
||
|
||
|
||
void TGestione_listini_semplice::save_rows()
|
||
{
|
||
TWait_cursor hourglass;
|
||
|
||
//attenzione!!! fatto questo casino per poter usare la find_art() che <20> un metodo della maschera listini
|
||
const TGestione_listini_semplice_mask& m = *_mask;
|
||
//instanzio un TISAM_recordset sulle righe listino e un localisamfile
|
||
TISAM_recordset righelist(build_query());
|
||
righelist.set_var("#CATVEN", m.get(FA_L_CATVEN));
|
||
righelist.set_var("#COD", m.get(FA_COD));
|
||
|
||
const long righelist_items = righelist.items();
|
||
|
||
TLocalisamfile& file = righelist.cursor()->file();
|
||
|
||
//sheet righe listino da salvare! (righe panda?)
|
||
TSheet_field& righe = m.sfield(FA_RIGHE);
|
||
|
||
//scorro tutte le righe listino ed elimino tutte quelle che non ci sono pi<70> sullo sheet (modifiche utonto)
|
||
for (bool ok = righelist.move_first(); ok; ok = righelist.move_next())
|
||
{
|
||
const char tiporiga = righelist.get("TIPORIGA").as_string()[0];
|
||
|
||
const TString& art = righelist.get("CODRIGA").as_string();
|
||
if (m.find_art(righe, tiporiga, art) < 0)
|
||
file.remove();
|
||
}
|
||
|
||
//procede al salvataggio di testata e righe
|
||
//-----------------------------------------
|
||
|
||
//per prima cosa servono i dati di testata utili per riempire la chiave di riga listino
|
||
const TString& catven = m.get(FA_L_CATVEN);
|
||
const TString& cod = m.get(FA_COD);
|
||
|
||
//recupero la maschera di riga
|
||
TMask& msk = righe.sheet_mask();
|
||
|
||
//per ogni riga dello sheet
|
||
FOR_EACH_SHEET_ROW(righe, r, row)
|
||
{
|
||
file.zero();
|
||
file.put(RCONDV_TIPO, "L");
|
||
file.put(RCONDV_CATVEN, catven);
|
||
file.put(RCONDV_COD, cod);
|
||
|
||
//per ogni campo della maschera setta all'interno del record corrente di file
|
||
//il valore di quei campi che hanno un field
|
||
FOR_EACH_MASK_FIELD(msk, i, f)
|
||
{
|
||
const TFieldref* fr = f->field();
|
||
if (fr != NULL && f->dlg() < 200)
|
||
{
|
||
const int pos = righe.cid2index(f->dlg());
|
||
fr->write(row->get(pos), file.curr());
|
||
}
|
||
}
|
||
//se <20> in inserimento deve fare un write, se in modifica la rewrite
|
||
if (m.insert_mode())
|
||
file.write_rewrite();
|
||
else
|
||
file.rewrite_write();
|
||
}
|
||
}
|
||
|
||
const TString& TGestione_listini_semplice::find_descr(TToken_string& row)
|
||
{
|
||
const char tiporiga = row.get_char(0);
|
||
const TString& codriga = row.get(1);
|
||
switch (tiporiga)
|
||
{
|
||
case 'A':
|
||
return cache().get(LF_ANAMAG, codriga, ANAMAG_DESCR);
|
||
case 'G':
|
||
case 'S':
|
||
return cache().get("GMC", codriga, "S0");
|
||
case 'R':
|
||
return cache().get("RFA", codriga, "S0");
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return EMPTY_STRING;
|
||
}
|
||
|
||
bool TGestione_listini_semplice::protected_record(TRectype& rec)
|
||
{
|
||
//non deve consentire l'eliminazione di un listino se ha dei figli da mantenere!
|
||
TString query;
|
||
query << "USE CONDV\n";
|
||
query << "SELECT (FATHCATVEN=#CATVEN)&&(FATHCOD=#COD)\n";
|
||
query << "FROM TIPO=L\n";
|
||
query << "TO TIPO=L\n";
|
||
TISAM_recordset figli(query);
|
||
figli.set_var("#CATVEN", rec.get(CONDV_CATVEN));
|
||
figli.set_var("#COD", rec.get(CONDV_COD));
|
||
|
||
return figli.items() > 0;
|
||
}
|
||
|
||
TString TGestione_listini_semplice::build_query() const
|
||
{
|
||
TString query;
|
||
query << "USE RCONDV\n";
|
||
query << "FROM TIPO=L CATVEN=#CATVEN COD=#COD\n";
|
||
query << "TO TIPO=L CATVEN=#CATVEN COD=#COD\n";
|
||
|
||
return query;
|
||
}
|
||
|
||
int TGestione_listini_semplice::read(TMask& m)
|
||
{
|
||
//eseguo la read() standard
|
||
int err = TRelation_application::read(m);
|
||
//se la read va a buon fine
|
||
if (err == NOERR)
|
||
{
|
||
TWait_cursor hourglass;
|
||
//instanzio un TISAM_recordset sulle righe listino (RCONDV)
|
||
TISAM_recordset righelist(build_query());
|
||
righelist.set_var("#CATVEN", m.get(FA_L_CATVEN));
|
||
righelist.set_var("#COD", m.get(FA_COD));
|
||
|
||
const long righelist_items = righelist.items();
|
||
|
||
const TRectype& rec = righelist.cursor()->curr();
|
||
|
||
//recupero sheet e realtiva mashera di riga
|
||
TSheet_field& sf_righe = m.sfield(FA_RIGHE);
|
||
TMask& msk = sf_righe.sheet_mask();
|
||
sf_righe.destroy();
|
||
|
||
//per ogni riga del recordset va ad aggiornare lo sheet sulla maschera (aggiunge la riga)
|
||
for (bool ok = righelist.move_first(); ok; ok = righelist.move_next())
|
||
{
|
||
TToken_string& row = sf_righe.row(-1);
|
||
//per ogni campo della maschera setta all'interno del record corrente di file
|
||
//il valore di quei campi che hanno un field
|
||
FOR_EACH_MASK_FIELD(msk, i, f)
|
||
{
|
||
const TFieldref* fr = f->field();
|
||
if (fr != NULL)
|
||
{
|
||
row.add(fr->read(rec), sf_righe.cid2index(f->dlg()));
|
||
|
||
//creatore delle descrizioni al posto della check_row; quest'ultima non si pu<70> usare..
|
||
//..perch<63> al cambio di tipo riga impazzisce; si fa solo con il campo codice
|
||
const int codice = f->dlg();
|
||
if (codice == S_CODRIGA_A || codice == S_CODRIGA_G || codice == S_CODRIGA_S || codice == S_CODRIGA_R)
|
||
{
|
||
TString80 descr = find_descr(row);
|
||
row.add(descr, 2);
|
||
}
|
||
} //if(fr!=NULL)
|
||
} //FOR_EACH_MASK_FIELD
|
||
|
||
} //for(bool ok=...
|
||
} //if(err==NOERR)
|
||
return err;
|
||
}
|
||
|
||
int TGestione_listini_semplice::rewrite(const TMask& m)
|
||
{
|
||
int err = TRelation_application::rewrite(m);
|
||
|
||
if (err == NOERR && m.curr_page() == 0) // Non salvo le righe stando a pagina 2!
|
||
save_rows();
|
||
|
||
return err;
|
||
}
|
||
|
||
int TGestione_listini_semplice::write(const TMask& m)
|
||
{
|
||
int err = TRelation_application::write(m);
|
||
|
||
if(err == NOERR)
|
||
save_rows();
|
||
|
||
return err;
|
||
}
|
||
|
||
|
||
bool TGestione_listini_semplice::remove()
|
||
{
|
||
//vanno rimosse prima le righe poi la testata (nucleare?)
|
||
const TRectype& rec_head = get_relation()->curr();
|
||
|
||
TISAM_recordset righelist(build_query());
|
||
righelist.set_var("#CATVEN", rec_head.get(RCONDV_CATVEN));
|
||
righelist.set_var("#COD", rec_head.get(RCONDV_COD));
|
||
const long righelist_items = righelist.items();
|
||
TProgind pi(righelist_items, TR("Eliminazione righe listino..."), true, true);
|
||
//strage di righe!
|
||
for (bool ok = righelist.move_first(); ok; ok = righelist.move_next())
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
righelist.cursor()->relation()->remove();
|
||
}
|
||
|
||
//questa rimuove la testata
|
||
return (TRelation_application::remove());
|
||
}
|
||
|
||
|
||
void TGestione_listini_semplice::init_query_mode(TMask& m)
|
||
{
|
||
m.disable(DLG_CREA);
|
||
}
|
||
|
||
void TGestione_listini_semplice::init_insert_mode(TMask& m)
|
||
{
|
||
m.enable(DLG_CREA);
|
||
}
|
||
|
||
void TGestione_listini_semplice::init_modify_mode(TMask& m)
|
||
{
|
||
m.enable(DLG_CREA);
|
||
}
|
||
|
||
bool TGestione_listini_semplice::user_create()
|
||
{
|
||
//controlla se la chiave ha l'autorizzazione a questo programma
|
||
Tdninst dninst;
|
||
if (!dninst.can_I_run(true))
|
||
return error_box(TR("Programma non autorizzato!"));
|
||
|
||
_rel = new TRelation(LF_CONDV);
|
||
|
||
//attenzione!! questo <20> il parametro per avere la lunghezza del numero riga sullo sheet
|
||
TSheet_field::set_line_number_width(5);
|
||
|
||
_mask = new TGestione_listini_semplice_mask;
|
||
return true;
|
||
}
|
||
|
||
bool TGestione_listini_semplice::user_destroy()
|
||
{
|
||
delete _mask;
|
||
delete _rel;
|
||
return true;
|
||
}
|
||
|
||
int ve2500(int argc, char* argv[])
|
||
{
|
||
TGestione_listini_semplice a;
|
||
a.run(argc, argv, "Gestione listini");
|
||
return 0;
|
||
} |