Files correlati : ci2.exe Ricompilazione Demo : [ ] Commento : Rlevazione ore git-svn-id: svn://10.65.10.50/branches/R_10_00@21237 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			877 lines
		
	
	
		
			23 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			877 lines
		
	
	
		
			23 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <automask.h>
 | 
						||
#include <colors.h>
 | 
						||
#include <defmask.h>
 | 
						||
#include <recset.h>
 | 
						||
#include <sheet.h>
 | 
						||
#include <utility.h>
 | 
						||
 | 
						||
#include <doc.h>
 | 
						||
 | 
						||
#include "ci2.h"
 | 
						||
#include "cilib.h"
 | 
						||
#include "ci2200a.h"
 | 
						||
#include "rilore.h"
 | 
						||
#include "../ca/calib01.h"
 | 
						||
#include "../ve/velib.h"
 | 
						||
 | 
						||
                                      ////////////////////////////////////////////
 | 
						||
                                      ////    CLASSE TRilevamento_cons_msk    ////
 | 
						||
                                      ////////////////////////////////////////////
 | 
						||
 | 
						||
//Classe TRilevamento_cons_msk
 | 
						||
class TRilevamento_cons_msk : public TAutomask
 | 
						||
{
 | 
						||
  int   _qtaore;
 | 
						||
	short _cdc_sid, _cdc_lid;
 | 
						||
	short _cms_sid, _cms_lid;
 | 
						||
	short _fase_sid, _fase_lid;
 | 
						||
	short _scdc_sid, _scdc_lid;
 | 
						||
	short _scms_sid, _scms_lid;
 | 
						||
	short _sfase_sid, _sfase_lid;
 | 
						||
  TDate _datasel;
 | 
						||
	int _anno;
 | 
						||
	int _mese;
 | 
						||
	int _giorno;
 | 
						||
	int _first_ex;
 | 
						||
	int _n_ex;
 | 
						||
	int _es_array[32];
 | 
						||
	TEsercizi_contabili _es;
 | 
						||
 | 
						||
protected:
 | 
						||
  const real proponi_costo(TToken_string& riga);
 | 
						||
	void get_anal_fields(TString & cdc, TString & cms, TString & fase);
 | 
						||
	void get_row_anal_fields(TToken_string & row, TString & cdc, TString & cms, TString & fase);
 | 
						||
	void put_row_anal_fields(TToken_string & row, const TString & cdc, const TString & cms, const TString & fase);
 | 
						||
  void carica_default();
 | 
						||
	void update_day();
 | 
						||
  void riempi_sheet();
 | 
						||
  void riempi_calendario(const TString & query);
 | 
						||
  void riempi_risoatt(char tipo = 'C');
 | 
						||
  void azzera_tutto();
 | 
						||
  void registra();
 | 
						||
 | 
						||
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
  
 | 
						||
public:
 | 
						||
  TRilevamento_cons_msk();
 | 
						||
};
 | 
						||
 | 
						||
const real TRilevamento_cons_msk::proponi_costo(TToken_string& riga)
 | 
						||
{
 | 
						||
  real costo = ZERO;
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
  const char tipo  = riga.get_char(sheet.cid2index(S_RISOATT));
 | 
						||
  TString80 codice;
 | 
						||
  switch(tipo)
 | 
						||
  {
 | 
						||
  case 'R': codice = riga.get(sheet.cid2index(S_CODRIS)); break;
 | 
						||
  case 'A': codice = riga.get(sheet.cid2index(S_CODATT)); break;
 | 
						||
  default : break;
 | 
						||
  }
 | 
						||
  
 | 
						||
	const TDate dal(1, _mese, _anno);
 | 
						||
	const TString4 tpora = riga.get(sheet.cid2index(S_TPORA));
 | 
						||
 | 
						||
  const TRisoatt_key chiave(tipo, codice, dal, tpora);
 | 
						||
	const TRectype & roa = cache().get("&ROA", chiave);
 | 
						||
 | 
						||
  if(!roa.empty())
 | 
						||
    costo = roa.get_real("R1");
 | 
						||
  else
 | 
						||
  {
 | 
						||
    TString8 tmp; tmp << _anno << _mese;
 | 
						||
    const long anme = atol(tmp);
 | 
						||
    TString query;
 | 
						||
    query << "USE &ROA\n"
 | 
						||
          << "SELECT I0<"   << anme << "\n"
 | 
						||
          << "FROM CODTAB=" << tipo << codice.left_just(16) << "\n"
 | 
						||
          << "TO CODTAB="   << tipo << codice.left_just(16) << "\n"
 | 
						||
          << "BY I0\n";
 | 
						||
     TISAM_recordset rec(query);
 | 
						||
 | 
						||
     if(rec.move_last())
 | 
						||
       costo = rec.cursor()->curr().get_real("R1");
 | 
						||
  }
 | 
						||
  return costo;
 | 
						||
}
 | 
						||
