191 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			191 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
// 776600.cpp - Gestione estinti
 | 
						|
#include <applicat.h>
 | 
						|
#include <mask.h>
 | 
						|
#include <isam.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <sheet.h>
 | 
						|
#include <urldefid.h>     
 | 
						|
#include "776600a.h"                       
 | 
						|
#include "77lib.h"
 | 
						|
// 
 | 
						|
// Lista modifiche
 | 
						|
// 3.4.96	Aggiunto controllo in save() per impedire la creazione di un record-dichiarazione
 | 
						|
//			anche quando si vuol solo cancellare il codice dichiarante senza immetterne un altro
 | 
						|
//
 | 
						|
 | 
						|
class TEstinti_app : public TApplication
 | 
						|
{
 | 
						|
    long			_codditta;
 | 
						|
    TMask*			_msk;
 | 
						|
    TLocalisamfile*	_base, *_basebis;           
 | 
						|
    TRelation*		_rel;
 | 
						|
    TCursor*		_cur;
 | 
						|
    TBrowse_sheet*	_estint_sheet;
 | 
						|
    static bool show_estinti(TMask_field& f, KEY k);    
 | 
						|
    void 		force_output(int dlg, const long cod);
 | 
						|
  protected:     
 | 
						|
    virtual bool create();
 | 
						|
    virtual bool destroy();
 | 
						|
    virtual bool menu(MENU_TAG m);             
 | 
						|
    bool	save(TMask& m, const long coddic_prec);
 | 
						|
    bool    set_codditta(TMask_field& f);
 | 
						|
    bool 	main_loop();
 | 
						|
};
 | 
						|
 | 
						|
TEstinti_app& app() { return (TEstinti_app&) main_app(); }
 | 
						|
 | 
						|
