981678913a
Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione P@rtners 2.0 patch 349 git-svn-id: svn://10.65.10.50/trunk@10709 c028cbd2-c16b-5b4b-a496-9718f37d4682
257 lines
6.2 KiB
C++
Executable File
257 lines
6.2 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <filetext.h>
|
|
#include <comuni.h>
|
|
#include "ba5300.h"
|
|
|
|
#define TABBAN_INDIR "S2"
|
|
#define TABBAN_NCIVICO "S7"
|
|
#define TABBAN_CODCOM "S5"
|
|
#define TABBAN_CAP "S3"
|
|
|
|
const char* cap2comune(const TString& field, const TString& denom);
|
|
const char* denom2comune(const TString& field, const char * stato=NULL);
|
|
const char* denom2com_alt(const TString& dencom, const char * stato=NULL);
|
|
bool confr_nomicomune(const TString & com1, const TString & com2);
|
|
|
|
class TABICAB_file : public TFile_text
|
|
{
|
|
int spezza_indirizzo(TString & indir,TString & ncivico);
|
|
protected:
|
|
// virtual void validate(TCursor& cur, TRecord_text &rec, TToken_string &val, TString& str)
|
|
virtual void preformat_field(const TFieldref&field,TString &str,TRelation& rel,const TString & tipo_tr);
|
|
virtual bool pre_writerel(TRelation& rel,const TRecord_text& rec);
|
|
public:
|
|
TABICAB_file(const char * path);
|
|
virtual ~TABICAB_file() {}
|
|
};
|
|
|
|
TABICAB_file::TABICAB_file(const char * path):
|
|
TFile_text(path, "ba5300.ini")
|
|
{
|
|
}
|
|
|
|
void TABICAB_file::preformat_field(const TFieldref&field,TString &str,TRelation& rel,const TString & tipo_tr)
|
|
{
|
|
if ((tipo_tr==TRACCIATO_ABI && field.name()=="S0") ||
|
|
(tipo_tr==TRACCIATO_DENCAB && field.name()=="S0")||
|
|
(tipo_tr==TRACCIATO_CAB && field.name()=="S3")
|
|
)
|
|
// ho già composto la chiave; cerco il record
|
|
rel.read();
|
|
}
|
|
|
|
bool TABICAB_file::pre_writerel(TRelation& rel,const TRecord_text& rec)
|
|
{
|
|
bool can_write=TRUE;
|
|
TRectype & curr_rec=rel.lfile().curr();
|
|
if (rec.type()==TRACCIATO_CAB)
|
|
{
|
|
// ***** check indirizzo/Ncivico
|
|
TString indir(rec.row(TXTCAB_INDIRIZZO));
|
|
TString nciv;
|
|
spezza_indirizzo(indir,nciv);
|
|
|
|
curr_rec.put(TABBAN_INDIR,indir);
|
|
curr_rec.put(TABBAN_NCIVICO,nciv);
|
|
// ***** check codice comune
|
|
TString codcomune(cap2comune(rec.row(TXTCAB_CAP),rec.row(TXTCAB_COMUNE)));
|
|
if (codcomune.empty())
|
|
codcomune=denom2comune(rec.row(TXTCAB_COMUNE) );
|
|
curr_rec.put(TABBAN_CODCOM, codcomune);
|
|
|
|
}
|
|
return can_write;
|
|
}
|
|
|
|
int TABICAB_file::spezza_indirizzo(TString & indir,TString & ncivico)
|
|
{
|
|
int last_c=indir.len();
|
|
//while (last_c && indir[last_c]>='0' && )
|
|
return last_c;
|
|
}
|
|
|
|
static TString16 tmp_cod_com;
|
|
|
|
// Cerca il cap e se lo trova controlla i primi caratteri della denominazione
|
|
const char* cap2comune(const TString& val_cap, const TString& dencom )
|
|
{
|
|
TString cap = val_cap;
|
|
if (!cap.empty())
|
|
{
|
|
TLocalisamfile comuni (LF_COMUNI);
|
|
|
|
bool trovato = FALSE;
|
|
bool prima_volta = TRUE;
|
|
|
|
tmp_cod_com = "";
|
|
|
|
// correzione CAP
|
|
if (cap.sub(2,3) == "1")
|
|
{
|
|
cap = cap.sub(0,3);
|
|
cap << "00";
|
|
}
|
|
|
|
comuni.setkey(3);
|
|
comuni.zero();
|
|
comuni.put(COM_CAPCOM, cap);
|
|
|
|
TRectype com (comuni.curr());
|
|
|
|
for (comuni.read(_isgteq); !comuni.eof(); comuni.next())
|
|
{
|
|
if (comuni.curr() != com) break;
|
|
|
|
TString d (comuni.get(COM_DENCOM));
|
|
if (prima_volta)
|
|
{
|
|
tmp_cod_com = comuni.get(COM_COM);
|
|
prima_volta = FALSE;
|
|
}
|
|
|
|
trovato = TRUE;
|
|
for (int i = 0; d[i]>='a' && d[i]<='z' || d[i]>='A' && d[i]<='Z' ; i++)
|
|
{
|
|
if (dencom[i] != d[i])
|
|
{
|
|
trovato = FALSE;
|
|
break;
|
|
}
|
|
}
|
|
if (trovato)
|
|
{
|
|
tmp_cod_com = comuni.get(COM_COM);
|
|
break;
|
|
}
|
|
else
|
|
continue;
|
|
}
|
|
if (!trovato)
|
|
tmp_cod_com.cut(0);
|
|
}
|
|
return tmp_cod_com;
|
|
}
|
|
|
|
const char* denom2comune(const TString& dencom, const char * stato)
|
|
{
|
|
tmp_cod_com.cut(0);
|
|
if (!dencom.empty())
|
|
{
|
|
TLocalisamfile comuni (LF_COMUNI);
|
|
|
|
comuni.setkey(2);
|
|
comuni.zero();
|
|
comuni.put(COM_DENCOM, dencom);
|
|
if (comuni.read()==NOERR
|
|
&& !((stato && comuni.get(COM_STATO)!=stato) || comuni.get(COM_STATO)!="") )
|
|
tmp_cod_com = comuni.get(COM_COM);
|
|
}
|
|
return tmp_cod_com;
|
|
}
|
|
|
|
// denominazioni di comuni alternative
|
|
const char* denom2com_alt(const TString& dencom, const char * stato)
|
|
{
|
|
tmp_cod_com.cut(0);
|
|
if (!dencom.empty())
|
|
{
|
|
bool prima_volta = TRUE;
|
|
|
|
TLocalisamfile comuni (LF_COMUNI);
|
|
|
|
comuni.setkey(2);
|
|
comuni.zero();
|
|
comuni.put(COM_DENCOM, dencom);
|
|
for (comuni.read(_isgteq); !comuni.eof(); comuni.next())
|
|
{
|
|
if (prima_volta)
|
|
{
|
|
|
|
prima_volta=FALSE;
|
|
}
|
|
if (confr_nomicomune(comuni.get(COM_DENCOM),dencom)
|
|
&& !((stato && comuni.get(COM_STATO)!=stato) || comuni.get(COM_STATO)!=""))
|
|
tmp_cod_com = comuni.get(COM_COM);
|
|
}
|
|
}
|
|
return tmp_cod_com;
|
|
}
|
|
|
|
bool confr_nomicomune(const TString & com1, const TString & com2)
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
class TRicezioneABICAB : public TSkeleton_application
|
|
{
|
|
void ricevi(const char *, bool abi, bool cab, bool cab_futuri, const char * filtro_reg);
|
|
protected:
|
|
virtual void main_loop();
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
public:
|
|
TRicezioneABICAB()
|
|
{}
|
|
virtual ~TRicezioneABICAB()
|
|
{}
|
|
};
|
|
|
|
bool TRicezioneABICAB::create()
|
|
{
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TRicezioneABICAB::destroy()
|
|
{
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
void TRicezioneABICAB::main_loop()
|
|
{
|
|
// open mask and get parameters
|
|
|
|
// receive
|
|
ricevi("c:\\piazze", TRUE, TRUE, TRUE,"RE");
|
|
}
|
|
|
|
void TRicezioneABICAB::ricevi(const char * path, bool abi, bool cab, bool cab_futuri, const char * filtro_prov)
|
|
{
|
|
TABICAB_file abicab(path);
|
|
TRecord_text txtrec;
|
|
abicab.open();
|
|
abicab.set_curr(txtrec);
|
|
|
|
while (abicab.read()==NOERR)
|
|
{
|
|
if (abicab.curr().type()==TRACCIATO_ABI && abi ||
|
|
(abicab.curr().type()==TRACCIATO_CAB || abicab.curr().type()==TRACCIATO_DENCAB) && cab
|
|
)
|
|
if (abicab.curr().type()==TRACCIATO_CAB && abi)
|
|
{
|
|
// filtro i CAB della provincia
|
|
if (filtro_prov && *filtro_prov
|
|
&& abicab.curr().row(TXTCAB_PROV)!=filtro_prov)
|
|
{
|
|
continue;
|
|
}
|
|
// filtro i CAB di prossima apertura
|
|
if (!cab_futuri && abicab.curr().row(TXTCAB_EFFICIENZA)==E_PROSS_AP)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
abicab.autosave(LF_TABCOM);
|
|
}
|
|
abicab.close();
|
|
}
|
|
|
|
|
|
int ba5300(int argc, char* argv[])
|
|
{
|
|
TRicezioneABICAB app;
|
|
app.run(argc,argv, TR("Ricezione ABI e CAB"));
|
|
return 0;
|
|
}
|
|
|