void TRilevamento_cons_msk::get_anal_fields(TString & cdc, TString & cms, TString & fase)
 | 
						||
{
 | 
						||
	TString val;
 | 
						||
 | 
						||
	cdc.cut(0);
 | 
						||
	if (_cdc_sid >= 0)
 | 
						||
		for ( short id = _cdc_sid; id <= _cdc_lid; id++)
 | 
						||
		{
 | 
						||
			val = get(id);
 | 
						||
			val.rpad(field(id).size());
 | 
						||
			cdc << val;
 | 
						||
		}
 | 
						||
	cdc.trim();
 | 
						||
	cms.cut(0);
 | 
						||
	if (_cms_sid >= 0)
 | 
						||
		for ( short id = _cms_sid; id <= _cms_lid; id++)
 | 
						||
		{
 | 
						||
			val = get(id);
 | 
						||
			val.rpad(field(id).size());
 | 
						||
			cms << val;
 | 
						||
		}
 | 
						||
	cms.trim();
 | 
						||
	fase.cut(0);
 | 
						||
	if (_fase_sid >= 0)
 | 
						||
		for ( short id = _fase_sid; id <= _fase_lid; id++)
 | 
						||
		{
 | 
						||
			val = get(id);
 | 
						||
			val.rpad(field(id).size());
 | 
						||
			fase << val;
 | 
						||
		}
 | 
						||
	fase.trim();
 | 
						||
}
 | 
						||
 | 
						||
void TRilevamento_cons_msk::get_row_anal_fields(TToken_string & row, TString & cdc, TString & cms, TString & fase)
 | 
						||
{
 | 
						||
	TSheet_field & s = sfield(F_SHEET);
 | 
						||
	TMask & m = s.sheet_mask();
 | 
						||
	TString val;
 | 
						||
 | 
						||
	cdc.cut(0);
 | 
						||
	if (_scdc_sid >= 0)
 | 
						||
		for ( short id = _scdc_sid; id <= _scdc_lid; id++)
 | 
						||
		{
 | 
						||
			val = row.get(s.cid2index(id));
 | 
						||
			val.rpad(m.field(id).size());
 | 
						||
			cdc << val;
 | 
						||
		}
 | 
						||
	cdc.trim();
 | 
						||
	cms.cut(0);
 | 
						||
	if (_scms_sid >= 0)
 | 
						||
		for ( short id = _scms_sid; id <= _scms_lid; id++)
 | 
						||
		{
 | 
						||
			val = row.get(s.cid2index(id));
 | 
						||
			val.rpad(m.field(id).size());
 | 
						||
			cms << val;
 | 
						||
		}
 | 
						||
	cms.trim();
 | 
						||
	fase.cut(0);
 | 
						||
	if (_sfase_sid >= 0)
 | 
						||
		for ( short id = _sfase_sid; id <= _sfase_lid; id++)
 | 
						||
		{
 | 
						||
			val = row.get(s.cid2index(id));
 | 
						||
			val.rpad(m.field(id).size());
 | 
						||
			fase << val;
 | 
						||
		}
 | 
						||
	fase.trim();
 | 
						||
}
 | 
						||
 | 
						||
void TRilevamento_cons_msk::put_row_anal_fields(TToken_string & row, const TString & cdc, const TString & cms, const TString & fase)
 | 
						||
{
 | 
						||
	TSheet_field & s = sfield(F_SHEET);
 | 
						||
	TMask & m = s.sheet_mask();
 | 
						||
	int pos = 0;
 | 
						||
 | 
						||
	if (_scdc_sid >= 0)
 | 
						||
		for (short id = _scdc_sid; id <= _scdc_lid; id++)
 | 
						||
		{
 | 
						||
			const int len = m.field(id).size();
 | 
						||
			row.add(cdc.mid(pos, len), s.cid2index(id));
 | 
						||
			pos += len;
 | 
						||
		}
 | 
						||
	pos = 0;
 | 
						||
	if (_scms_sid >= 0)
 | 
						||
		for (short id = _scms_sid; id <= _scms_lid; id++)
 | 
						||
		{
 | 
						||
			const int len = m.field(id).size();
 | 
						||
			row.add(cms.mid(pos, len), s.cid2index(id));
 | 
						||
			pos += len;
 | 
						||
		}
 | 
						||
	pos = 0;
 | 
						||
	if (_sfase_sid >= 0)
 | 
						||
		for (short id = _sfase_sid; id <= _sfase_lid; id++)
 | 
						||
		{
 | 
						||
			const int len = m.field(id).size();
 | 
						||
			row.add(fase.mid(pos, len), s.cid2index(id));
 | 
						||
			pos += len;
 | 
						||
		}
 | 
						||
}
 | 
						||
 | 
						||
