159 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			159 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <mask.h>
 | 
						|
#include <printapp.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <utility.h>
 | 
						|
#include <lffiles.h>
 | 
						|
 | 
						|
#include "at7.h"
 | 
						|
 | 
						|
// nomi dei campi
 | 
						|
#include "soggetti.h"
 | 
						|
#include "donaz.h"
 | 
						|
#include "storico.h"
 | 
						|
 | 
						|
class TPrimaDon : public TPrintapp
 | 
						|
{
 | 
						|
	TMask*						_msk;
 | 
						|
	TRelation*   			_rel;
 | 
						|
	int 							_cur;	
 | 
						|
	TLocalisamfile*		_donaz;
 | 
						|
	TRecord_array*		_sdonazioni;
 | 
						|
	TLocalisamfile*		_storico;
 | 
						|
	TRecord_array*		_sstorico;
 | 
						|
 | 
						|
protected:
 | 
						|
	virtual bool user_create();
 | 
						|
	virtual bool user_destroy();
 | 
						|
	virtual bool set_print(int m);
 | 
						|
	virtual void set_page(int file, int cnt);
 | 
						|
	virtual bool preprocess_page(int file, int counter);
 | 
						|
	
 | 
						|
public:
 | 
						|
	TPrimaDon() {}
 | 
						|
};
 | 
						|
 | 
						|
HIDDEN inline TPrimaDon& app() { return (TPrimaDon&) main_app(); }
 | 
						|
 | 
						|
bool TPrimaDon::preprocess_page(int file, int counter)
 | 
						|
{ 
 | 
						|
	bool rewrite = FALSE;
 | 
						|
	TRectype& recsog = current_cursor()->curr();
 | 
						|
	const TString sezsog = recsog.get(SOG_CODSEZ);
 | 
						|
	const TString sotsog = recsog.get(SOG_CODSOT);
 | 
						|
	const TDate dataisc = recsog.get_date(SOG_DATAISC);
 | 
						|
	const long codice = recsog.get_long(SOG_CODICE);
 | 
						|
	TRectype* keys = new TRectype(LF_STORICO);
 | 
						|
	keys->put(STO_CODICE, codice);
 | 
						|
	int errs = _sstorico->read(keys);
 | 
						|
	TRectype* keyd = new TRectype(LF_DONAZ);
 | 
						|
	keyd->put(DON_CODICE, codice);
 | 
						|
	int errd = _sdonazioni->read(keyd);
 | 
						|
	if ((errd == NOERR) && (_sdonazioni->rows()>0))
 | 
						|
	{   
 | 
						|
		for (int d=1; d<=_sdonazioni->rows(); d++)
 | 
						|
		{
 | 
						|
			TRectype& riga = _sdonazioni->row(d, TRUE);
 | 
						|
			TString16 codsez = riga.get(DON_CODSEZ);
 | 
						|
			TString16 codsot = riga.get(DON_CODSOT);
 | 
						|
			TDate datadon = riga.get_date(DON_DATADON);
 | 
						|
			if (codsez.empty() && codsot.empty())
 | 
						|
			{
 | 
						|
				if (_sstorico->rows()>0)
 | 
						|
				{
 | 
						|
					for (int s=1; s<=_sstorico->rows(); s++)
 | 
						|
					{
 | 
						|
						TRectype& rigas = _sstorico->row(s, TRUE);
 | 
						|
						TDate dataisc = rigas.get_date(STO_DATAISC);
 | 
						|
						TDate datadim = rigas.get_date(STO_DATADIM);
 | 
						|
						if ((datadon >= dataisc) && ( (datadon <= datadim) || (datadim.empty()) ))
 | 
						|
						{
 | 
						|
							riga.put(DON_CODSEZ,rigas.get(STO_CODSEZ));
 | 
						|
							riga.put(DON_CODSOT,rigas.get(STO_CODSOT));
 | 
						|
							s = _sstorico->rows()+1;
 | 
						|
							rewrite = TRUE;							
 | 
						|
						}
 | 
						|
					}						
 | 
						|
				}
 | 
						|
				else  
 | 
						|
				{
 | 
						|
					if (datadon >= dataisc)
 | 
						|
					{
 | 
						|
						riga.put(DON_CODSEZ, sezsog);
 | 
						|
						riga.put(DON_CODSOT, sotsog);
 | 
						|
					}	
 | 
						|
				}					
 | 
						|
			}
 | 
						|
	  }
 | 
						|
	  /*
 | 
						|
		TDate dataprisi = recsog.get(SOG_DATAPRISI);
 | 
						|
		TDate datapriaf = recsog.get(SOG_DATAPRIAF);
 | 
						|
		TRectype& riga = _sdonazioni->row(1, TRUE);
 | 
						|
		TDate datadon =	riga.get(DON_DATADON);			
 | 
						|
		if (datadon==dataprisi || datadon==datapriaf)
 | 
						|
		{
 | 
						|
			rewrite = TRUE;
 | 
						|
			riga.put(DON_PRIMADON, TRUE);
 | 
						|
		}			
 | 
						|
		else			
 | 
						|
			if ((!dataprisi.ok()) && (!datapriaf.ok()))
 | 
						|
			{
 | 
						|
				rewrite = TRUE;
 | 
						|
				riga.put(DON_PRIMADON, TRUE);
 | 
						|
			}				
 | 
						|
		*/			
 | 
						|
		if (rewrite)
 | 
						|
			_sdonazioni->rewrite();		
 | 
						|
	}			
 | 
						|
	return rewrite;	
 | 
						|
}
 | 
						|
 | 
						|
void TPrimaDon::set_page(int file, int cnt)
 | 
						|
{ 
 | 
						|
	set_row(1,"@0g@pn", FLD(LF_SOGGETTI,SOG_CODICE,"########"));
 | 
						|
}
 | 
						|
 | 
						|
bool TPrimaDon::set_print(int)
 | 
						|
{
 | 
						|
  KEY tasto;
 | 
						|
  tasto = _msk->run();
 | 
						|
	if (tasto == K_ENTER)
 | 
						|
	{  	 
 | 
						|
    reset_files(); 
 | 
						|
    add_file(LF_SOGGETTI);
 | 
						|
		reset_print();		
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
  else
 | 
						|
    return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
bool TPrimaDon::user_create()
 | 
						|
{
 | 
						|
	_msk 				= new TMask("at7200a");
 | 
						|
	_rel 				= new TRelation(LF_SOGGETTI);
 | 
						|
	_donaz 	   	= new TLocalisamfile(LF_DONAZ);
 | 
						|
	_storico  	= new TLocalisamfile(LF_STORICO);
 | 
						|
	_sdonazioni	= new TRecord_array(LF_DONAZ,DON_PROGDON);
 | 
						|
	_sstorico  	= new TRecord_array(LF_STORICO,STO_PROGSTO);
 | 
						|
  _cur 			  = add_cursor(new TCursor(_rel, "", 1));
 | 
						|
	return TRUE;
 | 
						|
}	
 | 
						|
 | 
						|
bool TPrimaDon::user_destroy()	
 | 
						|
{
 | 
						|
	delete _sstorico;
 | 
						|
	delete _sdonazioni;
 | 
						|
	delete _storico;
 | 
						|
	delete _donaz;
 | 
						|
	delete _rel;
 | 
						|
	delete _msk;
 | 
						|
	return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
int at7200(int argc, char* argv[])
 | 
						|
{
 | 
						|
	TPrimaDon a;
 | 
						|
	a.run(argc, argv, "Marca prime donazioni");
 | 
						|
	return 0;
 | 
						|
} |