Files correlati : ba8 Ricompilazione Demo : [ ] Commento : 0000917: archiviazione ottica Entro nella ricerca file archiviati, mi chiede se voglio creare la cartella, se rispondo no mi viene comunque chiesto dove creare la cartella. git-svn-id: svn://10.65.10.50/trunk@17659 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			240 lines
		
	
	
		
			5.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			240 lines
		
	
	
		
			5.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "ba8.h"
 | 
						|
 | 
						|
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <config.h>
 | 
						|
#include <defmask.h>
 | 
						|
#include <msksheet.h>
 | 
						|
#include <prefix.h>
 | 
						|
 | 
						|
#include "ba8600a.h"
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TGoogle_mask
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TGoogle_mask : public TAutomask
 | 
						|
{
 | 
						|
  TFilename _base_dir;
 | 
						|
  clock_t _next_update;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
  virtual void on_idle();
 | 
						|
 | 
						|
  void query_firm(int anno, long ditta);
 | 
						|
  void query_year(int anno);
 | 
						|
  void query();
 | 
						|
 | 
						|
public:
 | 
						|
  TGoogle_mask(const TFilename& base_dir);
 | 
						|
};
 | 
						|
 | 
						|
void TGoogle_mask::on_idle()
 | 
						|
{
 | 
						|
  if (_next_update > 0 && clock() >= _next_update)
 | 
						|
    query();
 | 
						|
}
 | 
						|
 | 
						|