void TRilevamento_cons_msk::carica_default()
 | 
						||
{
 | 
						||
  //leggo dalla maschera i campi chiave di ricerca
 | 
						||
  const TString4  risoatt  = get(F_RISOATT) == "T" ? "" : get(F_RISOATT);
 | 
						||
  const TString4  tpora    = get(F_TPORA);
 | 
						||
  TString80 codcosto;
 | 
						||
  TString80 codcms;
 | 
						||
  TString16 codfase;
 | 
						||
  TString16 codice;
 | 
						||
  TString query;
 | 
						||
	TString select;
 | 
						||
 | 
						||
	update_day();
 | 
						||
	switch(get(F_RISOATT)[0])
 | 
						||
  {
 | 
						||
	  case 'R': codice = get(F_CODRIS); break;
 | 
						||
		case 'A': codice = get(F_CODATT); break;
 | 
						||
		default: break;
 | 
						||
  }
 | 
						||
	get_anal_fields(codcosto, codcms, codfase);
 | 
						||
 | 
						||
	query << "USE " << LF_RILORE  << " KEY 2\n" ;
 | 
						||
	if (risoatt.full())
 | 
						||
		select << "(" << RILORE_TIPORA << "==\""  << risoatt << "\")";
 | 
						||
	if (codice.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODICE << "==\"" << codice << "\")";
 | 
						||
	}
 | 
						||
	if (tpora.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_TPORA << "==\"" << tpora    << "\")";
 | 
						||
	}
 | 
						||
	if (codcosto.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODCOSTO << "==\"" << codcosto << "\")";
 | 
						||
	}
 | 
						||
	if (codcms.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODCMS << "==\"" << codcms   << "\")";
 | 
						||
	}
 | 
						||
	if (codfase.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODFASE << "==\"" << codfase  << "\")";
 | 
						||
	}
 | 
						||
	if (select.full())
 | 
						||
		query << "SELECT " << select << "\n";
 | 
						||
 | 
						||
	TString fromto = RILORE_TIPO "=\"D\" ";
 | 
						||
 | 
						||
	if (_anno > 0)
 | 
						||
	{
 | 
						||
		fromto << "  " << RILORE_ANNO << "=" << _anno << " ";
 | 
						||
		if (_mese > 0)
 | 
						||
			fromto << RILORE_MESE << "=" << _mese << " ";
 | 
						||
	}
 | 
						||
	riempi_calendario(query);
 | 
						||
 | 
						||
	riempi_risoatt('D');
 | 
						||
}
 | 
						||
 | 
						||
//RIEMPI_CALENDARIO: coloro le celle dello sheet calendario secondo le festivit<69> e i giorni occupati
 | 
						||
void TRilevamento_cons_msk::riempi_calendario(const TString & query)
 | 
						||
{
 | 
						||
	TSheet_field& calendario = sfield(F_CALENDARIO);
 | 
						||
	const TString4 dett = get(F_INTERVALLO);
 | 
						||
	
 | 
						||
	update_day();
 | 
						||
	calendario.destroy(-1, false);
 | 
						||
	if (dett == "A")
 | 
						||
	{
 | 
						||
		TBit_array full_years;
 | 
						||
		TISAM_recordset recset(query);
 | 
						||
	  
 | 
						||
		for (bool ok = recset.move_first(); ok; ok = recset.move_next())
 | 
						||
		{
 | 
						||
			const int anno = recset.get(RILORE_ANNO).as_int();
 | 
						||
			
 | 
						||
			full_years.set(anno);
 | 
						||
		}
 | 
						||
		for (int i = 0; i < _n_ex; i++)
 | 
						||
		{
 | 
						||
			TToken_string & row = calendario.row(i);
 | 
						||
			COLOR back = NORMAL_BACK_COLOR;
 | 
						||
			COLOR fore = NORMAL_COLOR;
 | 
						||
 | 
						||
			if (full_years[_es_array[i]])
 | 
						||
			{
 | 
						||
				back = COLOR_DKBLUE; // coloro di blu le date con registrazioni
 | 
						||
				fore = COLOR_WHITE; // coloro di blu le date con registrazioni
 | 
						||
			}
 | 
						||
			calendario.set_back_and_fore_color(back, fore, i - 1, 0);
 | 
						||
			row.add(_es_array[i]);
 | 
						||
		}
 | 
						||
	}
 | 
						||
	else
 | 
						||
		if (dett == "M")
 | 
						||
		{
 | 
						||
			TBit_array full_months;
 | 
						||
			TISAM_recordset recset(query);
 | 
						||
		  
 | 
						||
			for (bool ok = recset.move_first(); ok; ok = recset.move_next())
 | 
						||
			{
 | 
						||
				const int mese = recset.get(RILORE_MESE).as_int();
 | 
						||
				
 | 
						||
				full_months.set(mese);
 | 
						||
			}
 | 
						||
 | 
						||
			for (int i = 1; i <= 12; i++)
 | 
						||
			{
 | 
						||
				TToken_string & row = calendario.row(i - 1);
 | 
						||
				COLOR back = NORMAL_BACK_COLOR;
 | 
						||
				COLOR fore = NORMAL_COLOR;
 | 
						||
	
 | 
						||
				if (full_months[i])
 | 
						||
				{
 | 
						||
					back = COLOR_DKBLUE; // coloro di blu le date con registrazioni
 | 
						||
					fore = COLOR_WHITE; // coloro di blu le date con registrazioni
 | 
						||
				}
 | 
						||
				calendario.set_back_and_fore_color(back, fore, i - 1, 0);
 | 
						||
				row.add(itom(i));
 | 
						||
			}
 | 
						||
		}
 | 
						||
		else
 | 
						||
			if (dett == "G")
 | 
						||
			{
 | 
						||
				TDate d(1, _mese, _anno); d.set_end_month();
 | 
						||
				const int end_month = d.day();
 | 
						||
				TBit_array fulldays;
 | 
						||
				TISAM_recordset recset(query);
 | 
						||
			  
 | 
						||
				//scorro il recordset, aggiungo una riga allo sheet per ogni chiave analitica che trovo e coloro di blu
 | 
						||
				//tutte le celle che corrispondono a una data interessata da qualcosa
 | 
						||
				for (bool ok = recset.move_first(); ok; ok = recset.move_next())
 | 
						||
				{
 | 
						||
					const int day = recset.get(RILORE_GIORNO).as_int();
 | 
						||
					
 | 
						||
					fulldays.set(day);
 | 
						||
				}
 | 
						||
 | 
						||
				for(int i = 1; i <= end_month; i++)
 | 
						||
				{
 | 
						||
					TToken_string & row = calendario.row(i - 1);
 | 
						||
					COLOR back = NORMAL_BACK_COLOR;
 | 
						||
					COLOR fore = NORMAL_COLOR;
 | 
						||
	
 | 
						||
					if (fulldays[i])
 | 
						||
					{
 | 
						||
						back = COLOR_DKBLUE; // coloro di blu le date con registrazioni
 | 
						||
						fore = COLOR_WHITE; // coloro di blu le date con registrazioni
 | 
						||
					}
 | 
						||
					else
 | 
						||
						if (TDate(i, _mese, _anno).is_holiday())
 | 
						||
						{
 | 
						||
							back = COLOR_DKRED; // coloro di rosso le festivit<69>
 | 
						||
							fore = COLOR_WHITE; // coloro di rosso le festivit<69>
 | 
						||
						}
 | 
						||
					calendario.set_back_and_fore_color(back, fore, i - 1, 0);
 | 
						||
					row.add(i);
 | 
						||
				}
 | 
						||
			}
 | 
						||
	calendario.force_update();
 | 
						||
}
 | 
						||
 | 
						||
