366 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			366 lines
		
	
	
		
			8.1 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <execp.h>
 | 
						|
#include <mask.h>
 | 
						|
#include <msksheet.h>
 | 
						|
#include <mailbox.h>
 | 
						|
#include <prefix.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <urldefid.h>
 | 
						|
#include <validate.h>
 | 
						|
 | 
						|
#include "at0.h"
 | 
						|
#include "lf.h"				// se non lo metto non riesco a usare gli LF
 | 
						|
 | 
						|
// nomi campi maschera
 | 
						|
#include "at0300a.h"
 | 
						|
          
 | 
						|
// nomi dei campi
 | 
						|
#include "soggetti.h"
 | 
						|
#include "donaz.h"
 | 
						|
#include "contsan.h"
 | 
						|
 | 
						|
#include "atlib.h"
 | 
						|
 | 
						|
#define ALIAS_CTD		100
 | 
						|
 | 
						|
class TContsan_app : public TApplication
 | 
						|
{
 | 
						|
	TMask*					_msk;
 | 
						|
	TRelation*   		_rel;
 | 
						|
	
 | 
						|
  TLocalisamfile* _soggetti;
 | 
						|
	TLocalisamfile* _donaz;
 | 
						|
	TLocalisamfile* _contsan;
 | 
						|
	TRecord_array*	_sdonazioni; 
 | 
						|
	TRecord_array*	_scontrolli;
 | 
						|
	TAssoc_array*		_asoggetti;	// array dei soggetti inseriti per controllare doppio ins.
 | 
						|
	bool						_modified;
 | 
						|
	
 | 
						|
protected:
 | 
						|
	virtual bool create();
 | 
						|
	virtual bool destroy();
 | 
						|
  virtual bool menu(MENU_TAG m);
 | 
						|
	virtual TMask& get_mask() { return *_msk; }
 | 
						|
	virtual TRelation* get_relation() const { return _rel; }
 | 
						|
	
 | 
						|
	TAssoc_array& get_array_sogg() { return *_asoggetti; }
 | 
						|
	int write(TSheet_field& s);
 | 
						|
 | 
						|
	bool check_sog_sheet(const char* codsog);	
 | 
						|
	static bool nome_handler(TMask_field& f, KEY k);
 | 
						|
	static bool tipocon_handler(TMask_field& f, KEY k);
 | 
						|
	static bool soggetti_notify(TSheet_field& s, int r, KEY k);
 | 
						|
	void add_rows_soggetti(TSheet_field& s, int count = 20, int start = 0);
 | 
						|
 | 
						|
public:
 | 
						|
	TContsan_app() {}
 | 
						|
	
 | 
						|
};
 | 
						|
 | 
						|
HIDDEN inline TContsan_app& app() { return (TContsan_app&) main_app(); }
 | 
						|
 | 
						|
void TContsan_app::add_rows_soggetti(TSheet_field& s, int count, int start)
 | 
						|
{ 
 | 
						|
	if (start == 0)
 | 
						|
		s.destroy();
 | 
						|
	for (int r=start; r<=start+count-1; r++)
 | 
						|
		TToken_string& row = s.row(r);
 | 
						|
}
 | 
						|
	
 | 
						|
bool TContsan_app::create()
 | 
						|
{
 | 
						|
	_modified = FALSE;
 | 
						|
	_msk = new TMask("at0300a");
 | 
						|
	_rel = new TRelation(LF_SOGGETTI);
 | 
						|
  _rel->add("CTD", "CODTAB==CATDON",1,0,ALIAS_CTD);
 | 
						|
	_donaz = new TLocalisamfile(LF_DONAZ);
 | 
						|
	_contsan = new TLocalisamfile(LF_CONTSAN);
 | 
						|
	_sdonazioni = new TRecord_array(LF_DONAZ,DON_PROGDON);
 | 
						|
	_scontrolli = new TRecord_array(LF_CONTSAN,CON_PROGCON);
 | 
						|
	_asoggetti = new TAssoc_array();
 | 
						|
	
 | 
						|
	TSheet_field& ss = (TSheet_field&)_msk->field(F_SOGGETTI);
 | 
						|
	ss.set_notify(soggetti_notify);
 | 
						|
	
 | 
						|
	ss.sheet_mask().set_handler(F_S_NOME,nome_handler);
 | 
						|
	//ss.sheet_mask().set_handler(F_S_TIPOCON,tipocon_handler);
 | 
						|
  
 | 
						|
  dispatch_e_menu(BAR_ITEM(1));
 | 
						|
  
 | 
						|
	return TRUE;
 | 
						|
}	
 | 
						|
 | 
						|