bool TEstinti_app::set_codditta(TMask_field& f)
 | 
						|
{
 | 
						|
  TString16 codditta; codditta << get_firm_770();
 | 
						|
  if (codditta != "0")
 | 
						|
  {
 | 
						|
    f.set(codditta);
 | 
						|
//      f.set_dirty();  
 | 
						|
    f.check();
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TEstinti_app::show_estinti(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
  if (k == K_SPACE)
 | 
						|
    app()._estint_sheet->run();
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TEstinti_app::create()
 | 
						|
{
 | 
						|
  TApplication::create();
 | 
						|
  _base    = new TLocalisamfile(LF_BASE);
 | 
						|
  _basebis = new TLocalisamfile(LF_BASEBIS);
 | 
						|
  _msk     = new TMask("776600a");
 | 
						|
  _rel     = new TRelation(LF_BASE);
 | 
						|
  _rel->add(LF_NDITTE, "CODDITTA=CODDITTA");  
 | 
						|
 | 
						|
  _codditta = get_firm_770();
 | 
						|
  set_codditta(_msk->field(F_CODDITTA));    
 | 
						|
  TString16 filt;
 | 
						|
  filt.format("CODDIC=%ld", _codditta);   
 | 
						|
  _cur  = new TCursor(_rel, filt);
 | 
						|
  TEdit_field& dummy = (TEdit_field&)_msk->field(F_CODDIC_DUMMY);
 | 
						|
  _estint_sheet = new TBrowse_sheet(_cur,"CODDITTA|9->RAGSOC", "Elenco estinti",              
 | 
						|
                                    "Codice|Ragione sociale@50", 8, &dummy);
 | 
						|
  _msk->set_handler(F_ESTINTI, show_estinti);
 | 
						|
  dispatch_e_menu (BAR_ITEM(1));
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TEstinti_app::destroy()
 | 
						|
{
 | 
						|
  delete _estint_sheet;
 | 
						|
  delete _rel;  delete _cur;
 | 
						|
  delete _msk;  delete _base; delete _basebis;
 | 
						|
  return TApplication::destroy();
 | 
						|
}
 | 
						|
 | 
						|
void TEstinti_app::force_output(int dlg, const long codditta)
 | 
						|
{
 | 
						|
  TLocalisamfile ditte(LF_NDITTE);
 | 
						|
  ditte.zero();
 | 
						|
  ditte.put("CODDITTA", (long)codditta);
 | 
						|
  int ret = ditte.read(_isequal);
 | 
						|
  if (ret == NOERR)
 | 
						|
  {
 | 
						|
    TString80 ragsoc(ditte.get("RAGSOC"));
 | 
						|
    _msk->set(dlg, ragsoc);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
bool TEstinti_app::save(TMask& m, const long codic_prec)
 | 
						|
{
 | 
						|
  const long new_codic = m.get_long(F_CODDIC);
 | 
						|
  
 | 
						|
  _base->zero();
 | 
						|
  _base->put("CODDITTA", (long)_codditta);     
 | 
						|
  _base->put("CODDIC",   (long)new_codic);
 | 
						|
  _base->rewrite();
 | 
						|
 | 
						|
// Stessa cosa su basebis
 | 
						|
  _basebis->zero();              
 | 
						|
  _basebis->put("CODDITTA", (long)_codditta);     
 | 
						|
  _basebis->put("CODDIC",   (long)new_codic);
 | 
						|
  _basebis->rewrite();                  
 | 
						|
 | 
						|
// Crea il record globale per il dichiarante scelto se non esiste
 | 
						|
// 3.4.96 - Solo se il dichiarante e' diverso da 0, senno' quando si vuol cancellare
 | 
						|
//          il dichiarante crea un record duplicato!
 | 
						|
  if (new_codic != 0L)
 | 
						|
    if (!exist_dichiar_770(new_codic, TRUE))
 | 
						|
      enter_dichiar_770(new_codic, anno_770(), TRUE);
 | 
						|
    
 | 
						|
  return TRUE;     
 | 
						|
}
 | 
						|
 | 
						|
bool TEstinti_app::main_loop()
 | 
						|
{
 | 
						|
  KEY     tasto;            
 | 
						|
 | 
						|
  const long codditta = _msk->get_long(F_CODDITTA);
 | 
						|
  _base->zero();            
 | 
						|
  _base->setkey(1);
 | 
						|
  _base->put("CODDITTA", (long)codditta);
 | 
						|
  _base->read();
 | 
						|
 | 
						|
  do  {                     
 | 
						|
    const bool dichiarante = sogg_dic(_codditta);
 | 
						|
    long  coddic = 0L;
 | 
						|
    if (!dichiarante)
 | 
						|
    {
 | 
						|
      coddic = sogg_estinto(_codditta);
 | 
						|
      if (coddic > 0L && coddic < COD_QUA_I_DIC)              
 | 
						|
      {
 | 
						|
        _msk->set(F_CODDIC, coddic);
 | 
						|
//        _msk->field(F_CODDIC).check();
 | 
						|
        force_output(F_RAGSOC, coddic);
 | 
						|
      }
 | 
						|
    }  
 | 
						|
    _msk->enable(F_CODDIC,   !dichiarante);
 | 
						|
    _msk->enable(F_ESTINTI,   dichiarante);
 | 
						|
    _msk->enable(DLG_SAVEREC,!dichiarante);
 | 
						|
    
 | 
						|
    tasto = _msk->run();
 | 
						|
 | 
						|
    switch (tasto) {      
 | 
						|
      case K_ENTER:
 | 
						|
        if (_msk->dirty())
 | 
						|
// Se e' un dichiarante F_CODDIC e' disabilitato e non c'e' nulla da salvare    
 | 
						|
          if (!dichiarante)
 | 
						|
            save(*_msk, coddic);
 | 
						|
        break;
 | 
						|
      case K_ESC :
 | 
						|
        tasto = K_QUIT;
 | 
						|
        break;
 | 
						|
      case K_QUIT :      
 | 
						|
        break;
 | 
						|
      case K_SAVE :
 | 
						|
        if (!dichiarante)
 | 
						|
          save(*_msk, coddic);
 | 
						|
        break;
 | 
						|
      default:
 | 
						|
        break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
  while (tasto != K_QUIT);                              
 | 
						|
  return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
bool TEstinti_app::menu(MENU_TAG m)
 | 
						|
{
 | 
						|
  if (m == BAR_ITEM(1))
 | 
						|
    return main_loop(); 
 | 
						|
  return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
int Estinti(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TEstinti_app a;         
 | 
						|
  a.run(argc, argv, "Gestione dichiarante / estinti");
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 |