void TRilevamento_cons_msk::riempi_risoatt(char tipo)
 | 
						||
{
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
 | 
						||
	if (sheet.items() > 0 && sheet.dirty() && yesno_box("Vuoi salvare le modifiche"))
 | 
						||
		registra();
 | 
						||
  sheet.destroy();
 | 
						||
 | 
						||
	update_day();
 | 
						||
	//leggo dalla maschera i campi chiave di ricerca
 | 
						||
  const TString4  risoatt  = get(F_RISOATT) == "T" ? "" : get(F_RISOATT);
 | 
						||
  const TString4  tpora    = get(F_TPORA);
 | 
						||
  TString80 codcosto;
 | 
						||
  TString80 codcms;
 | 
						||
  TString16 codfase;
 | 
						||
	TString16 codice;
 | 
						||
	TString query;
 | 
						||
	TString select;
 | 
						||
 | 
						||
	switch(get(F_RISOATT)[0])
 | 
						||
  {
 | 
						||
	  case 'R': codice = get(F_CODRIS); break;
 | 
						||
		case 'A': codice = get(F_CODATT); break;
 | 
						||
		default: break;
 | 
						||
  }
 | 
						||
	get_anal_fields(codcosto, codcms, codfase);
 | 
						||
  //preparo la query
 | 
						||
  
 | 
						||
	query << "USE " << LF_RILORE  << " KEY 2\n" ;
 | 
						||
	if (risoatt.full())
 | 
						||
		select << "(" << RILORE_TIPORA << "==\""  << risoatt << "\")";
 | 
						||
	if (codice.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODICE << "==\"" << codice << "\")";
 | 
						||
	}
 | 
						||
	if (tpora.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_TPORA << "==\"" << tpora    << "\")";
 | 
						||
	}
 | 
						||
	if (codcosto.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODCOSTO << "==\"" << codcosto << "\")";
 | 
						||
	}
 | 
						||
	if (codcms.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODCMS << "==\"" << codcms   << "\")";
 | 
						||
	}
 | 
						||
	if (codfase.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODFASE << "==\"" << codfase  << "\")";
 | 
						||
	}
 | 
						||
	if (select.full())
 | 
						||
		query << "SELECT " << select << "\n";
 | 
						||
 | 
						||
  TString fromto = RILORE_TIPO;
 | 
						||
	
 | 
						||
	fromto << "=\"" << tipo << "\"";
 | 
						||
  if (_anno > 0)
 | 
						||
  {
 | 
						||
    fromto << "  " << RILORE_ANNO << "=" << _anno << " ";
 | 
						||
    if (_mese > 0)
 | 
						||
    {
 | 
						||
      fromto << RILORE_MESE << "=" << _mese << " ";
 | 
						||
			if (tipo == 'C')
 | 
						||
        fromto << RILORE_GIORNO << "=" << _giorno << " ";
 | 
						||
    }
 | 
						||
  }
 | 
						||
  query << "FROM " << fromto  << "\n"
 | 
						||
        << "TO "   << fromto;
 | 
						||
 | 
						||
  TISAM_recordset def(query);
 | 
						||
 | 
						||
  //riempio lo sheet con i dati che soddisfano il filtro preparato prima
 | 
						||
  for(bool ok = def.move_first(); ok; ok = def.move_next())
 | 
						||
  {
 | 
						||
    TRilevamento_ore rilore(def.cursor()->curr());    
 | 
						||
    
 | 
						||
    TToken_string& riga = sheet.row(-1);
 | 
						||
		const char tipo = rilore.get(RILORE_TIPORA)[0];
 | 
						||
		TString16 cod = rilore.get(RILORE_CODICE);
 | 
						||
 | 
						||
		riga.add(tipo, sheet.cid2index(S_RISOATT));
 | 
						||
    switch(tipo)
 | 
						||
    {
 | 
						||
    case 'R': riga.add(cod, sheet.cid2index(S_CODRIS)); break;
 | 
						||
    case 'A': riga.add(cod, sheet.cid2index(S_CODATT)); break;
 | 
						||
    default : break;
 | 
						||
    }
 | 
						||
		riga.add(rilore.get(RILORE_TPORA), sheet.cid2index(S_TPORA));
 | 
						||
		put_row_anal_fields(riga, rilore.get(RILORE_CODCOSTO), rilore.get(RILORE_CODCMS), rilore.get(RILORE_CODFASE));
 | 
						||
    riga.add(rilore.get(RILORE_QTAORE), sheet.cid2index(S_QTAORE));
 | 
						||
    riga.add(rilore.get(RILORE_COSTO), sheet.cid2index(S_COSTO));
 | 
						||
    riga.add(rilore.get(RILORE_ID), sheet.cid2index(S_ID));
 | 
						||
 | 
						||
		sheet.check_row(sheet.items() - 1);
 | 
						||
  }
 | 
						||
  sheet.force_update();
 | 
						||
}
 | 
						||
 | 
						||
