Files correlati : fe0.exe fe0100a.msk Ricompilazione Demo : [ ] Commento : Aggiunta possibilità di annullamento e sostituzuione invio precedente git-svn-id: svn://10.65.10.50/branches/R_10_00@22524 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			225 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			225 lines
		
	
	
		
			5.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "felib.h"
 | 
						|
#include "fe0100a.h"
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TSomma_spesometro_msk
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TSomma_spesometro_msk : public TAutomask
 | 
						|
{
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
  void elabora(const TString_array& a, const TFilename& n) const;
 | 
						|
  
 | 
						|
  bool str2fname(const TString& name, TFilename& n) const;
 | 
						|
  bool row2fname(const TToken_string& row, TFilename& n) const;
 | 
						|
  void enable_buttons();
 | 
						|
 | 
						|
public:
 | 
						|
  TSomma_spesometro_msk() : TAutomask("fe0300a") { load_profile(); }
 | 
						|
  ~TSomma_spesometro_msk() { save_profile(); }
 | 
						|
};
 | 
						|
 | 
						|
bool TSomma_spesometro_msk::str2fname(const TString& name, TFilename& n) const
 | 
						|
{
 | 
						|
  if (name.blank() || name.len() < 4)
 | 
						|
    return false;
 | 
						|
 | 
						|
  if (name.full() && name[1] != ':')
 | 
						|
  {
 | 
						|
    n = get(F_OUTFOLDER); 
 | 
						|
    n.add(name);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    n = name;
 | 
						|
  n.replace('/', '\\');
 | 
						|
  return n.exist();
 | 
						|
}
 | 
						|
 | 
						|
bool TSomma_spesometro_msk::row2fname(const TToken_string& row, TFilename& n) const
 | 
						|
{
 | 
						|
  TString80 name; row.get(0, name);
 | 
						|
  return str2fname(name, n);
 | 
						|
}
 | 
						|
 | 
						|
void TSomma_spesometro_msk::elabora(const TString_array& infiles, const TFilename& outfile) const
 | 
						|
{
 | 
						|
  int anno = 2010;
 | 
						|
 | 
						|
  TFilename n;
 | 
						|
  if (row2fname(infiles.row(0), n))
 | 
						|
  {
 | 
						|
    const TDati_rilevanti_set s(n);
 | 
						|
    anno = s.anno();
 | 
						|
  }
 | 
						|
 | 
						|
  TDati_rilevanti_set outset(anno);
 | 
						|
  const int tipologia = outset.add_header(*this);
 | 
						|
  
 | 
						|
  if (tipologia != 2) // Invio i record solo quando non si tratta di annullamento
 | 
						|
  {
 | 
						|
    FOR_EACH_ARRAY_ROW(infiles, r, row) if (row2fname(*row, n))
 | 
						|
    {
 | 
						|
      const int len = outset.record_length();
 | 
						|
      ifstream s(n, ios::binary);
 | 
						|
      TString row(len);
 | 
						|
      while (!s.eof())
 | 
						|
      {
 | 
						|
        s.read(row.get_buffer(), len);
 | 
						|
        if (row[0] != '0' && row[0] != '9')
 | 
						|
          outset.new_rec(row);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  outset.add_footer();
 | 
						|
  outset.sort();
 | 
						|
  outset.save_as(outfile);
 | 
						|
 | 
						|
  if (outset.items() > 15000)
 | 
						|
  {
 | 
						|
    outset.split(outfile);
 | 
						|
    const int n = (outset.items()-1) / 15000 + 1;
 | 
						|
    warning_box(FR("E' stato generato il file %s, separato in %d parti da 15000 record."), (const char*)outfile, n);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    message_box(FR("E' stato generato il file %s"), (const char*)outfile);
 | 
						|
 | 
						|
  TDati_rilevanti_rep rep(outfile);
 | 
						|
  rep.preview();
 | 
						|
}
 | 
						|
 | 
						|
void TSomma_spesometro_msk::enable_buttons()
 | 
						|
{
 | 
						|
  const TSheet_field& righe = sfield(F_RIGHE);
 | 
						|
  enable(DLG_ELABORA, !righe.empty());
 | 
						|
 | 
						|
  TFilename n;
 | 
						|
  enable(DLG_PREVIEW, str2fname(get(F_OUTFILE), n));
 | 
						|
}
 | 
						|
 | 
						|
bool TSomma_spesometro_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case DLG_ELABORA:
 | 
						|
    if (e == fe_button && check_fields())
 | 
						|
    {
 | 
						|
      TFilename n;
 | 
						|
      str2fname(get(F_OUTFILE), n);
 | 
						|
      TSheet_field& righe = sfield(F_RIGHE);
 | 
						|
      TString_array& a = righe.rows_array();
 | 
						|
      if (!a.empty() && n.full())
 | 
						|
      {
 | 
						|
        elabora(a, n);
 | 
						|
        enable_buttons();
 | 
						|
      }
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case DLG_USER:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      TFilename fn;
 | 
						|
      if (str2fname(o.mask().get(101), fn))
 | 
						|
      {
 | 
						|
        TDati_rilevanti_rep rep(fn);
 | 
						|
        rep.preview();
 | 
						|
      }
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case DLG_PREVIEW:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      TFilename fn;
 | 
						|
      if (str2fname(get(F_OUTFILE), fn))
 | 
						|
      {
 | 
						|
        TDati_rilevanti_rep rep(fn);
 | 
						|
        rep.preview();
 | 
						|
      }
 | 
						|
    }
 | 
						|
    break;
 | 
						|
    case F_OUTFOLDER:
 | 
						|
    if ((e == fe_init || e == fe_modify) && !o.empty())
 | 
						|
    {
 | 
						|
      TSheet_field& righe = sfield(F_RIGHE);
 | 
						|
      TFilename dir = o.get(); dir.add("Spe*.txt");
 | 
						|
      TString_array& a = righe.rows_array();
 | 
						|
      a.destroy();
 | 
						|
      list_files(dir, a);
 | 
						|
      TFilename fn;
 | 
						|
      FOR_EACH_ARRAY_ROW(a, r, row)
 | 
						|
      {
 | 
						|
        fn = row->get(0);
 | 
						|
        *row = fn.name();
 | 
						|
        row->add(fsize(fn) / 1800);
 | 
						|
        const time_t t = xvt_fsys_file_attr(fn, XVT_FILE_ATTR_MTIME);
 | 
						|
        if (t > 0)
 | 
						|
        {
 | 
						|
          const struct tm& lt = *localtime(&t);
 | 
						|
          const TDate d(lt.tm_mday, lt.tm_mon+1, 1900+lt.tm_year);
 | 
						|
          row->add(d);
 | 
						|
          TString8 ora; ora.format("%02d:%02d:%02d", lt.tm_hour, lt.tm_min, lt.tm_sec);
 | 
						|
          row->add(ora);
 | 
						|
        }
 | 
						|
      }  
 | 
						|
 | 
						|
      // Elimina dalla lista il file di output
 | 
						|
      if (str2fname(get(F_OUTFILE), fn))
 | 
						|
      {
 | 
						|
        TFilename fr;
 | 
						|
        FOR_EACH_ARRAY_ROW(a, r, row)
 | 
						|
        {
 | 
						|
          row2fname(*row, fr);
 | 
						|
          if (fr.compare(fn, -1, true) == 0)
 | 
						|
          {
 | 
						|
            a.destroy(r, true);
 | 
						|
            break;
 | 
						|
          }
 | 
						|
        }
 | 
						|
      }
 | 
						|
 | 
						|
      righe.force_update();
 | 
						|
      enable_buttons();
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case F_RIGHE:
 | 
						|
    if (e == se_query_add || e == se_query_del)
 | 
						|
      return false;
 | 
						|
    break;
 | 
						|
  default: 
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TSomma_spesometro_app
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TSomma_spesometro_app : public TSkeleton_application
 | 
						|
{
 | 
						|
public:
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
void TSomma_spesometro_app::main_loop()
 | 
						|
{
 | 
						|
  TSomma_spesometro_msk msk;
 | 
						|
  msk.run();
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// main
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
int fe0300(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TSomma_spesometro_app app;
 | 
						|
  app.run(argc, argv, TR("Somma file Spesometro"));
 | 
						|
  return 0;
 | 
						|
}
 |