Files correlati : ci0 ci0500a.msk Ricompilazione Demo : [ ] Commento : Correzione errori segnalati da Robby git-svn-id: svn://10.65.10.50/branches/R_10_00@20766 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			416 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			416 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <automask.h>
 | 
						||
#include <defmask.h>
 | 
						||
#include <recset.h>
 | 
						||
#include <sheet.h>
 | 
						||
#include <utility.h>
 | 
						||
 | 
						||
#include <doc.h>
 | 
						||
 | 
						||
#include "ci0.h"
 | 
						||
#include "cilib.h"
 | 
						||
#include "ci0500a.h"
 | 
						||
#include "../ve/velib.h"
 | 
						||
 | 
						||
                                      ////////////////////////////////////////
 | 
						||
                                      ////    CLASSE TDISP_RISOATT_MSK    ////
 | 
						||
                                      ////////////////////////////////////////
 | 
						||
 | 
						||
//Classe TDisp_risoatt_msk
 | 
						||
class TDisp_risoatt_msk : public TAutomask
 | 
						||
{
 | 
						||
  int _preventivo;
 | 
						||
  int _consuntivo;
 | 
						||
protected:
 | 
						||
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
 | 
						||
	const TString& add_field_to_tab_filter(const short id, int len = 0, const char* empty_value = "");
 | 
						||
	const TString& add_field_to_tab_key(TToken_string& row, const short id, int len = 0);
 | 
						||
  void riempi_sheet();
 | 
						||
  void nuova_riga();
 | 
						||
  void azzera_riga(TSheet_field& sheet);
 | 
						||
  void azzera_tutto(TSheet_field& sheet);
 | 
						||
  void registra();
 | 
						||
  
 | 
						||
public:
 | 
						||
  void esegui() const;
 | 
						||
  TDisp_risoatt_msk();
 | 
						||
};
 | 
						||
 | 
						||
//ADD_FIELD_TO_TAB_FILTER: aggiunge un campo al filtro
 | 
						||
const TString& TDisp_risoatt_msk::add_field_to_tab_filter(const short id, int len, const char* empty_value)
 | 
						||
{
 | 
						||
	if (len <= 0)
 | 
						||
		len = field(id).size();
 | 
						||
	
 | 
						||
  TString& val = get_tmp_string();
 | 
						||
 | 
						||
	val = get(id);
 | 
						||
	if (val == empty_value)
 | 
						||
		val.fill('?', len);
 | 
						||
	else
 | 
						||
		val.left_just(len);
 | 
						||
  
 | 
						||
  return val;
 | 
						||
}
 | 
						||
 | 
						||
const TString& TDisp_risoatt_msk::add_field_to_tab_key(TToken_string& row, const short id, int len)
 | 
						||
{
 | 
						||
	TSheet_field& sh = sfield(F_SHEET);
 | 
						||
 | 
						||
	if (len <= 0)
 | 
						||
		len = sh.sheet_mask().field(id).size();
 | 
						||
	
 | 
						||
	TString& val = get_tmp_string();
 | 
						||
 | 
						||
	val = row.get(sh.cid2index(id));
 | 
						||
	val.left_just(len);
 | 
						||
  return val;
 | 
						||
}
 | 
						||
 | 
						||
//RIEMPI_SHEET: metodo che riempie lo sheet in base ai campi chiave
 | 
						||
//compilati sulla maschera
 | 
						||