//RIEMPI_SHEET: metodo che riempie lo sheet in base ai campi chiave
 | 
						||
//compilati sulla maschera
 | 
						||
void TRilevamento_cons_msk::riempi_sheet()
 | 
						||
{
 | 
						||
  //leggo dalla maschera i campi chiave di ricerca
 | 
						||
  const TString4  risoatt  = get(F_RISOATT) == "T" ? "" : get(F_RISOATT);
 | 
						||
  const TString4  tpora    = get(F_TPORA);
 | 
						||
  TString80 codcosto;
 | 
						||
  TString80 codcms;
 | 
						||
  TString16 codfase;
 | 
						||
  TString16 codice;
 | 
						||
	TString query;
 | 
						||
	TString select;
 | 
						||
  
 | 
						||
	update_day();
 | 
						||
	switch(get(F_RISOATT)[0])
 | 
						||
  {
 | 
						||
	  case 'R': codice = get(F_CODRIS); break;
 | 
						||
		case 'A': codice = get(F_CODATT); break;
 | 
						||
		default: break;
 | 
						||
  }
 | 
						||
 | 
						||
	get_anal_fields(codcosto, codcms, codfase);
 | 
						||
 | 
						||
  //preparo la query
 | 
						||
	query << "USE " << LF_RILORE  << " KEY 2\n" ;
 | 
						||
	if (risoatt.full())
 | 
						||
		select << "(" << RILORE_TIPORA << "==\""  << risoatt << "\")";
 | 
						||
	if (codice.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODICE << "==\"" << codice << "\")";
 | 
						||
	}
 | 
						||
	if (tpora.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_TPORA << "==\"" << tpora    << "\")";
 | 
						||
	}
 | 
						||
	if (codcosto.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODCOSTO << "==\"" << codcosto << "\")";
 | 
						||
	}
 | 
						||
	if (codcms.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODCMS << "==\"" << codcms   << "\")";
 | 
						||
	}
 | 
						||
	if (codfase.full())
 | 
						||
	{
 | 
						||
		if (select.full()) select << "&&";
 | 
						||
		select << "(" << RILORE_CODFASE << "==\"" << codfase  << "\")";
 | 
						||
	}
 | 
						||
	if (select.full())
 | 
						||
		query << "SELECT " << select << "\n";
 | 
						||
 | 
						||
  TString fromto = RILORE_TIPO "=\"C\"";
 | 
						||
 | 
						||
	if (_anno > 0)
 | 
						||
  {
 | 
						||
    fromto << "  " << RILORE_ANNO << "=" << _anno << " ";
 | 
						||
    if (_mese > 0)
 | 
						||
      fromto << RILORE_MESE << "=" << _mese << " ";
 | 
						||
  }
 | 
						||
  query << "FROM " << fromto  << "\n"
 | 
						||
        << "TO "   << fromto;
 | 
						||
  riempi_calendario(query);
 | 
						||
	riempi_risoatt();
 | 
						||
}
 | 
						||
 | 
						||
//AZZERA_TUTTO: metodo che azzera il valore unitario di tutte le righe visualizzate sullo sheet
 | 
						||
//(N.B.: le righe con valore unitario nullo verranno eliminate in fase di registrazione)
 | 
						||
