Patch level : 12.00 1414

Files correlati     : ba8.exe

Commento                :
Aggiornato stampatore di report
This commit is contained in:
Alessandro Bonazzi 2026-07-16 17:18:12 +02:00
parent db57568e58
commit d0d0ded00e
2 changed files with 227 additions and 268 deletions

View File

@ -11,13 +11,14 @@
#include "ba8400.h" #include "ba8400.h"
#include "ba8500.h" #include "ba8500.h"
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Utility // Utility
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
bool cod2app(const char* tok, TString& app) bool _cod2app(const char* tok, TString& app)
{ {
if (tok != NULL && isalpha(tok[0]) && isalpha(tok[1]) && atoi(tok+2) > 1000) if (tok != nullptr && isalpha(tok[0]) && isalpha(tok[1]) && atoi(tok + 2) > 1000)
{ {
TFilename f; TFilename f;
f.strncpy(tok, 3); f.strncpy(tok, 3);
@ -32,7 +33,7 @@ bool cod2app(const char* tok, TString& app)
return false; return false;
} }
bool get_xml_attr(const TString& line, const char* attr, TString& value) bool _get_xml_attr(const TString& line, const char* attr, TString& value)
{ {
TString str; str << ' ' << attr << "=\""; TString str; str << ' ' << attr << "=\"";
const int pos = line.find(str); const int pos = line.find(str);
@ -42,14 +43,14 @@ bool get_xml_attr(const TString& line, const char* attr, TString& value)
const int apicic = line.find('"', apicia); const int apicic = line.find('"', apicia);
if (apicic > apicia) if (apicic > apicia)
{ {
value = line.sub(apicia, apicic); value = line.ssub(apicia, apicic);
return true; return true;
} }
} }
return false; return false;
} }
bool get_xml_child(const TString& line, const char* tag, TString& value) bool _get_xml_child(const TString& line, const char* tag, TString& value)
{ {
TString80 str; str << '<' << tag << '>'; TString80 str; str << '<' << tag << '>';
const int pos = line.find(str); const int pos = line.find(str);
@ -59,14 +60,14 @@ bool get_xml_child(const TString& line, const char* tag, TString& value)
const int apicic = line.find('<', apicia); const int apicic = line.find('<', apicia);
if (apicic > apicia) if (apicic > apicia)
{ {
value = line.sub(apicia, apicic); value = line.ssub(apicia, apicic);
return true; return true;
} }
} }
return false; return false;
} }
bool rep2app(const char* name, TString& app, TString& desc) HIDDEN bool rep2app(const char* name, TString& app, TString& desc)
{ {
app = desc = ""; app = desc = "";
@ -80,92 +81,18 @@ bool rep2app(const char* name, TString& app, TString& desc)
for (int i = 0; i < 3 && scan.good(); i++) // Leggo solo le prime righe for (int i = 0; i < 3 && scan.good(); i++) // Leggo solo le prime righe
stringona << scan.line(); stringona << scan.line();
get_xml_child(stringona, "description", desc); _get_xml_child(stringona, "description", desc);
get_xml_attr(stringona, "command", app); _get_xml_attr(stringona, "command", app);
if (app.not_empty()) if (app.not_empty())
return app != "ba8 -4"; //in questo caso e' stata definita nel report l'applicazione per stamparlo ed e' diversa da me stesso (ba8 -4) return app != "ba8 -4"; //in questo caso e' stata definita nel report l'applicazione per stamparlo ed e' diversa da me stesso (ba8 -4)
return cod2app(report_name.name(), app); return _cod2app(report_name.name(), app);
} }
/////////////////////////////////////////////////////////// HIDDEN TVariant* str2var(const char* str)
// TKlarkKent_mask
///////////////////////////////////////////////////////////
class TKlarkKent_mask : public TAutomask
{ {
protected: TVariant* var = nullptr;
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TKlarkKent_mask() : TAutomask("ba8500a") { }
};
bool TKlarkKent_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_REPORT:
if (e == fe_button)
{
TFilename path;
if (select_custom_file(path, "rep", "C"))
{
o.set(path);
e = fe_modify;
}
}
if (e == fe_init || e == fe_modify)
{
TFilename name = o.get();
TString app, desc;
rep2app(name, app, desc);
set(F_FORM, desc);
set(F_DOC, app);
enable(DLG_PRINT, desc.not_empty());
}
break;
case DLG_EDIT:
if (e == fe_button && !field(F_REPORT).empty())
{
TString str;
str << "ba8 -2 " << get(F_REPORT);
TExternal_app app(str);
app.run(true);
}
break;
default:
break;
}
return true;
}
///////////////////////////////////////////////////////////
// TKlarkKent_app
///////////////////////////////////////////////////////////
TReport* TKlarkKent_app::create_report(const char* name) const
{
TReport* r = new TReport;
r->load(name);
TString custom_query;
TFilename filename(name);
filename = filename.name();
const TString module = (filename[3] >= '0') && (filename[3] <= '9') ? filename.left(2) : "";
get_custom_query(module, filename, custom_query);
if (custom_query.full())
r->set_recordset(custom_query);
return r;
}
static TVariant* str2var(const char* str)
{
TVariant* var = NULL;
if (str && *str) if (str && *str)
{ {
const int len = strlen(str); const int len = strlen(str);
@ -181,35 +108,48 @@ static TVariant* str2var(const char* str)
return var; return var;
} }
void TKlarkKent_app::main_loop()
{
TString_array arr; // Lista dei reports
TAssoc_array vars; // Variabili utente
bool trans = false;
HIDDEN const char *rep2mask(const char * name)
{
TFilename & maskname = (TFilename &)get_tmp_string();
maskname = name;
maskname.ext("msk");
return (const char *)maskname;
}
///////////////////////////////////////////////////////////
// TKlarkKent_app
///////////////////////////////////////////////////////////
bool TKlarkKent_app::user_create()
{
TString80 name, val; TString80 name, val;
for (int i = 2; i < argc(); i++) const int args = argc();
for (int i = 2; i < args; i++)
{ {
const TFixed_string arg(argv(i)); const TFixed_string arg(argv(i));
const int uguale = arg.find('='); const int uguale = arg.find('=');
if (uguale > 0) if (uguale > 0)
{ {
name = arg.left(uguale); name.trim(); name = arg.sleft(uguale); name.trim();
val = arg.mid(uguale+1); val.trim(); val = arg.smid(uguale + 1); val.trim();
if (name.full()) if (name.full())
{ {
TVariant* var = str2var(val); TVariant* var = str2var(val);
if (name[0] != '#') if (name[0] != '#')
name.insert("#"); name.insert("#");
vars.add(name, var); _vars.add(name, var);
} }
} }
else else
{ {
if (arg.starts_with("-i")) if (arg.starts_with("-i"))
{ {
trans = true; _trans = true;
TFilename ininame = arg.mid(2); TFilename ininame = arg.smid(2);
TConfig ini(ininame, "Vars"); TConfig ini(ininame, "Vars");
TAssoc_array& inivars = ini.list_variables(); TAssoc_array& inivars = ini.list_variables();
FOR_EACH_ASSOC_STRING(inivars, obj, key, str) FOR_EACH_ASSOC_STRING(inivars, obj, key, str)
@ -218,61 +158,85 @@ void TKlarkKent_app::main_loop()
name = key; name = key;
if (name[0] != '#') if (name[0] != '#')
name.insert("#"); name.insert("#");
vars.add(name, var); _vars.add(name, var);
} }
} }
else else
{ {
TFilename rep = arg; TFilename repname = arg;
rep.ext("rep"); if (repname[0] == '%' || repname.len() == 3)
if (rep.custom_path()) {
arr.add(arg); TTable tab(repname);
repname = tab.module();
repname << "st" << TString(arg).sright(3);
}
repname.ext("rep");
if (repname.custom_path())
_reps.add(repname);
} }
} }
} }
if (arr.items() == 0) if (_reps.items() == 0)
arr.add(EMPTY_STRING); return false;
bool can_repeat = false; _repname = _reps[0];
do _repname.ext("rep");
{
TReport* report = NULL; TFilename maskname = rep2mask(_repname);
TReport_book book;
FOR_EACH_ARRAY_ROW(arr, r, row) _mask = new TSimpleAutomask(maskname);
{ return true;
TFilename report_name = *row;
// Controlla se trattasi di tabella comune o di ditta
if (report_name[0] == '%' || report_name.len() == 3)
{
TTable tab(report_name);
report_name = tab.module();
report_name << "st" << row->right(3);
} }
report_name.ext("rep");
if (row->blank() || !report_name.custom_path()) bool TKlarkKent_app::user_destroy()
{ {
TKlarkKent_mask m; safe_delete(_mask);
m.set(F_REPORT, report_name); safe_delete(_rep);
if (m.run() == K_ENTER) return true;
}
TReport & TKlarkKent_app::get_report(const TAutomask & m)
{ {
report_name = m.get(F_REPORT); safe_delete(_rep);
report_name.ext("rep"); _rep = new TProgram_report;
report_name.custom_path(); _rep->load(_repname);
*row = report_name; return *_rep;
}
void TKlarkKent_app::set_vars(TReport & rep)
{
TRecordset* recset = rep.recordset();
if (recset != nullptr && _vars.items() > 0)
{
recset->clear_variables();
FOR_EACH_ASSOC_OBJECT(_vars, h, name, var)
recset->set_var(name, *(TVariant*)var, true);
} }
} }
void TKlarkKent_app::execute_print(TReport_book & book, TAutomask & mask, TReport & rep, export_type & type)
{
set_vars(rep);
rep.mask2report(mask);
rep.set_export_sections(type);
book.add(rep, type);
FOR_EACH_ARRAY_ROW(_reps, r, row)
{
if (r > 0)
{
TString appname, desc; TString appname, desc;
const bool custom_app = rep2app(report_name, appname, desc); const bool custom_app = rep2app(*row, appname, desc);
const TString& cust_cmd = cmd2name(appname); const TString& cust_cmd = cmd2name(appname);
const TString& this_cmd = cmd2name(argv(0), argv(1)); const TString& this_cmd = cmd2name(argv(0), argv(1));
if (custom_app && (cust_cmd != this_cmd)) //il contenuto dell && serve ad evitare spiacevoli infinite esecuzioni.. if (custom_app && (cust_cmd != this_cmd)) //il contenuto dell && serve ad evitare spiacevoli infinite esecuzioni..
{ //..e conseguenti forzati spegnimenti del computer { //..e conseguenti forzati spegnimenti del computer
appname << ' ' << report_name; appname << ' ' << *row;
if (vars.items() > 0) if (_vars.items() > 0)
{ {
FOR_EACH_ASSOC_OBJECT(vars, h, name, var) FOR_EACH_ASSOC_OBJECT(_vars, h, name, var)
appname << ' ' << name << '=' << ((TVariant *)var)->as_string(); appname << ' ' << name << '=' << ((TVariant *)var)->as_string();
} }
TExternal_app app(appname); TExternal_app app(appname);
@ -280,40 +244,20 @@ void TKlarkKent_app::main_loop()
} }
else else
{ {
if (report != NULL) TSimpleAutomask mask(rep2mask(*row));
delete report;
report = create_report(report_name);
if (report != NULL)
{
TRecordset* pset = report->recordset();
if (pset != NULL && vars.items() > 0)
{
FOR_EACH_ASSOC_OBJECT(vars, h, name, var)
pset->set_var(name, *(TVariant*)var, true);
}
const bool ok = book.add(*report);
if (ok && !trans && arr.items() == 1) // Controlla se e' pensabile ripetere la stampa
{
TFilename msk = report_name;
msk.ext("msk");
can_repeat = msk.custom_path(); // Posso ripetere se ho una maschera collegata
}
else
can_repeat = false;
}
}
} // ciclo sulla lista dei report da stampare
// L'anteprima funziona bene solo se non si distrugge il report corrente if (mask.run() != K_ESC)
if (report != NULL)
{ {
if (book.pages() > 0) TProgram_report rrep(*row);
book.print_or_preview();
delete report;
report = NULL;
}
} while (can_repeat); set_vars(rrep);
rrep.mask2report(mask);
rrep.set_export_sections(type);
book.add(rrep, type);
}
}
}
}
} }
int ba8500(int argc, char* argv[]) int ba8500(int argc, char* argv[])

View File

@ -9,11 +9,26 @@
#include <report.h> #include <report.h>
#endif #endif
class TKlarkKent_app : public TSkeleton_application #ifndef __REPAPP_H
#include <repapp.h>
#endif
class TKlarkKent_app : public TReport_application
{ {
TFilename _repname;
TSimpleAutomask * _mask;
TReport * _rep;
bool _trans;
TString_array _reps; // Lista dei reports
TAssoc_array _vars; // Variabili utente
protected: protected:
virtual TReport* create_report(const char* name) const; virtual bool user_create() override;
virtual void main_loop(); virtual bool user_destroy() override;
virtual TAutomask & get_mask() override { return *_mask; }
virtual TReport & get_report(const TAutomask & m) override;
virtual void execute_print(TReport_book & book, TAutomask & mask, TReport & rep, export_type & type) override;
void set_vars(TReport & rep);
}; };
#endif #endif