void TDisp_risoatt_msk::riempi_sheet()
 | 
						||
{
 | 
						||
  TString filtro;
 | 
						||
  char risoatt = get(F_RISOATT)[0];
 | 
						||
 | 
						||
  //guardo il tipo risorsa / attrezzatura che sto ricercando (se Tutti setto a '?')
 | 
						||
	filtro << add_field_to_tab_filter(F_RISOATT, 1, "T");
 | 
						||
  //leggo il codice corretto a seconda del tipo selezionato (se vuoto setto a 16 caratteri '?')
 | 
						||
  switch(risoatt)
 | 
						||
  {
 | 
						||
  case 'T': filtro << add_field_to_tab_filter(F_CODICE); break;
 | 
						||
  case 'R': filtro << add_field_to_tab_filter(F_CODRIS); break;
 | 
						||
  case 'A': filtro << add_field_to_tab_filter(F_CODATT); break;
 | 
						||
  default : break;
 | 
						||
  }
 | 
						||
 | 
						||
	filtro << add_field_to_tab_filter(F_ANNO);
 | 
						||
  //leggo il mese (se vuoto setto a '??')
 | 
						||
	filtro << add_field_to_tab_filter(F_MESE, 2);
 | 
						||
 | 
						||
  //leggo il tipo ora (se vuoto setto a '??')
 | 
						||
	filtro << add_field_to_tab_filter(F_TPORA);
 | 
						||
 | 
						||
  TString query;
 | 
						||
 | 
						||
	query << "USE &DRA\n";
 | 
						||
	if (filtro.full())
 | 
						||
    query << "SELECT CODTAB?=\"" << filtro << "\"";
 | 
						||
  if(risoatt != 'T')
 | 
						||
  {
 | 
						||
    query << "\n"
 | 
						||
          << "FROM CODTAB=" << risoatt << "\n"
 | 
						||
          << "TO CODTAB="   << risoatt << "\n";
 | 
						||
  }
 | 
						||
 | 
						||
  TISAM_recordset dra(query);
 | 
						||
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
  sheet.destroy();
 | 
						||
 | 
						||
  //riempio lo sheet con i dati che soddisfano il filtro preparato prima
 | 
						||
  for(bool ok = dra.move_first(); ok; ok = dra.move_next())
 | 
						||
  {
 | 
						||
    TDisp_risoatt disp(dra.cursor()->curr());
 | 
						||
    TRisoatt_key drakey(disp.chiave());
 | 
						||
    TToken_string& riga = sheet.row(-1);
 | 
						||
    riga.add(drakey.tipo(), sheet.cid2index(S_RISOATT));
 | 
						||
    TString16 cod = drakey.cod();
 | 
						||
    cod.trim();
 | 
						||
    switch(drakey.tipo())
 | 
						||
    {
 | 
						||
    case 'A': riga.add(cod, sheet.cid2index(S_CODATT)); break;
 | 
						||
    case 'R': riga.add(cod, sheet.cid2index(S_CODRIS)); break;
 | 
						||
    default : break;
 | 
						||
    }
 | 
						||
    riga.add(drakey.anno(),   sheet.cid2index(S_ANNO));
 | 
						||
    riga.add(drakey.mese(),   sheet.cid2index(S_MESE));
 | 
						||
    riga.add(drakey.tpora(),  sheet.cid2index(S_TPORA));
 | 
						||
    riga.add(disp.ore_prev(), sheet.cid2index(S_OREPREV));
 | 
						||
    riga.add(disp.ore_cons(), sheet.cid2index(S_ORECONS));
 | 
						||
 | 
						||
    sheet.check_row(sheet.items() - 1);
 | 
						||
  }
 | 
						||
 | 
						||
  sheet.force_update();
 | 
						||
}
 | 
						||
 | 
						||
//NUOVA_RIGA: metodo che aggiunge una riga allo sheet
 | 
						||
//tenendo conto dei campi chiave compilati in testata
 | 
						||
