git-svn-id: svn://10.65.10.50/branches/R_10_00@22898 c028cbd2-c16b-5b4b-a496-9718f37d4682
271 lines
6.2 KiB
C++
Executable File
271 lines
6.2 KiB
C++
Executable File
#include "velib.h"
|
|
#include "ve6700a.h"
|
|
|
|
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <config.h>
|
|
#include <defmask.h>
|
|
#include <execp.h>
|
|
#include <incstr.h>
|
|
#include <golem.h>
|
|
#include <prefix.h>
|
|
|
|
#include <clifo.h>
|
|
#include <doc.h>
|
|
#include <rdoc.h>
|
|
|
|
#include "ve6700a.h"
|
|
#include "velib04.h"
|
|
#include "../mg/mglib.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Maschera principale
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TCopia_interattiva_mask : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
TCopia_interattiva_mask() : TAutomask("ve6700a") {}
|
|
virtual ~TCopia_interattiva_mask() {}
|
|
};
|
|
|
|
bool TCopia_interattiva_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case DLG_SAVEREC:
|
|
if (e == fe_button)
|
|
stop_run(K_AUTO_ENTER);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Applicazione principale
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TCopia_interattiva : public TSkeleton_application
|
|
{
|
|
TDocumento * _outdoc;
|
|
TDocumento * _indoc;
|
|
TFilename _ini_name;
|
|
TArray _arts;
|
|
TString4 _num_in, _stato_in, _tipo_doc;
|
|
long _firm;
|
|
char _stato_fin;
|
|
bool _copy_header;
|
|
|
|
public:
|
|
bool load();
|
|
bool load_indoc(const TMask & m);
|
|
bool aggiorna_in();
|
|
void copia_doc();
|
|
virtual void main_loop();
|
|
};
|
|
|
|
bool TCopia_interattiva::load()
|
|
{
|
|
bool ok = false;
|
|
|
|
if (argc() > 2)
|
|
{
|
|
const TString& arg = argv(2);
|
|
if ((arg[0] != '-' && arg[0] != '/') || (arg[1] != 'i' && arg[1] != 'I'))
|
|
return false;
|
|
|
|
_ini_name = arg.mid(2);
|
|
if (_ini_name.blank() && argc() > 3)
|
|
_ini_name = argv(3);
|
|
|
|
if (_ini_name.exist())
|
|
{
|
|
TConfig ini(_ini_name, "Transaction");
|
|
const char provv = ini.get_char("ProvvOut");
|
|
const int anno = ini.get_int("AnnoOut");
|
|
const TString4 codnum = ini.get("CodNumOut");
|
|
const long numdoc = ini.get_long("NDocOut");
|
|
|
|
const TElaborazione_esterna ee(ini.get("Action"));
|
|
_num_in = ee.codice_numerazione_iniziale();
|
|
_stato_in << ee.stato_iniziale(0);
|
|
_stato_fin = ee.stato_finale_doc_iniziale()[0];
|
|
_copy_header = ee.aggiorna_testata_se_vuoto();
|
|
|
|
ok = _outdoc->read(provv, anno, codnum, numdoc) == NOERR;
|
|
|
|
const int i = _outdoc->physical_rows();
|
|
|
|
TString16 para; para.format("%d", LF_DOC);
|
|
_tipo_doc = ini.get(DOC_TIPODOC, para);
|
|
_firm = -1;
|
|
|
|
if (ok)
|
|
{
|
|
TFilename c("ve6700.ini");
|
|
if (c.custom_path())
|
|
{
|
|
TConfig val(c);
|
|
|
|
_firm = val.get_long("Firm", "Main", -1, -1L);
|
|
|
|
TString16 para;
|
|
TString tmp;
|
|
|
|
para.format("%d", LF_DOC);
|
|
val.set_paragraph(para);
|
|
TAssoc_array& vars = val.list_variables();
|
|
FOR_EACH_ASSOC_STRING(vars, obj, key, str)
|
|
{
|
|
if (*str == '"')
|
|
{
|
|
tmp = str;
|
|
tmp.strip("\"");
|
|
str = tmp;
|
|
}
|
|
_outdoc->put(key, str);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool TCopia_interattiva::load_indoc(const TMask& m)
|
|
{
|
|
// Uso avanzatissimo: m.get(NOME_CAMPO) invece di m.get(IDENTIFICATORE_CAMPO)
|
|
const char provv = m.get(DOC_PROVV)[0];
|
|
const int anno = atoi(m.get(DOC_ANNO));
|
|
const TString4 codnum = m.get(DOC_CODNUM);
|
|
const long numdoc = atol(m.get(DOC_NDOC));
|
|
|
|
const bool ok = numdoc > 0 && _indoc->read(provv, anno, codnum, numdoc) == NOERR;
|
|
if (ok)
|
|
{
|
|
const int rows = _indoc->physical_rows();
|
|
for (int i = 1; i <= rows; i++)
|
|
{
|
|
const TRiga_documento& r = (*_indoc)[i];
|
|
if (r.is_articolo())
|
|
{
|
|
const TString& codice = r.get(RDOC_CODARTMAG);
|
|
TArticolo* art = new TArticolo(codice);
|
|
art->um();
|
|
art->deslin();
|
|
art->codcorr();
|
|
_arts.add(art);
|
|
}
|
|
const TString & memo = r.get(RDOC_DESCEST); // Forza lettura memo!
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TCopia_interattiva::aggiorna_in()
|
|
{
|
|
_indoc->stato(_stato_fin);
|
|
const int err = _indoc->rewrite();
|
|
|
|
if (err != NOERR)
|
|
return error_box(FR("Errore %d di riscrittura del documento sorgente"), err);
|
|
|
|
const int rows = _indoc->physical_rows();
|
|
|
|
for (int j = 1; j <= rows; j++)
|
|
{
|
|
const TRiga_documento& rin = (*_indoc)[j];
|
|
TRiga_documento& rout = _outdoc->new_row(); // ... crea una riga nuova e
|
|
|
|
_outdoc->copy_data(rout, rin); // copiaci tutti i campi della riga sorgente.
|
|
rout.reset_original_rdoc_key(); // cancella riferimenti inutili
|
|
}
|
|
|
|
return err == NOERR;
|
|
}
|
|
|
|
void TCopia_interattiva::copia_doc()
|
|
{
|
|
_outdoc->reset_memo();
|
|
|
|
const int rows = _outdoc->physical_rows();
|
|
for (int j = 1; j <= rows; j++)
|
|
{
|
|
TRiga_documento& r = (*_outdoc)[j];
|
|
r.reset_memo();
|
|
}
|
|
|
|
const int err = _outdoc->rewrite();
|
|
if (err != NOERR)
|
|
{
|
|
error_box(FR("Errore %d di riscrittura del documento destinazione"), err);
|
|
return;
|
|
}
|
|
|
|
TLocalisamfile anamag(LF_ANAMAG);
|
|
FOR_EACH_ARRAY_ITEM(_arts, i, o)
|
|
{
|
|
TArticolo* art = (TArticolo *) o;
|
|
|
|
anamag.put(ANAMAG_CODART, art->codice());
|
|
if (anamag.read() != NOERR)
|
|
{
|
|
const int err = art->write(anamag);
|
|
if (err != NOERR)
|
|
error_box(FR("Errore %d nella scrittura dell'articolo %s"),
|
|
err, (const char*)art->codice());
|
|
}
|
|
}
|
|
TConfig ini(_ini_name, "Main");
|
|
ini.set("Result", "OUTDOC");
|
|
}
|
|
|
|
void TCopia_interattiva::main_loop()
|
|
{
|
|
open_files(LF_TAB, LF_TABCOM, LF_DOC, LF_RIGHEDOC, LF_MOVMAG, NULL);
|
|
open_files(LF_ANAMAG, LF_CLIFO, LF_CFVEN, LF_OCCAS, LF_RMOVMAG, NULL);
|
|
|
|
_outdoc = new TDocumento; // _outdoc serve nella load
|
|
if (load())
|
|
{
|
|
const long the_firm = get_firm();
|
|
int err = safely_close_closeable_isamfiles();
|
|
|
|
set_firm(_firm);
|
|
_indoc = new TDocumento();
|
|
|
|
TCopia_interattiva_mask m;
|
|
m.set(F_CODDITTA, _firm, true);
|
|
m.set(F_CODNUM, _num_in);
|
|
m.set(F_STATO, _stato_in);
|
|
m.set(F_TIPODOC, _tipo_doc);
|
|
|
|
KEY k = m.run();
|
|
|
|
bool ok = true;
|
|
|
|
ok = load_indoc(m);
|
|
if (ok)
|
|
ok = aggiorna_in();
|
|
delete _indoc;
|
|
err = safely_close_closeable_isamfiles();
|
|
set_firm(the_firm);
|
|
copia_doc();
|
|
}
|
|
delete _outdoc;
|
|
}
|
|
|
|
int ve6700(int argc, char** argv)
|
|
{
|
|
TCopia_interattiva app;
|
|
|
|
app.run(argc, argv, TR("Trasferimento documenti"));
|
|
return 0;
|
|
}
|