#include <relapp.h>

#include "cg0.h"
#include "cg0300.h"

class CG0300_application : public TRelation_application
{
  TMask* _msk;
  TRelation *_rel;
  TLocalisamfile* _ditte;
  TLocalisamfile* _attiv;
  TLocalisamfile* _clifo;

  bool user_create();
  bool user_destroy();
  virtual TMask* get_mask(int mode) {return _msk;}
  virtual bool changing_mask(int mode) {return FALSE;}
  virtual TRelation* get_relation() const {return _rel;}
  virtual void init_query_mode(TMask& m);
  virtual void init_query_insert_mode(TMask& m);
  virtual void init_modify_mode(TMask& m);
  virtual void init_insert_mode(TMask& m) { init_modify_mode(m); }

public:
  CG0300_application() {}
};

void CG0300_application::init_query_mode(TMask& m)

{ 
  disable_menu_item(M_FILE_NEW);
  m.show(-1);
  m.hide(-2);
}

void CG0300_application::init_query_insert_mode(TMask& m)

{
  disable_menu_item(M_FILE_NEW);
  m.hide(-1);
  m.show(-2); 
  m.enable(-3);
}

void CG0300_application::init_modify_mode(TMask& m)

{
  m.disable(-3);
}


bool CG0300_application::user_create() 
{
  _msk = new TMask("cg0300a") ;
  _rel = new TRelation(LF_ALLEG);
  _ditte = new TLocalisamfile(LF_NDITTE);
  _attiv = new TLocalisamfile(LF_ATTIV);
  _clifo = new TLocalisamfile(LF_CLIFO);
  const long ditta = get_firm();
  _msk->set(F_CODDITTA, ditta);
  _ditte->zero();
  _ditte->put(N_CODDITTA, ditta);
  _ditte->read();
  if (_ditte->good())
    _msk->set(F_CODATT,_ditte->get(N_CODATTPREV));
  return TRUE;
  
}

bool CG0300_application::user_destroy()
{
  delete  _msk;
  delete  _rel;
  delete  _ditte;
  delete  _attiv;
  delete  _clifo;
  return TRUE;
}

int cg0300(int argc, char* argv[])
{
  CG0300_application a;
  a.run(argc, argv, "Immissione progressivi allegati");
  return 0;
}
