campo-sirio/ba/ba8300.cpp
guy e1ff54dd39 Patch level : 2.0 nopatch
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :

COrrezioni varie ai generatori di query e form


git-svn-id: svn://10.65.10.50/trunk@11817 c028cbd2-c16b-5b4b-a496-9718f37d4682
2004-03-09 15:20:36 +00:00

264 lines
5.4 KiB
C++
Executable File

#include <xi.h>
#include <applicat.h>
#include <automask.h>
#include <execp.h>
#include <prefix.h>
#include <tree.h>
#include <xml.h>
#include "ba8201.h"
#include "ba8300.h"
///////////////////////////////////////////////////////////
// TReport_window
///////////////////////////////////////////////////////////
class TReport_window : public TField_window
{
protected:
virtual void update();
public:
TReport_window(int x, int y, int dx, int dy, WINDOW parent, TWindowed_field* owner);
virtual ~TReport_window() { }
};
void TReport_window::update()
{
}
TReport_window::TReport_window(int x, int y, int dx, int dy, WINDOW parent, TWindowed_field* owner)
: TField_window(x, y, dx, dy, parent, owner)
{
}
class TReport_drawer : public TWindowed_field
{
protected:
virtual TField_window* create_window(int x, int y, int dx, int dy, WINDOW parent);
public:
TReport_drawer(TMask* m) : TWindowed_field(m) { }
};
TField_window* TReport_drawer::create_window(int x, int y, int dx, int dy, WINDOW parent)
{
return new TReport_window(x, y, dx, dy, parent, this);
}
///////////////////////////////////////////////////////////
// TSection_tree
///////////////////////////////////////////////////////////
class TSection_tree_node : public TObject
{
TString _str;
public:
const TString& description() const { return _str; }
TSection_tree_node(int level, const char* str) { _str = str; }
};
class TSection_tree : public TObject_tree
{
protected:
bool get_description(TString& str) const;
public:
void add_node(const char* d)
{ add_son(new TSection_tree_node(0, d)); }
void add_rnode(const char* d)
{ add_rbrother(new TSection_tree_node(0, d)); }
};
bool TSection_tree::get_description(TString& str) const
{
const TSection_tree_node* rn = (const TSection_tree_node*)curr_node();
if (rn != NULL)
{
str = rn->description();
return true;
}
return false;
}
///////////////////////////////////////////////////////////
// TReport_mask
///////////////////////////////////////////////////////////
class TReport_mask : public TAutomask
{
TSection_tree _tree;
protected:
virtual TMask_field* parse_field(TScanner& scanner);
virtual void handler(WINDOW win, EVENT* ep);
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
protected:
bool select_query();
bool select_report();
public:
TReport_mask();
};
TMask_field* TReport_mask::parse_field(TScanner& scanner)
{
if (scanner.token().starts_with("RE"))
return new TReport_drawer(this);
return TAutomask::parse_field(scanner);
}
bool TReport_mask::select_report()
{
TFilename path;
const bool ok = select_sql_file(path, "rep");
if (ok)
{
path = path.name(); path.ext("");
set(F_CODICE, path);
}
return ok;
}
bool TReport_mask::select_query()
{
TFilename path;
bool ok = select_sql_file(path, "qry");
if (ok)
{
TXmlItem item; item.Load(path);
const TXmlItem* sql = item.FindFirst("sql");
ok = sql != NULL;
if (ok)
{
TString str; sql->GetEnclosedText(str);
set(F_SQL, str, true);
}
}
return ok;
}
void TReport_mask::handler(WINDOW win, EVENT* ep)
{
TAutomask::handler(win, ep);
}
bool TReport_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_CODICE:
if (e == fe_button)
select_report();
break;
case F_SQL:
if (e == fe_init || e == fe_modify)
enable(F_SHOW_QRY, !o.empty());
break;
case F_NEW_QRY:
if (e == fe_button)
{
TExternal_app q("ba8 -1");
q.run();
}
break;
case F_IMPORT_QRY:
if (e == fe_button)
select_query();
break;
case F_SHOW_QRY:
if (e == fe_button)
{
TSQL_query qry(get(F_SQL));
if (qry.columns() > 0)
{
TQuery_sheet sheet(qry);
sheet.run();
}
}
break;
default:
break;
}
return true;
}
TReport_mask::TReport_mask()
{
read_mask("ba8300a", 0, -1);
set_handlers();
TTree_field& albero = tfield(F_SECTIONS);
albero.set_tree(&_tree);
RCT rct_sec; albero.get_rect(rct_sec);
RCT rct_rep; field(F_REPORT).get_rect(rct_rep);
rct_rep.left = rct_sec.right+ROWY;
rct_rep.right -= ROWY;
rct_rep.bottom -= ROWY;
field(F_REPORT).set_rect(rct_rep);
TString body_id, tail_id;
_tree.add_node("Report");
for (int i = 0; i <= 4; i++)
{
if (body_id.not_empty())
_tree.goto_node(body_id);
const char* name[3] = { "Testa", "Corpo", "Coda" };
TString16 bodyn;
for (int j = 0; j < 3; j++)
{
if (i > 0)
bodyn.format("%s %d", name[j], i);
else
bodyn = name[j];
if (j == 0)
_tree.add_node(bodyn);
else
_tree.add_rnode(bodyn);
if (j == 1)
_tree.curr_id(body_id); else
if (i == 0 && j == 2)
_tree.curr_id(tail_id);
}
}
_tree.goto_node(tail_id);
_tree.add_rnode("Pagina");
_tree.add_node("Testa");
_tree.add_rnode("Coda");
_tree.goto_root();
_tree.expand();
}
///////////////////////////////////////////////////////////
// TReporter_app
///////////////////////////////////////////////////////////
class TReporter_app : public TSkeleton_application
{
protected:
virtual void main_loop();
};
void TReporter_app::main_loop()
{
TReport_mask* msk = new TReport_mask;
msk->run();
delete msk;
}
int ba8300(int argc, char* argv[])
{
TReporter_app app;
app.run(argc, argv, TR("Report Generator"));
return 0;
}