campo-sirio/ba/ba2100.cpp
guy f62c380327 Aggiunte ricerche per descrizione
git-svn-id: svn://10.65.10.50/trunk@808 c028cbd2-c16b-5b4b-a496-9718f37d4682
1995-01-02 09:29:29 +00:00

276 lines
5.9 KiB
C++
Executable File

#include <applicat.h>
#include <form.h>
#include <msksheet.h>
#include <prefix.h>
#include <relation.h>
#include <utility.h>
#include <urldefid.h>
#include "ba2100.h"
class TForm_editor : public TApplication
{
TForm* _form;
protected:
virtual bool create();
virtual bool destroy();
virtual bool menu(MENU_TAG);
virtual void print();
static bool file_handler(TMask_field& f, KEY k);
bool edit_relation();
bool edit(char s, pagetype p);
public:
TForm_editor();
virtual ~TForm_editor();
};
TForm_editor::TForm_editor() : _form(NULL)
{}
TForm_editor::~TForm_editor()
{}
bool TForm_editor::create()
{
TApplication::create();
if (argc() < 3)
return error_box("Specificare il nome del profilo di stampa");
TFilename form(argv(2)); form.ext("frm");
if (!fexist(form))
{
TFilename base(form.left(3)); base.ext("frm");
if (!fexist(base))
return error_box("Non esiste il profilo campione %s", (const char*)base);
if (!yesno_box("Si desidera creare un nuovo profilo %s", (const char*)form))
return FALSE;
if (!fcopy(base, form))
return error_box("Impossibile copiare %s in %s", (const char*)base, (const char*)form);
}
_form = new TForm(form);
enable_menu_item(M_FILE_PRINT);
return TRUE;
}
bool TForm_editor::destroy()
{
if (_form) delete _form;
return TApplication::destroy();
}
bool TForm_editor::menu(MENU_TAG tag)
{
char sec = 'B';
pagetype pt = odd_page;
switch(tag)
{
case MENU_ITEM(11):
sec = 'R'; pt = odd_page; break;
case MENU_ITEM(21):
sec = 'H'; pt = odd_page; break;
case MENU_ITEM(22):
sec = 'H'; pt = even_page; break;
case MENU_ITEM(23):
sec = 'H'; pt = first_page; break;
case MENU_ITEM(24):
sec = 'H'; pt = last_page; break;
case MENU_ITEM(31):
sec = 'B'; pt = odd_page; break;
case MENU_ITEM(32):
sec = 'B'; pt = even_page; break;
case MENU_ITEM(33):
sec = 'B'; pt = first_page; break;
case MENU_ITEM(34):
sec = 'B'; pt = last_page; break;
case MENU_ITEM(41):
sec = 'F'; pt = odd_page; break;
case MENU_ITEM(42):
sec = 'F'; pt = even_page; break;
case MENU_ITEM(43):
sec = 'F'; pt = first_page; break;
case MENU_ITEM(44):
sec = 'F'; pt = last_page; break;
default:
break;
}
edit(sec, pt);
return TRUE;
}
void TForm_editor::print()
{
_form->print();
}
bool TForm_editor::file_handler(TMask_field& f, KEY k)
{
bool ok = TRUE;
if (k == K_TAB && f.dirty())
{
const char* d = prefhndl->description(f.get());
if (*d == '\0') ok = error_box("Nome di file o tabella errato");
f.mask().set(f.dlg()+1, d);
}
return ok;
}
bool TForm_editor::edit_relation()
{
TMask m("ba2100r");
TSheet_field& s = (TSheet_field&)m.field(F_ITEMS);
s.sheet_mask().set_handler(101, file_handler);
TRelation* & rel = _form->_relation;
TCursor* & cur = _form->_cursor;
if (rel)
{
rel->print_on(s.rows_array());
s.force_update();
s.disable_cell(0, 2); s.disable_cell(0, 5);
}
if (m.run() != K_ENTER || !m.dirty())
return FALSE;
if (rel)
{
delete cur; cur = NULL;
delete rel; rel = NULL;
}
TToken_string& r = s.row(0);
TString16 name = r.get(0);
if (name.not_empty())
{
int logicnum = atoi(name);
r.get(); // Skip description
int alias = 0, to = 0, key = r.get_int(2);
TString80 exp = r.get(4);
rel = (logicnum > 0) ? new TRelation(logicnum) : new TRelation(name);
cur = new TCursor(rel, exp, key);
for (int i = 1; i < s.items(); i++)
{
TToken_string& r = s.row(i);
name = r.get(0); logicnum = atoi(name);
to = name2log(r.get());
key = r.get_int();
alias = r.get_int();
exp = r.get();
const int l = exp.len();
for (int j = 0; j < l; j++)
if (exp[j] == ' ') exp[j] = '|';
if (logicnum > 0)
rel->add(logicnum, exp, key, to, alias); // join file
else
rel->add(name, exp, key, to, alias); // join table
}
}
return TRUE;
}
bool TForm_editor::edit(char s, pagetype t)
{
bool dirty = FALSE;
if (s == 'R')
dirty = edit_relation();
else
{
TString80 caption;
switch(s)
{
case 'F':
caption << "Pie' di pagina"; break;
case 'H':
caption << "Intestazione"; break;
default:
caption << "Corpo"; break;
}
switch(t)
{
case first_page:
caption << " della prima pagina"; break;
case even_page:
caption << " delle pagine pari"; break;
case last_page:
caption << " dell'ultima pagina"; break;
default:
caption << " standard"; break;
}
dirty = TRUE;
if (!_form->exist(s, t))
{
const KEY k = yesnocancel_box("La sezione %s non esiste: "
"si desidera ricopiare quella standard",
(const char*)caption);
if (k == K_ESC)
dirty = FALSE;
else
{
TPrint_section* sec = _form->exist(s, t, TRUE);
if (k == K_YES)
{
const TPrint_section* def = _form->exist(s, odd_page);
if (def) *sec = *def;
else dirty = FALSE;
}
}
}
if (dirty)
dirty = _form->section(s, t).edit(caption);
}
if (dirty && yesno_box("Salvare le modifiche?"))
{
CURSOR old = get_cursor(TASK_WIN);
set_cursor(TASK_WIN, CURSOR_WAIT);
const TFilename& n = _form->name();
TFilename bak(n); bak.ext("bak");
rename(n, bak);
ofstream out(n);
_form->print_on(out);
set_cursor(TASK_WIN, old);
}
return dirty;
}
int ba2100(int argc, char* argv[])
{
TForm_editor a;
a.run(argc, argv, "Parametrizzazione stampa");
return 0;
}