Patch level :4.0 nopatch

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :cominciato programma importazione movimenti bufget per il mitico Adolfo!


git-svn-id: svn://10.65.10.50/trunk@14277 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
luca 2006-08-30 14:15:53 +00:00
parent 6a74af03b2
commit aa2fc94c9d
5 changed files with 435 additions and 0 deletions

310
crpa/crpa1.cpp Executable file
View File

@ -0,0 +1,310 @@
#include <applicat.h>
#include <automask.h>
#include <config.h>
#include <execp.h>
#include <filetext.h>
//#include <log.h>
#include <progind.h>
#include <reprint.h>
#include <tabutil.h>
#include <utility.h>
#include "../ca/movana.h"
#include "../ca/rmovana.h"
#include "crpa1a.h"
//---------------------------------
// TAutomask
//---------------------------------
class TBudget_Import_mask : public TAutomask
{
protected:
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
bool select_file_ext(const char* ext, TFilename& filename);
public:
TBudget_Import_mask();
virtual ~TBudget_Import_mask(){};
};
TBudget_Import_mask::TBudget_Import_mask() :TAutomask ("crpa1a")
{
}
bool TBudget_Import_mask::select_file_ext(const char* ext, TFilename& filename)
{
TArray_sheet as(-1, -1, 72, 20, TR("Selezione file"),
"File@48");
TFilename path = get(F_PATH);
path.add("*");
path.ext(ext);
list_files(path, as.rows_array());
TFilename name;
FOR_EACH_ARRAY_ROW(as.rows_array(), i, row)
{
name = *row;
*row = name.name();
}
bool ok = as.run() == K_ENTER;
if (ok)
{
filename = as.row(as.selected());
}
return ok;
}
bool TBudget_Import_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
{
switch (f.dlg())
{
//giochetto per avere la lista dei files validi nella directory di trasferimento!
case F_NAMEFILE:
if (e == fe_button)
{
TFilename name;
if (select_file_ext("csv", name))
f.set(name);
if (f.get() == get(F_LASTFILE))
return error_box(TR("File gia' importato!\nNON e' consigliabile proseguire!"));
}
break;
default:
break;
}
return true;
}
//--------------------------------
// TFile_text
//--------------------------------
class TBudget_Import_file: public TFile_text
{
protected:
virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
public:
TBudget_Import_file(const TString& file_name);
virtual ~TBudget_Import_file() { }
};
TBudget_Import_file::TBudget_Import_file(const TString& file_name)
: TFile_text(file_name, "crpa1.ini")
{
}
void TBudget_Import_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
{
const TString code(s.get(0));
TString valore = str;
if (code == "_UPPERCASE")
{
valore.upper();
}
else NFCHECK("Macro non definita: %s", (const char *)code);
str = valore;
}
//----------------------------------
// TSkeleton_application
//----------------------------------
class TBudget_Import : public TSkeleton_application
{
TBudget_Import_mask* _msk;
TBudget_Import_file* _trasfile;
TConfig* _configfile;
TRelation* _relmovana;
TRelation* _relrmovana;
TCursor* _cur;
TProgind* _prog;
TString _lastfile;
virtual const char * extra_modules() const {return "ba";}
protected:
void mask2ini();
void ini2mask();
bool transfer();
void transfer_testata(const TRecord_text& curr); //, TError_log& log);
// int crea_riga_mov(const TRecord_text& curr, TDocumento& bol, bool is_omaggio);
long get_next_key();
public:
virtual bool create();
virtual bool destroy();
virtual void main_loop();
TBudget_Import() {}
};
long TBudget_Import::get_next_key()
{
TLocalisamfile& lfile = _relmovana->lfile();
long numreg = 1L ;
if (!lfile.empty())
{
lfile.zero() ;
lfile.setkey(1) ;
lfile.read(_isgteq);
if (lfile.good()) //se e' tutto ok,si posiziona sull'ultimo record
lfile.last();
if (lfile.good())
numreg += lfile.get_long(MOVANA_NUMREG);
}
return numreg;
}
void TBudget_Import::transfer_testata(const TRecord_text& curr) //, TError_log& log)
{
const TString codcms = curr.get(1);
const TString codconto = curr.get(2);
const real soldini = curr.get(3);
const TString16 str_dataini = curr.get(4);
const TString16 str_datafine = curr.get(5);
TString4 gg = str_dataini.left(2);
TString4 mm = str_dataini.mid(3,2);
TString4 yy = str_dataini.right(2);
yy.insert("20", 0);
const TDate dataini(atoi(gg),atoi(mm),atoi(yy));
gg = str_datafine.left(2);
mm = str_datafine.mid(3,2);
yy = str_datafine.right(2);
yy.insert("20", 0);
const TDate datafine(atoi(gg),atoi(mm),atoi(yy));
//aggiunge il movimento ai movana al primo posto libero
long numreg = get_next_key();
// creo il documento, se esiste cancello le righe perche' le ricreo successivamente
/* TDocumento& bol = _doc.doc(datadoc.year(), _numbol, num_bol);
const bool isnew = bol.rows() == 0;
if (isnew)
{
_forbidden_ndoc = 0L;
bol.put(DOC_TIPODOC, _tipobol);
bol.put(DOC_DATADOC, datadoc);
bol.put(DOC_STATO, _statobol);
bol.put("DAANNO", anno_ord);
bol.put("DANDOC", num_ord);
//legge la testata dell'ordine per avere il clifo
TDocumento& ordine = _doc.doc(anno_ord, _numord, num_ord);
const char tipocf = ordine.get_char(DOC_TIPOCF);
const long codcf = ordine.get_int(DOC_CODCF);
bol.put(DOC_TIPOCF, tipocf);
bol.put(DOC_CODCF, codcf);
_lastbol = num_bol; //aggiorna l'indicatore dell'ultima bolla trasferita
}
else
{
_forbidden_ndoc = num_bol;
TString msg;
msg.format(FR("La bolla %ld e' gia' stata trasferita"), num_bol);
log.log(1, msg);
}*/
}
bool TBudget_Import::transfer()
{
//file da trasferire
//costruire il nome del file con path
TFilename file = _msk->get(F_PATH);
file.add(_msk->get(F_NAMEFILE));
file.ext("csv");
_trasfile = new TBudget_Import_file(file);
_trasfile->open(file,'r');
//*** prima va inserito il log in libreria preparazione del log
// TError_log log;
// log.set_header(TR("Importazione movimenti"));
const long dimension = fsize(file);
TProgind pi(dimension,TR("Importazione bolle in corso..."));
int err = NOERR;
TRecord_text curr;
while (_trasfile->read(curr) == NOERR && !pi.iscancelled() && err == NOERR)
{
pi.setstatus(_trasfile->read_file()->tellg());
transfer_testata(curr); //, log);
}
_trasfile->close();
delete _trasfile;
// log.show();
_lastfile = _msk->get(F_NAMEFILE);
return true;
}
void TBudget_Import::mask2ini()
{
//aggiorna l'ultimo file inviato su msk e ini
_msk->set(F_LASTFILE, _lastfile);
_configfile->set_paragraph("BUDGET");
_configfile->set("PATH", _msk->get(F_PATH));
_configfile->set("LASTFILE", _lastfile);
}
void TBudget_Import::ini2mask()
{
//carica i parametri del file di configurazione
_configfile->set_paragraph("BUDGET");
TString path = _configfile->get("PATH");
_lastfile = _configfile->get("LASTFILE");
_msk->set(F_PATH, path);
_msk->set(F_LASTFILE, _lastfile);
}
bool TBudget_Import::create()
{
_configfile = new TConfig("crpa1conf.ini");
_msk = new TBudget_Import_mask();
open_files(LF_MOVANA, LF_RMOVANA, 0);
_relmovana = new TRelation(LF_MOVANA);
_relrmovana = new TRelation(LF_RMOVANA);
return TSkeleton_application::create();
}
bool TBudget_Import::destroy()
{
delete _msk;
delete _configfile;
return TApplication::destroy();
}
void TBudget_Import::main_loop()
{
KEY tasto;
ini2mask();
tasto = _msk->run();
if (tasto == K_ENTER)
{
if (transfer())
message_box(TR("Importazione movimenti completata"));
}
mask2ini();
}
int main(int argc, char** argv)
{
TBudget_Import a;
a.run(argc, argv, TR("Importazione movimenti di budget per CRPA"));
return 0;
}

