dddb1a668f
git-svn-id: svn://10.65.10.50/branches/R_10_00@23185 c028cbd2-c16b-5b4b-a496-9718f37d4682
314 lines
7.6 KiB
C++
Executable File
314 lines
7.6 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <config.h>
|
|
#include <defmask.h>
|
|
#include <execp.h>
|
|
#include <prefix.h>
|
|
#include <reprint.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
|
|
#include "ba8400.h"
|
|
#include "ba8500.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Utility
|
|
///////////////////////////////////////////////////////////
|
|
|
|
bool cod2app(const char* tok, TString& app)
|
|
{
|
|
if (tok != NULL && isalpha(tok[0]) && isalpha(tok[1]) && atoi(tok+2) > 1000)
|
|
{
|
|
TFilename f;
|
|
f.strncpy(tok, 3);
|
|
f.ext("exe");
|
|
if (!f.custom_path())
|
|
return false;
|
|
|
|
app.strncpy(tok, 3);
|
|
app << " -" << char(tok[3]-1);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool get_xml_attr(const TString& line, const char* attr, TString& value)
|
|
{
|
|
TString str; str << ' ' << attr << "=\"";
|
|
const int pos = line.find(str);
|
|
if (pos >= 0)
|
|
{
|
|
const int apicia = line.find('"', pos)+1;
|
|
const int apicic = line.find('"', apicia);
|
|
if (apicic > apicia)
|
|
{
|
|
value = line.sub(apicia, apicic);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool get_xml_child(const TString& line, const char* tag, TString& value)
|
|
{
|
|
TString80 str; str << '<' << tag << '>';
|
|
const int pos = line.find(str);
|
|
if (pos >= 0)
|
|
{
|
|
const int apicia = line.find('>', pos)+1;
|
|
const int apicic = line.find('<', apicia);
|
|
if (apicic > apicia)
|
|
{
|
|
value = line.sub(apicia, apicic);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool rep2app(const char* name, TString& app, TString& desc)
|
|
{
|
|
app = desc = "";
|
|
|
|
TFilename report_name(name);
|
|
report_name.ext("rep");
|
|
if (!report_name.custom_path())
|
|
return false;
|
|
|
|
TString stringona;
|
|
TScanner scan(report_name);
|
|
for (int i = 0; i < 3 && scan.good(); i++) // Leggo solo le prime righe
|
|
stringona << scan.line();
|
|
|
|
get_xml_child(stringona, "description", desc);
|
|
|
|
get_xml_attr(stringona, "command", app);
|
|
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 cod2app(report_name.name(), app);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TKlarkKent_mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TKlarkKent_mask : public TAutomask
|
|
{
|
|
protected:
|
|
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"))
|
|
{
|
|
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);
|
|
return r;
|
|
}
|
|
|
|
static TVariant* str2var(const char* str)
|
|
{
|
|
TVariant* var = NULL;
|
|
if (str && *str)
|
|
{
|
|
const int len = strlen(str);
|
|
if (len <= 8 && real::is_natural(str))
|
|
var = new TVariant(atol(str)); else
|
|
if (len <= 15 && real::is_real(str))
|
|
var = new TVariant(real(str));
|
|
else
|
|
var = new TVariant(str);
|
|
}
|
|
else
|
|
var = new TVariant;
|
|
return var;
|
|
}
|
|
|
|
void TKlarkKent_app::main_loop()
|
|
{
|
|
TString_array arr; // Lista dei reports
|
|
TAssoc_array vars; // Variabili utente
|
|
bool trans = false;
|
|
|
|
TString80 name, val;
|
|
for (int i = 2; i < argc(); i++)
|
|
{
|
|
const TFixed_string arg(argv(i));
|
|
const int uguale = arg.find('=');
|
|
if (uguale > 0)
|
|
{
|
|
name = arg.left(uguale); name.trim();
|
|
val = arg.mid(uguale+1); val.trim();
|
|
if (name.full())
|
|
{
|
|
TVariant* var = str2var(val);
|
|
if (name[0] != '#')
|
|
name.insert("#");
|
|
vars.add(name, var);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (arg.starts_with("-i"))
|
|
{
|
|
trans = true;
|
|
TFilename ininame = arg.mid(2);
|
|
TConfig ini(ininame, "Vars");
|
|
TAssoc_array& inivars = ini.list_variables();
|
|
FOR_EACH_ASSOC_STRING(inivars, obj, key, str)
|
|
{
|
|
TVariant* var = str2var(str);
|
|
name = key;
|
|
if (name[0] != '#')
|
|
name.insert("#");
|
|
vars.add(name, var);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TFilename rep = arg;
|
|
rep.ext("rep");
|
|
if (rep.custom_path())
|
|
arr.add(arg);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (arr.items() == 0)
|
|
arr.add(EMPTY_STRING);
|
|
|
|
bool can_repeat = false;
|
|
do
|
|
{
|
|
TReport* report = NULL;
|
|
TReport_book book;
|
|
FOR_EACH_ARRAY_ROW(arr, r, row)
|
|
{
|
|
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())
|
|
{
|
|
TKlarkKent_mask m;
|
|
m.set(F_REPORT, report_name);
|
|
if (m.run() == K_ENTER)
|
|
{
|
|
report_name = m.get(F_REPORT);
|
|
report_name.ext("rep");
|
|
report_name.custom_path();
|
|
*row = report_name;
|
|
}
|
|
}
|
|
|
|
TString appname, desc;
|
|
const bool custom_app = rep2app(report_name, appname, desc);
|
|
const TString& cust_cmd = cmd2name(appname);
|
|
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..
|
|
{ //..e conseguenti forzati spegnimenti del computer
|
|
appname << ' ' << report_name;
|
|
if (vars.items() > 0)
|
|
{
|
|
FOR_EACH_ASSOC_OBJECT(vars, h, name, var)
|
|
appname<< ' ' << name << '=' << ((TVariant *) var)->as_string();
|
|
}
|
|
TExternal_app app(appname);
|
|
app.run(true);
|
|
}
|
|
else
|
|
{
|
|
if (report != NULL)
|
|
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 (report != NULL)
|
|
{
|
|
if (book.pages() > 0)
|
|
book.print_or_preview();
|
|
delete report;
|
|
report = NULL;
|
|
}
|
|
|
|
} while (can_repeat);
|
|
}
|
|
|
|
int ba8500(int argc, char* argv[])
|
|
{
|
|
TKlarkKent_app app;
|
|
app.run(argc, argv, TR("Stampa Report"));
|
|
return 0;
|
|
}
|