// 771232.h - Quadro G, G1 e distinta
#include <relapp.h>
#include <config.h>
#include <msksheet.h>
#include <sort.h>
#include <tabutil.h>
#include <progind.h>
#include "77lib.h"
#include <defmask.h>

#include "774200.h"

// void ss_pack(TSheet_field& ss);

class TQuadroG : public TRelation_application
{
  private:
    TRelation*       	_rel;
    TMask*           	_msk;
    int              	_anno_dic;  // anno dichiarazione
    long				_codditta;
    TLocalisamfile*		_qg;
    TTable*				_ca7; 
    TRiporti			_rip;
    TString16			_quadro;
    TString80			_title;
    bool  				_registra, _bUsatoDistinta;
    static bool			p1_notify(TSheet_field& s, int r, KEY k);
    static bool			p2_notify(TSheet_field& s, int r, KEY k);
    static bool			pII_notify(TSheet_field& s, int r, KEY k);
    static bool			pIII_notify(TSheet_field& s, int r, KEY k);
    static bool			calc_amm(TMask_field& f, KEY k);
    static bool			exec_distinta(TMask_field& f, KEY k);
  	static void			update_totals(TSheet_field& f, int ss);
  protected:
    virtual bool	user_create();
    virtual bool	user_destroy();
    virtual int		read(TMask& m);
    virtual int		rewrite(const TMask& m);
    virtual int		write  (const TMask& m);  
    virtual bool	remove();
    virtual TRelation*	get_relation() const { return _rel; }
    virtual TMask*	get_mask(int mode)       { return _msk; }
    virtual bool	changing_mask(int mode)  { return FALSE; }
    virtual void	init_insert_mode (TMask&);    
    virtual void	init_query_mode (TMask&);
    virtual void	init_modify_mode (TMask&);
    void			fill_ss(TMask& m);
    void			fill_arr(TMask& m);    
    void			ss2rel(const TMask& m);
    void			arr2rel(const TMask& m);                  
  public:                      
    const char* 	taitol() { return (const char*)_title; }
    TMask&			main_mask() const { return (TMask&) *_msk; }
        
    TQuadroG(const char quadro='0');
    virtual ~TQuadroG() {};
};                    


class TDistintaQuadroG : public TRelation_application
{
    TRelation*       _rel;
    TMask*           _msk;
    long             _codanagr;
    char             _tipoa;
    int              _nproga;
    int              _mode;
    int              _anno_dic;  // anno dichiarazione
    TString80		_title;
    TRiporti        _rip;
    bool  			_registra;
    int   			_file;           
    TString16		_quadro;
    
  private:               
    static bool nprog_handler   (TMask_field& f, KEY key);
    static bool codanagr_handler(TMask_field& f, KEY key);
    static bool codditta_hnd    (TMask_field& f, KEY key);    
    static bool setta_nprog     (TMask_field& f);
  
  protected:
    virtual bool user_create();
    virtual bool user_destroy(); 
    virtual int  rewrite(const TMask& m);
    virtual int  write  (const TMask& m);  
    virtual bool remove();
    virtual TRelation* get_relation() const { return _rel; }
    virtual TMask* get_mask(int mode)       { return _msk; }
    virtual bool changing_mask(int mode)    { return FALSE; }
    virtual void init_query_mode (TMask&);
    virtual void init_query_insert_mode (TMask&);    
    virtual void on_config_change();    
    bool		scrivi_dati_per(TRectype& rec);
    
  public:                    
    const char* 	taitol() { return (const char*)_title; }  
  public:
    TDistintaQuadroG();
    virtual ~TDistintaQuadroG() {};
};                    

class TQuadroG1 : public TRelation_application
{
  private:
    TRelation*       	_rel;
    TMask*           	_msk;
    int              	_anno_dic;  
    long				_codditta;
    TLocalisamfile*		_qg1;
    TTable*				_ca7; 
    TRiporti			_rip;
    TString16			_quadro;
    TString80			_title;
    bool  				_registra;
    static bool			p1_notify(TSheet_field& s, int r, KEY k);
	static void			update_totals(TSheet_field& f);
  protected:
    virtual bool	user_create();
    virtual bool	user_destroy();
    virtual int		rewrite(const TMask& m);
    virtual int 	read(TMask& m);
    virtual int		write  (const TMask& m);  
    virtual bool	remove();
    virtual TRelation*	get_relation() const { return _rel; }
    virtual TMask*	get_mask(int mode)       { return _msk; }
    virtual bool	changing_mask(int mode)  { return FALSE; }
    virtual void	init_query_mode (TMask&); 
    virtual void	init_insert_mode (TMask&);    
    virtual void	init_modify_mode (TMask&);
//    void			init_mask (TMask&);
    void			fill_arr(TMask& m);    
    void			arr2rel(const TMask& m);                  
  public:                      
    const char* 	taitol() { return (const char*)_title; }
    TMask&			main_mask() const { return (TMask&) *_msk; }
        
    TQuadroG1();
    virtual ~TQuadroG1() {};
};                    

