Patch level : 10.0
Files correlati : pl002 Ricompilazione Demo : [ ] Commento : Importazione dati LIF git-svn-id: svn://10.65.10.50/branches/R_10_00@21595 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
db995ea4fd
commit
3f62e9654e
24
ps/pl0002.cpp
Executable file
24
ps/pl0002.cpp
Executable file
@ -0,0 +1,24 @@
|
||||
#include <xvt.h>
|
||||
|
||||
#include "pl0002.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const int op = argc < 2 ? 0 : argv[1][1]-'0';
|
||||
switch (op)
|
||||
{
|
||||
case 0:
|
||||
pl0002100(argc,argv);
|
||||
break;
|
||||
default:
|
||||
pl0002100(argc,argv);
|
||||
break;
|
||||
}
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
1
ps/pl0002.h
Executable file
1
ps/pl0002.h
Executable file
@ -0,0 +1 @@
|
||||
int pl0002100(int argc, char* argv[]);
|
446
ps/pl0002100.cpp
Executable file
446
ps/pl0002100.cpp
Executable file
@ -0,0 +1,446 @@
|
||||
#include "../lv/lvlib.h"
|
||||
#include "pl0002lib.h"
|
||||
#include "pl0002100a.h"
|
||||
|
||||
#include <applicat.h>
|
||||
#include <automask.h>
|
||||
#include <defmask.h>
|
||||
#include <progind.h>
|
||||
#include <reprint.h>
|
||||
#include <reputils.h>
|
||||
#include <tabutil.h>
|
||||
|
||||
#include <clifo.h>
|
||||
#include <..\lv\lvcondv.h>
|
||||
#include <..\lv\lvrcondv.h>
|
||||
#include <..\ve\condv.h>
|
||||
#include <..\ve\rcondv.h>
|
||||
|
||||
const char* const APPNAME = TR("Conversione anagrafiche");
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Trasferimenti veri e propri
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TLif_clifo_co_clifor : public TLif_transfer
|
||||
{
|
||||
public:
|
||||
virtual bool trasferisci();
|
||||
};
|
||||
|
||||
class TLif_clifo_ca_anagrafiche : public TLif_transfer
|
||||
{
|
||||
public:
|
||||
virtual bool trasferisci();
|
||||
};
|
||||
|
||||
|
||||
class TLif_contratti : public TLif_transfer
|
||||
{
|
||||
public:
|
||||
virtual bool trasferisci();
|
||||
};
|
||||
|
||||
class TLif_articoli : public TLif_transfer
|
||||
{
|
||||
public:
|
||||
virtual bool trasferisci();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TLif_clienti
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// trasferisce la prima parte dei clienti
|
||||
bool TLif_clifo_co_clifor::trasferisci()
|
||||
{
|
||||
TString query =
|
||||
"SELECT * "
|
||||
"FROM dbo.CO_CLIFOR";
|
||||
|
||||
TRecordset& recset = create_recordset(query);
|
||||
TConfig& ini = config();
|
||||
|
||||
TString_array lista_campi;
|
||||
ini.list_variables(lista_campi, true, "CO_CLIFOR", true);
|
||||
|
||||
TSystemisamfile clienti(LF_CLIFO);
|
||||
clienti.open(_lock);
|
||||
TRectype& rec = clienti.curr();
|
||||
|
||||
TSystemisamfile cfven(LF_CFVEN);
|
||||
cfven.open(_lock);
|
||||
TRectype& cfv_rec = cfven.curr();
|
||||
|
||||
TLif_iterator hi(this);
|
||||
while (++hi)
|
||||
{
|
||||
const char tipocf = get_str("ind_clifor")[0];
|
||||
const long codcf = get_long("cod_clifor");
|
||||
const TString4 condpag = get_str("cod_pag");
|
||||
const real fido = get_real("val_fido");
|
||||
const char sospeso = get_str("ind_bloccato")[0];
|
||||
|
||||
TString16 codabi = get_str("cod_banca1"); codabi.lpad(5,'0');
|
||||
TString16 codcab = get_str("cod_agenzia1"); codcab.lpad(5,'0');
|
||||
TString80 iban = get_str("sig_iban1"); iban << get_str("sig_bban1");
|
||||
|
||||
rec.zero();
|
||||
rec.put(CLI_TIPOCF, tipocf);
|
||||
rec.put(CLI_CODCF, codcf);
|
||||
rec.put(CLI_CODPAG, condpag);
|
||||
rec.put(CLI_FIDO, fido);
|
||||
rec.put(CLI_SOSPESO, sospeso == '0' ? false : true);
|
||||
rec.put(CLI_CODABI, codabi);
|
||||
rec.put(CLI_CODCAB, codcab);
|
||||
rec.put(CLI_IBAN, iban);
|
||||
|
||||
aggiorna_record(rec, lista_campi);
|
||||
if (test_write(clienti))
|
||||
{
|
||||
TString msg;
|
||||
msg << TR("Inserito cliente ") << " '" << tipocf << "\' -> "
|
||||
<< codcf << " - " << rec.get(CLI_RAGSOC);
|
||||
log(msg);
|
||||
}
|
||||
}
|
||||
cfven.close();
|
||||
clienti.close();
|
||||
return write_enabled();
|
||||
return true;
|
||||
}
|
||||
|
||||
// trasferisce la seconda parte dei clienti
|
||||
bool TLif_clifo_ca_anagrafiche::trasferisci()
|
||||
{
|
||||
TString query =
|
||||
"SELECT * "
|
||||
"FROM dbo.CA_ANAGRAFICHE";
|
||||
|
||||
TRecordset& recset = create_recordset(query);
|
||||
TConfig& ini = config();
|
||||
|
||||
TString_array lista_campi;
|
||||
ini.list_variables(lista_campi, true, "CA_ANAGRAFICHE", true);
|
||||
|
||||
TSystemisamfile clienti(LF_CLIFO);
|
||||
clienti.open(_lock);
|
||||
TRectype& rec = clienti.curr();
|
||||
|
||||
TSystemisamfile cfven(LF_CFVEN);
|
||||
cfven.open(_lock);
|
||||
TRectype& cfv_rec = cfven.curr();
|
||||
|
||||
TLif_iterator hi(this);
|
||||
while (++hi)
|
||||
{
|
||||
const long codcf = get_long("cod_anagra");
|
||||
|
||||
char tipocf = 'C';
|
||||
rec.zero();
|
||||
rec.put(CLI_TIPOCF, tipocf);
|
||||
rec.put(CLI_CODCF, codcf);
|
||||
int err = rec.read(clienti);
|
||||
if(err != NOERR)
|
||||
{
|
||||
tipocf = 'F';
|
||||
rec.zero();
|
||||
rec.put(CLI_TIPOCF, tipocf);
|
||||
rec.put(CLI_CODCF, codcf);
|
||||
err = rec.read(clienti);
|
||||
}
|
||||
|
||||
if(err == NOERR)
|
||||
{
|
||||
const TString4 stato = get_str("cod_naz");
|
||||
const TString80 ragsoc = get_str("des_ragsoc");
|
||||
const TString16 cofi = get_str("cod_cfisc");
|
||||
const TString16 paiv = get_str("cod_piva");
|
||||
const char tpper = get_str("flg_per_fis")[0];
|
||||
const TString80 mail = get_str("des_email1");
|
||||
const TString80 tel = get_str("sig_tel_fis");
|
||||
const TString80 fax = get_str("sig_fax_fis");
|
||||
const TString localita = get_str("des_localita_fis");
|
||||
const long cap = get_long("cod_cap_fis");
|
||||
|
||||
rec.put(CLI_TIPOCF, tipocf);
|
||||
rec.put(CLI_CODCF, codcf);
|
||||
rec.put(CLI_STATOCF, stato);
|
||||
rec.put(CLI_RAGSOC, ragsoc);
|
||||
rec.put(CLI_TIPOPERS, tpper == '0' ? false : true);
|
||||
rec.put(CLI_COFI, cofi);
|
||||
rec.put(CLI_PAIV, paiv);
|
||||
rec.put(CLI_MAIL, mail);
|
||||
rec.put(CLI_TEL, tel);
|
||||
rec.put(CLI_FAX, fax);
|
||||
rec.put(CLI_LOCCF, localita);
|
||||
rec.put(CLI_CAPCF, cap);
|
||||
|
||||
aggiorna_record(rec, lista_campi);
|
||||
if (test_write(clienti))
|
||||
{
|
||||
TString msg;
|
||||
msg << TR("Inserito cliente ") << " '" << tipocf << "\' -> "
|
||||
<< codcf << " - " << rec.get(CLI_RAGSOC);
|
||||
log(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
cfven.close();
|
||||
clienti.close();
|
||||
return write_enabled();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TLif_contratti
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
bool TLif_contratti::trasferisci()
|
||||
{
|
||||
TString query =
|
||||
"SELECT * "
|
||||
"FROM dbo.LIF_Contratti";
|
||||
|
||||
TRecordset& recset = create_recordset(query);
|
||||
TConfig& ini = config();
|
||||
TString_array lista_campi;
|
||||
ini.list_variables(lista_campi, true, "CONTRATTI", true);
|
||||
TSystemisamfile condv(LF_LVCONDV);
|
||||
TSystemisamfile rcondv(LF_LVRCONDV);
|
||||
condv.open(_lock);
|
||||
rcondv.open(_lock);
|
||||
TRectype& trec = condv.curr();
|
||||
TRectype& rrec = rcondv.curr();
|
||||
TLif_iterator hi(this);
|
||||
|
||||
TAssoc_array contratti;
|
||||
|
||||
while (++hi)
|
||||
{
|
||||
const long codcf = get_long("cod_clifor");
|
||||
TString8 tmp; tmp << codcf;
|
||||
if(!contratti.is_key(tmp))
|
||||
{
|
||||
TDate dadata(get_str("dat_inizio"));
|
||||
bool inbolla = get_str("flg_nonriportaddt")[0] == 'N' ? false : true;
|
||||
|
||||
trec.zero();
|
||||
trec.put(LVCONDV_CODCF, codcf);
|
||||
trec.put(LVCONDV_CODCONT, 1);
|
||||
trec.put(LVCONDV_DATAIN, dadata);
|
||||
trec.put(LVCONDV_STPRZBOL, inbolla);
|
||||
test_write(condv);
|
||||
contratti.add(tmp, tmp);
|
||||
}
|
||||
|
||||
rrec.zero();
|
||||
rrec.put(LVRCONDV_CODCF, codcf);
|
||||
rrec.put(LVRCONDV_CODCONT, 1);
|
||||
//real dotin(get_str("qta_iniziale"));
|
||||
//real dotod(get_str("qta_attuale"));
|
||||
|
||||
TString80 codart = get_str("cod_art");
|
||||
real prezzo(get_str("prezzo_inuso"));
|
||||
real mincic(get_str("qta_minimociclaggio"));
|
||||
real valcon(get_str("valore_convenzionale"));
|
||||
real percfo(get_str("perc_forfait"));
|
||||
real przfis(get_str("prezzo_fisso_articolo"));
|
||||
|
||||
bool bloccato = get_str("flg_disabilitato")[0] == '0' ? false : true;
|
||||
|
||||
rrec.put(LVRCONDV_CODART, codart);
|
||||
rrec.put(LVRCONDV_PREZZO, prezzo);
|
||||
rrec.put(LVRCONDV_MINCIC, mincic);
|
||||
rrec.put(LVRCONDV_VALCONV, valcon);
|
||||
rrec.put(LVRCONDV_FORFPERCL, percfo);
|
||||
rrec.put(LVRCONDV_ARTBLOC, bloccato);
|
||||
rrec.put(LVRCONDV_IMPFISART, przfis);
|
||||
|
||||
test_write(rcondv);
|
||||
}
|
||||
condv.close();
|
||||
rcondv.close();
|
||||
|
||||
return write_enabled();
|
||||
}
|
||||
|
||||
bool TLif_articoli::trasferisci()
|
||||
{
|
||||
TString query =
|
||||
"SELECT * "
|
||||
"FROM dbo.MG_ARTICOLI";
|
||||
|
||||
TRecordset& recset = create_recordset(query);
|
||||
TConfig& ini = config();
|
||||
|
||||
TString_array lista_campi;
|
||||
ini.list_variables(lista_campi, true, "MG_ARTICOLI", true);
|
||||
|
||||
TSystemisamfile anamag(LF_ANAMAG);
|
||||
anamag.open(_lock);
|
||||
TRectype& rec = anamag.curr();
|
||||
|
||||
TLif_iterator hi(this);
|
||||
while (++hi)
|
||||
{
|
||||
const TString80 codart = get_str("cod_art");
|
||||
const TString80 descr = get_str("des_articolo");
|
||||
const TString descragg = get_str("des_articolo_ex");
|
||||
const real plordo(get_str("qta_pes_lordo_kg"));
|
||||
const real pnetto(get_str("qta_pes_netto_kg"));
|
||||
const long ppconf = get_long("num_colli");
|
||||
|
||||
rec.put(ANAMAG_CODART, codart);
|
||||
rec.put(ANAMAG_DESCR, descr);
|
||||
rec.put(ANAMAG_DESCRAGG, descragg);
|
||||
rec.put(ANAMAG_PESO, plordo);
|
||||
rec.put(ANAMAG_TARA, plordo - pnetto);
|
||||
rec.put(ANAMAG_PPCONF, ppconf);
|
||||
|
||||
aggiorna_record(rec, lista_campi);
|
||||
if (test_write(anamag))
|
||||
{
|
||||
TString msg;
|
||||
msg << TR("Inserito articolo ") << " '" << codart << "\' -> " << descr;
|
||||
log(msg);
|
||||
}
|
||||
}
|
||||
anamag.close();
|
||||
return write_enabled();
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TImportazione_lif_msk
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TImportazione_lif_msk : public TAutomask
|
||||
{
|
||||
protected:
|
||||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||||
void serialize(bool bSave);
|
||||
|
||||
public:
|
||||
void trasferisci();
|
||||
|
||||
TImportazione_lif_msk();
|
||||
virtual ~TImportazione_lif_msk();
|
||||
};
|
||||
|
||||
// Funzione di trasferimento dati da/verso file .ini con lo stesso nome della maschera
|
||||
// Andrebbe messo in libreria
|
||||
void TImportazione_lif_msk::serialize(bool bSave)
|
||||
{
|
||||
TFilename n = source_file(); n.ext("ini"); // Construisce il nome del .ini in base al .msk
|
||||
TConfig cfg(n, "Main"); // Crea il file di configurazione
|
||||
TString4 id;
|
||||
for (int i = fields()-1; i >= 0; i--) // Scandisce tutti i campi della maschera ...
|
||||
{
|
||||
TMask_field& f = fld(i);
|
||||
if (f.active() && f.is_loadable()) // ... selezionando solo quelli editabili
|
||||
{
|
||||
id.format("%d", f.dlg());
|
||||
if (bSave) // A seconda del flag di scrittura ...
|
||||
cfg.set(id, f.get()); // ... o scrive sul .ini
|
||||
else
|
||||
f.set(cfg.get(id)); // ... o legge dal .ini
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TImportazione_lif_msk::trasferisci()
|
||||
{
|
||||
TString query_header1;
|
||||
TString query_header2;
|
||||
|
||||
query_header1 << "ODBC(" << get(F_DSN1) << ',' << get(F_USR) << ',' << get(F_PWD) << ")\n";
|
||||
query_header2 << "ODBC(" << get(F_DSN2) << ',' << get(F_USR) << ',' << get(F_PWD) << ")\n";
|
||||
|
||||
TReport_book book;
|
||||
TLif_log log;
|
||||
|
||||
bool rep_to_print = false;
|
||||
bool go_on = true;
|
||||
|
||||
if (go_on && get_bool(F_ANAGRAFICHE))
|
||||
{
|
||||
TLif_clifo_co_clifor pc;
|
||||
pc.init(TR("Clienti / Fornitori"), query_header1, log);
|
||||
go_on = pc.trasferisci();
|
||||
|
||||
TLif_clifo_ca_anagrafiche pc1;
|
||||
pc1.init(TR("Clienti / Fornitori"), query_header2, log);
|
||||
go_on = pc1.trasferisci();
|
||||
|
||||
book.add(log);
|
||||
rep_to_print = true;
|
||||
}
|
||||
|
||||
if (go_on && get_bool(F_CONTRATTI))
|
||||
{
|
||||
TLif_contratti pc;
|
||||
pc.init(TR("Contratti"), query_header1, log);
|
||||
go_on = pc.trasferisci();
|
||||
book.add(log);
|
||||
rep_to_print = true;
|
||||
}
|
||||
|
||||
if (go_on && get_bool(F_ARTICOLI))
|
||||
{
|
||||
TLif_articoli pc;
|
||||
pc.init(TR("Articoli"), query_header1, log);
|
||||
go_on = pc.trasferisci();
|
||||
book.add(log);
|
||||
rep_to_print = true;
|
||||
}
|
||||
|
||||
if (rep_to_print && book.pages() > 0)
|
||||
book.preview();
|
||||
}
|
||||
|
||||
bool TImportazione_lif_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||||
{
|
||||
switch (o.dlg())
|
||||
{
|
||||
case DLG_OK:
|
||||
if (e == fe_button)
|
||||
serialize(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TImportazione_lif_msk::TImportazione_lif_msk() : TAutomask("pl0002100a")
|
||||
{
|
||||
serialize(false);
|
||||
}
|
||||
|
||||
TImportazione_lif_msk::~TImportazione_lif_msk()
|
||||
{ }
|
||||
|
||||
/////////////////////////////////////
|
||||
//// TIMPORTAZIONE_LIF_APP ////
|
||||
/////////////////////////////////////
|
||||
|
||||
class TImportazione_lif_app : public TSkeleton_application
|
||||
{
|
||||
protected:
|
||||
virtual const char * extra_modules() const {return "ba";}
|
||||
virtual void main_loop();
|
||||
};
|
||||
|
||||
void TImportazione_lif_app::main_loop()
|
||||
{
|
||||
TImportazione_lif_msk mask;
|
||||
while (mask.run() == K_ENTER)
|
||||
mask.trasferisci();
|
||||
}
|
||||
|
||||
int pl0002100(int argc, char* argv[])
|
||||
{
|
||||
TImportazione_lif_app ih;
|
||||
ih.run(argc, argv, APPNAME);
|
||||
return 0;
|
||||
}
|
66
ps/pl0002100a.uml
Executable file
66
ps/pl0002100a.uml
Executable file
@ -0,0 +1,66 @@
|
||||
#include "pl0002100a.h"
|
||||
|
||||
TOOLBAR "topbar" 0 0 0 2
|
||||
|
||||
#include <elabar.h>
|
||||
|
||||
ENDPAGE
|
||||
|
||||
PAGE "Importatore LIF" 0 2 0 0
|
||||
|
||||
GROUPBOX DLG_NULL 78 5
|
||||
BEGIN
|
||||
PROMPT 1 1 "@bArchivi"
|
||||
END
|
||||
|
||||
BOOLEAN F_ANAGRAFICHE
|
||||
BEGIN
|
||||
PROMPT 2 2 "Anagrafiche clienti / Fornitori"
|
||||
END
|
||||
|
||||
BOOLEAN F_CONTRATTI
|
||||
BEGIN
|
||||
PROMPT 2 3 "Contratti"
|
||||
END
|
||||
|
||||
BOOLEAN F_ARTICOLI
|
||||
BEGIN
|
||||
PROMPT 2 4 "Articoli"
|
||||
END
|
||||
|
||||
|
||||
ENDPAGE
|
||||
|
||||
PAGE "Configurazione" -1 -1 78 18
|
||||
|
||||
GROUPBOX DLG_NULL 78 6
|
||||
BEGIN
|
||||
PROMPT 1 1 "@bDatabase"
|
||||
END
|
||||
|
||||
STRING F_DSN1 30
|
||||
BEGIN
|
||||
PROMPT 2 2 "DSN 1 "
|
||||
CHECKTYPE REQUIRED
|
||||
END
|
||||
|
||||
STRING F_DSN2 30
|
||||
BEGIN
|
||||
PROMPT 2 3 "DSN 2 "
|
||||
CHECKTYPE REQUIRED
|
||||
END
|
||||
|
||||
STRING F_USR 16
|
||||
BEGIN
|
||||
PROMPT 2 4 "User "
|
||||
END
|
||||
|
||||
STRING F_PWD 16
|
||||
BEGIN
|
||||
PROMPT 2 5 "Password "
|
||||
FLAGS "*"
|
||||
END
|
||||
|
||||
ENDPAGE
|
||||
|
||||
ENDMASK
|
493
ps/pl0002lib.cpp
Executable file
493
ps/pl0002lib.cpp
Executable file
@ -0,0 +1,493 @@
|
||||
#include "pl0002lib.h"
|
||||
//#include "../lv/lvlib.h"
|
||||
|
||||
#include <applicat.h>
|
||||
#include <automask.h>
|
||||
#include <defmask.h>
|
||||
#include <progind.h>
|
||||
#include <reprint.h>
|
||||
#include <reputils.h>
|
||||
#include <tabutil.h>
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TLif_iterator
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
bool TLif_iterator::cancelled() const
|
||||
{
|
||||
return _pi != NULL && _pi->iscancelled();
|
||||
}
|
||||
|
||||
bool TLif_iterator::ok() const
|
||||
{
|
||||
if (cancelled())
|
||||
return _ht->log_cancelled();
|
||||
return _rec >= 0 && _rec < _ht->recordset().items();
|
||||
}
|
||||
|
||||
TLif_iterator& TLif_iterator::operator=(TRecnotype n)
|
||||
{
|
||||
if (_pi != NULL)
|
||||
_pi->setstatus(n+1);
|
||||
_ht->recordset().move_to(_rec = n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TLif_iterator& TLif_iterator::operator++()
|
||||
{
|
||||
return *this = ++_rec;
|
||||
}
|
||||
|
||||
TLif_iterator::TLif_iterator(TLif_transfer* ht) : _ht(ht), _pi(NULL)
|
||||
{
|
||||
const TRecnotype tot = _ht->recordset().items();
|
||||
TString title;
|
||||
title << _ht->title() << ": " << tot << ' ' << TR("righe");
|
||||
if (tot > 1)
|
||||
_pi = new TProgind(tot, title, true, true);
|
||||
else
|
||||
::begin_wait();
|
||||
|
||||
if (tot > 0)
|
||||
_ht->log(title);
|
||||
|
||||
_rec = -1;
|
||||
}
|
||||
|
||||
TLif_iterator::~TLif_iterator()
|
||||
{
|
||||
if (_pi != NULL)
|
||||
delete _pi;
|
||||
else
|
||||
::end_wait();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Cache tabelle
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TCache_tab : public TCache_th
|
||||
{
|
||||
protected:
|
||||
virtual TObject* key2obj(const char* key);
|
||||
|
||||
public:
|
||||
virtual const TString& decode(const TToken_string& cod_codtab);
|
||||
TCache_tab(TLif_transfer* ht) : TCache_th(ht) {}
|
||||
};
|
||||
|
||||
const TString& TCache_tab::decode(const TToken_string& cod_codtab)
|
||||
{
|
||||
TString4 cod; cod_codtab.get(0, cod);
|
||||
if (cod.full())
|
||||
{
|
||||
const TRectype& rec = *(const TRectype*)objptr(cod_codtab);
|
||||
if (!rec.empty())
|
||||
{
|
||||
const char* field = "CODTAB";
|
||||
if (cod == "%TPM" || cod == "%TPP" || cod == "%TPI") // Tipo trasporto e porto
|
||||
field = "S6";
|
||||
return rec.get(field);
|
||||
}
|
||||
}
|
||||
return EMPTY_STRING;
|
||||
}
|
||||
|
||||
TObject* TCache_tab::key2obj(const char* key)
|
||||
{
|
||||
TToken_string tok(key);
|
||||
TString4 tab = tok.get(); tab.upper();
|
||||
TString80 cod = tok.get(); cod.upper();
|
||||
|
||||
if (tab == "%IVA")
|
||||
{
|
||||
// Campo non digerisce i codici IVA numerici di un solo carattere
|
||||
if (cod.len() < 2 && isdigit(cod[0]))
|
||||
cod.right_just(2, '0'); // per cui aggiungo uno 0 iniziale
|
||||
}
|
||||
|
||||
TTable table(tab);
|
||||
table.put("CODTAB", cod);
|
||||
if (table.read() != NOERR)
|
||||
{
|
||||
table.zero();
|
||||
table.put("CODTAB", cod);
|
||||
table.put("S0", cod);
|
||||
test_write(table);
|
||||
}
|
||||
return table.curr().dup();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TLif_transfer
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
void TLif_transfer::init(const char* title, const char* qry_hdr, TLif_log& log)
|
||||
{
|
||||
_log = &log;
|
||||
_log->reset();
|
||||
_log->set_title(title);
|
||||
_query_header = qry_hdr;
|
||||
_write_enabled = true;
|
||||
}
|
||||
|
||||
const TString& TLif_transfer::title() const
|
||||
{ return _log->title(); }
|
||||
|
||||
void TLif_transfer::log(const char* msg, int sev) const
|
||||
{
|
||||
_log->log(sev, msg);
|
||||
}
|
||||
|
||||
TRecordset& TLif_transfer::create_recordset(const char* query)
|
||||
{
|
||||
if (_recset != NULL)
|
||||
{
|
||||
delete _recset;
|
||||
_recset = NULL;
|
||||
}
|
||||
if (_outset != NULL)
|
||||
{
|
||||
_outset->exec("COMMIT TRANS");
|
||||
delete _outset;
|
||||
_outset = NULL;
|
||||
}
|
||||
|
||||
TString qry = query;
|
||||
if (!qry.starts_with("US") && !qry.starts_with("ODBC"))
|
||||
qry.insert(query_header());
|
||||
_recset = ::create_recordset(qry);
|
||||
return *_recset;
|
||||
}
|
||||
|
||||
const TRecordset& TLif_transfer::recordset() const
|
||||
{
|
||||
CHECK(_recset != NULL, "NULL recordset");
|
||||
return *_recset;
|
||||
}
|
||||
|
||||
TRecordset& TLif_transfer::recordset()
|
||||
{
|
||||
CHECK(_recset != NULL, "NULL recordset");
|
||||
return *_recset;
|
||||
}
|
||||
|
||||
long TLif_transfer::odbc_exec(const char* cmd)
|
||||
{
|
||||
long err = 0;
|
||||
if (_write_enabled)
|
||||
{
|
||||
if (_outset == NULL)
|
||||
{
|
||||
_outset = new TODBC_recordset(query_header());
|
||||
err = _outset->exec("BEGIN TRANS");
|
||||
}
|
||||
if (err >= 0)
|
||||
{
|
||||
err = _outset->exec(cmd);
|
||||
if (err < 0)
|
||||
{
|
||||
log("", 0); // Salto una riga
|
||||
TParagraph_string msg(cmd, 100);
|
||||
FOR_EACH_TOKEN(msg, str)
|
||||
log(str, 0); // Riporto tutta la query
|
||||
log_error(TR("ERRORE in esecuzione della query."));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TString msg;
|
||||
msg << TR("ERRORE di connessione a ") << _outset->dsn() << " : BEGIN TRANS";
|
||||
log_error(msg);
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
bool TLif_transfer::log_error(const char* msg)
|
||||
{
|
||||
log(msg, 2);
|
||||
if (_write_enabled)
|
||||
{
|
||||
_write_enabled = false;
|
||||
log("");
|
||||
log(TR("LA SCRITTURA SUGLI ARCHIVI VIENE DISABILITATA DA QUESTO MOMENTO IN POI"), 2);
|
||||
log("");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TLif_transfer::log_cancelled()
|
||||
{
|
||||
return log_error(TR("Procedura interrotta dall'utente"));
|
||||
}
|
||||
|
||||
bool TLif_transfer::test_write(TBaseisamfile& file)
|
||||
{
|
||||
int err = NOERR;
|
||||
if (_write_enabled)
|
||||
{
|
||||
err = file.rewrite_write();
|
||||
if (err != NOERR)
|
||||
{
|
||||
TString msg;
|
||||
TString80 code, desc;
|
||||
const int logic = file.num();
|
||||
if (logic == LF_TAB || logic == LF_TABCOM || logic == LF_TABMOD)
|
||||
{
|
||||
code = file.get("CODTAB");
|
||||
desc = file.get("S0");
|
||||
}
|
||||
else
|
||||
{
|
||||
code = file.curr().build_key(1);
|
||||
desc = file.curr().build_key(2);
|
||||
}
|
||||
msg.format(FR("Errore %d durante la scrittura sul file %d: %s - %s"),
|
||||
err, logic, (const char*)code, (const char*)desc);
|
||||
log_error(msg);
|
||||
}
|
||||
}
|
||||
return err == NOERR;
|
||||
}
|
||||
|
||||
const TString& TLif_transfer::get_str(const char* field) const
|
||||
{
|
||||
return recordset().get(field).as_string();
|
||||
}
|
||||
|
||||
const TString& TLif_transfer::get_real_str(const char* campo) const
|
||||
{
|
||||
const TVariant& var = recordset().get(campo);
|
||||
if (var.is_zero())
|
||||
return EMPTY_STRING;
|
||||
return var.as_string();
|
||||
}
|
||||
|
||||
real TLif_transfer::get_real(const char* field) const
|
||||
{
|
||||
return recordset().get(field).as_real();
|
||||
}
|
||||
|
||||
long TLif_transfer::get_long(const char* field) const
|
||||
{
|
||||
return recordset().get(field).as_int();
|
||||
}
|
||||
|
||||
const TString& TLif_transfer::decode_value(const char* tab, const TString& cod)
|
||||
{
|
||||
if (cod.full())
|
||||
{
|
||||
if (_tab == NULL)
|
||||
_tab = new TCache_tab(this);
|
||||
TToken_string tok; tok.add(tab); tok.add(cod);
|
||||
return _tab->decode(tok);
|
||||
}
|
||||
return EMPTY_STRING;
|
||||
}
|
||||
|
||||
const TString& TLif_transfer::decode_field(const char* tab, const char* field)
|
||||
{
|
||||
const TString& cod = get_str(field);
|
||||
return decode_value(tab, cod);
|
||||
}
|
||||
|
||||
const TString& TLif_transfer::build_insert_query(const char* table, const char* f, const char* v) const
|
||||
{
|
||||
TString qry(255);
|
||||
|
||||
qry << "INSERT INTO " << table;
|
||||
|
||||
TAuto_token_string fields(f);
|
||||
TToken_string values(v);
|
||||
if (fields.items() > 0)
|
||||
{
|
||||
qry << " (";
|
||||
FOR_EACH_TOKEN(fields, tok)
|
||||
qry << tok << ',';
|
||||
qry.rtrim(1);
|
||||
qry << ')';
|
||||
}
|
||||
qry << " VALUES (";
|
||||
|
||||
TString tmp;
|
||||
FOR_EACH_TOKEN(values, tok)
|
||||
{
|
||||
tmp = tok;
|
||||
if (tmp.full() && !tmp.starts_with("0") && real::is_natural(tmp))
|
||||
qry << tok;
|
||||
else
|
||||
{
|
||||
if (tmp[0] != '\'')
|
||||
{
|
||||
for (int i = tmp.len()-1; i >= 0; i--)
|
||||
{
|
||||
if (tmp[i] == '\'')
|
||||
tmp.insert("'", i);
|
||||
}
|
||||
qry << '\'' << tmp << '\'';
|
||||
}
|
||||
else
|
||||
qry << tmp;
|
||||
}
|
||||
qry << ',';
|
||||
}
|
||||
qry.rtrim(1);
|
||||
qry << ')';
|
||||
|
||||
return get_tmp_string() = qry;
|
||||
}
|
||||
|
||||
TLif_transfer::TLif_transfer()
|
||||
: _log(NULL), _config("hacnv100a.ini"), _recset(NULL), _outset(NULL), _tab(NULL)
|
||||
{}
|
||||
|
||||
TLif_transfer::~TLif_transfer()
|
||||
{
|
||||
if (_tab != NULL)
|
||||
delete _tab;
|
||||
if (_outset != NULL)
|
||||
{
|
||||
_outset->exec("COMMIT TRANS");
|
||||
delete _outset;
|
||||
}
|
||||
if (_recset != NULL)
|
||||
delete _recset;
|
||||
}
|
||||
|
||||
void TLif_transfer::aggiorna_record(TRectype& rec, const TString_array& lista_campi)
|
||||
{
|
||||
TString campo_dest, campo_orig, valore, str;
|
||||
FOR_EACH_ARRAY_ROW(lista_campi,i,row)
|
||||
{
|
||||
row->get(0, campo_dest);
|
||||
row->get(1, campo_orig);
|
||||
if (campo_orig.full())
|
||||
{
|
||||
if (campo_orig[0] == '_')
|
||||
{
|
||||
if (campo_orig.starts_with("_SCONTO")) // è uno sconto (ca..o!)
|
||||
{
|
||||
valore.cut(0);
|
||||
real sconto;
|
||||
TString8 field;
|
||||
for (int i = 1; i < 6; i++)
|
||||
{
|
||||
field.format("Sconto%1d",i);
|
||||
sconto = get_real(field);
|
||||
sconto.round(2);
|
||||
if (sconto != ZERO)
|
||||
{
|
||||
valore << sconto.string();
|
||||
valore << "+";
|
||||
}
|
||||
}
|
||||
if (valore.len()>0)
|
||||
valore = valore.left(valore.len()-1);
|
||||
} else
|
||||
if (campo_orig.starts_with("_REAL")) // è un real
|
||||
{
|
||||
const TString80 campo = campo_orig.after(',');
|
||||
valore = get_real_str(campo);
|
||||
} else
|
||||
if (campo_orig.starts_with("_ROUND")) // arrotondo a due decimali
|
||||
{
|
||||
const TString80 campo = campo_orig.after(',');
|
||||
real contenuto = get_real(campo);
|
||||
contenuto.round(2);
|
||||
valore = contenuto.string();
|
||||
} else
|
||||
if (campo_orig.starts_with("_FISSO")) // valore fisso indicato in configurazione
|
||||
{
|
||||
valore = campo_orig.after(',');
|
||||
valore.trim();
|
||||
} else
|
||||
if (campo_orig.starts_with("_STREXPR")) // formato _STREXPR, espressione
|
||||
{
|
||||
TExpression expr(campo_orig.after(','), _strexpr);
|
||||
for (int v = 0; v < expr.numvar(); v++)
|
||||
{
|
||||
const char* varname = expr.varname(v);
|
||||
expr.setvar(v, get_str(varname));
|
||||
}
|
||||
valore = expr.as_string();
|
||||
valore.trim();
|
||||
} else
|
||||
if (campo_orig.starts_with("_TAB")) // formato _TAB,<tabella da leggere>,<valore CODTAB>, <campo da leggere>
|
||||
{
|
||||
TToken_string elabora(campo_orig, ',');
|
||||
const TString4 tab = elabora.get(1); // tabella da leggere
|
||||
const TString16 codtab = get_str(elabora.get());
|
||||
const TString16 campotab = elabora.get();
|
||||
valore = cache().get(tab, codtab, campotab);
|
||||
} else
|
||||
if (campo_orig.starts_with("_TRADUCI"))
|
||||
{
|
||||
const TString80 campo = campo_orig.after(',');
|
||||
const TString80 contenuto = get_str(campo);
|
||||
TConfig& ini = config();
|
||||
valore = ini.get(contenuto,campo);
|
||||
}
|
||||
else
|
||||
valore.cut(0);
|
||||
}
|
||||
else
|
||||
valore = get_str(campo_orig);
|
||||
rec.put(campo_dest, valore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TLif_transfer::aggiorna_ini(TConfig& conf, const TString_array& lista_campi)
|
||||
{
|
||||
TString campo_dest, campo_orig, valore, str;
|
||||
FOR_EACH_ARRAY_ROW(lista_campi,i,row)
|
||||
{
|
||||
row->get(0, campo_dest);
|
||||
row->get(1, campo_orig);
|
||||
if (campo_orig.full())
|
||||
{
|
||||
if (campo_orig[0] == '_')
|
||||
{
|
||||
if (campo_orig.starts_with("_FISSO")) // valore fisso indicato in configurazione
|
||||
{
|
||||
valore = campo_orig.after(',');
|
||||
valore.trim();
|
||||
} else
|
||||
if (campo_orig.starts_with("_STREXPR")) // formato _STREXPR, espressione
|
||||
{
|
||||
TExpression expr(campo_orig.after(','), _strexpr);
|
||||
for (int v = 0; v < expr.numvar(); v++)
|
||||
{
|
||||
const char* varname = expr.varname(v);
|
||||
expr.setvar(v, get_str(varname));
|
||||
}
|
||||
valore = expr.as_string();
|
||||
valore.trim();
|
||||
} else
|
||||
if (campo_orig.starts_with("_TAB")) // formato _TAB,<tabella da leggere>,<valore CODTAB>, <campo da leggere>
|
||||
{
|
||||
TToken_string elabora(campo_orig, ',');
|
||||
const TString4 tab = elabora.get(1); // tabella da leggere
|
||||
const TString16 codtab = get_str(elabora.get());
|
||||
const TString16 campotab = elabora.get();
|
||||
valore = cache().get(tab, codtab, campotab);
|
||||
}
|
||||
else
|
||||
if (campo_orig.starts_with("_TRADUCI"))
|
||||
{
|
||||
const TString80 campo = campo_orig.after(',');
|
||||
const TString80 contenuto = get_str(campo);
|
||||
TConfig& ini = config();
|
||||
valore = ini.get(contenuto,campo);
|
||||
}
|
||||
else
|
||||
valore.cut(0);
|
||||
}
|
||||
else
|
||||
valore = get_str(campo_orig);
|
||||
conf.set(campo_dest, valore);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user