void TDisp_risoatt_msk::nuova_riga()
 | 
						||
{
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
  TToken_string& riga = sheet.row(-1);
 | 
						||
	const int r = sheet.items() - 1;
 | 
						||
  sheet.select(r);
 | 
						||
  TMask& msk = sheet.sheet_mask();
 | 
						||
  const bool tutti = get(F_RISOATT)[0] == 'T';
 | 
						||
  const TString4  tipo = tutti ? "R" : get(F_RISOATT);
 | 
						||
  int mese         = get_int(F_MESE);
 | 
						||
	int anno         = get_int(F_ANNO);
 | 
						||
  TString tpora    = get(F_TPORA);
 | 
						||
 | 
						||
	riga.add(tipo, sheet.cid2index(S_RISOATT));
 | 
						||
	if (!tutti)
 | 
						||
	{
 | 
						||
		if (tipo == "R") 
 | 
						||
			riga.add(get(F_CODRIS), sheet.cid2index(S_CODRIS));
 | 
						||
		else
 | 
						||
		riga.add(get(F_CODATT), sheet.cid2index(S_CODATT));
 | 
						||
	}
 | 
						||
	riga.add(anno, sheet.cid2index(S_ANNO));
 | 
						||
	riga.add(mese, sheet.cid2index(S_MESE));
 | 
						||
	riga.add(tpora, sheet.cid2index(S_TPORA));
 | 
						||
	sheet.update_mask(r);
 | 
						||
	msk.enable(S_RISOATT, tutti);
 | 
						||
	if (tutti || tipo == "R") 
 | 
						||
    msk.enable(S_CODRIS);
 | 
						||
	if (tutti || tipo == "A") 
 | 
						||
    msk.enable(S_CODATT);
 | 
						||
  msk.enable(S_ANNO, anno == 0);
 | 
						||
  msk.enable(S_MESE, mese == 0);
 | 
						||
  msk.enable(S_TPORA, tpora.empty());
 | 
						||
  //lancio la maschera di riga da compilare
 | 
						||
  if(msk.run() == K_ENTER)
 | 
						||
  {
 | 
						||
    const int oreprev = msk.get_int(S_OREPREV);
 | 
						||
    const int orecons = msk.get_int(S_ORECONS);
 | 
						||
 | 
						||
    if(oreprev > 0 || orecons > 0)
 | 
						||
    {
 | 
						||
			riga.add(msk.get(S_RISOATT)[0], sheet.cid2index(S_RISOATT));
 | 
						||
      const char tipo = msk.get(S_RISOATT)[0];
 | 
						||
 | 
						||
      switch(tipo)
 | 
						||
      {
 | 
						||
      case 'R':
 | 
						||
        {
 | 
						||
          riga.add(msk.get(S_CODRIS), sheet.cid2index(S_CODRIS));
 | 
						||
          riga.add(msk.get(S_DESRIS), sheet.cid2index(S_DESRIS));
 | 
						||
        }
 | 
						||
        break;
 | 
						||
      case 'A':
 | 
						||
        {
 | 
						||
          riga.add(msk.get(S_CODATT), sheet.cid2index(S_CODATT));
 | 
						||
          riga.add(msk.get(S_DESATT), sheet.cid2index(S_DESATT));
 | 
						||
        }
 | 
						||
        break;
 | 
						||
      default : break;
 | 
						||
      }
 | 
						||
      riga.add(msk.get(S_ANNO), sheet.cid2index(S_ANNO));
 | 
						||
      riga.add(msk.get(S_MESE), sheet.cid2index(S_MESE));
 | 
						||
      riga.add(msk.get(S_TPORA), sheet.cid2index(S_TPORA));
 | 
						||
      riga.add(msk.get(S_OREPREV), sheet.cid2index(S_OREPREV));
 | 
						||
      riga.add(msk.get(S_ORECONS), sheet.cid2index(S_ORECONS));
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      sheet.destroy(r);
 | 
						||
      sheet.force_update();
 | 
						||
    }
 | 
						||
  }
 | 
						||
  msk.enable_default();
 | 
						||
  sheet.force_update();
 | 
						||
}
 | 
						||
 | 
						||
//AZZERA_RIGA: metodo che azzera il valore unitario della riga selezionata
 | 
						||
//(N.B.: le righe con valore unitario nullo verranno eliminate in fase di registrazione)
 | 
						||
