Patch level : 2.1 nopatch

Files correlati     : ba8.exe
Ricompilazione Demo : [ ]
Commento            :

Salvataggio situazione attuale generazione report:
stato avanzamento lavori 50%


git-svn-id: svn://10.65.10.50/trunk@11899 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2004-03-23 16:39:40 +00:00
parent 276f827798
commit c6a02882e8
11 changed files with 1608 additions and 559 deletions

View File

@ -329,8 +329,18 @@ bool TColor_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
case 214:
if (e == fe_button)
{
xvt_dm_post_font_sel(TASK_WIN, xvt_default_font(), NULL, 0);
force_update();
XVT_FNTID fontid = xvt_default_font();
if (xvt_dm_post_font_sel(TASK_WIN, fontid, NULL, 0))
{
char font_ser_desc[512];
TConfig font(CONFIG_GUI, "Font");
xvt_font_serialize(fontid, font_ser_desc, sizeof(font_ser_desc));
font.set("FontDesc", font_ser_desc);
font.set_paragraph("Colors"); // Forza la scrittura del paragrafo
xvt_load_default_font();
force_update();
}
}
break;
default:

View File

@ -283,8 +283,6 @@ TTable_mask::~TTable_mask()
// TQuery_mask
///////////////////////////////////////////////////////////
enum TQueryExportFormat { fmt_unknown, fmt_html, fmt_txt, fmt_slk, fmt_campo };
// Maschera principale della costruzione della query
class TQuery_mask : public TAutomask
{
@ -323,11 +321,7 @@ protected:
bool save_tables_tree(TXmlItem& xml);
bool save_fields_sheet(TXmlItem& xml);
bool save_as_html(TSQL_query& qry, const TFilename& path, TProgind& pi) const;
bool save_as_silk(TSQL_query& qry, const TFilename& path, TProgind& pi) const;
bool save_as_text(TSQL_query& qry, const TFilename& path, TProgind& pi) const;
bool save_as_campo(TSQL_query& qry, const TFilename& path, TProgind& pi) const;
void save_as(TQueryExportFormat fmt);
void save_as(TRecordsetExportFormat fmt);
public:
bool load_query();
@ -686,178 +680,18 @@ static int select_callback(void* jolly, int argc, char** value, char** field)
void TQuery_mask::edit_query()
{
TSQL_query qry(get(F_SQL));
TSQL_recordset qry(get(F_SQL));
if (qry.columns() > 0)
{
TQuery_sheet sht(qry);
TRecordset_sheet sht(qry);
sht.run();
}
else
warning_box(TR("Nessuna riga risultato"));
}
bool TQuery_mask::save_as_html(TSQL_query& qry, const TFilename& path, TProgind& pi) const
{
ofstream out(path);
out << "<html>" << endl;
out << "<body>" << endl;
out << "<table border=\"1\">" << endl;
out << " <caption><h1>" << get(F_CODICE) << "</h1></caption>" << endl;
out << " <thead>";
for (unsigned int c = 0; c < qry.columns(); c++)
{
const TSQL_column_info& ci = qry.column_info(c);
TToken_string header(ci._name, '.');
TString str;
FOR_EACH_TOKEN(header, tok)
{
if (str.not_empty())
str << "<br/>";
str << tok;
}
out << " <th>" << str << "</th>" << endl;
}
out << " </thead>" << endl;
for (TRecnotype n = 0; n < qry.items(); n++)
{
pi.addstatus(1);
if (pi.iscancelled())
break;
const TString_array* arr = qry.row(n);
const int last = arr != NULL ? arr->last() : 0;
out << " <tr>" << endl;
for (int c = 0; c <= last; c++)
{
const TSQL_column_info& ci = qry.column_info(c);
out << " <td";
if (ci._numeric)
out << " align=\"right\"";
out << ">";
TString* val = (TString*)arr->objptr(c);
if (val && !val->blank())
{
val->rtrim();
out << *val;
}
out << " </td>" << endl;
}
out << " </tr>" << endl;
}
out << "</table>" << endl;
out << "</body>" << endl;
out << "</html>" << endl;
return !pi.iscancelled();
}
bool TQuery_mask::save_as_silk(TSQL_query& qry, const TFilename& path, TProgind& pi) const
{
ofstream out(path);
out << "ID;PWXL;N;E" << endl;
for (unsigned int c = 0; c < qry.columns(); c++)
{
const TSQL_column_info& ci = qry.column_info(c);
out << "C;Y1;X" << (c+1) << ";K\"" << ci._name << '"' << endl;
}
for (TRecnotype n = 0; n < qry.items(); n++)
{
pi.addstatus(1);
if (pi.iscancelled())
break;
const TString_array* arr = qry.row(n);
const int last = arr->last();
for (int c = 0; c <= last; c++)
{
out << "C;Y" << (n+2) << ";X" << (c+1) << ";K\"";
TString* val = (TString*)arr->objptr(c);
if (val && !val->blank())
{
val->rtrim();
val->replace('"', '\'');
out << *val;
}
out << '"' << endl;
}
}
out << "E" << endl;
return !pi.iscancelled();
}
bool TQuery_mask::save_as_text(TSQL_query& qry, const TFilename& path, TProgind& pi) const
{
ofstream out(path);
for (TRecnotype n = 0; n < qry.items(); n++)
{
const TString_array* arr = qry.row(n);
const int last = arr != NULL ? arr->last() : 0;
for (int c = 0; c <= last; c++)
{
if (c > 0)
out << '\t';
TString* val = (TString*)arr->objptr(c);
if (val && !val->blank())
{
val->rtrim();
out << *val;
}
}
out << endl;
pi.addstatus(1);
if (pi.iscancelled())
break;
}
return !pi.iscancelled();
}
bool TQuery_mask::save_as_campo(TSQL_query& qry, const TFilename& path, TProgind& pi) const
{
ofstream out(path);
out << "[Head]" << endl;
out << "Version=0";
for (unsigned int c = 0; c < qry.columns(); c++)
{
const TSQL_column_info& ci = qry.column_info(c);
if ((c % 8) == 0)
out << endl << "Fields=";
else
out << '|';
out << ci._name;
}
out << endl << endl << "[Data]" << endl;
for (TRecnotype n = 0; n < qry.items(); n++)
{
const TString_array* arr = qry.row(n);
const int last = arr != NULL ? arr->last() : 0;
for (int c = 0; c <= last; c++)
{
if (c > 0)
out << '|';
TString* val = (TString*)arr->objptr(c);
if (val && !val->blank())
{
val->rtrim();
out << *val;
}
}
out << endl;
pi.addstatus(1);
if (pi.iscancelled())
break;
}
return !pi.iscancelled();
}
void TQuery_mask::save_as(TQueryExportFormat fmt)
void TQuery_mask::save_as(TRecordsetExportFormat fmt)
{
xvt_fsys_save_dir();
TFilename path; path.tempdir();
@ -866,7 +700,7 @@ void TQuery_mask::save_as(TQueryExportFormat fmt)
switch (fmt)
{
case fmt_html: ext = "html"; break;
case fmt_slk : ext = "xls"; break;
case fmt_silk: ext = "xls"; break;
default: break;
}
@ -883,20 +717,11 @@ void TQuery_mask::save_as(TQueryExportFormat fmt)
xvt_fsys_convert_dir_to_str(&fs.dir, path.get_buffer(), path.size());
path.add(fs.name);
TSQL_query qry(get(F_SQL));
TSQL_recordset qry(get(F_SQL));
bool ok = qry.items() > 0;
if (ok)
{
TProgind pi(qry.items(), TR("Esportazione in corso..."), true, true);
switch (fmt)
{
case fmt_html : ok = save_as_html(qry, path, pi); break;
case fmt_slk : ok = save_as_silk(qry, path, pi); break;
case fmt_txt : ok = save_as_text(qry, path, pi); break;
case fmt_campo: ok = save_as_campo(qry, path, pi); break;
default: break;
}
ok = qry.save_as(path, fmt);
if (ok)
xvt_sys_goto_url(path, "open");
}
@ -988,14 +813,15 @@ bool TQuery_mask::save_fields_sheet(TXmlItem& xml)
bool TQuery_mask::save_query()
{
if (_curr_query.empty() && !field(F_CODICE).empty())
get_qry_path(_curr_query);
if (_curr_query.empty())
bool ok = _curr_query.not_empty();
if (!ok)
ok = get_qry_path(_curr_query);
if (!ok)
return field(F_CODICE).on_key(K_ENTER); // Segnala errore
char name[_MAX_FNAME];
xvt_fsys_parse_pathname (_curr_query, NULL, NULL, name, NULL, NULL);
const bool ok = *name > ' ';
ok = *name > ' ';
if (ok)
{
TXmlItem xml;
@ -1174,7 +1000,6 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
save_if_needed();
load_query();
get_qry_path(_curr_query);
}
break;
case F_TABLES:
@ -1233,11 +1058,11 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
break;
case F_EXPORT_EXCEL:
if (e == fe_button)
save_as(fmt_slk);
save_as(fmt_silk);
break;
case F_EXPORT_TXT:
if (e == fe_button)
save_as(fmt_txt);
save_as(fmt_text);
break;
case F_EXPORT_CAMPO:
if (e == fe_button)
@ -1266,7 +1091,10 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
send_key(K_F9, F_CODICE);
case DLG_SAVEREC:
if (e == fe_button)
{
get_qry_path(_curr_query);
save_query();
}
break;
case DLG_DELREC:
if (e == fe_button && jolly == 0) // Elimina della Toolbar
@ -1349,16 +1177,16 @@ TQuery_mask::TQuery_mask() : TAutomask("ba8200a"), _curr_num(0), _is_dirty(false
}
///////////////////////////////////////////////////////////
// TSQL_query_app
// TSQL_recordset_app
///////////////////////////////////////////////////////////
class TSQL_query_app : public TSkeleton_application
class TSQL_recordset_app : public TSkeleton_application
{
public:
virtual void main_loop();
};
void TSQL_query_app::main_loop()
void TSQL_recordset_app::main_loop()
{
TQuery_mask* msk = new TQuery_mask;
msk->run();
@ -1367,7 +1195,7 @@ void TSQL_query_app::main_loop()
int ba8200(int argc, char* argv[])
{
TSQL_query_app app;
TSQL_recordset_app app;
app.run(argc, argv, TR("Query Generator"));
return 0;
}

View File

@ -13,6 +13,234 @@
#include "ba8201.h"
const TString& TRecordset::get(const char* column_name) const
{
for (unsigned int i = 0; i < columns(); i++)
{
const TRecordset_column_info& info = column_info(i);
if (info._name == column_name)
return get(i);
}
return EMPTY_STRING;
}
const TToken_string& TRecordset::sheet_head() const
{
TToken_string& head = get_tmp_string();
TToken_string tablefield(32, '.');
for (unsigned int c = 0; c < columns(); c++)
{
const TRecordset_column_info& ci = column_info(c);
tablefield = ci._name;
int maxlen = 0;
FOR_EACH_TOKEN(tablefield, tok)
{
if (maxlen == 0)
head.add(tok);
else
head << '\n' << tok;
const int len = strlen(tok);
if (len > maxlen)
maxlen = len;
}
head << '@' << max(ci._width, maxlen);
if (ci._numeric)
head << 'R';
}
return head;
}
bool TRecordset::save_as_html(const char* path)
{
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
ofstream out(path);
out << "<html>" << endl;
out << "<body>" << endl;
out << "<table border=\"1\">" << endl;
out << " <caption><h1>" << path << "</h1></caption>" << endl;
out << " <thead>";
for (unsigned int c = 0; c < columns(); c++)
{
const TRecordset_column_info& ci = column_info(c);
TToken_string header(ci._name, '.');
TString str;
FOR_EACH_TOKEN(header, tok)
{
if (str.not_empty())
str << "<br/>";
str << tok;
}
out << " <th>" << str << "</th>" << endl;
}
out << " </thead>" << endl;
TString val;
for (TRecnotype n = 0; n < items(); n++)
{
move_to(n);
pi.addstatus(1);
if (pi.iscancelled())
break;
out << " <tr>" << endl;
for (unsigned int c = 0; c < columns(); c++)
{
const TRecordset_column_info& ci = column_info(c);
out << " <td";
if (ci._numeric)
out << " align=\"right\"";
out << ">";
val = get(c);
if (!val.blank())
{
val.rtrim();
out << val;
}
out << " </td>" << endl;
}
out << " </tr>" << endl;
}
out << "</table>" << endl;
out << "</body>" << endl;
out << "</html>" << endl;
return !pi.iscancelled();
}
bool TRecordset::save_as_silk(const char* path)
{
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
ofstream out(path);
out << "ID;PWXL;N;E" << endl;
for (unsigned int c = 0; c < columns(); c++)
{
const TRecordset_column_info& ci = column_info(c);
out << "C;Y1;X" << (c+1) << ";K\"" << ci._name << '"' << endl;
}
TString val;
for (TRecnotype n = 0; n < items(); n++)
{
move_to(n);
pi.addstatus(1);
if (pi.iscancelled())
break;
for (unsigned int c = 0; c < columns(); c++)
{
out << "C;Y" << (n+2) << ";X" << (c+1) << ";K\"";
val = get(c);
if (!val.blank())
{
val.rtrim();
val.replace('"', '\'');
out << val;
}
out << '"' << endl;
}
}
out << "E" << endl;
return !pi.iscancelled();
}
bool TRecordset::save_as_text(const char* path)
{
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
ofstream out(path);
TString val;
for (TRecnotype n = 0; n < items(); n++)
{
move_to(n);
for (unsigned int c = 0; c < columns(); c++)
{
if (c > 0)
out << '\t';
val = get(c);
if (!val.blank())
{
val.rtrim();
out << val;
}
}
out << endl;
pi.addstatus(1);
if (pi.iscancelled())
break;
}
return !pi.iscancelled();
}
bool TRecordset::save_as_campo(const char* path)
{
TProgind pi(items(), TR("Esportazione in corso..."), true, true);
ofstream out(path);
out << "[Head]" << endl;
out << "Version=0";
for (unsigned int c = 0; c < columns(); c++)
{
const TRecordset_column_info& ci = column_info(c);
if ((c % 8) == 0)
out << endl << "Fields=";
else
out << '|';
out << ci._name;
}
out << endl << endl << "[Data]" << endl;
TString val;
for (TRecnotype n = 0; n < items(); n++)
{
move_to(n);
for (unsigned int c = 0; c < columns(); c++)
{
if (c > 0)
out << '|';
val = get(c);
if (!val.blank())
{
val.rtrim();
out << val;
}
}
out << endl;
pi.addstatus(1);
if (pi.iscancelled())
break;
}
return !pi.iscancelled();
}
bool TRecordset::save_as(const char* path, TRecordsetExportFormat fmt)
{
if (fmt == fmt_unknown)
{
TString ext;
xvt_fsys_parse_pathname(path, NULL, NULL, NULL, ext.get_buffer(), NULL);
ext.lower();
if (ext.starts_with("htm"))
fmt = fmt_html; else
if (ext == "xls" || ext == "slk")
fmt = fmt_silk;
}
bool ok = false;
switch (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;
default : ok = save_as_text(path); break;
}
return ok;
}
///////////////////////////////////////////////////////////
// Utility
///////////////////////////////////////////////////////////
@ -441,10 +669,10 @@ TSQLite::~TSQLite()
}
///////////////////////////////////////////////////////////
// TSQL_query
// TSQL_recordset
///////////////////////////////////////////////////////////
void TSQL_query::reset()
void TSQL_recordset::reset()
{
_firstrow = _items = 0;
_pagesize = 512;
@ -452,13 +680,13 @@ void TSQL_query::reset()
_column.destroy();
}
int TSQL_query::on_get_items(int argc, char** values, char** columns)
int TSQL_recordset::on_get_items(int argc, char** values, char** columns)
{
if (_column.items() == 0)
{
for (int i = 0; i < argc; i++)
{
TSQL_column_info* info = new TSQL_column_info;
TRecordset_column_info* info = new TRecordset_column_info;
info->_name = columns[i];
info->_width = 1;
info->_numeric = true;
@ -469,7 +697,7 @@ int TSQL_query::on_get_items(int argc, char** values, char** columns)
{
for (int i = 0; i < argc; i++) if (values[i] && *values[i])
{
TSQL_column_info& info = (TSQL_column_info&)_column[i];
TRecordset_column_info& info = (TRecordset_column_info&)_column[i];
const int len = strlen(values[i]);
if (len > info._width)
info._width = len;
@ -484,28 +712,28 @@ int TSQL_query::on_get_items(int argc, char** values, char** columns)
static int query_get_items(void* jolly, int argc, char** values, char** columns)
{
TSQL_query* q = (TSQL_query*)jolly;
TSQL_recordset* q = (TSQL_recordset*)jolly;
q->on_get_items(argc, values, columns);
return SQLITE_OK;
}
TRecnotype TSQL_query::items() const
TRecnotype TSQL_recordset::items() const
{
if (_items == 0)
_TheDataBase.exec(_sql, query_get_items, (TSQL_query*)this);
_TheDataBase.exec(_sql, query_get_items, (TSQL_recordset*)this);
return _items;
}
unsigned int TSQL_query::columns() const
unsigned int TSQL_recordset::columns() const
{
if (_column.items() == 0)
items();
return _column.items();
}
const TSQL_column_info& TSQL_query::column_info(unsigned int c) const
const TRecordset_column_info& TSQL_recordset::column_info(unsigned int c) const
{
return (const TSQL_column_info&)_column[c];
return (const TRecordset_column_info&)_column[c];
}
static int query_get_rows(void* jolly, int argc, char** values, char** columns)
@ -518,10 +746,11 @@ static int query_get_rows(void* jolly, int argc, char** values, char** columns)
return SQLITE_OK;
}
const TString_array* TSQL_query::row(TRecnotype n)
bool TSQL_recordset::move_to(TRecnotype n)
{
_current_row = n;
if (n < 0 || n >= items())
return NULL;
return false;
if (n < _firstrow || n >= _firstrow+_page.items())
{
@ -542,10 +771,30 @@ const TString_array* TSQL_query::row(TRecnotype n)
_TheDataBase.exec(sql, query_get_rows, &_page);
}
return (const TString_array*)_page.objptr(n-_firstrow);
return true;
}
void TSQL_query::set(const char* sql)
const TString_array* TSQL_recordset::row(TRecnotype n)
{
const TString_array* a = NULL;
if (move_to(n))
a = (const TString_array*)_page.objptr(n-_firstrow);
return a;
}
const TString& TSQL_recordset::get(unsigned int c) const
{
const TString_array* a = (const TString_array*)_page.objptr(_current_row-_firstrow);
if (a != NULL)
{
const TString* s = (const TString*)a->objptr(c);
if (s != NULL)
return *s;
}
return EMPTY_STRING;
}
void TSQL_recordset::set(const char* sql)
{
reset();
_sql = sql;
@ -553,59 +802,32 @@ void TSQL_query::set(const char* sql)
_TheDataBase.parse_select_from(_sql);
}
const TToken_string& TSQL_query::sheet_head() const
{
TToken_string& head = get_tmp_string();
TToken_string tablefield(32, '.');
for (unsigned int c = 0; c < columns(); c++)
{
const TSQL_column_info& ci = column_info(c);
tablefield = ci._name;
int maxlen = 0;
FOR_EACH_TOKEN(tablefield, tok)
{
if (maxlen == 0)
head.add(tok);
else
head << '\n' << tok;
const int len = strlen(tok);
if (len > maxlen)
maxlen = len;
}
head << '@' << max(ci._width, maxlen);
if (ci._numeric)
head << 'R';
}
return head;
}
TSQL_query::TSQL_query(const char* sql)
TSQL_recordset::TSQL_recordset(const char* sql)
{
set(sql);
}
///////////////////////////////////////////////////////////
// TQuery_sheet
// TRecordset_sheet
///////////////////////////////////////////////////////////
void TQuery_sheet::get_row(long r, TToken_string& row)
void TRecordset_sheet::get_row(long r, TToken_string& row)
{
row.separator('\t');
row.cut(0);
if (r >= 0 && r < items())
if (_query.move_to(r))
{
TString_array& arr = (TString_array&)*_query.row(r);
FOR_EACH_ARRAY_ROW(arr, i, str)
row.add(*str);
for (unsigned int c = 0; c < _query.columns(); c++)
row.add(_query.get(c));
}
}
long TQuery_sheet::get_items() const
long TRecordset_sheet::get_items() const
{
return _query.items();
}
TQuery_sheet::TQuery_sheet(TSQL_query& query)
: TSheet(-1, -1, -2, -4, "Query", query.sheet_head()), _query(query)
TRecordset_sheet::TRecordset_sheet(TRecordset& query)
: TSheet(-1, -1, -2, -4, "Query", query.sheet_head()), _query(query)
{
}

View File

@ -5,63 +5,90 @@
#include <sheet.h>
#endif
///////////////////////////////////////////////////////////
// TSQL_query
///////////////////////////////////////////////////////////
struct TSQL_column_info : public TObject
struct TRecordset_column_info : public TObject
{
TString _name;
int _width;
bool _numeric;
};
///////////////////////////////////////////////////////////
// TRecordset
///////////////////////////////////////////////////////////
class TSQL_query : public TObject
enum TRecordsetExportFormat { fmt_unknown, fmt_html, fmt_text, fmt_silk, fmt_campo };
class TRecordset : public TObject
{
protected:
bool save_as_html(const char* path);
bool save_as_silk(const char* path);
bool save_as_text(const char* path);
bool save_as_campo(const char* path);
public: // Absolutely needed methods
virtual TRecnotype items() const pure;
virtual bool move_to(TRecnotype pos) pure;
virtual TRecnotype current_row() const pure;
virtual unsigned int columns() const pure;
virtual const TRecordset_column_info& column_info(unsigned int column) const pure;
virtual const TString& get(unsigned int column) const pure;
virtual const TString& get(const char* column_name) const;
virtual const TToken_string& sheet_head() const;
virtual bool save_as(const char* path, TRecordsetExportFormat fmt = fmt_unknown);
};
///////////////////////////////////////////////////////////
// TSQL_recordset
///////////////////////////////////////////////////////////
class TSQL_recordset : public TRecordset
{
TString _sql;
TRecnotype _firstrow, _pagesize, _items;
TRecnotype _firstrow, _pagesize, _items, _current_row;
TArray _column;
TArray _page;
protected:
void reset();
bool save_as_html(const TFilename& path);
bool save_as_silk(const TFilename& path);
bool save_as_text(const TFilename& path);
bool save_as_campo(const TFilename& path);
public: // TRecordset
virtual TRecnotype items() const;
virtual bool move_to(TRecnotype pos);
virtual TRecnotype current_row() const { return _current_row; }
virtual unsigned int columns() const;
virtual const TRecordset_column_info& column_info(unsigned int c) const;
virtual const TString& get(unsigned int column) const;
public:
void set(const char* sql);
// Internal use only
virtual int on_get_items(int argc, char** values, char** columns);
TRecnotype items() const;
const TString_array* row(TRecnotype n);
unsigned int columns() const;
const TSQL_column_info& column_info(unsigned int c) const;
const TToken_string& sheet_head() const; // Used by TQuery_sheet
TSQL_query(const char* sql);
virtual ~TSQL_query() { }
TSQL_recordset(const char* sql);
virtual ~TSQL_recordset() { }
};
///////////////////////////////////////////////////////////
// TQuery_sheet
// TRecordset_sheet
///////////////////////////////////////////////////////////
class TQuery_sheet : public TSheet
class TRecordset_sheet : public TSheet
{
TSQL_query& _query;
TRecordset& _query;
protected:
virtual void get_row(long r, TToken_string& row);
virtual long get_items() const;
public:
TQuery_sheet(TSQL_query& sql);
TRecordset_sheet(TRecordset& sql);
};
///////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +1,29 @@
#define F_CODICE 101
#define F_DESCR 102
#define F_CODICE 101
#define F_DESCR 102
#define F_SECTIONS 103
#define F_REPORT 104
#define F_FIELD 105
#define F_PROPERTIES 106
#define F_X 111
#define F_Y 112
#define F_DX 113
#define F_DY 114
#define F_TEXT 115
#define F_SOURCE 116
#define F_HALIGN 117
#define F_VALIGN 118
#define F_BORDER 119
#define F_FGCOLOR 120
#define F_BGCOLOR 121
#define F_SECTIONS 103
#define F_REPORT 104
#define F_TYPE 105
#define F_FLD_PROPERTIES 106
#define F_SEC_PROPERTIES 107
#define F_X 111
#define F_Y 112
#define F_DX 113
#define F_DY 114
#define F_TEXT 115
#define F_SOURCE 116
#define F_HALIGN 117
#define F_VALIGN 118
#define F_BORDER 119
#define F_FGCOLOR 120
#define F_BGCOLOR 121
#define F_FONT_SELECT 122
#define F_LEVEL 130
#define F_GROUP_BY 131
#define F_HIDE_IF_NEEDED 132
#define F_SQL 201
#define F_IMPORT_QRY 202
#define F_NEW_QRY 203
#define F_SHOW_QRY 204
#define F_SQL 201
#define F_IMPORT_QRY 202
#define F_NEW_QRY 203
#define F_SHOW_QRY 204

View File

@ -71,18 +71,24 @@ BEGIN
PROMPT 21 3 ""
END
BUTTON F_FIELD 10 2
BUTTON F_TYPE 10 2
BEGIN
PROMPT -16 -1 "Campo"
GROUP 1
END
BUTTON F_PROPERTIES 10 2
BUTTON F_FLD_PROPERTIES 10 2
BEGIN
PROMPT -26 -1 "Proprieta'"
GROUP 1
END
BUTTON F_SEC_PROPERTIES 10 2
BEGIN
PROMPT -36 -1 "Sezione"
GROUP 1
END
NUMBER F_Y 3
BEGIN
PROMPT 58 -1 "Riga "

120
ba/ba8300b.uml Executable file
View File

@ -0,0 +1,120 @@
#include "ba8300.h"
PAGE "Campo" -1 -1 60 13
RADIOBUTTON F_TYPE 1 16
BEGIN
PROMPT 1 0 "@bTipo"
ITEM "T|Testo"
MESSAGE SHOW,1@
ITEM "S|Stringa"
MESSAGE SHOW,1@
ITEM "N|Numero"
MESSAGE SHOW,1@
ITEM "D|Data"
MESSAGE SHOW,1@
ITEM "L|Linea"
MESSAGE HIDE,1@
ITEM "R|Rettangolo"
MESSAGE HIDE,1@
ITEM "I|Immagine"
MESSAGE HIDE,1@|SHOW,F_SOURCE
END
GROUPBOX DLG_NULL 40 9
BEGIN
PROMPT 18 0 "@bParametri"
END
STRING F_Y 6
BEGIN
PROMPT 20 1 "Riga "
FLAGS "R"
END
STRING F_X 6
BEGIN
PROMPT 40 1 "Colonna "
FLAGS "R"
END
STRING F_DX 6
BEGIN
PROMPT 20 2 "Larghezza "
FLAGS "R"
END
STRING F_DY 6
BEGIN
PROMPT 40 2 "Altezza "
FLAGS "R"
END
LIST F_HALIGN 1 12
BEGIN
PROMPT 20 3 "Allineamento orizz. "
ITEM "L|Sinistra"
ITEM "R|Destra"
ITEM "C|Centrato"
ITEM "J|Giustificato"
GROUP 1
END
LIST F_VALIGN 1 12
BEGIN
PROMPT 20 4 "Allineamento vert. "
ITEM "B|Basso"
ITEM "C|Centrato"
ITEM "T|Alto"
GROUP 1
END
LIST F_BORDER 1 12
BEGIN
PROMPT 20 5 "Bordo "
ITEM "0|Nessuno"
ITEM "1|Normale"
ITEM "3|Spesso"
END
BUTTON F_FGCOLOR 14 1
BEGIN
PROMPT 20 6 "Colore Testo"
END
BUTTON F_BGCOLOR 14 1
BEGIN
PROMPT 20 7 "Colore Sfondo"
END
STRING F_TEXT 196 50
BEGIN
PROMPT 1 9 "Formato "
GROUP 1
END
STRING F_SOURCE 80 50
BEGIN
PROMPT 1 10 "Dato "
GROUP 1
END
BUTTON DLG_CANCEL 10 2
BEGIN
PROMPT -13 -1 ""
END
BUTTON DLG_DELREC 10 2
BEGIN
PROMPT -23 -1 ""
END
BUTTON DLG_OK 10 2
BEGIN
PROMPT -33 -1 ""
END
ENDPAGE
ENDMASK

70
ba/ba8300c.uml Executable file
View File

@ -0,0 +1,70 @@
#include "ba8300.h"
PAGE "Sezione" -1 -1 60 13
LISTBOX F_TYPE 1 8
BEGIN
PROMPT 1 1 "Tipo "
ITEM "H|Testa"
ITEM "B|Corpo"
ITEM "F|Coda"
FLAGS "D"
END
NUMBER F_LEVEL 1
BEGIN
PROMPT 21 1 "Livello "
FLAGS "D"
END
STRING F_DX 6
BEGIN
PROMPT 1 2 "Larghezza "
FLAGS "R"
END
STRING F_DY 6
BEGIN
PROMPT 21 2 "Altezza "
FLAGS "R"
END
STRING F_GROUP_BY 80 50
BEGIN
// Visibile per sezioni con livello > 1
PROMPT 1 3 "Raggruppamento "
FLAGS "H"
CHECKTYPE REQUIRED
END
BOOLEAN F_HIDE_IF_NEEDED
BEGIN
// Visibile per testa e coda di pagina
PROMPT 1 3 "Nascondi sezione sulla prima/ultima pagina"
FLAGS "H"
END
BUTTON F_FONT_SELECT 10 2
BEGIN
PROMPT -13 -3 "~Font"
END
BUTTON DLG_CANCEL 10 2
BEGIN
PROMPT -13 -1 ""
END
BUTTON DLG_DELREC 10 2
BEGIN
PROMPT -23 -1 ""
END
BUTTON DLG_OK 10 2
BEGIN
PROMPT -33 -1 ""
END
ENDPAGE
ENDMASK

View File

@ -1,66 +1,39 @@
#include <colors.h>
#include <diction.h>
#include <mask.h>
#include <printer.h>
#include <xml.h>
#include "ba8301.h"
#include <bagn003.h>
///////////////////////////////////////////////////////////
// TXVT_font
///////////////////////////////////////////////////////////
// boxing di un XVT_FNTID in un TObject per poterlo inserire in un TArray
class TXVT_font : public TObject
{
XVT_FNTID _fontid;
public:
operator XVT_FNTID() const { return _fontid; }
void create(const TString& name, int size, XVT_FONT_STYLE_MASK style);
void destroy();
TXVT_font() : _fontid(NULL) { }
virtual ~TXVT_font() { destroy(); }
};
void TXVT_font::create(const TString& name, int size, XVT_FONT_STYLE_MASK style)
{
destroy();
_fontid = xvt_font_create();
xvt_font_set_family(_fontid, (char*)(const char*)name);
xvt_font_set_size(_fontid, size);
xvt_font_set_style(_fontid, style);
}
void TXVT_font::destroy()
{
if (_fontid != NULL)
{
xvt_font_destroy(_fontid);
_fontid = NULL;
}
}
///////////////////////////////////////////////////////////
// TReport_font
///////////////////////////////////////////////////////////
XVT_FNTID TReport_font::get_xvt_font(WINDOW win, int ppi) const
XVT_FNTID TReport_font::get_xvt_font(const TWindow& win) const
{
TXVT_font* font = (TXVT_font*)_physical.objptr(ppi);
if (font == NULL)
if (win.win() != _win_mapped)
{
int mi = 0, me = 0, ma = ppi/4;
const int cpi = 120 / DEFAULT_FONT_SIZE;
const PNT pnt0 = win.log2dev(0,0);
const PNT pnt1 = win.log2dev(cpi*100,100);
const int ppi = pnt1.h - pnt0.h;
const TString emme(cpi, 'M');
int mi = 0, me = 0, ma = 2*(pnt1.v - pnt0.v);
int best = 0, best_error = 0;
TXVT_font f;
while (mi < ma)
while (mi <= ma)
{
me = (mi+ma)/2;
f.create("Courier New", me, XVT_FS_NONE);
xvt_dwin_set_font(win, f);
const int width = xvt_dwin_get_text_width(win, "MMMMMMMMMMMMMMMMMMMMMMMM", _cpi);
XVT_FNTID fontid = xvt_font_create();
xvt_font_set_family(fontid, "Courier New");
xvt_font_set_size(fontid, me);
xvt_dwin_set_font(win.win(), fontid);
const int width = xvt_dwin_get_text_width(win.win(), emme, -1);
const int error = abs(width - ppi);
xvt_font_destroy(fontid);
if (best == 0 || error < best_error)
{
best = me;
@ -73,42 +46,65 @@ XVT_FNTID TReport_font::get_xvt_font(WINDOW win, int ppi) const
else
mi = me+1;
}
const int nSize = cpi * best / _cpi;
XVT_FONT_STYLE_MASK style = 0;
if (_bold) style |= XVT_FS_BOLD;
if (_italic) style |= XVT_FS_ITALIC;
if (_underline) style |= XVT_FS_UNDERLINE;
font = new TXVT_font;
font->create(_name, best, style);
((TArray&)_physical).add(font, ppi);
XVT_FNTID fontid = xvt_font_create();
xvt_font_set_family(fontid, (char*)(const char*)_name);
xvt_font_set_size(fontid, best);
xvt_font_set_style(fontid, _style);
if (_fontid != NULL)
xvt_font_destroy(_fontid);
((TReport_font*)this)->_fontid = fontid;
((TReport_font*)this)->_win_mapped = win.win();
}
return *font;
return _fontid;
}
TReport_font::TReport_font()
: _name("Courier New"), _size(DEFAULT_FONT_SIZE),
_bold(false), _italic(false), _underline(false)
{
void TReport_font::create(const char* name, int size, XVT_FONT_STYLE_MASK style)
{
_name = name;
_size = size;
_style = style;
_cpi = 120 / _size;
if (_fontid != NULL)
{
xvt_font_destroy(_fontid);
_fontid = NULL;
_win_mapped = NULL_WIN;
}
}
void TReport_font::copy(const TReport_font& font)
{
create(font.name(), font.size(), font.style());
}
TReport_font::TReport_font() : _fontid(NULL), _win_mapped(NULL_WIN)
{
create("Courier New", DEFAULT_FONT_SIZE, XVT_FS_NONE);
}
TReport_font::~TReport_font()
{
if (_fontid != NULL)
xvt_font_destroy(_fontid);
}
///////////////////////////////////////////////////////////
// TReport_section
///////////////////////////////////////////////////////////
void TReport_section::description(TString& str) const
TReport_section* TReport_section::father_section() const
{
switch (_type)
if (level() <= 0)
{
case 'B': str = TR("Corpo"); break;
case 'F': str = TR("Coda"); break;
case 'H': str = TR("Testa"); break;
case 'P': str = TR("Sfondo"); break; // Virtual section
case 'R': str = TR("Report"); break; // Virtual section
default : break;
if (type() != 'B')
return _report.find_section('B', 0);
}
if (_level > 0)
str << ' ' << _level;
else
return _report.find_section('B', type() == 'B' ? 0 : 1);
return NULL;
}
const TReport_font& TReport_section::font() const
@ -116,19 +112,56 @@ const TReport_font& TReport_section::font() const
const TReport_font* f = _font;
if (f == NULL)
{
if (_father == NULL)
{
(TReport_font*)_font = new TReport_font;
f = _font;
}
TReport_section* father = father_section();
if (father == NULL)
f = &_report.font();
else
f = &_father->font();
f = &father->font();
}
return *f;
}
TReport_section::TReport_section(const TReport_section* f, char t, int l)
: _father(f), _type(t), _level(l), _font(NULL)
void TReport_section::set_font(const char* name, int size, XVT_FONT_STYLE_MASK style)
{
if (_font == NULL)
_font = new TReport_font;
_font->create(name, size, style);
}
int TReport_section::add(TObject* obj)
{
TReport_field* rf = (TReport_field*)obj;
rf->set_section(this);
return TArray::add(obj);
}
int TReport_section::add(TObject& obj)
{
TReport_field& rf = (TReport_field&)obj;
rf.set_section(this);
return TArray::add(obj);
}
bool TReport_section::get_rect(RCT& rct) const
{
rct.left = rct.top = 0;
rct.right = _width;
rct.bottom = _height;
FOR_EACH_ARRAY_ITEM((*this), i, o)
{
const TReport_field& rf = (const TReport_field&)o;
RCT r; rf.get_rect(r);
if (r.right > rct.right)
rct.right = r.right;
if (r.bottom > rct.bottom)
rct.bottom = r.bottom;
}
return xvt_rect_is_empty(&rct) == FALSE;
}
TReport_section::TReport_section(TReport& r, char t, int l)
: _report(r), _type(t), _level(l), _font(NULL),
_width(0), _height(0), _hidden_if_needed(false)
{ }
TReport_section::~TReport_section()
@ -156,7 +189,7 @@ void TReport_field::set_size(short w, short h)
void TReport_field::get_rect(RCT& r) const
{
r.left = _x; r.top = _y;
r.right = _x + _width; r.bottom = _y+_height;
r.right = _x + _width; r.bottom = _y + _height;
}
void TReport_field::offset(const TPoint& pt)
@ -180,16 +213,129 @@ void TReport_field::copy(const TReport_field& rf)
_halign = rf._halign; _valign = rf._valign;
_picture = rf._picture; _field = rf._field;
_selected = false;
_font = NULL;
if (_font != NULL)
{
delete _font;
_font = NULL;
}
if (rf._font != NULL)
_font = new TReport_font(rf.font());
}
TReport_field::TReport_field(TReport_section* sec)
: _section(sec), _type('T'), _selected(false), _font(NULL),
_fgcolor(COLOR_BLACK), _bgcolor(COLOR_WHITE)
const char* TReport_field::type_name() const
{
const char* n = NULL;
switch (_type)
{
case 'D': n = "Data"; break;
case 'I': n = "Immagine"; break;
case 'L': n = "Linea"; break;
case 'N': n = "Numero"; break;
case 'R': n = "Rettangolo"; break;
case 'S': n = "Stringa"; break;
case 'T': n = "Testo"; break;
default : break;
}
return n;
}
void TReport_field::draw_rect(TWindow& win) const
{
if (border() > 0 || color_distance(back_color(), COLOR_WHITE) != 0)
{
win.set_pen(fore_color(), border());
win.set_brush(back_color(), PAT_SOLID);
RCT r; get_rect(r);
const PNT f = win.log2dev(r.left, r.top);
const PNT t = win.log2dev(r.right, r.bottom);
r.left = f.h; r.top = f.v;
r.right = t.h; r.bottom = t.v;
xvt_dwin_draw_rect(win.win(), &r);
}
}
void TReport_field::draw_text(TWindow& win, const char* text) const
{
draw_rect(win);
win.set_color(fore_color(), back_color());
XVT_FNTID fid = font().get_xvt_font(win);
xvt_dwin_set_font(win.win(), fid);
RCT r; get_rect(r);
const PNT f = win.log2dev(r.left, r.top);
const PNT t = win.log2dev(r.right, r.bottom);
xvt_dwin_draw_text(win.win(), f.h, t.v-2, text, -1);
}
void TReport_field::draw(TWindow& win) const
{
switch (_type)
{
case 'L':
{
win.set_pen(fore_color(), border());
RCT r; get_rect(r);
win.line(r.left, r.top, r.right, r.bottom);
}
break;
case 'R': draw_rect(win); break;
default : draw_text(win, picture()); break;
}
}
static short get_num_attr(const TXmlItem& item, const char* attr, short def = 0)
{
const TString& str = item.GetAttr(attr);
if (str.not_empty())
{
real n = str; n *=CENTO ;
def = (short)n.integer();
}
return def;
}
static COLOR get_col_attr(const TXmlItem& item, const char* attr, COLOR col)
{
const TString& str = item.GetAttr(attr);
if (str[0] == '#')
sscanf(str, "#%X", &col);
return col;
}
static char get_chr_attr(const TXmlItem& item, const char* attr, char c)
{
const TString& str = item.GetAttr(attr);
if (str[0] > ' ')
c = toupper(str[0]);
return c;
}
TReport_field::TReport_field()
: _section(NULL), _type('T'), _selected(false), _font(NULL),
_border(0), _fgcolor(COLOR_BLACK), _bgcolor(COLOR_WHITE)
{
set_pos(0,0);
set_size(1600,100);
_picture = "###.###.##@,@@";
}
TReport_field::TReport_field(const TXmlItem& fld)
: _section(NULL), _selected(false), _font(NULL)
{
set_type(get_chr_attr(fld, "type", 'T'));
set_column(get_num_attr(fld, "x"));
set_row(get_num_attr(fld, "y"));
set_width(get_num_attr(fld, "width"));
set_height(get_num_attr(fld, "height", 100));
set_border(fld.GetIntAttr("border"));
set_back_color(get_col_attr(fld, "bg_color", COLOR_WHITE));
set_fore_color(get_col_attr(fld, "fg_color", COLOR_BLACK));
set_horizontal_alignment(get_chr_attr(fld, "align", 'L'));
set_vertical_alignment(get_chr_attr(fld, "valign", 'B'));
set_picture(fld.GetAttr("text"));
TXmlItem* src = fld.FindFirst("source");
if (src != NULL)
src->GetEnclosedText(_field);
}
///////////////////////////////////////////////////////////
@ -206,28 +352,103 @@ TReport_section* TReport::find_section(char type, int level) const
return sec;
}
bool TReport::kill_section(char type, int level)
{
TString4 key; build_section_key(type, level, key);
return _sections.remove(key);
}
int TReport::find_max_level() const
{
int lev = 1;
TAssoc_array& ass = (TAssoc_array&)_sections;
FOR_EACH_ASSOC_OBJECT(ass, h, k, o)
{
const int l = k[1]-'0';
if (l > lev)
lev = l;
}
return lev;
}
TReport_section& TReport::section(char type, int level)
{
TReport_section* sec = find_section(type, level);
if (sec == NULL)
{
TString4 key; build_section_key(type, level, key);
TReport_section* father = NULL;
if (level > 1)
father = find_section('B', level-1);
else
{
if (type != 'R')
father = find_section('R', 0);
}
CHECK(type == 'R' || father != NULL, "Mater certa est...");
sec = new TReport_section(father, type, level);
sec = new TReport_section(*this, type, level);
TString4 key; key.format("%c%d", type, level);
_sections.add(key, sec);
}
return *sec;
}
TReport::TReport() : _cpi(12), _lpi(6)
void TReport::destroy()
{
_sections.destroy();
_sql.cut(0);
_description.cut(0);
}
void TReport::load_sections(const TXmlItem& xml)
{
for (int i = 0; i < xml.GetChildren(); i++)
{
const TXmlItem& sec = *xml.GetChild(i);
if (sec.GetTag() != "section")
continue;
const char type = sec.GetAttr("type")[0];
const int level = sec.GetIntAttr("level");
TReport_section& rs = section(type, level);
rs.hide_if_needed(sec.GetIntAttr("hidden_if_needed") != 0);
if (level > 1)
{
const TXmlItem* gb = xml.FindFirst("groupby");
if (gb != NULL)
{
TString str;
gb->GetEnclosedText(str);
rs.group_by(str);
}
}
for (int j = 0; j < sec.GetChildren(); j++)
{
const TXmlItem& fld = *sec.GetChild(j);
if (fld.GetTag() != "field")
continue;
TReport_field* rf = new TReport_field(fld);
rs.add(rf);
}
}
}
bool TReport::load(const char* fname)
{
destroy();
TXmlItem xml;
_path = fname;
bool ok = xml.Load(_path);
if (ok)
{
const TXmlItem* desc = xml.FindFirst("description");
if (desc != NULL)
desc->GetEnclosedText(_description);
if (xml.FindFirst("section") != NULL)
load_sections(xml);
const TXmlItem* sql = xml.FindFirst("sql");
if (sql != NULL)
sql->GetEnclosedText(_sql);
}
return ok;
}
TReport::TReport() : _lpi(6)
{ }
///////////////////////////////////////////////////////////

View File

@ -9,40 +9,82 @@
#include <window.h>
#endif
///////////////////////////////////////////////////////////
// TReport_font
///////////////////////////////////////////////////////////
class TReport_font : public TObject
{
enum { DEFAULT_FONT_SIZE = 10 };
TString _name;
int _size, _cpi;
bool _bold, _italic, _underline;
TArray _physical;
XVT_FONT_STYLE_MASK _style;
WINDOW _win_mapped;
XVT_FNTID _fontid;
protected:
void copy(const TReport_font& f);
public:
const TString& name() const { return _name; }
int size() const { return _size; }
XVT_FNTID get_xvt_font(WINDOW win, int size) const;
XVT_FONT_STYLE_MASK style() const { return _style; }
int cpi() const { return _cpi; }
XVT_FNTID get_xvt_font(const TWindow& win) const;
void create(const char* name, int size, XVT_FONT_STYLE_MASK style);
TReport_font& operator=(const TReport_font& f) { copy(f); return *this; }
TReport_font();
virtual ~TReport_font() { }
TReport_font(const TReport_font& f) { copy(f); }
virtual ~TReport_font();
};
class TReport;
class TReport_field;
class TReport_section : public TArray
{
const TReport_section* _father;
TReport& _report;
char _type; // Head,Body,Tail
int _level; // 0,1,2,...
short _width, _height; // In centesimi
TString _groupby;
bool _hidden_if_needed;
TReport_font* _font;
protected:
TReport_section* father_section() const;
public:
virtual int add(TObject* obj);
virtual int add(TObject& obj);
TReport_field& field(int i) { return *(TReport_field*)objptr(i); }
const TReport_field& field(int i) const { return *(TReport_field*)objptr(i); }
TReport& report() { return _report; }
char type() const { return _type; }
int level() const { return _level; }
void description(TString& str) const;
const TReport_font& font() const;
TReport_section(const TReport_section* f, char t, int l);
short width() const { return _width; }
short height() const { return _height; }
void set_width(short w) { _width = w; }
void set_height(short h) { _height = h; }
bool get_rect(RCT& rct) const;
const TString& grouped_by() const { return _groupby; }
void group_by(const char* gb) { _groupby = gb; }
bool hidden_if_needed() const { return _hidden_if_needed; }
void hide_if_needed(bool h) { _hidden_if_needed = h; }
void set_font(const char* name, int size, XVT_FONT_STYLE_MASK style);
TReport_section(TReport& r, char t, int l);
virtual ~TReport_section();
};
@ -71,6 +113,8 @@ public:
void set_section(TReport_section* sec) { _section = sec; }
char type() const { return _type; }
const char* type_name() const;
const TReport_font& font() const;
const TString& picture() const { return _picture; }
@ -81,7 +125,11 @@ public:
void set_type(char t) { _type = t; }
void set_pos(short x, short y);
void set_row(short y) { _y = y; }
void set_column(short x) { _x = x; }
void set_size(short w, short h);
void set_width(short dx) { _width = dx; }
void set_height(short dy) { _height = dy; }
void get_rect(RCT& rct) const;
void set_fore_color(COLOR c) { _fgcolor = c; }
@ -97,28 +145,50 @@ public:
void select(bool ok = true) { _selected = ok; }
bool selected() const { return _selected; }
void offset(const TPoint& pt);
TReport_field(TReport_section* sec);
virtual void draw_rect(TWindow& win) const;
virtual void draw_text(TWindow& win, const char* text) const;
virtual void draw(TWindow& win) const;
TReport_field();
TReport_field(const TXmlItem& item);
TReport_field(const TReport_field& rf) { copy(rf); }
};
class TReport : public TObject
{
TAssoc_array _sections;
int _cpi, _lpi;
TFilename _path;
TString _description, _sql;
TReport_font _font;
int _lpi; // Lines per inch
protected:
void build_section_key(char type, int level, TString& key) const;
void load_sections(const TXmlItem& xml);
short get_num_attr(const TXmlItem& item, const char* attr, short def = 0) const;
COLOR get_col_attr(const TXmlItem& item, const char* attr, COLOR defcol = COLOR_BLACK) const;
public:
TReport_section* find_section(char type, int level) const;
TReport_section& section(char type, int level);
TReport_section& background_section(char type) { return section(type, 0); }
bool kill_section(char type, int level);
int find_max_level() const;
int cpi() const { return _cpi; }
TReport_font& font() { return _font; }
int cpi() const { return _font.cpi(); }
int lpi() const { return _lpi; }
void set_sql(const char* sql);
const TString& sql() const { return _sql; }
void set_description(const char* d);
const TString& description() const { return _description; }
bool load(const char* fname);
void destroy();
TReport();
};