bool TGoogle_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case DLG_USER:
 | 
						|
    if (e == fe_button)
 | 
						|
    {
 | 
						|
      const TMask& m = o.mask();
 | 
						|
      TFilename name = _base_dir;
 | 
						|
      name.add(m.get(102));
 | 
						|
      TString8 str; str.format("%05ldA", m.get_int(101));
 | 
						|
      name.add(str);
 | 
						|
      name.add(m.get(103));
 | 
						|
      xvt_sys_goto_url(name, "open");
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case F_SHEET:
 | 
						|
    if (e == se_query_add || e == se_query_del)
 | 
						|
      return false;
 | 
						|
    break;
 | 
						|
  case DLG_ELABORA:
 | 
						|
    if (e == fe_button)
 | 
						|
      query();
 | 
						|
    break;
 | 
						|
  default: 
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  if (e == fe_modify && jolly ==0)
 | 
						|
    _next_update = clock() + 5*CLOCKS_PER_SEC;
 | 
						|
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
void TGoogle_mask::query_firm(int anno, long firm)
 | 
						|
{
 | 
						|
  const TString& tipodoc = get(F_TIPODOC);
 | 
						|
  const long codcf = get_long(F_CLIFO);
 | 
						|
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						|
 | 
						|
  TFilename name = _base_dir;
 | 
						|
  TString8 str; 
 | 
						|
  str.format("%04d", anno); name.add(str); 
 | 
						|
  str.format("%05ldA", firm); name.add(str); 
 | 
						|
 | 
						|
  xvt_fsys_save_dir();
 | 
						|
  DIRECTORY dir; xvt_fsys_convert_str_to_dir(name, &dir);
 | 
						|
  xvt_fsys_set_dir(&dir);
 | 
						|
 | 
						|
  SLIST files = xvt_fsys_list_files("", "*.*", FALSE);
 | 
						|
  for (SLIST_ELT e = xvt_slist_get_first(files); e; e = xvt_slist_get_next(files, e))
 | 
						|
  { 
 | 
						|
    TToken_string file(xvt_slist_get(files, e, NULL), '_');
 | 
						|
    if (file.items() < 3)
 | 
						|
      continue;
 | 
						|
 | 
						|
    if (tipodoc.full() && tipodoc.compare(file.get(1), -1, true) != 0)
 | 
						|
      continue;
 | 
						|
 | 
						|
    if (codcf > 0 && codcf != file.get_long(3))
 | 
						|
      continue;
 | 
						|
 | 
						|
    TToken_string& row = sheet.row(-1);
 | 
						|
    row.add(firm);
 | 
						|
    row.add(anno);
 | 
						|
    row.add(file);
 | 
						|
  }
 | 
						|
  xvt_slist_destroy(files);
 | 
						|
 | 
						|
  xvt_fsys_restore_dir();
 | 
						|
}
 | 
						|
 | 
						|
void TGoogle_mask::query_year(int anno)
 | 
						|
{
 | 
						|
  const long firm = get_long(F_DITTA);
 | 
						|
  if (firm <= 0)
 | 
						|
  {
 | 
						|
    TFilename name = _base_dir;
 | 
						|
    TString8 str; str.format("%04d", anno);
 | 
						|
    name.add(str); 
 | 
						|
    name.add("?????A");
 | 
						|
 | 
						|
    SLIST files = xvt_fsys_list_files(DIR_TYPE, name, TRUE);
 | 
						|
    for (SLIST_ELT e = xvt_slist_get_first(files); e; e = xvt_slist_get_next(files, e))
 | 
						|
    { 
 | 
						|
      const TFilename name = xvt_slist_get(files, e, NULL);
 | 
						|
      const long firm = atol(name.name());
 | 
						|
      query_firm(anno, firm);
 | 
						|
    }
 | 
						|
    xvt_slist_destroy(files);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    query_firm(anno, firm);
 | 
						|
}
 | 
						|
 | 
						|
void TGoogle_mask::query()
 | 
						|
{
 | 
						|
  _next_update = 0;
 | 
						|
 | 
						|
  TWait_cursor hourglass;
 | 
						|
 | 
						|
  TSheet_field& sheet = sfield(F_SHEET);
 | 
						|
  sheet.destroy();
 | 
						|
 | 
						|
  int anno = get_int(F_ANNO);
 | 
						|
  if (anno < 1000)
 | 
						|
  {
 | 
						|
    TFilename name = _base_dir;
 | 
						|
    name.add("????");
 | 
						|
    SLIST files = xvt_fsys_list_files(DIR_TYPE, name, TRUE);
 | 
						|
    for (SLIST_ELT e = xvt_slist_get_first(files); e; e = xvt_slist_get_next(files, e))
 | 
						|
    { 
 | 
						|
      const TFilename dirname = xvt_slist_get(files, e, NULL);
 | 
						|
      anno = atoi(dirname.right(4));
 | 
						|
      if (anno >= 1000)
 | 
						|
        query_year(anno);
 | 
						|
    }
 | 
						|
    xvt_slist_destroy(files);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    query_year(anno);
 | 
						|
 | 
						|
  sheet.force_update();
 | 
						|
  _next_update = 0;
 | 
						|
}
 | 
						|
 | 
						|
TGoogle_mask::TGoogle_mask(const TFilename& base_dir) 
 | 
						|
            : _base_dir(base_dir), _next_update(0)
 | 
						|
{
 | 
						|
  TSheet_field::set_line_number_width(7);
 | 
						|
  read_mask("ba8600a", 0, 1);
 | 
						|
  set_handlers();
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TGoogle_app
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TGoogle_app : public TSkeleton_application
 | 
						|
{
 | 
						|
  TGoogle_mask* _mask;
 | 
						|
 | 
						|
public:
 | 
						|
  virtual bool create();
 | 
						|
  virtual void main_loop();
 | 
						|
  virtual bool destroy();
 | 
						|
};
 | 
						|
 | 
						|
bool TGoogle_app::create()
 | 
						|
{
 | 
						|
  TConfig ini("servers/servers.ini", "Spotlite");
 | 
						|
  TFilename name = ini.get("Data");
 | 
						|
  bool ok = name.exist();
 | 
						|
  if (!ok)
 | 
						|
  {
 | 
						|
    name = firm2dir(-1);
 | 
						|
    name.add("spotlite");
 | 
						|
    TString msg;
 | 
						|
    msg << TR("Il server di archiviazione non e' configurato")
 | 
						|
        << ":\n" << TR("si desidera usare la seguente cartella?")
 | 
						|
        << '\n' << name;
 | 
						|
    const KEY ync = yesnocancel_box(msg);
 | 
						|
    if (ync != K_ESC)
 | 
						|
    {
 | 
						|
      ok = ync == K_YES;
 | 
						|
      if (!ok)
 | 
						|
      {
 | 
						|
        DIRECTORY dir; xvt_fsys_convert_str_to_dir(name, &dir);
 | 
						|
        ok = xvt_dm_post_dir_sel(&dir) == FL_OK;
 | 
						|
        if (ok)
 | 
						|
          xvt_fsys_convert_dir_to_str(&dir, name.get_buffer(), name.size());
 | 
						|
      }
 | 
						|
      if (ok)
 | 
						|
      {
 | 
						|
        ok = xvt_fsys_mkdir(name) != 0;
 | 
						|
        if (ok)
 | 
						|
          ini.set("Data", name);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  _mask = ok ? new TGoogle_mask(name) : NULL;
 | 
						|
 | 
						|
  return ok && TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
void TGoogle_app::main_loop()
 | 
						|
{
 | 
						|
  _mask->run();
 | 
						|
}
 | 
						|
 | 
						|
bool TGoogle_app::destroy()
 | 
						|
{
 | 
						|
  delete _mask;
 | 
						|
  return TSkeleton_application::destroy();
 | 
						|
}
 | 
						|
 | 
						|
int ba8600(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TGoogle_app app;
 | 
						|
  app.run(argc, argv, TR("Ricerca documenti archiviati"));
 | 
						|
  return 0;
 | 
						|
} |