Files correlati :dl0.exe Ricompilazione Demo : [ ] Commento :velocizzata la ricerca articoli (sia in ricerca semplice che avanzata); corretta la gestione del campo etichetta nell'importazione dati da discolatio git-svn-id: svn://10.65.10.50/trunk@11064 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			385 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			385 lines
		
	
	
		
			9.8 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------------------------------------------------------------------------------//
 | 
						|
 | 
						|
enum TFilter_type { dl_normal, dl_date, dl_um };
 | 
						|
enum TFilter_comp { dl_eq, dl_gt, dl_lt, dl_match };
 | 
						|
 | 
						|
struct TFilter_exp : public TObject
 | 
						|
{
 | 
						|
  TFilter_type _type;
 | 
						|
  TString16 _field;
 | 
						|
  TFilter_comp _cmp;
 | 
						|
  TString80 _value;  
 | 
						|
 | 
						|
  TFilter_exp() : _type(dl_normal), _cmp(dl_eq) { }
 | 
						|
};
 | 
						|
 | 
						|
class TIntmag: public TSkeleton_application
 | 
						|
{
 | 
						|
  TIntmag_mask * _mask;
 | 
						|
  TIntmag_form * _form;
 | 
						|
 | 
						|
  static TArray _filtro;
 | 
						|
  
 | 
						|
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);
 | 
						|
 | 
						|
  static bool fast_filter(const TRelation* rel);
 | 
						|
  
 | 
						|
public:
 | 
						|
  void add_expr_filter(const char * field, short id, TFilter_comp cmp) const;
 | 
						|
  void add_meta_filter(const char * field, short id) const;
 | 
						|
  void add_range_filter(const char * field, short fid, short tid = -1) const;
 | 
						|
 | 
						|
  TIntmag() {}
 | 
						|
  virtual ~TIntmag() {}
 | 
						|
};
 | 
						|
 | 
						|
TArray TIntmag::_filtro;
 | 
						|
 | 
						|
// 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(const char * field, short id, TFilter_comp cmp) const
 | 
						|
{       
 | 
						|
  TMask_field& fld = _mask->field(id);  //prende il campo dalla maschera
 | 
						|
  if (!fld.empty())                     //..se non e' vuoto
 | 
						|
  {
 | 
						|
    TFilter_exp* fe = new TFilter_exp;
 | 
						|
    fe->_field = field;
 | 
						|
    fe->_cmp = cmp;
 | 
						|
    //se e' un campo data deve ANSIzzare il contenuto del campo per aggiungerlo al filtro
 | 
						|
    if (fld.class_id() == CLASS_DATE_FIELD) 
 | 
						|
    {
 | 
						|
      fe->_type = dl_date; 
 | 
						|
      const TDate date = fld.get();
 | 
						|
      fe->_value = date.string(ANSI);
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      if (stricmp(field, "UM") == 0)
 | 
						|
        fe->_type = dl_um;
 | 
						|
      fe->_value = fld.get(); //aggiunge il contenuto del campo al filtro
 | 
						|
    }
 | 
						|
    _filtro.add(fe);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
//aggiunge ad un filtro una espressione con l'*
 | 
						|
void TIntmag::add_meta_filter(const char * field, short id) const
 | 
						|
{     
 | 
						|
  const TString& value = _mask->get(id);
 | 
						|
  TFilter_comp cmp = dl_eq;
 | 
						|
  if (value.find('*') >= 0 || value.find('?') >= 0)
 | 
						|
    cmp = dl_match;
 | 
						|
  add_expr_filter(field, id, cmp);  
 | 
						|
}
 | 
						|
 | 
						|
//aggiunge ad un filtro un range di valori presi due campi o da uno (se coincidenti) 
 | 
						|
void TIntmag::add_range_filter(const char * field, short fid, short tid) const
 | 
						|
{
 | 
						|
  if (tid > fid)
 | 
						|
  {
 | 
						|
    add_expr_filter(field, fid, dl_gt);
 | 
						|
    add_expr_filter(field, tid, dl_lt);  
 | 
						|
  }
 | 
						|
  else
 | 
						|
    add_expr_filter(field, fid, dl_eq);
 | 
						|
}
 | 
						|
 | 
						|
bool TIntmag::fast_filter(const TRelation* rel)
 | 
						|
{
 | 
						|
  for (int i = 0; i < _filtro.items(); i++)
 | 
						|
  {
 | 
						|
    const TFilter_exp& fe = (const TFilter_exp&)_filtro[i];
 | 
						|
    TString80 field_value;
 | 
						|
    switch (fe._type)
 | 
						|
    {
 | 
						|
    case dl_date:
 | 
						|
      {
 | 
						|
        const TDate d = rel->curr().get(fe._field);
 | 
						|
        field_value = d.string(ANSI);
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    case dl_um:
 | 
						|
      {
 | 
						|
        TString80 key = rel->curr().get(ANAMAG_CODART);
 | 
						|
        key << "|1";
 | 
						|
        field_value = cache().get(LF_UMART, key, fe._field);
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      field_value = rel->curr().get(fe._field);
 | 
						|
    }
 | 
						|
    switch (fe._cmp)
 | 
						|
    {
 | 
						|
    case dl_lt:
 | 
						|
      if (field_value > fe._value)
 | 
						|
        return FALSE;
 | 
						|
      break;
 | 
						|
    case dl_gt:
 | 
						|
      if (field_value < fe._value)
 | 
						|
        return FALSE;
 | 
						|
      break;
 | 
						|
    case dl_match:
 | 
						|
      if (!field_value.match(fe._value))
 | 
						|
        return FALSE;
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      if (field_value != fe._value)
 | 
						|
        return FALSE;
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TIntmag::main_loop()
 | 
						|
{
 | 
						|
  while (_mask->run() == K_ENTER)
 | 
						|
  {  
 | 
						|
    //laboriosissima costruzione del filtro
 | 
						|
    _filtro.destroy();
 | 
						|
    add_range_filter(ANAMAG_CODART, F_DABARCODE, F_ABARCODE); 
 | 
						|
    add_meta_filter(ANAMAG_USER2, F_ARTISTA);
 | 
						|
    add_meta_filter(ANAMAG_DESCR, F_TITOLO);
 | 
						|
    add_meta_filter(ANAMAG_USER3, F_COMPOSITORE);
 | 
						|
    add_meta_filter(ANAMAG_USER4, F_ETICHETTA);
 | 
						|
    
 | 
						|
    add_range_filter(ANAMAG_GRMERC, F_GENEREMUSICALE);    
 | 
						|
    add_range_filter(ANAMAG_USER5, F_DATAE_INI, F_DATAE_FIN);
 | 
						|
    add_range_filter(ANAMAG_USER6, F_DATAV_INI, F_DATAV_FIN);
 | 
						|
//caso sfigato: c'e' il tipo supporto tra i parametri di filtro!   
 | 
						|
    add_range_filter("UM", F_TIPOSUPPORTO);
 | 
						|
 | 
						|
//dopo il filtrone tocca al cursore x scandire i records    
 | 
						|
    TIntmag_form form;
 | 
						|
    form.cursor()->set_filterfunction(fast_filter, FALSE); 
 | 
						|
 | 
						|
//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;
 | 
						|
}
 |