void TRilevamento_cons_msk::azzera_tutto()
 | 
						||
{
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
  FOR_EACH_SHEET_ROW(sheet, r, row)
 | 
						||
  {
 | 
						||
    TToken_string& row = sheet.row(r);
 | 
						||
    row.add(0, sheet.cid2index(S_QTAORE));
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
//REGISTRA: metodo che salva nella tabella di modulo le
 | 
						||
//righe dello sheet che hanno valore > 0, ed elimina quelle che hanno
 | 
						||
//vaoler pari a zero, e poi ricarica lo sheet
 | 
						||
void TRilevamento_cons_msk::registra()
 | 
						||
{
 | 
						||
  TSheet_field& calendario = sfield(F_CALENDARIO);
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
  TRilevamento_ore rilroa;
 | 
						||
  const int      mese = get_int(F_MESE);
 | 
						||
  const int      anno = get_int(F_ANNO);
 | 
						||
  TString80 codcosto;
 | 
						||
  TString80 codcms;
 | 
						||
  TString16 codfase;
 | 
						||
	int err = NOERR;
 | 
						||
 | 
						||
	FOR_EACH_SHEET_ROW(sheet, r, row)
 | 
						||
  {
 | 
						||
    TToken_string&  riga = *(TToken_string*)row;
 | 
						||
    const char      tipora   = riga.get_char(sheet.cid2index(S_RISOATT));
 | 
						||
    const TString16 codice   = tipora == 'R' ? riga.get(sheet.cid2index(S_CODRIS)) : riga.get(sheet.cid2index(S_CODATT));
 | 
						||
    const TString4  tpora    = riga.get(sheet.cid2index(S_TPORA));
 | 
						||
    const int       qtaore   = riga.get_int(sheet.cid2index(S_QTAORE));
 | 
						||
		const long id = riga.get_long(sheet.cid2index(S_ID));
 | 
						||
    const real      costo(riga.get(sheet.cid2index(S_COSTO)));
 | 
						||
    
 | 
						||
		get_row_anal_fields(riga, codcosto, codcms, codfase);
 | 
						||
    rilroa.read('C', id);
 | 
						||
    if(qtaore == 0)
 | 
						||
      err = rilroa.remove();
 | 
						||
    else
 | 
						||
    {
 | 
						||
			rilroa.put(RILORE_TIPO, "C");
 | 
						||
      rilroa.put(RILORE_ID,  id);
 | 
						||
			rilroa.put(RILORE_ANNO,     anno);
 | 
						||
			rilroa.put(RILORE_MESE,     mese);
 | 
						||
			rilroa.put(RILORE_GIORNO,   _giorno);
 | 
						||
			rilroa.put(RILORE_TIPORA,   tipora);
 | 
						||
			rilroa.put(RILORE_CODICE,   codice);
 | 
						||
			rilroa.put(RILORE_TPORA,    tpora);
 | 
						||
			rilroa.put(RILORE_CODCOSTO, codcosto);
 | 
						||
			rilroa.put(RILORE_CODCMS,   codcms);
 | 
						||
			rilroa.put(RILORE_CODFASE,  codfase);
 | 
						||
			rilroa.put(RILORE_QTAORE, qtaore);
 | 
						||
      rilroa.put(RILORE_COSTO, costo);
 | 
						||
      err = rilroa.rewrite_write();
 | 
						||
    }
 | 
						||
		if (err != NOERR)
 | 
						||
			break;
 | 
						||
  }
 | 
						||
	if (err == NOERR)
 | 
						||
	{
 | 
						||
		sheet.destroy();
 | 
						||
		riempi_sheet();
 | 
						||
	}
 | 
						||
	else
 | 
						||
		error_box(FR("Errore %d in scrittura"), err);
 | 
						||
}
 | 
						||
 | 
						||
void TRilevamento_cons_msk::update_day()
 | 
						||
{
 | 
						||
	const int row = sfield(F_CALENDARIO).selected();
 | 
						||
	const TString4 dett = get(F_INTERVALLO);
 | 
						||
 | 
						||
	if (dett == "G")
 | 
						||
	{
 | 
						||
		_anno = get_int(F_ANNO);
 | 
						||
		_mese	= get_int(F_MESE);
 | 
						||
		_giorno = row +1;
 | 
						||
	}
 | 
						||
	else
 | 
						||
		if (dett == "M")
 | 
						||
		{
 | 
						||
			_anno = get_int(F_ANNO);
 | 
						||
			_mese	= row + 1;
 | 
						||
			_giorno = 1;
 | 
						||
		}
 | 
						||
		else
 | 
						||
			if (dett == "A")
 | 
						||
			{
 | 
						||
				_anno = _es_array[row];
 | 
						||
				_mese	= 1;
 | 
						||
				_giorno = 1;
 | 
						||
			}
 | 
						||
}
 | 
						||
 | 
						||
//ON_FIELD_EVENT: metodo che gestisce gli eventi sui vari campi della maschera
 | 
						||
bool TRilevamento_cons_msk::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | 
						||
{
 | 
						||
 	if (e == fe_modify && f.dlg() >= F_ANAL && f.dlg() < F_ANAL+12)
 | 
						||
	  riempi_sheet();
 | 
						||
  switch (f.dlg())
 | 
						||
	{
 | 
						||
  case DLG_DEFAULT:
 | 
						||
    if(e == fe_button)
 | 
						||
      carica_default();
 | 
						||
    break;
 | 
						||
  case DLG_CERCA:
 | 
						||
    if(e == fe_button)
 | 
						||
      riempi_sheet();
 | 
						||
    break;
 | 
						||
  case DLG_SAVEREC:
 | 
						||
    if(e == fe_button)
 | 
						||
      registra();
 | 
						||
  case F_ANNO:
 | 
						||
  case F_MESE:
 | 
						||
  case F_RISOATT:
 | 
						||
  case F_CODRIS:
 | 
						||
  case F_CODATT:
 | 
						||
  case F_TPORA:
 | 
						||
    if (e == fe_modify)
 | 
						||
      riempi_sheet();
 | 
						||
    break;
 | 
						||
  case F_CALENDARIO:
 | 
						||
    if (e == se_enter)
 | 
						||
      riempi_risoatt();
 | 
						||
    break;
 | 
						||
		case F_INTERVALLO:
 | 
						||
	    if (e == fe_modify)
 | 
						||
			{
 | 
						||
				const TString4 dett = ini_get_string(CONFIG_DITTA, "ci", "DETTCONS");
 | 
						||
				if (dett == "A")
 | 
						||
				{
 | 
						||
					reset(F_ANNO);
 | 
						||
					disable(F_ANNO);
 | 
						||
					reset(F_MESE);
 | 
						||
					disable(F_MESE);
 | 
						||
				}
 | 
						||
				else
 | 
						||
				{
 | 
						||
					if (dett == "M")
 | 
						||
					{
 | 
						||
						reset(F_MESE);
 | 
						||
						disable(F_MESE);
 | 
						||
					}
 | 
						||
				}
 | 
						||
				riempi_sheet();
 | 
						||
			}
 | 
						||
			break;
 | 
						||
  case S_RISOATT:  
 | 
						||
  case S_CODRIS:
 | 
						||
  case S_CODATT:
 | 
						||
  case S_TPORA:
 | 
						||
    if(e == fe_modify)
 | 
						||
    {
 | 
						||
      TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
			TMask & sm = sheet.sheet_mask();
 | 
						||
 | 
						||
      if(sm.get(S_RISOATT).full() && (sm.get(S_CODRIS).full() || sm.get(S_CODATT).full()) && sm.get(S_TPORA).full())
 | 
						||
        proponi_costo(sheet.row(sheet.selected()));
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  default: break;
 | 
						||
  }
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
TRilevamento_cons_msk::TRilevamento_cons_msk() 
 | 
						||
                     : TAutomask("ci2200a")
 | 
						||
{
 | 
						||
  const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
 | 
						||
	TConfig& ini = ca_config();
 | 
						||
	TSheet_field & s = sfield(F_SHEET);
 | 
						||
	TMask & sm = s.sheet_mask();
 | 
						||
	int y = 4;
 | 
						||
	int sy = 8;
 | 
						||
  short dlg = F_ANAL;        // id del primo campo da generare
 | 
						||
  short sdlg = S_CDC1 + 100; // id del primo campo da generare
 | 
						||
 | 
						||
	_cdc_sid = _cdc_lid = _cms_sid = _cms_lid =	_fase_sid = _fase_lid =	-1;
 | 
						||
	_scdc_sid = _scdc_lid =	_scms_sid = _scms_lid =	_sfase_sid = _sfase_lid = -1;
 | 
						||
 | 
						||
	for (int i = 0; i < 2; i++)
 | 
						||
  {
 | 
						||
    const TString& level = ini.get("Level", NULL, i+1);  // Legge il livello 1 o 2
 | 
						||
 | 
						||
		if (level == "CDC")                                  // Crea centro di costo 
 | 
						||
    {
 | 
						||
      if (fasinfo.parent() == LF_CDC)
 | 
						||
			{
 | 
						||
				int h = ca_multilevel_code_info(LF_CDC).levels();
 | 
						||
        const int h1 = ca_create_fields_compact(*this, 0, LF_FASI, 2, y, dlg, dlg + 100);
 | 
						||
				y += 2;
 | 
						||
				_cdc_sid = dlg;
 | 
						||
				_cdc_lid = dlg + h - 1;
 | 
						||
				_fase_sid = _cdc_lid + 1;
 | 
						||
				_fase_lid = dlg + h1 - 1;
 | 
						||
				dlg += h1;
 | 
						||
        const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy, sdlg, sdlg + 50);
 | 
						||
				sy += 2;
 | 
						||
				_scdc_sid = sdlg;
 | 
						||
				_scdc_lid = sdlg + h - 1;
 | 
						||
				_sfase_sid = _scdc_lid + 1;
 | 
						||
				_sfase_lid = sdlg + sh - 1;
 | 
						||
				sdlg += sh;
 | 
						||
      }
 | 
						||
			else
 | 
						||
			{
 | 
						||
				const int h = ca_create_fields_compact(*this, 0, LF_CDC, 2, y++, dlg, dlg + 100);
 | 
						||
				_cdc_sid = dlg;
 | 
						||
				_cdc_lid = dlg + h - 1;
 | 
						||
				dlg += h;
 | 
						||
				const int sh = ca_create_fields_compact(sm, 0, LF_CDC, 2, sy++, sdlg, sdlg + 50);
 | 
						||
				_scdc_sid = sdlg;
 | 
						||
				_scdc_lid = sdlg + sh - 1;
 | 
						||
				sdlg += h;
 | 
						||
			}
 | 
						||
    }
 | 
						||
	else
 | 
						||
		if (level == "CMS")                                   // Crea commessa
 | 
						||
		{
 | 
						||
		  if (fasinfo.parent() == LF_COMMESSE)
 | 
						||
			{
 | 
						||
				int h = ca_multilevel_code_info(LF_COMMESSE).levels();
 | 
						||
        const int h1 = ca_create_fields_compact(*this, 0, LF_FASI, 2, y, dlg, dlg + 100);
 | 
						||
				y += 2;
 | 
						||
				_cms_sid = dlg;
 | 
						||
				_cms_lid = dlg + h - 1;
 | 
						||
				_fase_sid = _cms_lid + 1;
 | 
						||
				_fase_lid = dlg + h1 - 1;
 | 
						||
				dlg += h1;
 | 
						||
        const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy, sdlg, sdlg + 50);
 | 
						||
				sy += 2;
 | 
						||
				_scms_sid = sdlg;
 | 
						||
				_scms_lid = sdlg + h - 1;
 | 
						||
				_sfase_sid = _scms_lid + 1;
 | 
						||
				_sfase_lid = sdlg + sh - 1;
 | 
						||
				sdlg += sh;
 | 
						||
			}
 | 
						||
			else
 | 
						||
			{
 | 
						||
				const int h = ca_create_fields_compact(*this, 0, LF_COMMESSE, 2, y++, dlg, dlg + 100);
 | 
						||
				_cms_sid = dlg;
 | 
						||
				_cms_lid = dlg + h - 1;
 | 
						||
				dlg += h;
 | 
						||
				const int sh = ca_create_fields_compact(sm, 0, LF_COMMESSE, 2, sy++, sdlg, sdlg + 50);
 | 
						||
				_scms_sid = sdlg;
 | 
						||
				_scms_lid = sdlg + sh - 1;
 | 
						||
				sdlg += sh;
 | 
						||
			}
 | 
						||
		}
 | 
						||
  }
 | 
						||
  if (fasinfo.levels() > 0 && fasinfo.parent() <= 0)
 | 
						||
	{
 | 
						||
    const int h = ca_create_fields_compact(*this, 0, LF_FASI, 2, y++, dlg, dlg + 100);
 | 
						||
		_fase_sid = dlg;
 | 
						||
		_fase_lid = dlg + h - 1;
 | 
						||
		dlg += h;
 | 
						||
    const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy++, sdlg, sdlg + 50);
 | 
						||
		_sfase_sid = sdlg;
 | 
						||
		_sfase_lid = sdlg + sh - 1;
 | 
						||
		sdlg += h;
 | 
						||
	}
 | 
						||
 | 
						||
  for (int i = 0; i < 12; i++)
 | 
						||
  {
 | 
						||
		const short id = F_ANAL + i;
 | 
						||
 | 
						||
    const int pos = id2pos(id);
 | 
						||
    if (pos >= 0)
 | 
						||
    {
 | 
						||
			set_universal_handler(id);
 | 
						||
			set_universal_handler(id + 100);
 | 
						||
		}
 | 
						||
	}
 | 
						||
 for (short id = S_CDC12 + 100; id >= S_CDC1 + 100; id--)
 | 
						||
  {
 | 
						||
    const int pos = sm.id2pos(id);
 | 
						||
    if (pos >= 0)
 | 
						||
    {
 | 
						||
      TMask_field& f = sm.fld(pos);
 | 
						||
      const int size = f.size();
 | 
						||
      const TString prompt = ((TEditable_field &)f).get_warning();
 | 
						||
      s.set_column_header(id, prompt);
 | 
						||
      s.set_column_justify(id, f.is_kind_of(CLASS_REAL_FIELD));
 | 
						||
      s.set_column_width(id, (max(3+size, prompt.len()+1)) * CHARX);
 | 
						||
			s.enable_column(id);
 | 
						||
 			set_insheet_universal_handler(F_SHEET, id);
 | 
						||
			set_insheet_universal_handler(F_SHEET, id + 50);
 | 
						||
   }
 | 
						||
    else
 | 
						||
      s.delete_column(id);
 | 
						||
  }
 | 
						||
  _qtaore = 0;
 | 
						||
	const TString4 dett = ini_get_string(CONFIG_DITTA, "ci", "DETTCONS");
 | 
						||
	TSheet_field & sc = sfield(F_CALENDARIO);
 | 
						||
 | 
						||
	_n_ex = 0;
 | 
						||
	for (int codes = _es.first(); codes != 0; codes = _es.next(codes))
 | 
						||
		_es_array[_n_ex++] = codes;
 | 
						||
	if (dett == "A")
 | 
						||
		disable(F_INTERVALLO);
 | 
						||
	else
 | 
						||
	{
 | 
						||
		if (dett == "M")
 | 
						||
		{
 | 
						||
			TList_field & f = lfield(F_INTERVALLO);
 | 
						||
 | 
						||
			f.delete_item("G");
 | 
						||
		}
 | 
						||
		set(F_ANNO, TDate(TODAY).year());
 | 
						||
	}
 | 
						||
	set(F_INTERVALLO, dett);
 | 
						||
}
 | 
						||
 | 
						||
                                      ////////////////////////////////////////////
 | 
						||
                                      ////    CLASSE TRilevamento_cons_app    ////
 | 
						||
                                      ////////////////////////////////////////////
 | 
						||
 | 
						||
//classe TRilevamento_cons_app
 | 
						||
class TRilevamento_cons_app : public TSkeleton_application
 | 
						||
{
 | 
						||
public:
 | 
						||
  virtual void main_loop();  
 | 
						||
};
 | 
						||
 | 
						||
void TRilevamento_cons_app::main_loop()
 | 
						||
{
 | 
						||
  TRilevamento_cons_msk msk; 
 | 
						||
  while (msk.run() != K_QUIT) ;
 | 
						||
}
 | 
						||
 | 
						||
int ci2200(int argc, char *argv[])
 | 
						||
{
 | 
						||
  TRilevamento_cons_app a;
 | 
						||
  a.run (argc, argv, TR("Rilevamento Ore Consuntivo"));
 | 
						||
  return TRUE;
 | 
						||
} |