bool TContsan_app::destroy()	
 | 
						|
{
 | 
						|
	delete _rel;
 | 
						|
	delete _msk;
 | 
						|
	delete _donaz;
 | 
						|
	delete _contsan;
 | 
						|
	delete _sdonazioni;
 | 
						|
	delete _scontrolli;
 | 
						|
	delete _asoggetti;
 | 
						|
	return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TContsan_app::menu(MENU_TAG m)
 | 
						|
{ 
 | 
						|
	TMask& msk = get_mask();
 | 
						|
	const TDate oggi(TODAY);
 | 
						|
	KEY tasto;
 | 
						|
	do
 | 
						|
	{
 | 
						|
		TSheet_field& s = (TSheet_field&)msk.field(F_SOGGETTI);
 | 
						|
		s.reset();
 | 
						|
		add_rows_soggetti(s);
 | 
						|
		_asoggetti->destroy();
 | 
						|
		msk.set(F_DATACON,oggi);
 | 
						|
  	tasto = msk.run();
 | 
						|
  	switch (tasto)
 | 
						|
  	{
 | 
						|
  		case K_ESC:		// annulla
 | 
						|
  		{
 | 
						|
  			if (_modified)
 | 
						|
  				if (yesno_box("Registrare le modifiche?"))
 | 
						|
  					TContsan_app::write(s);
 | 
						|
				_modified = FALSE;  					
 | 
						|
				msk.reset();
 | 
						|
			}	
 | 
						|
  		break;
 | 
						|
  		case K_SAVE:	// registra
 | 
						|
  		{
 | 
						|
  			TContsan_app::write(s);
 | 
						|
				_modified = FALSE;  					
 | 
						|
  			msk.reset();
 | 
						|
  		}  			
 | 
						|
  		break;
 | 
						|
  		case K_INS:		// nuovo
 | 
						|
  		{
 | 
						|
				TContsan_app::write(s);  			
 | 
						|
				_modified = FALSE;
 | 
						|
				msk.reset();
 | 
						|
			}	
 | 
						|
  		break;
 | 
						|
  		case K_QUIT:	// fine
 | 
						|
  		{                   
 | 
						|
  			if (_modified)
 | 
						|
  				if (yesno_box("Registrare le modifiche?"))
 | 
						|
  					TContsan_app::write(s);
 | 
						|
				msk.reset();
 | 
						|
				_modified = FALSE;  					
 | 
						|
  		}
 | 
						|
  		break;
 | 
						|
  	}	
 | 
						|
  }	
 | 
						|
	while (tasto != K_QUIT);
 | 
						|
  return FALSE;
 | 
						|
}  
 | 
						|
 | 
						|
int TContsan_app::write(TSheet_field& s)
 | 
						|
{ 
 | 
						|
	
 | 
						|
	const TMask& m = s.mask();
 | 
						|
	const TDate data = m.get(F_DATACON);
 | 
						|
	
 | 
						|
  int items = s.items();
 | 
						|
  TProgind *pi;
 | 
						|
  pi = new TProgind(items,"Registrazione controlli", FALSE, TRUE, 10);
 | 
						|
  pi->setstatus(1);
 | 
						|
	
 | 
						|
	for (int r=1; r<=s.items(); r++)
 | 
						|
	{	
 | 
						|
		
 | 
						|
    pi->addstatus(1);
 | 
						|
    
 | 
						|
		TToken_string& row = s.row(r-1);
 | 
						|
		const long codsog = row.get_long(0);
 | 
						|
		if (codsog != 0)
 | 
						|
		{
 | 
						|
			TLocalisamfile& sog = get_relation()->lfile();
 | 
						|
			sog.setkey(1);
 | 
						|
			sog.zero();
 | 
						|
			sog.put(SOG_CODICE, codsog);
 | 
						|
			int err = sog.read();
 | 
						|
			if (err == NOERR)
 | 
						|
			{ 
 | 
						|
				const TString16 tipocon = row.get(3);
 | 
						|
				if (!tipocon.blank())
 | 
						|
				{
 | 
						|
					TRectype* recc = new TRectype(LF_CONTSAN);
 | 
						|
					recc->put(CON_CODICE, row.get(0));
 | 
						|
					recc->put(CON_DATACON, m.get(F_DATACON));
 | 
						|
					recc->put(CON_TIPOCON, tipocon);
 | 
						|
					recc->put(CON_PROSSTIPO, row.get(4));
 | 
						|
					recc->put(CON_PROSSDATA, row.get(5));
 | 
						|
					bool insert = FALSE;
 | 
						|
					bool exist =  FALSE;
 | 
						|
					TRectype* keyc = new TRectype(LF_CONTSAN);
 | 
						|
					keyc->put(CON_CODICE, row.get(0));
 | 
						|
					int err = _scontrolli->read(keyc);
 | 
						|
					if (err == NOERR)
 | 
						|
					{
 | 
						|
						int r=_scontrolli->rows();
 | 
						|
						while (r>=1 && !insert && !exist)
 | 
						|
						{
 | 
						|
							const TRectype& riga = _scontrolli->row(r);
 | 
						|
							const TDate d = riga.get(CON_DATACON);
 | 
						|
							if (data==d)	// esiste gia' un controllo in questa data
 | 
						|
							{
 | 
						|
								exist=TRUE;
 | 
						|
								r=0;
 | 
						|
							}	 
 | 
						|
							else
 | 
						|
								if (data > d)
 | 
						|
								{                            
 | 
						|
									recc->put(CON_PROGCON,r+1);
 | 
						|
									_scontrolli->insert_row(recc);
 | 
						|
									insert=TRUE;
 | 
						|
								}
 | 
						|
							r--;						
 | 
						|
						}
 | 
						|
						if (!exist && !insert)
 | 
						|
						{
 | 
						|
							recc->put(CON_PROGCON,1);
 | 
						|
							_scontrolli->insert_row(recc);
 | 
						|
						}
 | 
						|
					}	
 | 
						|
					else
 | 
						|
			  		if (err == _iseof || err == _isemptyfile)
 | 
						|
			  		{
 | 
						|
							recc->put(CON_PROGCON,1);
 | 
						|
							_scontrolli->insert_row(recc);		  	
 | 
						|
						}
 | 
						|
					if (!exist)					
 | 
						|
						_scontrolli->write(TRUE);
 | 
						|
					con_reord(sog.curr(), _scontrolli);						
 | 
						|
				  sog.put(SOG_DATAULTAGG,TODAY);
 | 
						|
				  sog.put(SOG_UTENULTAGG,user());
 | 
						|
					sog.rewrite();
 | 
						|
				}						
 | 
						|
			}				
 | 
						|
		}														
 | 
						|
	}
 | 
						|
 | 
						|
  delete pi;
 | 
						|
	
 | 
						|
	return NOERR;	
 | 
						|
}
 | 
						|
 | 
						|
bool TContsan_app::check_sog_sheet(const char* codsog)
 | 
						|
{ 
 | 
						|
	TAssoc_array& array_sogg = app().get_array_sogg();
 | 
						|
	if (array_sogg.is_key(codsog))
 | 
						|
		return FALSE;
 | 
						|
	else
 | 
						|
		return TRUE;
 | 
						|
}		
 | 
						|
 | 
						|
bool TContsan_app::soggetti_notify(TSheet_field& s, int r, KEY k)
 | 
						|
{              
 | 
						|
	bool ok = TRUE;
 | 
						|
	switch (k)
 | 
						|
	{ 
 | 
						|
		case K_CTRL+K_DEL:
 | 
						|
		// avvenuta cancellazione riga
 | 
						|
		break;
 | 
						|
		case K_SPACE:
 | 
						|
		// inizio modifica riga
 | 
						|
		break;
 | 
						|
		case K_TAB:
 | 
						|
		// entrata riga			
 | 
						|
		{                
 | 
						|
			if (r > 1)
 | 
						|
			{
 | 
						|
				if ((r == s.items()-1) && (r == s.first_empty()))
 | 
						|
				{
 | 
						|
					app().add_rows_soggetti(s,10,r+1);
 | 
						|
					s.select(r);
 | 
						|
				} 
 | 
						|
				TToken_string& row = s.row(r);
 | 
						|
				if (row.empty_items())
 | 
						|
					s.set_focus_cell(r,1);
 | 
						|
			}				
 | 
						|
		}
 | 
						|
	  break;
 | 
						|
		case K_ENTER:
 | 
						|
		// uscita da riga modificata
 | 
						|
		case K_CTRL+K_TAB:
 | 
						|
		// uscita riga
 | 
						|
		{
 | 
						|
			app()._modified = TRUE;
 | 
						|
			TToken_string& row = s.row(r);
 | 
						|
			const long codsog = row.get_long(0);
 | 
						|
			if (codsog != 0)
 | 
						|
				for (int i=s.items()-1; i>=0; i--)
 | 
						|
				{
 | 
						|
					if (i != r)
 | 
						|
					{
 | 
						|
						TToken_string& row = s.row(i); 
 | 
						|
						if (codsog == row.get_long(0))
 | 
						|
							return s.sheet_mask().field(F_S_CODICE).error_box("Soggetto gia' inserito");
 | 
						|
					}					
 | 
						|
				}				
 | 
						|
			else
 | 
						|
			{
 | 
						|
				const char* cognome = row.get(1);
 | 
						|
				if ((cognome != NULL) && (cognome != "\0"))
 | 
						|
				{
 | 
						|
					s.sheet_mask().field(F_S_NOME).set_focusdirty();
 | 
						|
					s.set_focus_cell(r,2);
 | 
						|
				}						
 | 
						|
			}
 | 
						|
			s.force_update(r);
 | 
						|
			if (r == s.items()-1)
 | 
						|
			{
 | 
						|
				app().add_rows_soggetti(s,10,r+1);
 | 
						|
				s.select(r);
 | 
						|
			}
 | 
						|
		}
 | 
						|
	  break;  	
 | 
						|
	}  
 | 
						|
  return ok;  
 | 
						|
}
 | 
						|
 | 
						|
bool TContsan_app::nome_handler(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
	bool ok = TRUE;
 | 
						|
  //if (k == K_TAB && f.focusdirty())
 | 
						|
  if (f.to_check(k))
 | 
						|
  {
 | 
						|
  	TMask& m = f.mask();
 | 
						|
  	long codsog = m.get_long(F_S_CODICE);
 | 
						|
  	if (codsog == 0)
 | 
						|
      f.on_key(K_F9);
 | 
						|
  }	
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TContsan_app::tipocon_handler(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
	bool ok = TRUE;
 | 
						|
	if (k == K_TAB && !f.focusdirty())
 | 
						|
	{
 | 
						|
  	TMask& m = f.mask();
 | 
						|
		TString16 tipoconsog = m.get(F_S_TIPOCON);  
 | 
						|
		TString80 nome = m.get(F_S_NOME);
 | 
						|
		if (tipoconsog.empty() && nome.not_empty())
 | 
						|
		{
 | 
						|
			TString16 tipocon 	= app().get_mask().get(F_TIPOCON);      
 | 
						|
			TString16 prosstipo = app().get_mask().get(F_PROSSTIPO);      
 | 
						|
			TDate prossdata 		= app().get_mask().get(F_PROSSDATA);      
 | 
						|
			m.field(F_S_TIPOCON).set(tipocon);
 | 
						|
			m.field(F_S_PROSSTIPO).set(prosstipo);
 | 
						|
			m.field(F_S_PROSSDATA).set(prossdata);
 | 
						|
		}	
 | 
						|
	}		
 | 
						|
	return TRUE;
 | 
						|
}
 | 
						|
		
 | 
						|
int at0300(int argc, char* argv[])
 | 
						|
{
 | 
						|
	TContsan_app a;
 | 
						|
	a.run(argc, argv, "Giornaliero controlli");
 | 
						|
	return 0;
 | 
						|
} |