68
crpa/crpa1.ini Executable file
View File

@ -0,0 +1,68 @@
[MAIN]
DECSEP = ,
FIELDSEP = ;
RECORDSEP =
SKIPLINES = 1
TYPEFIELD = -1
TYPELEN = -1
TYPEPOS = -1
[TYPE FISSO]
ALIGN =
DATA =
DECIMAL = 0
FILLER = ' '
LENGTH = 0
PICTURE =
[TYPE DATA]
ALIGN =
DATA = D
DECIMAL = 0
FILLER =
LENGTH = 6
PICTURE =
[TYPE NUMERO]
ALIGN = R
DATA = N
DECIMAL = 0
FILLER = '0'
LENGTH = 0
PICTURE =
[TYPE STRINGA]
ALIGN = L
DATA = S
DECIMAL = 0
FILLER = ' '
LENGTH = 0
PICTURE =
[TYPE IMPORTO]
ALIGN = R
DATA = S
DECIMAL = 0
FILLER = '0'
LENGTH = 0
PICTURE =
[RECORD]
NAME(0)=PROGRESSIVO
TYPE(0)=NUMERO
NAME(1) = CODCMS
TYPE(1) = STRINGA
NAME(2) = CODCONTO
TYPE(2) = STRINGA
NAME(3) = IMPORTO
TYPE(3) = IMPORTO
NAME(4) = DATAINI
TYPE(4) = DATA
NAME(5) = DATAFINE
TYPE(5) = DATA

5
crpa/crpa1a.h Executable file
View File

@ -0,0 +1,5 @@
// campi della maschera principale
#define F_PATH 101
#define F_NAMEFILE 102
#define F_LASTFILE 103

49
crpa/crpa1a.uml Executable file
View File

@ -0,0 +1,49 @@
#include "crpa1a.h"
TOOLBAR "" 0 20 0 2
BUTTON DLG_OK 10 2
BEGIN
PROMPT -12 -1 ""
END
BUTTON DLG_QUIT 10 2
BEGIN
PROMPT -22 -1 ""
END
ENDPAGE
PAGE "Parametri Importazione" -1 -1 78 20
GROUPBOX DLG_NULL 78 4
BEGIN
PROMPT 1 1 ""
END
STRING F_PATH 255 40
BEGIN
PROMPT 2 2 "Percorso files da importare "
DSELECT
FLAGS "M"
CHECKTYPE REQUIRED
WARNING "Selezionare una cartella valida!"
FIELD PATH
END
STRING F_NAMEFILE 40
BEGIN
PROMPT 2 3 "Nome file da importare "
FLAGS "B"
CHECKTYPE REQUIRED
FIELD NAMEFILE
END
STRING F_LASTFILE 40
BEGIN
PROMPT 1 5 "Ultimo file importato "
FLAGS "D"
END
ENDPAGE
ENDMASK

3
crpa/crpa1conf.ini Executable file
View File

@ -0,0 +1,3 @@
[BUDGET]
PATH =
LASTFILE =