void TDisp_risoatt_msk::azzera_riga(TSheet_field& sheet)
 | 
						||
{
 | 
						||
  const int nriga = sheet.selected();
 | 
						||
  TToken_string& row = sheet.row(nriga);
 | 
						||
 | 
						||
  row.add(0, sheet.cid2index(S_OREPREV));
 | 
						||
  row.add(0, sheet.cid2index(S_ORECONS));
 | 
						||
 | 
						||
  TMask& msk = sheet.sheet_mask();
 | 
						||
  _preventivo = msk.get_int(S_OREPREV);
 | 
						||
  _consuntivo = msk.get_int(S_ORECONS);
 | 
						||
  msk.set(S_OREPREV, 0L);
 | 
						||
  msk.set(S_ORECONS, 0L);
 | 
						||
}
 | 
						||
 | 
						||
//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 TDisp_risoatt_msk::azzera_tutto(TSheet_field& sheet)
 | 
						||
{
 | 
						||
  FOR_EACH_SHEET_ROW(sheet, r, row)
 | 
						||
  {
 | 
						||
    TToken_string& row = sheet.row(r);
 | 
						||
    row.add(0, sheet.cid2index(S_OREPREV));
 | 
						||
    row.add(0, sheet.cid2index(S_ORECONS));
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
//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 TDisp_risoatt_msk::registra()
 | 
						||
{
 | 
						||
  TLocalisamfile tabmod(LF_TABMOD);
 | 
						||
  TModule_table tab("&DRA");
 | 
						||
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
  TString80 chiave;
 | 
						||
 | 
						||
  FOR_EACH_SHEET_ROW(sheet, r, row)
 | 
						||
  {
 | 
						||
		chiave.cut(0);
 | 
						||
    TToken_string& riga = *(TToken_string*)row;
 | 
						||
    
 | 
						||
    const TString4 tipo = add_field_to_tab_key(riga, S_RISOATT, 1);
 | 
						||
    chiave << tipo;
 | 
						||
		chiave << add_field_to_tab_key(riga, tipo[0] == 'R' ? S_CODRIS : S_CODATT);
 | 
						||
 | 
						||
    TString8 anme; anme << add_field_to_tab_key(riga, S_ANNO) << add_field_to_tab_key(riga, S_MESE, 2);
 | 
						||
    chiave << anme;
 | 
						||
    chiave << add_field_to_tab_key(riga, S_TPORA);
 | 
						||
    const TString80 descr = tipo[0] == 'R' ? riga.get(sheet.cid2index(S_DESRIS)) : riga.get(sheet.cid2index(S_DESATT));
 | 
						||
    const int oreprev = riga.get_int(sheet.cid2index(S_OREPREV));
 | 
						||
    const int orecons = riga.get_int(sheet.cid2index(S_ORECONS));
 | 
						||
 | 
						||
    tab.put("CODTAB", chiave);
 | 
						||
    int err = tab.read();
 | 
						||
 | 
						||
    if(err == NOERR)
 | 
						||
    {
 | 
						||
      if(oreprev == 0 && orecons == 0)
 | 
						||
        tab.remove();
 | 
						||
      else
 | 
						||
      {
 | 
						||
        tab.put("I0", oreprev);
 | 
						||
        tab.put("I1", orecons);
 | 
						||
        tab.rewrite();
 | 
						||
      }
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      tab.put("CODTAB", chiave);
 | 
						||
      tab.put("S0", descr);
 | 
						||
      tab.put("I0", oreprev);
 | 
						||
      tab.put("I1", orecons);
 | 
						||
      tab.write();
 | 
						||
    }
 | 
						||
  }
 | 
						||
  riempi_sheet();
 | 
						||
}
 | 
						||
 | 
						||
//ON_FIELD_EVENT: metodo che gestisce gli eventi sui vari campi della maschera
 | 
						||
bool TDisp_risoatt_msk::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | 
						||
{
 | 
						||
  switch (f.dlg())
 | 
						||
	{
 | 
						||
  case DLG_CERCA:
 | 
						||
    if (e == fe_button)
 | 
						||
    {
 | 
						||
      riempi_sheet();
 | 
						||
      return false;
 | 
						||
    }
 | 
						||
	case DLG_NEWREC:
 | 
						||
    if (e == fe_button)
 | 
						||
    {
 | 
						||
      nuova_riga();
 | 
						||
      return false;
 | 
						||
    }
 | 
						||
  case DLG_SAVEREC:
 | 
						||
    if (e == fe_button)
 | 
						||
    {
 | 
						||
      registra();
 | 
						||
      return false;
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case DLG_RESET:
 | 
						||
    if(e == fe_button)
 | 
						||
    {
 | 
						||
      TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
      switch(jolly)
 | 
						||
      {
 | 
						||
      case  0: azzera_tutto(sheet); break;
 | 
						||
      case  1: azzera_riga(sheet);  break;
 | 
						||
      default:                      break;
 | 
						||
      }
 | 
						||
      sheet.force_update();
 | 
						||
      return false;
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case DLG_CANCEL:
 | 
						||
    if(e == fe_button && jolly == 1)
 | 
						||
    {
 | 
						||
      TSheet_field& sheet = sfield(F_SHEET);
 | 
						||
      TMask& msk = sheet.sheet_mask();
 | 
						||
      const int oreprev = msk.get_int(S_OREPREV);
 | 
						||
      const int orecons = msk.get_int(S_ORECONS);
 | 
						||
 | 
						||
      if(sheet.selected() == sheet.items() - 1)
 | 
						||
      {
 | 
						||
        sheet.destroy(sheet.items() - 1);
 | 
						||
        sheet.force_update();
 | 
						||
      }
 | 
						||
      else if(_preventivo > 0 && _consuntivo > 0)
 | 
						||
      {
 | 
						||
        TToken_string& row = sheet.row(sheet.selected());
 | 
						||
        row.add(_preventivo, sheet.cid2index(S_OREPREV));
 | 
						||
        row.add(_consuntivo, sheet.cid2index(S_ORECONS));
 | 
						||
        _preventivo = 0;
 | 
						||
        _consuntivo = 0;
 | 
						||
      }
 | 
						||
    }    
 | 
						||
    break;
 | 
						||
  case F_ANNO:
 | 
						||
  case F_MESE:
 | 
						||
  case F_RISOATT:
 | 
						||
  case F_CODICE:
 | 
						||
  case F_CODRIS:
 | 
						||
  case F_CODATT:
 | 
						||
  case F_TPORA:
 | 
						||
    if (e == fe_modify)
 | 
						||
      riempi_sheet();
 | 
						||
    break;
 | 
						||
  case F_SHEET:
 | 
						||
    if (e == se_query_add)
 | 
						||
    {
 | 
						||
      send_key(K_SPACE, DLG_NEWREC);
 | 
						||
      return false;
 | 
						||
    }
 | 
						||
  default: break;
 | 
						||
  }
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
void TDisp_risoatt_msk::esegui() const
 | 
						||
{
 | 
						||
}
 | 
						||
 | 
						||
TDisp_risoatt_msk::TDisp_risoatt_msk() 
 | 
						||
            : TAutomask("ci0500a")
 | 
						||
{
 | 
						||
  _preventivo = 0;
 | 
						||
  _consuntivo = 0;
 | 
						||
}
 | 
						||
 | 
						||
                                      ////////////////////////////////////////
 | 
						||
                                      ////    CLASSE TDisp_risoatt_APP    ////
 | 
						||
                                      ////////////////////////////////////////
 | 
						||
 | 
						||
//classe TDisp_risoatt_app
 | 
						||
class TDisp_risoatt_app : public TSkeleton_application
 | 
						||
{
 | 
						||
public:
 | 
						||
  virtual void main_loop();  
 | 
						||
};
 | 
						||
 | 
						||
void TDisp_risoatt_app::main_loop()
 | 
						||
{
 | 
						||
  TDisp_risoatt_msk msk; 
 | 
						||
  while (msk.run() != K_QUIT)
 | 
						||
	  msk.esegui();
 | 
						||
}
 | 
						||
 | 
						||
int ci0500(int argc, char *argv[])
 | 
						||
{
 | 
						||
  TDisp_risoatt_app a;
 | 
						||
  a.run (argc, argv, TR("Disponibilit<EFBFBD>"));
 | 
						||
  return TRUE;
 | 
						||
}
 |