Files correlati : Ricompilazione Demo : [ ] Commento : modificati path di include; ci si dovrebbe chiedere se ba3900 e ba5200 siano veramente di ba o forse siano di cg. git-svn-id: svn://10.65.10.50/trunk@18393 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			171 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			171 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <prefix.h>
 | 
						|
#include <relapp.h>
 | 
						|
 | 
						|
#include <nditte.h>
 | 
						|
 | 
						|
#include "../cg/cgtbinl.h"
 | 
						|
 | 
						|
class TIndici_app : public TRelation_application
 | 
						|
{ 
 | 
						|
  TRelation* _indici;
 | 
						|
  TMask* _maschera;
 | 
						|
  
 | 
						|
protected:  
 | 
						|
  virtual bool user_create();
 | 
						|
  virtual bool user_destroy();
 | 
						|
  
 | 
						|
  virtual bool changing_mask(int) { return FALSE; }
 | 
						|
  virtual TMask* get_mask(int) { return _maschera; }
 | 
						|
  virtual TRelation* get_relation() const { return _indici; }
 | 
						|
 | 
						|
  virtual bool get_next_key(TToken_string& key);
 | 
						|
  virtual bool save_and_new() const { return TRUE; } 
 | 
						|
  virtual int read(TMask& m);
 | 
						|
  virtual void init_query_mode(TMask& m);
 | 
						|
  
 | 
						|
  static bool ditta_handler(TMask_field& f, KEY key);  
 | 
						|
  static TIndici_app& app() { return (TIndici_app&) main_app(); }
 | 
						|
 | 
						|
public:
 | 
						|
  TIndici_app() { }
 | 
						|
  virtual ~TIndici_app() { }  
 | 
						|
};
 | 
						|
  
 | 
						|
bool TIndici_app::ditta_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  /*
 | 
						|
  if (key == K_TAB && f.to_check(key, TRUE) && f.empty())
 | 
						|
  {
 | 
						|
    TMask& m = f.mask();
 | 
						|
    m.reset(F_CODREG);   m.reset(F_DESCREG);
 | 
						|
    m.disable(F_CODREG); m.disable(F_DESCREG);
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
  */
 | 
						|
  if ((key == K_TAB && f.to_check(key)/*f.focusdirty()*/) || key == K_ENTER)
 | 
						|
  {
 | 
						|
    const long ditta = atol(f.get());
 | 
						|
    if (ditta == 0L) 
 | 
						|
      return TRUE;
 | 
						|
 | 
						|
    TMask& m = f.mask();
 | 
						|
    if (prefix().exist(ditta))
 | 
						|
    {
 | 
						|
      app().set_firm(ditta);
 | 
						|
      m.enable(F_CODREG); m.enable(F_DESCREG);
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      m.reset(F_CODREG);m.reset(F_DESCREG);
 | 
						|
      m.disable(F_CODREG); m.disable(F_DESCREG);
 | 
						|
      return f.error_box(FR("La ditta %5ld non e' abilitata in contabilita'"), ditta);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}  
 | 
						|
 | 
						|
void TIndici_app::init_query_mode(TMask& m)
 | 
						|
{
 | 
						|
  m.enable(F_CODREG);m.enable(F_DESCREG);
 | 
						|
}
 | 
						|
 | 
						|
int TIndici_app::read(TMask& m)
 | 
						|
{
 | 
						|
  int r = TRelation_application::read(m);
 | 
						|
  const long ditta = m.get_long(F_DITTA);
 | 
						|
  if (ditta > 0L)
 | 
						|
    if (prefix().exist(ditta))
 | 
						|
      set_firm(ditta);
 | 
						|
    else
 | 
						|
    {
 | 
						|
      error_box(FR("Ditta %5ld non abilitata in contabilita'"),ditta);
 | 
						|
      //m.reset(F_CODREG);m.reset(F_DESCREG);
 | 
						|
      m.disable(F_CODREG); m.disable(F_DESCREG);
 | 
						|
    }
 | 
						|
  return r;
 | 
						|
}
 | 
						|
 | 
						|
bool TIndici_app::user_create()
 | 
						|
{
 | 
						|
  if (get_firm() == 0) // Se e' posizionato nel direttorio comune, setta la prima ditta abilitata in contabilita'
 | 
						|
  {
 | 
						|
    TLocalisamfile ditte(LF_NDITTE);
 | 
						|
 | 
						|
    bool found = FALSE;
 | 
						|
    long ditta = 0L;
 | 
						|
    for (ditte.first(); !found && !ditte.eof(); ditte.next())
 | 
						|
    {
 | 
						|
      ditta = ditte.get_long(NDT_CODDITTA);
 | 
						|
      found = prefix().exist(ditta);
 | 
						|
    }
 | 
						|
    
 | 
						|
    if (!found) 
 | 
						|
    {
 | 
						|
      error_box(TR("Abilitare almeno una ditta in contabilita'."));
 | 
						|
      return FALSE;
 | 
						|
    } 
 | 
						|
    else
 | 
						|
      set_firm(ditta);
 | 
						|
  }
 | 
						|
  _indici = new TRelation(LF_INDLIB);
 | 
						|
  _maschera = new TMask("batbinl");
 | 
						|
  _maschera->set_handler(F_DITTA, ditta_handler);
 | 
						|
  return TRUE;
 | 
						|
}                 
 | 
						|
 | 
						|
bool TIndici_app::user_destroy()
 | 
						|
{
 | 
						|
  delete _maschera;
 | 
						|
  delete _indici;
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TIndici_app::get_next_key(TToken_string& key)
 | 
						|
{                  
 | 
						|
  const int anno = _maschera->get_int(F_ANNO);
 | 
						|
  const TString16 libro = _maschera->get(F_CODLIB);
 | 
						|
  if (anno == 0 || libro.empty())
 | 
						|
    return TRUE;
 | 
						|
 | 
						|
  TLocalisamfile index(LF_INDLIB);
 | 
						|
  index.zero();
 | 
						|
  index.put("ANNO", anno);
 | 
						|
  index.put("CODLIB", libro);
 | 
						|
  index.put("NUMREG", 9999999L);
 | 
						|
  
 | 
						|
  long cod = 0;
 | 
						|
  int err = index.read(_isgteq);
 | 
						|
  switch (err)
 | 
						|
  {
 | 
						|
  case _iseof:
 | 
						|
    index.last();
 | 
						|
    err = NOERR;
 | 
						|
    break;
 | 
						|
  case NOERR:  
 | 
						|
    index.prev();
 | 
						|
    break;  
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }      
 | 
						|
  
 | 
						|
  if (err == NOERR)
 | 
						|
  {
 | 
						|
    if (index.get_int("ANNO") == anno && index.get("CODLIB") == libro)
 | 
						|
      cod = index.get_long("NUMREG") + 1;    
 | 
						|
  }
 | 
						|
  
 | 
						|
  if (cod > 0)
 | 
						|
    key.format("%d|%d|%d|%s|%d|%ld", F_ANNO, anno, F_CODLIB, (const char*)libro, F_INDEX, cod);
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
int ba3900(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TIndici_app app;
 | 
						|
  app.run(argc, argv, TR("Indici libro unico"));
 | 
						|
  return 0;
 | 
						|
}
 |