Patch level : 2.2

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Aggiunta possibilita' di esportare in dbf


git-svn-id: svn://10.65.10.50/trunk@13650 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2005-12-29 12:46:33 +00:00
parent c53c790f0b
commit 5014e83f00
7 changed files with 176 additions and 122 deletions

View File

@ -116,9 +116,6 @@ protected:
// @access Public Member
public:
// @cmember Modifca la barra dei menu' inserendo la <p menubar>
// void setbar(int menubar) { _bar = menubar;}
// @cmember Fa partire l'applicazione
void run(int argc, char* argv[], const char* name);
@ -136,8 +133,7 @@ public:
// @cmember Controlla se al programma corrente e' concesso cambiare ditta da menu.
virtual bool firm_change_enabled() const;
// @cmember Ritorna la <c TToken_string> con la lista dei moduli cui appartiene il programma
virtual const char * extra_modules() const
{return "";}
virtual const char * extra_modules() const { return ""; }
// @cmember Abilita la verifica del modulo cui appartiene il programma
virtual bool check_autorization() const
{return TRUE;}

View File

@ -37,6 +37,7 @@ void TODBC_recordset::reset()
_pagesize = 512;
_page.destroy();
_column.destroy();
_columns_loaded = false;
}
int TODBC_recordset::on_get_columns(int argc, char** values, char** columns)
@ -113,24 +114,46 @@ void TODBC_recordset::requery()
_page.destroy();
}
int TODBC_recordset::on_get_items(int argc, char** values, char** columns)
{
if (!_columns_loaded)
on_get_rows(argc, values, columns);
return 0;
}
static int query_get_items(void* jolly, int argc, char** values, char** columns)
{
TODBC_recordset* q = (TODBC_recordset*)jolly;
return q->on_get_items(argc, values, columns);
}
TRecnotype TODBC_recordset::items() const
{
if (_items == 0)
{
TString sql; parsed_text(sql);
TPerformance_profiler prof("ODBC count");
((TODBC_recordset*)this)->_items = xvt_odbc_execute(connection(), _sql, NULL, NULL);
TRecnotype& i = (TRecnotype&)_items;
if (!_columns_loaded)
{
((TArray&)_page).destroy();
i = xvt_odbc_execute(connection(), sql, query_get_items, (void*)this);
(bool&)_columns_loaded = true;
}
else
i = xvt_odbc_execute(connection(), sql, NULL, NULL);
}
return _items;
}
unsigned int TODBC_recordset::columns() const
{
if (_column.empty())
if (!_columns_loaded && _column.items() == 0)
{
TString sql; parsed_text(sql);
TPerformance_profiler prof("ODBC info");
xvt_odbc_execute(connection(), sql, query_get_columns, (void*)this);
(bool&)_columns_loaded = true;
}
return _column.items();
}
@ -143,8 +166,14 @@ const TRecordset_column_info& TODBC_recordset::column_info(unsigned int c) const
}
// Funzione chiamata per riempire la pagina corrente delle righe della query
int TODBC_recordset::on_get_rows(int argc, char** values)
int TODBC_recordset::on_get_rows(int argc, char** values, char** columns)
{
if (!_columns_loaded)
on_get_columns(argc, values, columns);
if (_page.items() >= _pagesize)
return -1;
TArray* a = new TArray;
for (int c = 0; c < argc; c++)
{
@ -178,15 +207,16 @@ int TODBC_recordset::on_get_rows(int argc, char** values)
static int query_get_rows(void* jolly, int argc, char** values, char** columns)
{
TODBC_recordset* rs = (TODBC_recordset*)jolly;
return rs->on_get_rows(argc, values);
return rs->on_get_rows(argc, values, columns);
}
bool TODBC_recordset::move_to(TRecnotype n)
{
const TRecnotype tot = items();
_current_row = n;
if (n < 0 || n >= items())
if (n < 0 || n >= tot)
{
_page.destroy(); // Forza rilettura la prossiva volta
_page.destroy(); // Forza rilettura la prossima volta
_first_row = 0;
return false;
}
@ -194,7 +224,7 @@ bool TODBC_recordset::move_to(TRecnotype n)
if (n < _first_row || n >= _first_row+_page.items())
{
TString sql; parsed_text(sql);
if (sql.find("LIMIT ") < 0)
if (tot > _pagesize && sql.find("LIMIT ") < 0)
{
const int semicolon = sql.rfind(';');
if (semicolon >= 0)
@ -205,15 +235,28 @@ bool TODBC_recordset::move_to(TRecnotype n)
_first_row = n-_pagesize/8; // Prendo qualche riga dalla pagina precedente, per velocizzare il pagina su
else
_first_row = n;
sql << "\nLIMIT " << _first_row << ',' << _pagesize << ";";
sql << "\nLIMIT ";
if (_first_row > 0)
sql << _first_row << ',';
sql << _pagesize << ';';
}
TPerformance_profiler prof("ODBC query");
xvt_odbc_execute(connection(), sql, query_get_rows, this);
if (!_columns_loaded)
_columns_loaded = true; // Brutto posto ma necessario
}
return true;
}
long TODBC_recordset::exec(const char* sql)
{
TPerformance_profiler prof("ODBC command");
set(sql);
TString cmd; parsed_text(cmd);
return xvt_odbc_execute(connection(), cmd, NULL, NULL);
}
TRecnotype TODBC_recordset::current_row() const
{
return _current_row;
@ -239,6 +282,11 @@ const TVariant& TODBC_recordset::get(unsigned int c) const
return NULL_VARIANT;
}
const TVariant& TODBC_recordset::get(const char* name) const
{
return TRecordset::get(name);
}
void TODBC_recordset::set(const char* sql)
{
reset();

View File

@ -11,9 +11,11 @@ class TODBC_recordset : public TRecordset
XVT_ODBC _odbc;
TRecnotype _first_row, _pagesize, _items, _current_row;
TArray _column;
TArray _page;
TArray _column;
bool _columns_loaded;
protected:
XVT_ODBC connection() const;
void close();
@ -21,23 +23,26 @@ protected:
void reset();
const TArray* row(TRecnotype n);
unsigned int columns() const;
const TRecordset_column_info& column_info(unsigned int c) const;
public:
virtual TRecnotype items() const;
virtual unsigned int columns() const;
virtual const TRecordset_column_info& column_info(unsigned int c) const;
virtual bool move_to(TRecnotype pos);
virtual TRecnotype current_row() const;
virtual void requery();
virtual const TString& query_text() const;
const TVariant& get(unsigned int c) const;
virtual const TVariant& get(unsigned int c) const;
virtual const TVariant& get(const char* name) const;
// Callbacks
int on_get_items(int argc, char** values, char** columns);
int on_get_columns(int argc, char** values, char** columns);
int on_get_rows(int argc, char** values);
int on_get_rows(int argc, char** values, char** columns);
void set(const char* sql);
long exec(const char* sql);
bool connect(const char* dsn, const char* usr = "", const char* pwd = "", const char* dir = "");
TODBC_recordset(const char* sql);

View File

@ -1,78 +0,0 @@
# prassid.doc - File configurazione ditte (commentato]
# una copia di questo file viene affibbiata a ogni nuova ditta
# NON MODIFICARE! Copiare prima in prassid.ini
[cg]
# Maschera
EdMask = cg5100a.msk
# Anno liquidazione IVA
AnLiIv =
# Anagrafica clienti/fornitori in comune
AnCfCm =
# Piano conti/tabella causali in comune
PcTcCm =
# Gestione libro cronologico
GsLbCn =
# Codice libro incassi pagamenti
CodLIC =
# Stampa totali fatture a fine registro
StTfFr =
# Stampa libro giornale e libro IVA unico
StLgiU =
# Gestione saldaconto
GesSal =
# N. rif. allineato a destra per clienti
NrCliDx =
# N. rif. allineato a destra per fornitori
NrForDx =
# Riferimenti partite
RifPar =
# Gestione valuta
GesVal =
# Codice lingua
CodLin =
# Credito IVA anno precedente
CrIvAp =
# Gestione liquidazione differita
GeLiDi =
# Codice causale chiusura
CoCaCh =
# Codice causale apertura
CoCaAp =
# Codici sottoconto Bilancio di Chiusura
CsBiChG =
CsBiChC =
CsBiChS =
# Codici sottoconto Profitti e perdite
CsPrPeG =
CsPrPeC =
CsPrPeS =
# Codici sottoconto Bilancio di Apertura
CsBiApG =
CsBiApC =
CsBiApS =
# Codici sottoconto Utile esercizio conto patrimoniale
CsUeCpG =
CsUeCpC =
CsUeCpS =
# Codici sottoconto Perdite esercizio conto patrimoniale
CsPeCpG =
CsPeCpC =
CsPeCpS =
# Codici sottoconto Utile esercizio conto economico
CsUeCeG =
CsUeCeC =
CsUeCeS =
# Codici sottoconto Perdite esercizio conto economico
CsPeCeG =
CsPeCeC =
CsPeCeS =
# Frequenza ratei/riscontri
RrFrAm = A
# Mese commerciale ratei/riscontri
RrMeCo =
# Codice causale ratei
RrCcRa =
# Codice causale riscontri
RrCcRi =
[EOF]

View File

@ -1,23 +0,0 @@
[Main]
Editor = notepad
[cg]
Sind11 =
StiReg =
CodCAB =
InTr(1) =
CodABI =
CoDaPn =
EdMask = cg5000a.msk
PoCuDr =
InTr(2) =
NoViIP =
NoDtRg =
InTr(3) =
GsAcMi =
CodAgv =
InTr(0) =
NoViPC =
Cg02SN =
Cg21SN =
[EOF]

View File

@ -350,7 +350,7 @@ bool TRecordset::save_as_campo(const char* path)
return !pi.iscancelled();
}
bool TRecordset::save_as(const char* path, TRecordsetExportFormat fmt)
bool TRecordset::save_as(const char* path, TRecordsetExportFormat fmt, int mode)
{
if (fmt == fmt_unknown)
{
@ -368,6 +368,7 @@ bool TRecordset::save_as(const char* path, TRecordsetExportFormat fmt)
case fmt_html : ok = save_as_html(path); break;
case fmt_silk : ok = save_as_silk(path); break;
case fmt_campo: ok = save_as_campo(path); break;
case fmt_dbf : ok = save_as_dbf(path, mode); break;
default : ok = save_as_text(path); break;
}
@ -1466,6 +1467,107 @@ const TVariant& TSQL_recordset::get(unsigned int c) const
return NULL_VARIANT;
}
bool TRecordset::save_as_dbf(const char* table, int mode)
{
char volume[_MAX_DRIVE];
char dirname[_MAX_PATH];
char name[_MAX_FNAME];
char ext[_MAX_EXT];
xvt_fsys_parse_pathname (table, volume, dirname, name, ext, NULL);
const int logicnum = table2logic(name);
if (mode == 0x0)
mode = 0x1;
if (mode & 0x4)
{
if (logicnum >= LF_USER && *dirname == '\0')
{
TSystemisamfile isam(logicnum);
if (isam.zap() != NOERR)
return error_box(TR("Impossibile cancellare il file '%s'"), table);
}
else
{
TFilename n;
n = volume; n.add(dirname); n.add(name); n.ext("*");
TString_array files; list_files(n, files);
FOR_EACH_ARRAY_ROW(files, f, row)
xvt_fsys_removefile(*row);
}
mode = 0x1;
}
TLocalisamfile* pisam = NULL;
if (logicnum >= LF_USER)
{
if (*dirname)
pisam = new TIsamtempfile(logicnum, table);
else
pisam = new TLocalisamfile(logicnum);
}
if (pisam == NULL)
return error_box("Impossibile creare il file %s", table);
TLocalisamfile& isam = *pisam;
TProgind pi(items(), TR("Esportazione in corso..."));
TRectype& rec = isam.curr();
TString_array names;
int valid = 0;
for (unsigned int j = 0; j < columns(); j++)
{
const TVariant& var = get(j);
const TString& name = column_info(j)._name;
if (rec.exist(name))
{
names.add(name);
valid++;
}
else
names.add(EMPTY_STRING);
}
bool ok = true;
for (bool go = move_first(); go; go = move_next())
{
pi.addstatus(1);
rec.zero();
FOR_EACH_ARRAY_ROW(names, j, name) if (name->not_empty())
rec.put(*name, get(j).as_string());
int err = NOERR;
bool to_be_written = true;
// Devo solo aggiornare parte dei campi?
if ((mode & 0x2) && valid < rec.items())
{
err = isam.read(_isequal, _lock);
if (err != NOERR)
rec.zero();
FOR_EACH_ARRAY_ROW(names, j, name) if (name->not_empty())
rec.put(*name, get(j).as_string());
if (err == NOERR)
to_be_written = isam.rewrite() != NOERR;
}
if (to_be_written)
{
err = (mode & 0x1) ? isam.write() : isam.rewrite();
if (err != NOERR && (mode & 0x3) != 0)
err = (mode & 0x1) ? isam.rewrite() : isam.write();
}
if (err != NOERR)
{
ok = error_box(FR("Errore %d durante la scrittura del record %s"), err, rec.build_key());
break;
}
}
return ok;
}
void TSQL_recordset::set(const char* sql)
{
reset();

View File

@ -24,7 +24,7 @@ struct TRecordset_column_info : public TObject
// TRecordset
///////////////////////////////////////////////////////////
enum TRecordsetExportFormat { fmt_unknown, fmt_html, fmt_text, fmt_silk, fmt_campo };
enum TRecordsetExportFormat { fmt_unknown, fmt_html, fmt_text, fmt_silk, fmt_campo, fmt_dbf };
class TRecordset : public TObject
{
@ -37,10 +37,12 @@ protected:
bool save_as_silk(const char* path);
bool save_as_text(const char* path);
bool save_as_campo(const char* path);
bool save_as_dbf(const char* table, int mode);
void find_and_reset_vars();
void parsed_text(TString& sql) const;
TVariant& get_tmp_var() const;
bool export_dbf(int logicnum);
public: // Absolutely needed methods
virtual TRecnotype items() const pure;
@ -70,7 +72,9 @@ public: // Absolutely needed methods
virtual const TVariant& get(const char* column_name) const;
virtual const TToken_string& sheet_head() const;
virtual bool save_as(const char* path, TRecordsetExportFormat fmt = fmt_unknown);
// mode = 0|1=append 2=update 3=update|append 4=zap before writing
virtual bool save_as(const char* path, TRecordsetExportFormat fmt = fmt_unknown, int mode = 0);
void set_parent(const TRecordset* rs) { _parentset = rs; }
TRecordset();
virtual ~TRecordset() { }