Files correlati : Ricompilazione Demo : [ ] Commento :aggiunti files discolatio alla 32 bit git-svn-id: svn://10.65.10.50/trunk@11035 c028cbd2-c16b-5b4b-a496-9718f37d4682
342 lines
9.5 KiB
C++
Executable File
342 lines
9.5 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <form.h>
|
|
#include <relation.h>
|
|
#include <printer.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include <utility.h>
|
|
#include <utility.h>
|
|
|
|
#include "..\mg\umart.h"
|
|
#include "..\mg\anamag.h"
|
|
#include "..\mg\mglib.h"
|
|
#include "..\ve\condv.h"
|
|
#include "..\ve\rcondv.h"
|
|
#include "dl0.h"
|
|
#include "dl0600.h"
|
|
#include "dl0600a.h"
|
|
|
|
//-----FORM--------------------------------------------------------------------------------------//
|
|
|
|
class TIntmag_form : public TForm
|
|
{
|
|
TArray _lista_offerte;
|
|
TString4 _codoff, _codlis;
|
|
TArticolo_giacenza _artgiac;
|
|
TDate _oggi;
|
|
|
|
public:
|
|
virtual bool validate(TForm_item& cf, TToken_string& s);
|
|
TIntmag_form();
|
|
virtual ~TIntmag_form();
|
|
};
|
|
|
|
bool TIntmag_form::validate(TForm_item &cf, TToken_string &s)
|
|
{
|
|
const TString16 code(s.get(0));
|
|
|
|
if (code == "_GIACENZA")
|
|
{
|
|
TRectype& recanamag = cf.form().cursor()->curr(); //prende il record corrente
|
|
_artgiac.read(recanamag);
|
|
real giac_anno = _artgiac.giacenza_anno("","",TDate(TODAY).year());
|
|
cf.set(giac_anno.string());
|
|
return TRUE;
|
|
}
|
|
if (code == "_ORDF")
|
|
{
|
|
TString8 anno;
|
|
anno.format("%d",_oggi.year());
|
|
int nriga = _artgiac.find_mag(anno);
|
|
if (nriga > 0)
|
|
{
|
|
const TRectype& magrec = _artgiac.mag(anno)[nriga];
|
|
cf.set(magrec.get(MAG_ORDF));
|
|
}
|
|
return TRUE;
|
|
}
|
|
if (code == "_ACQ")
|
|
{
|
|
TString8 anno;
|
|
anno.format("%d",_oggi.year());
|
|
int nriga = _artgiac.find_mag(anno);
|
|
if (nriga > 0)
|
|
{
|
|
const TRectype& magrec = _artgiac.mag(anno)[nriga];
|
|
cf.set(magrec.get(MAG_ACQ));
|
|
}
|
|
return TRUE;
|
|
}
|
|
if (code == "_VEN")
|
|
{
|
|
TString8 anno;
|
|
anno.format("%d",_oggi.year());
|
|
int nriga = _artgiac.find_mag(anno);
|
|
if (nriga > 0)
|
|
{
|
|
const TRectype& magrec = _artgiac.mag(anno)[nriga];
|
|
cf.set(magrec.get(MAG_VEN));
|
|
}
|
|
return TRUE;
|
|
}
|
|
if (code == "_PREZZO")
|
|
{ //crea la lista delle offerte valide (campagne di vendita in corso)
|
|
if (_lista_offerte.items() == 0)
|
|
{
|
|
TLocalisamfile condv(LF_CONDV);
|
|
for (int err = condv.first(); err == NOERR; err = condv.next())
|
|
{
|
|
if (condv.get_char(CONDV_TIPO) == 'O' && condv.get_char(CONDV_COD) == _codoff[0] &&
|
|
_oggi >= condv.get_date(CONDV_VALIN) && _oggi <= condv.get_date(CONDV_VALFIN))
|
|
_lista_offerte.add(condv.curr());
|
|
}
|
|
}
|
|
|
|
TString prezzo;
|
|
TString4 lo;
|
|
for (int i = _lista_offerte.last(); i>=0 && prezzo.empty(); i--)
|
|
{
|
|
const TRectype& condv = (const TRectype&) _lista_offerte[i];
|
|
|
|
TToken_string chiave;
|
|
chiave.add('O'); //TIPO = offerta
|
|
chiave.add(" "); //CATVEN = " "
|
|
chiave.add(" "); //TIPOCF = " "
|
|
chiave.add(" "); //CODCF = " "
|
|
lo = condv.get(CONDV_COD);
|
|
chiave.add(lo); //COD = cod offerta
|
|
chiave.add("A"); //TIPORIGA = A
|
|
chiave.add(_artgiac.codice()); //CODRIGA
|
|
chiave.add(_artgiac.um().row(1).get(UMART_UM)); //UM = supporto
|
|
chiave.add(" "); //NSCAGL = " "
|
|
prezzo = cache().get(LF_RCONDV, chiave, "PREZZO");
|
|
}
|
|
|
|
if (prezzo.empty())
|
|
{
|
|
TToken_string chiave;
|
|
chiave.add('L'); //TIPO = offerta
|
|
chiave.add(" "); //CATVEN = " "
|
|
chiave.add(" "); //TIPOCF = " "
|
|
chiave.add(" "); //CODCF = " "
|
|
lo = _codlis;
|
|
chiave.add(_codlis); //COD = cod listino
|
|
chiave.add("A"); //TIPORIGA = A
|
|
chiave.add(_artgiac.codice()); //CODRIGA
|
|
chiave.add(_artgiac.um().row(1).get(UMART_UM)); //UM = supporto
|
|
chiave.add(" "); //NSCAGL = " "
|
|
prezzo = cache().get(LF_RCONDV, chiave, "PREZZO");
|
|
}
|
|
cf.set(prezzo); //lo passa al form x la stampa
|
|
|
|
TForm_item& condv = cf.section().find_field(s.get_int(1));
|
|
condv.set(lo);
|
|
|
|
return TRUE;
|
|
}
|
|
return TForm::validate(cf, s);
|
|
}
|
|
|
|
|
|
TIntmag_form::TIntmag_form() :TForm ("dl0600a"),_oggi(TODAY)
|
|
{
|
|
TConfig config("cat2dl.ini","PARAMS"); //gli serve il prefisso delle campagne di offerta (vendita)
|
|
_codoff = config.get("OFFEVEND");
|
|
_codlis = config.get("LISTVEND");
|
|
}
|
|
|
|
TIntmag_form::~TIntmag_form()
|
|
{
|
|
}
|
|
|
|
//-----AUTOMASK---------------------------------------------------------------------------------//
|
|
|
|
class TIntmag_mask : public TAutomask
|
|
{
|
|
TRelation * _rel;
|
|
TCursor * _cur;
|
|
|
|
protected:
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
public:
|
|
|
|
TIntmag_mask();
|
|
|
|
virtual ~TIntmag_mask(){};
|
|
};
|
|
|
|
TIntmag_mask::TIntmag_mask() :TAutomask ("dl0600a")
|
|
{
|
|
}
|
|
|
|
bool TIntmag_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
/* switch (o.dlg())
|
|
{
|
|
default:
|
|
break;
|
|
} */
|
|
return TRUE;
|
|
}
|
|
|
|
//-------SKELETON APPLICATION------------------------------------------------------------------------------//
|
|
class TIntmag: public TSkeleton_application
|
|
{
|
|
TIntmag_mask * _mask;
|
|
TIntmag_form * _form;
|
|
|
|
protected:
|
|
virtual bool create(void);
|
|
virtual bool destroy(void);
|
|
virtual void main_loop();
|
|
|
|
void print_header();
|
|
void print_footer();
|
|
void print_line(const TString& r, const long j);
|
|
|
|
public:
|
|
void add_expr_filter(TString& filtro, const char * field, short id, const char * cmp) const;
|
|
void add_meta_filter(TString& filtro, const char * field, short id) const;
|
|
void add_range_filter(TString& filtro, const char * field, short fid, short tid = -1) const;
|
|
|
|
TIntmag() {}
|
|
virtual ~TIntmag() {}
|
|
};
|
|
|
|
// restituisce un riferimento all' applicazione
|
|
inline TIntmag& app() { return (TIntmag&) main_app();}
|
|
|
|
// creazione dell'applicazione
|
|
bool TIntmag::create()
|
|
{
|
|
open_files(LF_ANAMAG, LF_RMOVMAG, LF_UMART, LF_MAG, LF_CONDV, LF_RCONDV, 0);
|
|
_mask = new TIntmag_mask;
|
|
_form = new TIntmag_form();
|
|
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
// distruzione dell'applicazione
|
|
bool TIntmag::destroy()
|
|
{
|
|
delete _mask;
|
|
delete _form;
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
//aggiunge effettivamente una espressione ad un filtro
|
|
void TIntmag::add_expr_filter(TString& filtro, const char * field, short id, const char * cmp) const
|
|
{
|
|
TMask_field& fld = _mask->field(id); //prende il campo dalla maschera
|
|
if (!fld.empty()) //..se non e' vuoto
|
|
{
|
|
if (filtro.not_empty()) //distinzione tra filtro vuoto e filtro esistente
|
|
filtro << "&&";
|
|
if (fld.class_id() == CLASS_DATE_FIELD) //se e' un campo data deve ANSIzzare il contenuto del campo per aggiungerlo al filtro
|
|
{
|
|
const TDate data = fld.get();
|
|
TString8 val = data.string(ANSI);
|
|
filtro << "(ANSI(" << field << ")" << cmp << val << ")";
|
|
}
|
|
else
|
|
filtro << "(" << field << cmp << "\"" << fld.get() << "\")"; //aggiunge il contenuto del campo al filtro
|
|
}
|
|
}
|
|
|
|
//aggiunge ad un filtro una espressione con l'*
|
|
void TIntmag::add_meta_filter(TString& filtro, const char * field, short id) const
|
|
{
|
|
const TString& value = _mask->get(id);
|
|
const char* cmp = "==";
|
|
if (value.find('*') >= 0 || value.find('?') >= 0)
|
|
cmp = "?=";
|
|
add_expr_filter(filtro, field, id, cmp);
|
|
}
|
|
|
|
//aggiunge ad un filtro un range di valori presi due campi o da uno (se coincidenti)
|
|
void TIntmag::add_range_filter(TString& filtro, const char * field, short fid, short tid) const
|
|
{
|
|
if (tid > fid)
|
|
{
|
|
add_expr_filter(filtro, field, fid, ">=");
|
|
add_expr_filter(filtro, field, tid, "<=");
|
|
}
|
|
else
|
|
add_expr_filter(filtro, field, fid, "==");
|
|
}
|
|
|
|
static TString16 fast_field;
|
|
static TString80 fast_value;
|
|
static bool meta_type;
|
|
|
|
static bool fast_filter(const TRelation* rel)
|
|
{
|
|
const TRectype& rec = rel->curr();
|
|
if (meta_type)
|
|
return rec.get(fast_field).match(fast_value);
|
|
return rec.get(fast_field) == fast_value;
|
|
}
|
|
|
|
void TIntmag::main_loop()
|
|
{
|
|
while (_mask->run() == K_ENTER)
|
|
{
|
|
TString16 nomecampo;
|
|
//laboriosissima costruzione del filtro
|
|
TString filtro;
|
|
|
|
add_range_filter(filtro, ANAMAG_CODART, F_DABARCODE, F_ABARCODE);
|
|
|
|
add_meta_filter(filtro, ANAMAG_DESCR, F_TITOLO);
|
|
add_meta_filter(filtro, ANAMAG_USER2, F_ARTISTA);
|
|
add_meta_filter(filtro, ANAMAG_USER3, F_COMPOSITORE);
|
|
add_meta_filter(filtro, ANAMAG_USER4, F_ETICHETTA);
|
|
|
|
add_range_filter(filtro, ANAMAG_GRMERC, F_GENEREMUSICALE);
|
|
add_range_filter(filtro, ANAMAG_USER5, F_DATAE_INI, F_DATAE_FIN);
|
|
add_range_filter(filtro, ANAMAG_USER6, F_DATAV_INI, F_DATAV_FIN);
|
|
//caso sfigato: c'e' il tipo supporto tra i parametri di filtro!
|
|
nomecampo.format("%d->%s", LF_UMART, "UM");
|
|
add_range_filter(filtro, nomecampo, F_TIPOSUPPORTO);
|
|
|
|
//dopo il filtrone tocca al cursore x scandire i records
|
|
TIntmag_form form;
|
|
//ottimizzazione tempi di ricerca: caso di filtro semplice (senza AND, con ?= o ==)
|
|
|
|
if (filtro.find("&&") < 0 && filtro.find('=') > 0)
|
|
{
|
|
filtro.strip("()");
|
|
meta_type = filtro.find("?=") > 0;
|
|
const int pos = filtro.rfind('=');
|
|
fast_value = filtro.mid(pos+1);
|
|
fast_value.strip("\"");
|
|
fast_field = filtro.left(pos-1);
|
|
|
|
form.cursor()->set_filterfunction(fast_filter, !_mask->field(F_TIPOSUPPORTO).empty());
|
|
}
|
|
else
|
|
form.cursor()->setfilter(filtro, !_mask->field(F_TIPOSUPPORTO).empty());
|
|
|
|
//procedimento mistico di costruzione del form columnwise
|
|
const int hh = 5; //altezza header = 5 righe
|
|
int rows[4];
|
|
rows[0] = hh - 2;
|
|
rows[1] = hh;
|
|
rows[2] = printer().formlen();
|
|
rows[3] = 0;
|
|
|
|
form.genera_intestazioni(odd_page, hh - 1);
|
|
form.genera_fincatura(odd_page, hh - 2, rows[2], rows);
|
|
|
|
form.print();
|
|
}
|
|
}
|
|
|
|
int dl0600(int argc, char* argv[])
|
|
{
|
|
TIntmag a ;
|
|
a.run(argc, argv, "Interrogazione magazzino");
|
|
return 0;
|
|
}
|