
#include <applicat.h>
#include <tabapp.h>  
#include <strings.h>
#include <stdtypes.h>
#include <tabutil.h>
#include <utility.h>

#include "../ba/batbreg.h"

#define REG_JOURNAL 5

HIDDEN bool tiporeg_handler(TMask_field& f, KEY k);

class m70000_app : public Tab_application
{
  private:
    TMask*  _msk;   
    TString _tabname;
    long       _oldditta;
    int        _oldanno;
    bool       _exist_journal;
          
  public:
    bool user_create();
    bool exist_journal() {return _exist_journal;}    
    m70000_app() {}
    virtual ~m70000_app() {}
};

HIDDEN inline m70000_app& app() { return (m70000_app&) main_app();}

HIDDEN bool tiporeg_handler(TMask_field& f, KEY k)
{
  if ((k == K_TAB || k == K_ENTER) && app().exist_journal() &&
      (atoi(f.get()) == REG_JOURNAL)
      )
    return error_box("Non e' possibile avere due registri giornale nello stesso anno");
  return TRUE;
}


bool m70000_app::user_create()
{ 
  Tab_application::user_create();
  _msk     = get_mask();
  _tabname = get_tabname();
  if (_tabname == "REG") _msk->set_handler(F_TIPO, tiporeg_handler);
  return TRUE;
}

main(int argc, char* argv[])
{
  m70000_app a;
  
  a.run(argc,argv, "Prova di tabapp");
  return 0;
}


