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
This commit is contained in:
guy 2004-03-09 15:20:36 +00:00
parent 1f52426e43
commit e1ff54dd39
7 changed files with 289 additions and 93 deletions

View File

@ -593,8 +593,7 @@ void TQuery_mask::enable_field_buttons()
{
const TSheet_field& sf = sfield(F_FIELDS);
const bool ok = sf.items() > 0;
enable(DLG_USER, ok);
enable(F_ASTERISK, ok);
enable(-1, ok);
}
void TQuery_mask::move_curr_field(int dir)
@ -706,7 +705,7 @@ void TQuery_mask::sheet2sql()
sql << "ORDER BY " << orderby << '\n';
sql << ";";
set(F_SQL, sql);
set(F_SQL, sql, true);
}
static int select_callback(void* jolly, int argc, char** value, char** field)
@ -778,30 +777,14 @@ bool TQuery_mask::get_qry_path(TFilename& path) const
bool TQuery_mask::select_query()
{
TEdit_field& fld = efield(F_CODICE);
TFilename dirname; get_sql_directory(dirname);
xvt_fsys_save_dir();
FILE_SPEC fs;
xvt_fsys_convert_str_to_dir(dirname, &fs.dir);
strcpy(fs.type, "qry");
strcpy(fs.name, "*");
strcpy(fs.creator, "AGA");
const bool good = xvt_dm_post_file_open(&fs, (char*)fld.prompt()) == FL_OK;
xvt_fsys_restore_dir();
if (good)
TFilename path;
const bool ok = select_sql_file(path, "qry");
if (ok)
{
char name[_MAX_FNAME];
xvt_fsys_parse_pathname (fs.name, NULL, NULL, name, NULL, NULL);
fld.set(name);
path = path.name(); path.ext("");
set(F_CODICE, path);
}
return good;
return ok;
}
static bool xml_save_tree_handler(TTree& tree, void* jolly, word flags)
@ -877,7 +860,7 @@ bool TQuery_mask::save_query()
TXmlItem xml;
xml.SetTag("query");
xml.SetAttr("Name", name);
xml.SetAttr("Description", get(F_DESCR));
xml.AddChild("description") << get(F_DESCR);
save_tables_tree(xml);
save_fields_sheet(xml);
xml.AddChild("sql") << get(F_SQL);
@ -993,8 +976,16 @@ bool TQuery_mask::load_query()
{
_curr_query = path;
global_reset();
set(F_CODICE, xml.GetAttr("Name"));
set(F_DESCR, xml.GetAttr("Description"));
path = path.name(); path.ext("");
set(F_CODICE, path);
const TXmlItem* desc = xml.FindFirst("description");
if (desc != NULL)
{
TString str; desc->GetEnclosedText(str);
set(F_DESCR, str);
}
TXmlItem* tables = xml.FindFirst("tables");
if (tables != NULL)
@ -1006,7 +997,7 @@ bool TQuery_mask::load_query()
if (sql != NULL)
{
TString str; sql->GetEnclosedText(str);
set(F_SQL, str);
set(F_SQL, str, true);
}
_is_dirty = false;
@ -1089,8 +1080,11 @@ bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
edit_query();
break;
case F_SQL:
if (e == fe_modify)
_is_dirty = true;
if (e == fe_init || e == fe_modify)
{
enable(-2, !o.empty());
_is_dirty = e == fe_modify;
}
break;
case F_EXPORT_HTML:
if (e == fe_button)

View File

@ -80,11 +80,13 @@ END
BUTTON DLG_USER 10 2
BEGIN
PROMPT -35 11 "~Campo"
GROUP 1
END
BUTTON F_ASTERISK 10 2
BEGIN
PROMPT -45 11 "Campo ~*"
GROUP 1
END
BUTTON F_GENSQL 10 2
@ -105,13 +107,13 @@ END
BUTTON F_MOVEUP 2 2
BEGIN
PROMPT -1 15 "Up"
PROMPT -1 15 ""
PICTURE 1662
END
BUTTON F_MOVEDN 2 2
BEGIN
PROMPT -1 18 "Dn"
PROMPT -1 18 ""
PICTURE 1663
END
@ -128,26 +130,31 @@ BUTTON F_EDITQUERY 10 2
BEGIN
PROMPT -15 -1 ""
PICTURE BMP_EDIT
GROUP 2
END
BUTTON F_EXPORT_HTML 10 2
BEGIN
PROMPT -25 -1 "~HTML"
GROUP 2
END
BUTTON F_EXPORT_EXCEL 10 2
BEGIN
PROMPT -35 -1 "~Excel"
GROUP 2
END
BUTTON F_EXPORT_TXT 10 2
BEGIN
PROMPT -45 -1 "~Testo+Tab"
GROUP 2
END
BUTTON F_EXPORT_CAMPO 10 2
BEGIN
PROMPT -55 -1 "~Scarica"
GROUP 2
END

View File

@ -5,6 +5,7 @@
#include <progind.h>
#include <relation.h>
#include <utility.h>
#include <xml.h>
#include "ba8201.h"
@ -20,6 +21,51 @@ void get_sql_directory(TFilename& name)
make_dir(name);
}
bool select_sql_file(TFilename& path, const char* ext)
{
get_sql_directory(path);
path.add("*");
path.ext(ext);
TString_array files;
list_files(path, files);
TArray_sheet sheet(-1, -1, 78, 20, TR("Selezione"), TR("Nome@20|Descrizione@50"));
TString str;
FOR_EACH_ARRAY_ROW(files, i, row)
{
TXmlItem item;
if (item.Load(*row))
{
TToken_string* riga = new TToken_string;
path = *row;
path = path.name();
path.ext("");
riga->add(path);
const TXmlItem* desc = item.FindFirst("description");
str = *row;
if (desc != NULL)
desc->GetEnclosedText(str);
riga->add(str);
sheet.add(riga);
}
}
const bool ok = sheet.run() == K_ENTER;
if (ok)
{
get_sql_directory(path);
path.add(sheet.row(-1).get(0));
path.ext(ext);
}
return ok;
}
///////////////////////////////////////////////////////////
// Private interface
///////////////////////////////////////////////////////////
@ -93,6 +139,9 @@ void TSQLite::test_path()
bool TSQLite::exec(const char* sql, sqlite_callback callback, void* jolly, bool show_error)
{
if (_handle == NULL)
test_path();
TWait_cursor hourglass;
char* errmsg = NULL;
const int rc = sqlite_exec(_handle, sql, callback, jolly, &errmsg);
@ -349,7 +398,7 @@ bool TSQLite::parse_select_from(const char* szSql)
test_path();
TString sql(szSql);
sql.trim();
sql.trim(); sql.upper();
if (!sql.starts_with("SELECT"))
return false;
@ -495,7 +544,7 @@ void TSQL_query::set(const char* sql)
{
reset();
_sql = sql;
if (_sql.find("SELECT") >= 0)
if (_sql.find("SELECT") >= 0 || _sql.find("select") >= 0)
_TheDataBase.parse_select_from(_sql);
}

View File

@ -72,6 +72,8 @@ public:
///////////////////////////////////////////////////////////
void get_sql_directory(TFilename& path);
bool select_sql_file(TFilename& path, const char* ext);
#endif

View File

@ -4,14 +4,95 @@
#include <automask.h>
#include <execp.h>
#include <prefix.h>
#include <tree.h>
#include <xml.h>
#include "ba8201.h"
#include "ba8300.h"
class TReport_mask : public TAutomask
///////////////////////////////////////////////////////////
// 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);
@ -20,68 +101,44 @@ protected:
bool select_report();
public:
TReport_mask() : TAutomask("ba8300a") { }
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()
{
TEdit_field& fld = efield(F_CODICE);
TFilename dirname; get_sql_directory(dirname);
xvt_fsys_save_dir();
FILE_SPEC fs;
xvt_fsys_convert_str_to_dir(dirname, &fs.dir);
strcpy(fs.type, "rep");
strcpy(fs.name, "*");
strcpy(fs.creator, "AGA");
const bool good = xvt_dm_post_file_open(&fs, (char*)fld.prompt()) == FL_OK;
xvt_fsys_restore_dir();
if (good)
TFilename path;
const bool ok = select_sql_file(path, "rep");
if (ok)
{
char name[_MAX_FNAME];
xvt_fsys_parse_pathname (fs.name, NULL, NULL, name, NULL, NULL);
fld.set(name);
path = path.name(); path.ext("");
set(F_CODICE, path);
}
return good;
return ok;
}
bool TReport_mask::select_query()
{
TFilename path; get_sql_directory(path);
xvt_fsys_save_dir();
FILE_SPEC fs;
xvt_fsys_convert_str_to_dir(path, &fs.dir);
strcpy(fs.type, "qry");
strcpy(fs.name, "*");
strcpy(fs.creator, "AGA");
bool good = xvt_dm_post_file_open(&fs, "Selezione query") == FL_OK;
xvt_fsys_restore_dir();
if (good)
TFilename path;
bool ok = select_sql_file(path, "qry");
if (ok)
{
xvt_fsys_convert_dir_to_str(&fs.dir, path.get_buffer(), path.size());
path.add(fs.name);
TXmlItem item; item.Load(path);
const TXmlItem* sql = item.FindFirst("sql");
good = sql != NULL;
if (good)
ok = sql != NULL;
if (ok)
{
TString str; sql->GetEnclosedText(str);
set(F_SQL, str);
set(F_SQL, str, true);
}
}
return good;
return ok;
}
void TReport_mask::handler(WINDOW win, EVENT* ep)
@ -97,6 +154,10 @@ bool TReport_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
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)
{
@ -108,12 +169,75 @@ bool TReport_mask::on_field_event(TOperable_field& o, TField_event e, long jolly
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
///////////////////////////////////////////////////////////

View File

@ -1,6 +1,11 @@
#define F_CODICE 101
#define F_DESCR 102
#define F_SQL 103
#define F_IMPORT_QRY 104
#define F_NEW_QRY 105
#define F_SECTIONS 103
#define F_REPORT 104
#define F_SQL 201
#define F_IMPORT_QRY 202
#define F_NEW_QRY 203
#define F_SHOW_QRY 204

View File

@ -56,24 +56,39 @@ BEGIN
PROMPT 30 1 ""
END
GROUPBOX DLG_NULL 78 -1
TREE F_SECTIONS 30 12
BEGIN
PROMPT 1 3 "Origine dei dati"
PROMPT 0 3 ""
END
BUTTON F_NEW_QRY 20 1
REPORT F_REPORT -3 -1
BEGIN
PROMPT 30 3 "Nuova query"
PROMPT 21 3 ""
END
BUTTON F_IMPORT_QRY 20 1
BEGIN
PROMPT 57 3 "Importa query"
END
ENDPAGE
PAGE "Sql" -1 -1 78 23
MEMO F_SQL 76 -2
BEGIN
PROMPT 2 3 ""
PROMPT 2 1 "Query SQL origine dei dati"
END
BUTTON F_NEW_QRY 20 2
BEGIN
PROMPT -25 -1 "Nuova query"
END
BUTTON F_IMPORT_QRY 20 2
BEGIN
PROMPT -35 -1 "Importa query"
END
BUTTON F_SHOW_QRY 20 2
BEGIN
PROMPT -45 -1 "~Edit"
PICTURE BMP_EDIT
END
ENDPAGE