Files correlati : Ricompilazione Demo : [ ] Commento : listini-contratti-offerte comprensibili git-svn-id: svn://10.65.10.50/branches/R_10_00@21054 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1152 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1152 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <automask.h>
 | |
| #include <defmask.h>
 | |
| #include <dongle.h>
 | |
| #include <progind.h>
 | |
| #include <recarray.h>
 | |
| #include <recset.h>
 | |
| #include <relapp.h>
 | |
| 
 | |
| #include "../mg/anamag.h"
 | |
| #include "../mg/codcorr.h"
 | |
| #include "../mg/umart.h"
 | |
| #include "condv.h"
 | |
| #include "rcondv.h"
 | |
| 
 | |
| #include "ve2500a.h"
 | |
| #include "ve2500b.h"
 | |
| 
 | |
| 
 | |
| const TString& build_query(const char tipo)
 | |
| {
 | |
|   TString& query = get_tmp_string();
 | |
|   query << "USE RCONDV";
 | |
|   switch (tipo)
 | |
|   {
 | |
|   case 'C':
 | |
|     {
 | |
|       query << "\nFROM TIPO=C TIPOCF=#TIPOCF CODCF=#CODCF COD=#COD";
 | |
|       query << "\nTO TIPO=C TIPOCF=#TIPOCF CODCF=#CODCF COD=#COD";
 | |
|     }
 | |
|     break;
 | |
|   case 'O':
 | |
|     {
 | |
|       query << "\nFROM TIPO=O COD=#COD";
 | |
|       query << "\nTO TIPO=O COD=#COD";
 | |
|     }
 | |
|     break;
 | |
|   default:  //il default è 'L', listini
 | |
|     {
 | |
|       query << "\nFROM TIPO=L CATVEN=#CATVEN COD=#COD";
 | |
|       query << "\nTO TIPO=L CATVEN=#CATVEN COD=#COD";
 | |
|     }
 | |
|     break;
 | |
|   }
 | |
|   return query;
 | |
| }
 | |
| ////////////////////////////////////////////////////////////////////
 | |
| //  MASCHERA SECONDARIA DI GENERAZIONE LISTINO 
 | |
| ////////////////////////////////////////////////////////////////////
 | |
| class TGestione_listini_semplice_mask_genera: public TAutomask
 | |
| {
 | |
| 
 | |
|   TMask* _main_mask;  //puntatore maschera principale
 | |
| 
 | |
| protected:
 | |
|   int find_art_in_sheet(const char tipo, const TString& cod, const TString& um, const int nscagl) const;
 | |
|   void copia_listino();
 | |
|   void crea_da_anamag();
 | |
| 
 | |
| public:
 | |
|   void crea_listino();
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
|   TGestione_listini_semplice_mask_genera(TMask* main_mask, const TString& mask_name);
 | |
| };
 | |
| 
 | |
| 
 | |
| bool TGestione_listini_semplice_mask_genera::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | |
| {
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| TGestione_listini_semplice_mask_genera::TGestione_listini_semplice_mask_genera(TMask* main_mask, const TString& mask_name)
 | |
|                                       : TAutomask(mask_name), _main_mask(main_mask)
 | |
| { 
 | |
|   const bool gesliscv = ini_get_bool(CONFIG_DITTA, "ve", "GESLISCV");
 | |
|   enable(FB_L_CATVEN, gesliscv);
 | |
|   enable(FB_L_DESVEN, gesliscv);
 | |
| }
 | |
| 
 | |
| // COPIA LISTINO
 | |
| //----------------------------------------------------------------------------------------------------------------------
 | |
| //metodo che restituisce l'indice della riga dello sheet che contiene
 | |
| //la coppia tipo-articolo desiderata (-1 se non lo trova)
 | |
| int TGestione_listini_semplice_mask_genera::find_art_in_sheet(const char tipo, const TString& cod,
 | |
|                                                               const TString& um, const int nscagl) const
 | |
| {
 | |
|   TSheet_field& s = _main_mask->sfield(FA_RIGHE);
 | |
|   int i = -1;
 | |
|   FOR_EACH_SHEET_ROW(s, r, row)
 | |
|   {
 | |
|     const char tiporiga = row->get_char(0);
 | |
|     const TString& codart = row->get(1);
 | |
|     TString4 umis = row->get(4);
 | |
|     umis.trim();
 | |
|     const int numscagl = row->get_int(5);
 | |
|     if (tipo == tiporiga && cod == codart && um == umis && nscagl == numscagl)
 | |
|     {
 | |
|       i = r;
 | |
|       break;
 | |
|     }
 | |
|   }
 | |
|   return i;
 | |
| }
 | |
| 
 | |
| //metodo per la copia da un listino esistente
 | |
| void TGestione_listini_semplice_mask_genera::copia_listino()
 | |
| {
 | |
|   //inizializza il tipo di condv che serve ('L'istino, 'C'ontratto, 'O'fferta)
 | |
|   char tipo = main_app().argv(2)[0];
 | |
|   tipo = toupper(tipo);
 | |
| 
 | |
|   //parametri listino/contratto/offerta origine
 | |
|   TString4 ori_catven;
 | |
|   char ori_tipocf;
 | |
|   long ori_codcf;
 | |
| 
 | |
|   switch (tipo)
 | |
|   {
 | |
|   case 'C':
 | |
|     ori_tipocf = get(FB_C_TIPOCF)[0];
 | |
|     ori_codcf = get_long(FB_C_CODCF);
 | |
|     break;
 | |
|   case 'O':
 | |
|     break;
 | |
|   default:  //il default è 'L'
 | |
|     ori_catven = get(FB_L_CATVEN);
 | |
|     break;
 | |
|   }
 | |
| 
 | |
|   //parametri comuni  
 | |
|   const TString& ori_condv = get(FB_COD);
 | |
|   const real ricarico = get_real(FB_RICARICO);
 | |
| 
 | |
|   //vanno fuori dall'if(get_bool(FB_COPIATESTA)) perchè rec_ori_testata serve in seguito! (che schifo!)
 | |
|   TToken_string key;
 | |
|   key.add(tipo);
 | |
| 
 | |
|   switch(tipo)
 | |
|   {
 | |
|   case 'C':
 | |
|     {
 | |
|       key.add("");
 | |
|       key.add(ori_tipocf);
 | |
|       key.add(ori_codcf);
 | |
|     }
 | |
|     break;
 | |
|   case 'O':
 | |
|     {
 | |
|       key.add("");
 | |
|       key.add("");
 | |
|       key.add("");
 | |
|     }
 | |
|     break;
 | |
|   default:  //'L', come sopra
 | |
|     {
 | |
|       key.add(ori_catven);
 | |
|       key.add("");
 | |
|       key.add("");
 | |
|     }
 | |
|     break;
 | |
|   }
 | |
| 
 | |
|   key.add(ori_condv);
 | |
|   const TRectype& rec_ori_testata = cache().get(LF_CONDV, key);
 | |
| 
 | |
|   //TESTATA
 | |
|   //se richiesto mette nei campi della maschera principale i dati di testata
 | |
|   if (get_bool(FB_COPIATESTA))
 | |
|   {
 | |
|     //magico metodino per scrivere sui campi della maschera principale (testata nuovo listino) i dati della testata..
 | |
|     //..del listino originale (senza usare una lunghissima serie di set su ogni campo!)
 | |
|     FOR_EACH_MASK_FIELD((*_main_mask), i, f)
 | |
|     {
 | |
|       const TFieldref* fld_file = f->field();
 | |
|       if (fld_file != NULL && !f->in_key(0) && f->enabled() && f->empty())
 | |
|         f->set(fld_file->read(rec_ori_testata));
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   //RIGHE
 | |
|   //prende il recordset delle righe del listino origine e lo mette sullo sheet
 | |
|   TISAM_recordset righe(build_query(tipo));   //la build query è un metodo dell'altra maschera (A)
 | |
|   switch (tipo)
 | |
|   {
 | |
|   case 'C':
 | |
|     {
 | |
|       TString4 str_tipocf;
 | |
|       str_tipocf << ori_tipocf;
 | |
|       righe.set_var("#TIPOCF", str_tipocf);
 | |
|       righe.set_var("#CODCF", ori_codcf);
 | |
|     }
 | |
|     break;
 | |
|   case 'O':
 | |
|     break;
 | |
|   default:  //il default è 'L'
 | |
|     righe.set_var("#CATVEN", ori_catven);
 | |
|     break;
 | |
|   }
 | |
| 
 | |
|   righe.set_var("#COD", ori_condv);
 | |
| 
 | |
|   const long righe_items = righe.items();
 | |
|   TProgind pi(righe_items, TR("Copia righe origine..."), true, true);
 | |
| 
 | |
|   //sheet righe listino da riempire nella maschera principale
 | |
|   TSheet_field& sf_righe = _main_mask->sfield(FA_RIGHE);
 | |
|   TMask& msk = sf_righe.sheet_mask();
 | |
| 
 | |
|   //record corrente del recordset (non const perchè la modifica eventualmente causa ricarico)
 | |
|   TRectype& riga_corrente = righe.cursor()->curr();
 | |
|   TString80 val;
 | |
| 
 | |
|   //alcune date utili nelle righe; prese qui perchè vengono dalla testata o dalla maschera e sono poi riportate..
 | |
|   //..nelle righe
 | |
|   TDate data_ult_aum = _main_mask->get_date(FA_VALINI);
 | |
|   if (!data_ult_aum.ok())
 | |
|     data_ult_aum = TDate(TODAY);
 | |
|   TDate data_prz_storico = rec_ori_testata.get_date(CONDV_VALIN);
 | |
|   if (!data_prz_storico.ok())
 | |
|     data_prz_storico = data_ult_aum - 1L;
 | |
| 
 | |
|   //scorre tutte le righe listino del recordset e le sbatte nello sheet della maschera principale
 | |
|   for (bool ok = righe.move_first(); ok; ok = righe.move_next())
 | |
|   {
 | |
|     if (!pi.addstatus(1))
 | |
|       break;
 | |
|     //controlla che il record non esista per caso già nel listino di destinazione (caso della copia listino in più..
 | |
|     //..fasi separate: un lavoro da mica normali!). Prende quindi la chiave di riga e cerca nello sheet...
 | |
|     const char tiporiga = riga_corrente.get_char(RCONDV_TIPORIGA);
 | |
|     const TString& codice = riga_corrente.get(RCONDV_CODRIGA);
 | |
|     const TString& um = riga_corrente.get(RCONDV_UM);
 | |
|     const int nscagl = riga_corrente.get_int(RCONDV_NSCAGL);
 | |
|     //se il record non esiste può aggiungerlo allo sheet
 | |
|     if (find_art_in_sheet(tiporiga, codice, um, nscagl) < 0)
 | |
|     {
 | |
|       TToken_string& row = sf_righe.row(-1);
 | |
|       //per ogni campo della maschera setta all'interno del record corrente di file
 | |
|       //il valore di quei campi che hanno un field
 | |
|       FOR_EACH_MASK_FIELD(msk, i, f)
 | |
|       {
 | |
|         const TFieldref* fr = f->field();
 | |
|         if (fr != NULL)
 | |
|         {
 | |
|           val = fr->read(riga_corrente);
 | |
|           if (fr->name() == RCONDV_PREZZO && !ricarico.is_zero()) //gestione del ricarico sul listino
 | |
|           {
 | |
|             const real old_prezzo = riga_corrente.get_real(RCONDV_PREZZO);
 | |
|             const real new_prezzo = old_prezzo * (1 + ricarico / CENTO);
 | |
|             val = new_prezzo.string();
 | |
|             //aggiorna i campi direttamente sul record, in modo che quando saranno incontrati successivamente,...
 | |
|             //..saranno già a posto senza dover rifare tutti i ragionamenti sul ricarico
 | |
|             riga_corrente.put(RCONDV_DATAULTAUM, data_ult_aum);
 | |
|             riga_corrente.put(RCONDV_PRZSTO, old_prezzo);
 | |
|             riga_corrente.put(RCONDV_DATAPRZSTO, data_prz_storico);
 | |
|           }
 | |
|           row.add(val, sf_righe.cid2index(f->dlg()));
 | |
|         }
 | |
|       }
 | |
|       //forza una check_row
 | |
|       sf_righe.check_row(sf_righe.items()-1, 3);
 | |
|     }
 | |
|   }
 | |
|   sf_righe.force_update();
 | |
| }
 | |
| 
 | |
| 
 | |
| //CREA DA ANAGRAFICA ARTICOLI
 | |
| //----------------------------------------------------------------------------------------------------------------------
 | |
| void TGestione_listini_semplice_mask_genera::crea_da_anamag()
 | |
| {
 | |
|   //prende i dati dalla maschera per crearsi una query di generazione righe sheet
 | |
|   TString query;
 | |
|   query << "USE ANAMAG\n";
 | |
|   //incasinatissima SELECT
 | |
|   TString select;
 | |
|  
 | |
|   //è stato selezionato il gruppo/sottogruppo merceologico?
 | |
|   TString8 grmerc;
 | |
|   if (!field(FB_GRMERC).empty())
 | |
|   {
 | |
|     grmerc.format("%-3s%-2s", (const char*)get(FB_GRMERC),(const char*)get(FB_SOTGRMERC));
 | |
|     grmerc.rtrim();
 | |
|     select << "(GRMERC=#GRMERC)";
 | |
|   }
 | |
|   //è stato selezionato il raggruppamento fiscale?
 | |
|   const TString& raggfis = get(FB_RAGFIS);
 | |
|   if (raggfis.full())
 | |
|   {
 | |
|     if (select.full())
 | |
|       select << "&&";
 | |
|     select << "(RAGGFIS=#RAGGFIS)";
 | |
|   }
 | |
|   if (select.full())
 | |
|     query << "SELECT " << select << "\n";
 | |
| 
 | |
|   //parte FROM/TO comune
 | |
|   query << "FROM CODART=#DACODART\n";
 | |
|   query << "TO CODART=#ACODART\n";
 | |
| 
 | |
|   TISAM_recordset recset(query);
 | |
|   recset.set_var("#DACODART", get(FB_DACODART));
 | |
|   recset.set_var("#ACODART", get(FB_ACODART));
 | |
|   if (grmerc.full())
 | |
|     recset.set_var("#GRMERC", grmerc);
 | |
|   if (raggfis.full())
 | |
|     recset.set_var("#RAGGFIS", raggfis);
 | |
| 
 | |
|   const long recset_items = recset.items();
 | |
|   TProgind pi(recset_items, TR("Importazione righe da anagrafica..."), true, true);
 | |
| 
 | |
|   //fase riempimento sheet maschera principale
 | |
|   TSheet_field& sf_righe = _main_mask->sfield(FA_RIGHE);
 | |
| 
 | |
|   //attenzione! ci possono essere articoli presenti più volte in UMART con diverse unità di misura: li mette tutti
 | |
|   const bool gest_um = _main_mask->get_bool(FA_GESTUM);
 | |
|   TRecord_array arr_art_um(LF_UMART, UMART_NRIGA);
 | |
|   //la gestione omaggi (misteriosamente definita gestsco) attiva l'iva
 | |
|   const bool gest_sco = _main_mask->get_bool(FA_GESTSCO);
 | |
| 
 | |
|   //per ogni riga del recordset va ad aggiornare lo sheet sulla maschera (aggiunge la riga)
 | |
|   for (bool ok = recset.move_first(); ok; ok = recset.move_next())
 | |
|   {
 | |
|     if (!pi.addstatus(1))
 | |
|       break;
 | |
| 
 | |
|     const TString& codart = recset.get("CODART").as_string();
 | |
|     TRectype* key = new TRectype(LF_UMART);
 | |
|     key->put(UMART_CODART, codart);
 | |
|     arr_art_um.read(key);
 | |
|     const int num_um = gest_um ? arr_art_um.rows() : 1;
 | |
|     //se ci sono più unità di misura per lo stesso codart ci sono tanti record quante um
 | |
|     for (int u = 1; u <= num_um; u++)
 | |
|     {
 | |
|       TToken_string& row = sf_righe.row(-1);
 | |
|       row.add('A', 0);
 | |
|       row.add(codart, 1);
 | |
|       row.add(recset.get("DESCR").as_string(), 2);
 | |
|       const TRectype& rec_umart = arr_art_um.row(u);
 | |
|       row.add(rec_umart.get(UMART_PREZZO), 3);
 | |
|       //se attivata gestione unità di misura...
 | |
|       if (gest_um)
 | |
|         row.add(rec_umart.get(UMART_UM), 4);
 | |
| 
 | |
|       row.add(recset.get("SCONTO").as_string(), 7);
 | |
|       if (gest_sco)
 | |
|       {
 | |
|         const TString& codiva = recset.get("CODIVA").as_string();
 | |
|         if (codiva.full())
 | |
|         {
 | |
|           row.add("X", 8);
 | |
|           row.add(codiva, 9);
 | |
|         }
 | |
|       }
 | |
| 
 | |
|       row.add(recset.get("PERCPROVV").as_string(), 18);
 | |
|     }
 | |
|   } //for(bool ok=...
 | |
|   sf_righe.force_update();
 | |
| }
 | |
| 
 | |
| 
 | |
| // GESTIONE COPIA/GENERA IN AUTOMATICO
 | |
| //------------------------------------
 | |
| void TGestione_listini_semplice_mask_genera::crea_listino()
 | |
| {
 | |
|   //per prima cosa controlla se deve copiare da un listino esistente o generare da nuovo
 | |
|   const int f_tipo_gen = get_int(FB_SELECT);
 | |
|   switch (f_tipo_gen)
 | |
|   {
 | |
|   case 1:
 | |
|     copia_listino();
 | |
|     break;
 | |
|   case 2:
 | |
|     crea_da_anamag();
 | |
|     break;
 | |
|   default:
 | |
|     break;
 | |
|   }
 | |
| }
 | |
| 
 | |
| ////////////////////////////////////////////////////////////////////
 | |
| //  MASCHERA PRINCIPALE DI GESTIONE LISTINO (quella con lo sheet)
 | |
| ////////////////////////////////////////////////////////////////////
 | |
| class TGestione_listini_semplice_mask: public TAutomask
 | |
| {
 | |
|   int _pos_tipo, _pos_art, _pos_desc, _pos_um;
 | |
| protected:
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
| public:
 | |
|   int find_art(TSheet_field& s, const char tipo, const TString& art, const TString& um, const int tranne = -1) const;
 | |
|   int guess_art(TSheet_field& s, const char tipo, const TString& art, const int column) const;
 | |
|   TGestione_listini_semplice_mask(const TString& mask_name);
 | |
| 
 | |
| };
 | |
| 
 | |
| 
 | |
| TGestione_listini_semplice_mask::TGestione_listini_semplice_mask(const TString& mask_name) : TAutomask(mask_name)
 | |
| {
 | |
|   //assegna le posizioni delle colonne dello sheet
 | |
|   TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|   _pos_tipo = sf_righe.cid2index(S_TIPORIGA);   //0
 | |
|   _pos_art = sf_righe.cid2index(S_CODRIGA_A);   //1
 | |
|   _pos_desc = sf_righe.cid2index(S_DESRIGA_A);  //2
 | |
|   _pos_um = sf_righe.cid2index(S_UM);           //4
 | |
| 
 | |
|   //inizializza il tipo di condv che serve ('L'istino, 'C'ontratto, 'O'fferta)
 | |
|   char tipo = main_app().argv(2)[0];
 | |
|   tipo = toupper(tipo);
 | |
| 
 | |
|   switch (tipo)
 | |
|   {
 | |
|   case 'C':
 | |
|     break;
 | |
|   case 'O':
 | |
|     break;
 | |
|   default:  //il default è L
 | |
|     {
 | |
|       //in base alla cervellotica configurazione impostata dall'utonto abilita/disabilita campi
 | |
|       const bool gesliscv = ini_get_bool(CONFIG_DITTA, "ve", "GESLISCV");
 | |
|       enable(FA_L_CATVEN, gesliscv);
 | |
|       enable(FA_L_DESVEN, gesliscv);
 | |
|       //attenzione!!! il campo CATVEN è in chiave 1! per disabilitarlo ci vuole questo trucco! 
 | |
|       if (!gesliscv)
 | |
|         efield(FA_L_CATVEN).reset_key(1);
 | |
|     }
 | |
|     break;
 | |
|   }
 | |
| 
 | |
| }
 | |
| 
 | |
| //metodo per la ricerca al volo di un articolo (serve per posizionare il cursore sullo sheet in tempo reale..
 | |
| //..mentre si digita il codice articolo nel campo di ricerca
 | |
| int TGestione_listini_semplice_mask::guess_art(TSheet_field& s, const char tipo, const TString& art, 
 | |
|                                                const int column) const
 | |
| {
 | |
|   int i = -1;
 | |
|   FOR_EACH_SHEET_ROW(s, r, row)
 | |
|   {
 | |
|     const char tiporiga = row->get_char(_pos_tipo);
 | |
|     const TString& cod = row->get(column);
 | |
|     if (tipo == tiporiga && cod.starts_with(art, true))
 | |
|     {
 | |
|       i = r;
 | |
|       break;
 | |
|     }
 | |
|   }
 | |
|   return i;
 | |
| }
 | |
| 
 | |
| //metodo che restituisce l'indice della riga dello sheet che contiene
 | |
| //la coppia tipo-articolo desiderata (-1 se non lo trova)
 | |
| int TGestione_listini_semplice_mask::find_art(TSheet_field& s, const char tipo, const TString& art, 
 | |
|                                               const TString& um, const int tranne) const
 | |
| {
 | |
|   int i = -1;
 | |
|   //tranne serve per evitare una riga specifica;di default è posto =-1 perchè non si usa
 | |
|   FOR_EACH_SHEET_ROW(s, r, row)
 | |
|   {
 | |
|     if (r != tranne)
 | |
|     {
 | |
|       const char tiporiga = row->get_char(_pos_tipo);
 | |
|       const char* codart = row->get(_pos_art);
 | |
|       TString4 umart = row->get(_pos_um);
 | |
|       umart.trim();
 | |
|       if (tipo == tiporiga && art == codart && um == umart)
 | |
|       {
 | |
|         i = r;
 | |
|         break;
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|   return i;
 | |
| }
 | |
| 
 | |
| 
 | |
| bool TGestione_listini_semplice_mask::on_field_event(TOperable_field &o, TField_event e, long jolly)
 | |
| {
 | |
|   switch(o.dlg())
 | |
|   {
 | |
|   case FA_CODRIGA_A:
 | |
|   case FA_CODRIGA_G:
 | |
|   case FA_CODRIGA_S:
 | |
|   case FA_CODRIGA_R:
 | |
|     //ricerca della riga listino attraverso codice nello sheet usando il campo di ricerca 
 | |
|     if (e == fe_edit || e == fe_modify)
 | |
|     {
 | |
|       const char tiporiga = get(FA_TIPORIGA)[0];
 | |
|       const TString& codriga = ((TEditable_field&)o).get_window_data();
 | |
|       TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|       const long riga = guess_art(sf_righe, tiporiga, codriga, 1);
 | |
|       if (riga >= 0 && riga != sf_righe.selected())
 | |
|       {
 | |
|         sf_righe.select(riga, true);
 | |
|         const short f_descr = o.dlg() + 1;
 | |
|         const char* descr = sf_righe.cell(riga, 2);
 | |
|         set(f_descr, descr);
 | |
|       }
 | |
|     }
 | |
|     break;
 | |
|   case FA_DESRIGA_A:
 | |
|   case FA_DESRIGA_G:
 | |
|   case FA_DESRIGA_S:
 | |
|   case FA_DESRIGA_R:
 | |
|     //ricerca della riga listino attraverso descrizione nello sheet usando il campo di ricerca
 | |
|     if (!o.empty() && e == fe_edit)
 | |
|     {
 | |
|       const char tiporiga = get(FA_TIPORIGA)[0];
 | |
|       const TString& desriga = ((TEditable_field&)o).get_window_data();
 | |
|       TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|       const long riga = guess_art(sf_righe, tiporiga, desriga, 2);
 | |
|       if (riga >= 0)
 | |
|       {
 | |
|         sf_righe.select(riga, true);
 | |
|         const short f_cod = o.dlg() - 1;
 | |
|         const char* cod = sf_righe.cell(riga, 1);
 | |
|         set(f_cod, cod);
 | |
|       }
 | |
|     }
 | |
|     break;
 | |
|     //se abilita la gestione scaglioni nello sheet devono comparire le colonne NSCAGL e QLIM
 | |
|   case FA_GESTSCAGL:
 | |
|     if (e == fe_init || e == fe_modify)
 | |
|     {
 | |
|       TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|       const bool gest_scagl = o.get().full();
 | |
|       sf_righe.enable_column(S_NSCAGL, gest_scagl);
 | |
|       sf_righe.enable_column(S_QLIM, gest_scagl);
 | |
| 
 | |
|       sf_righe.force_update();
 | |
|     }
 | |
|     break;
 | |
|     //stesso giochetto per UM
 | |
|   case FA_GESTUM:
 | |
|     if (e == fe_init || e == fe_modify)
 | |
|     {
 | |
|       TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|       const bool gest_um = o.get().full();
 | |
|       sf_righe.enable_column(S_UM, gest_um);
 | |
| 
 | |
|       sf_righe.force_update();
 | |
|     }
 | |
|     break;
 | |
|     //e anche per i campi omaggio
 | |
|   case FA_GESTSCO:
 | |
|     if (e == fe_init || e == fe_modify)
 | |
|     {
 | |
|       TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|       const bool gest_sco = o.get().full();
 | |
|       sf_righe.enable_column(S_ADDIVA, gest_sco);
 | |
|       sf_righe.enable_column(S_CODIVA, gest_sco);
 | |
|       sf_righe.enable_column(S_QOM, gest_sco);
 | |
|       sf_righe.enable_column(S_QBASE, gest_sco);
 | |
|       sf_righe.enable_column(S_CODARTOM, gest_sco);
 | |
|       sf_righe.enable_column(S_UMOM, gest_sco);
 | |
|       sf_righe.enable_column(S_PROMAGGIO, gest_sco);
 | |
| 
 | |
|       sf_righe.force_update();
 | |
|     }
 | |
|     break;
 | |
|     //controllo della unicità del tiporiga+codriga nello sheet
 | |
|   case FA_RIGHE:
 | |
|     if (e == se_notify_modify)
 | |
|     {
 | |
|       TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|       TToken_string& riga = sf_righe.row(jolly);
 | |
|       const char tipo = riga.get_char(_pos_tipo);
 | |
|       const TString& art = riga.get(_pos_art);
 | |
|       TString4 umart = riga.get(_pos_um);
 | |
|       umart.trim();
 | |
|       const long found_riga = find_art(sf_righe, tipo, art, umart, jolly);
 | |
|       if (found_riga >= 0)
 | |
|         return error_box(TR("Non è possibile inserire lo stesso articolo più di una volta!"));
 | |
|     }
 | |
|     if (e == se_enter)
 | |
|     {
 | |
|       TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|       TToken_string& riga = sf_righe.row(jolly);
 | |
|       const char tipo = riga.get_char(_pos_tipo);
 | |
|       const TString& art = riga.get(_pos_art);
 | |
| 
 | |
|       if (get(FA_TIPO)[0] != tipo)
 | |
|         set(FA_TIPO, tipo, 0x1); //0x1 perchè ha dei message e non degli output
 | |
| 
 | |
|       switch (tipo)
 | |
|       {
 | |
|       case 'A':
 | |
|         if (art.full() && get(FA_CODRIGA_A) != art)
 | |
|         {
 | |
|           //deve scriversi nel campo di ricerca; 0x2 serve x far funzionare le output del campo stesso
 | |
|           set(FA_CODRIGA_A, art, 0x2);
 | |
|         }
 | |
|         break;
 | |
|       case 'G':
 | |
|         if (art.full() && get(FA_CODRIGA_G) != art)
 | |
|         {
 | |
|           set(FA_CODRIGA_G, art, 0x2);
 | |
|         }
 | |
|         break;
 | |
|       case 'S':
 | |
|         if (art.full() && get(FA_CODRIGA_S) != art)
 | |
|         {
 | |
|           set(FA_CODRIGA_S, art, 0x2);
 | |
|         }
 | |
|         break;
 | |
|       case 'R':
 | |
|         if (art.full() && get(FA_CODRIGA_R) != art)
 | |
|         {
 | |
|           set(FA_CODRIGA_R, art, 0x2);
 | |
|         }
 | |
|         break;
 | |
|       default:
 | |
|         break;
 | |
|       }
 | |
|     }
 | |
|     break;
 | |
|   case DLG_GRMERC:
 | |
|     if (e == fe_button)
 | |
|     {
 | |
|       TISAM_recordset gmc_recset("USE GMC");
 | |
|       
 | |
|       TToken_string siblings;
 | |
|       TBrowse_sheet cs (gmc_recset.cursor(), "CODTAB|S0", TR("Gruppi merceologici"), HR("Gr.Merc.|Descrizione@50"), 0,
 | |
|                         efield(FA_GRMERC_A), siblings);
 | |
|       if (cs.run() == K_ENTER)
 | |
|       {
 | |
|         TLocalisamfile anamag(LF_ANAMAG);
 | |
|         anamag.put(ANAMAG_CODART, get(FA_CODRIGA_A));
 | |
|         int err = anamag.read();
 | |
|         if (err == NOERR)
 | |
|         {
 | |
|           TToken_string& row = cs.row(cs.selected());
 | |
|           const TString& grmerc = row.get(0);
 | |
|           anamag.put(ANAMAG_GRMERC, grmerc);
 | |
|           anamag.rewrite();
 | |
| 
 | |
|           set(FA_GRMERC_A, grmerc, 0x2);
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|     break;
 | |
|   case DLG_CREA:    //copia / generazione listino,contratto,offerta
 | |
|     if (e == fe_button)
 | |
|     {
 | |
|       char tipo = main_app().argv(2)[0];
 | |
|       tipo = toupper(tipo);
 | |
|       TString16 mask_name;
 | |
|       mask_name << "ve2500b" << tipo;
 | |
|       //gli passa la maschera principale ed il nome della maschera di generazione in base al tipo di condv in esame
 | |
|       TGestione_listini_semplice_mask_genera mask_gen(this, mask_name);
 | |
|       if (mask_gen.run() == K_ENTER)
 | |
|         mask_gen.crea_listino();
 | |
|     }
 | |
|     break;
 | |
|   case DLG_COMPATTA:  //eliminazione delle righe con articoli inesistenti!
 | |
|     if (e == fe_button)
 | |
|     {
 | |
|       TSheet_field& sf_righe = sfield(FA_RIGHE);
 | |
|       FOR_EACH_SHEET_ROW_BACK(sf_righe, r, row) //deve andare all'indietro per minimizzare il riordino righe
 | |
|       {
 | |
|         if (row->get_char(_pos_desc) <= ' ')  //le righe senza descrizione sono sbagliate (è obbligatoria per articoli ecc.)
 | |
|         {
 | |
|           bool kill_row = true;
 | |
|           if (row->get_char(_pos_tipo) == 'A')  //solo se è un articolo tenta di recuperarlo con il codice alternativo..(mah?)
 | |
|           {
 | |
|             TLocalisamfile file_codcorr(LF_CODCORR);
 | |
|             file_codcorr.setkey(2);
 | |
|             file_codcorr.put(CODCORR_CODARTALT, row->get(1));
 | |
|             int err = file_codcorr.read();
 | |
|             //se miracolosamente trova il record con il vecchio codart come codartalt...
 | |
|             if (err == NOERR)
 | |
|             {
 | |
|               const TString& new_codart = file_codcorr.get(CODCORR_CODART);  //il nuovo codart c'è x' è in key 1
 | |
|               const TString& new_descr = cache().get(LF_ANAMAG, new_codart, ANAMAG_DESCR);
 | |
|               if (!new_descr.blank())
 | |
|               {
 | |
|                 row->add(new_codart, 1);
 | |
|                 row->add(new_descr, 2);
 | |
|                 kill_row = false;
 | |
|               }
 | |
|             }
 | |
|           } //if(row->get_char(0)..
 | |
|           if (kill_row)
 | |
|             sf_righe.destroy(r, false);
 | |
|         }
 | |
|       }
 | |
|       sf_righe.force_update();
 | |
|     }
 | |
|     break;
 | |
|   default:
 | |
|     break;
 | |
|   }
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////////
 | |
| //  APPLICAZIONE
 | |
| ///////////////////////////////////////////////////////////////
 | |
| class TGestione_listini_semplice : public TRelation_application 
 | |
| {
 | |
|   TGestione_listini_semplice_mask *_mask;
 | |
|   TRelation* _rel;
 | |
|   char _tipo;
 | |
| 
 | |
| private:
 | |
|   void save_rows();
 | |
| 
 | |
| protected:    
 | |
|   virtual bool user_create();
 | |
|   virtual bool user_destroy();                        
 | |
|   virtual TMask *get_mask(int) { return _mask; }
 | |
|   virtual bool changing_mask(int) { return false; }
 | |
|   virtual void init_query_mode(TMask& m);
 | |
|   virtual void init_insert_mode(TMask& m);
 | |
|   virtual void init_modify_mode(TMask& m);
 | |
| 
 | |
|   virtual bool protected_record(TRectype& rec);
 | |
|   
 | |
|   virtual int read(TMask& m);
 | |
|   virtual int write(const TMask& m);          
 | |
|   virtual int rewrite(const TMask& m);
 | |
|   virtual bool remove();
 | |
|   virtual void mask2ini(const TMask& m, TConfig& ini);
 | |
|   virtual void ini2mask(TConfig& ini, TMask&m, bool query);
 | |
| 
 | |
|   const TString& find_descr(TToken_string& row);
 | |
| 
 | |
| public:
 | |
|   virtual TRelation *get_relation() const { return _rel; }
 | |
| 
 | |
|   TGestione_listini_semplice() { _rel = NULL; _mask = NULL;}
 | |
|   virtual ~TGestione_listini_semplice() {}
 | |
| };
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| void TGestione_listini_semplice::save_rows()
 | |
| {
 | |
|   TWait_cursor hourglass;
 | |
| 
 | |
|   //attenzione!!! fatto questo casino per poter usare la find_art() che è un metodo della maschera listini
 | |
|   const TGestione_listini_semplice_mask& m = *_mask;
 | |
|   //instanzio un TISAM_recordset sulle righe listino e un localisamfile
 | |
|   TISAM_recordset righelist(build_query(_tipo));
 | |
|   switch (_tipo)
 | |
|   {
 | |
|   case 'C':
 | |
|     righelist.set_var("#TIPOCF", m.get(FA_C_TIPOCF));
 | |
|     righelist.set_var("#CODCF", m.get(FA_C_CODCF));
 | |
|     break;
 | |
|   case 'O':
 | |
|     break;
 | |
|   default:  //il default è 'L'
 | |
|     righelist.set_var("#CATVEN", m.get(FA_L_CATVEN));
 | |
|     break;
 | |
|   }
 | |
|   
 | |
|   righelist.set_var("#COD", m.get(FA_COD));
 | |
| 
 | |
|   const long righelist_items = righelist.items();
 | |
| 
 | |
|   TLocalisamfile& file = righelist.cursor()->file();
 | |
| 
 | |
|   //sheet righe listino da salvare! (righe panda?)
 | |
|   TSheet_field& righe = m.sfield(FA_RIGHE);
 | |
|   
 | |
|   //scorro tutte le righe listino ed elimino tutte quelle che non ci sono più sullo sheet (modifiche utonto)
 | |
|   for (bool ok = righelist.move_first(); ok; ok = righelist.move_next())
 | |
|   {
 | |
|     const char tiporiga = righelist.get(RCONDV_TIPORIGA).as_string()[0];
 | |
| 
 | |
|     const TString& art = righelist.get(RCONDV_CODRIGA).as_string();
 | |
|     const TString& umart = righelist.get(RCONDV_UM).as_string();
 | |
|     if (m.find_art(righe, tiporiga, art, umart) < 0)
 | |
|        file.remove();
 | |
|   }
 | |
| 
 | |
|   //procede al salvataggio di testata e righe
 | |
|   //-----------------------------------------
 | |
| 
 | |
|   //per prima cosa servono i dati di testata utili per riempire la chiave di riga listino
 | |
|   char tipocf;
 | |
|   long codcf;
 | |
|   TString4 catven;
 | |
|   switch (_tipo)
 | |
|   {
 | |
|   case 'C':
 | |
|       tipocf = m.get(FA_C_TIPOCF)[0];
 | |
|       codcf = m.get_long(FA_C_CODCF);
 | |
|     break;
 | |
|   case 'O':
 | |
|     break;
 | |
|   default:  //il default è 'L'
 | |
|     catven = m.get(FA_L_CATVEN);
 | |
|     break;
 | |
|   }
 | |
|   
 | |
|   const TString& cod = m.get(FA_COD);
 | |
| 
 | |
|   //recupero la maschera di riga
 | |
|   TMask& msk = righe.sheet_mask();
 | |
| 
 | |
|   //per ogni riga dello sheet
 | |
|   FOR_EACH_SHEET_ROW(righe, r, row)
 | |
|   {
 | |
|     file.zero();
 | |
|     file.put(RCONDV_TIPO, _tipo);
 | |
| 
 | |
|     switch (_tipo)
 | |
|     {
 | |
|     case 'C':
 | |
|       file.put(RCONDV_TIPOCF, tipocf);
 | |
|       file.put(RCONDV_CODCF, codcf);
 | |
|       break;
 | |
|     case 'O':
 | |
|       break;
 | |
|     default:  //il default è 'L'
 | |
|       file.put(RCONDV_CATVEN, catven);
 | |
|       break;
 | |
|     }
 | |
| 
 | |
|     file.put(RCONDV_COD, cod);
 | |
| 
 | |
|     //per ogni campo della maschera setta all'interno del record corrente di file
 | |
|     //il valore di quei campi che hanno un field
 | |
|     FOR_EACH_MASK_FIELD(msk, i, f)
 | |
|     {
 | |
|       const TFieldref* fr = f->field();
 | |
|       if (fr != NULL && f->dlg() < 200)
 | |
|       {
 | |
|         const int pos = righe.cid2index(f->dlg());
 | |
|         fr->write(row->get(pos), file.curr());
 | |
|       }
 | |
|     }
 | |
|     //se è in inserimento deve fare un write, se in modifica la rewrite
 | |
|     if (m.insert_mode())
 | |
|       file.write_rewrite();
 | |
|     else
 | |
|       file.rewrite_write();
 | |
|   }
 | |
| }
 | |
| 
 | |
| const TString& TGestione_listini_semplice::find_descr(TToken_string& row)
 | |
| {
 | |
|   const char tiporiga = row.get_char(0);
 | |
|   const TString& codriga = row.get(1);
 | |
|   switch (tiporiga)
 | |
|   {
 | |
|   case 'A':
 | |
|     return cache().get(LF_ANAMAG, codriga, ANAMAG_DESCR);
 | |
|   case 'G':
 | |
|   case 'S':
 | |
|     return cache().get("GMC", codriga, "S0");
 | |
|   case 'R':
 | |
|     return cache().get("RFA", codriga, "S0");
 | |
|   default:
 | |
|     break;
 | |
|   }
 | |
| 
 | |
|   return EMPTY_STRING;
 | |
| }
 | |
| 
 | |
| bool TGestione_listini_semplice::protected_record(TRectype& rec)
 | |
| {
 | |
|   //non deve consentire l'eliminazione di un listino se ha dei figli da mantenere!
 | |
|   //SOLO i listini possono avere la disgrazia della paternità, quindi il controllo non si..
 | |
|   //..estende per ora a contratti ed offerte
 | |
|   TString query;
 | |
|   query << "USE CONDV\n";
 | |
|   query << "SELECT (FATHCATVEN=#CATVEN)&&(FATHCOD=#COD)\n";
 | |
|   query << "FROM TIPO=L\n";
 | |
|   query << "TO TIPO=L\n";
 | |
|   TISAM_recordset figli(query);
 | |
|   figli.set_var("#CATVEN", rec.get(CONDV_CATVEN));
 | |
|   figli.set_var("#COD", rec.get(CONDV_COD));
 | |
| 
 | |
|   return figli.items() > 0;
 | |
| }
 | |
| 
 | |
| 
 | |
| int TGestione_listini_semplice::read(TMask& m)
 | |
| {
 | |
|   //eseguo la read() standard
 | |
|   int err = TRelation_application::read(m);
 | |
|   //se la read va a buon fine
 | |
|   if (err == NOERR)
 | |
|   {
 | |
|     TWait_cursor hourglass;
 | |
|     //instanzio un TISAM_recordset sulle righe listino (RCONDV)
 | |
|     TISAM_recordset righelist(build_query(_tipo));
 | |
|     switch (_tipo)
 | |
|     {
 | |
|     case 'C':
 | |
|       righelist.set_var("#TIPOCF", m.get(FA_C_TIPOCF));
 | |
|       righelist.set_var("#CODCF", m.get(FA_C_CODCF));
 | |
|       break;
 | |
|     case 'O':
 | |
|       break;
 | |
|     default:  //il default è 'L'
 | |
|       righelist.set_var("#CATVEN", m.get(FA_L_CATVEN));
 | |
|       break;
 | |
|     }
 | |
| 
 | |
|     righelist.set_var("#COD", m.get(FA_COD));
 | |
| 
 | |
|     const long righelist_items = righelist.items();
 | |
| 
 | |
|     const TRectype& rec = righelist.cursor()->curr();
 | |
| 
 | |
|     //recupero sheet e realtiva mashera di riga
 | |
|     TSheet_field& sf_righe = m.sfield(FA_RIGHE);
 | |
|     TMask& msk = sf_righe.sheet_mask();
 | |
|     sf_righe.destroy();
 | |
| 
 | |
|     //per ogni riga del recordset va ad aggiornare lo sheet sulla maschera (aggiunge la riga)
 | |
|     for (bool ok = righelist.move_first(); ok; ok = righelist.move_next())
 | |
|     {
 | |
|       TToken_string& row = sf_righe.row(-1);
 | |
|       //per ogni campo della maschera setta all'interno del record corrente di file
 | |
|       //il valore di quei campi che hanno un field
 | |
|       FOR_EACH_MASK_FIELD(msk, i, f)
 | |
|       {
 | |
|         const TFieldref* fr = f->field();
 | |
|         if (fr != NULL)
 | |
|         {
 | |
|           row.add(fr->read(rec), sf_righe.cid2index(f->dlg()));
 | |
| 
 | |
|           //creatore delle descrizioni al posto della check_row; quest'ultima non si può usare..
 | |
|           //..perchè al cambio di tipo riga impazzisce; si fa solo con il campo codice
 | |
|           const int codice = f->dlg();
 | |
|           if (codice == S_CODRIGA_A || codice == S_CODRIGA_G || codice == S_CODRIGA_S || codice == S_CODRIGA_R)
 | |
|           {
 | |
|             TString80 descr = find_descr(row);
 | |
|             row.add(descr, 2);
 | |
|           }
 | |
|         } //if(fr!=NULL)
 | |
|       } //FOR_EACH_MASK_FIELD
 | |
| 
 | |
|     } //for(bool ok=...
 | |
|   } //if(err==NOERR)
 | |
|   return err;
 | |
| }
 | |
| 
 | |
| int TGestione_listini_semplice::rewrite(const TMask& m)
 | |
| {
 | |
|   int err = TRelation_application::rewrite(m);
 | |
| 
 | |
|   if (err == NOERR && m.curr_page() == 0) // Non salvo le righe stando a pagina 2!
 | |
|     save_rows();
 | |
| 
 | |
|   return err;
 | |
| }
 | |
| 
 | |
| int TGestione_listini_semplice::write(const TMask& m)
 | |
| {
 | |
|   int err = TRelation_application::write(m);
 | |
| 
 | |
|   if(err == NOERR) 
 | |
|     save_rows();
 | |
| 
 | |
|   return err;
 | |
| }
 | |
| 
 | |
| 
 | |
| bool TGestione_listini_semplice::remove()
 | |
| {
 | |
|   //vanno rimosse prima le righe poi la testata (nucleare?)
 | |
|   const TRectype& rec_head = get_relation()->curr();
 | |
| 
 | |
|   TISAM_recordset righelist(build_query(_tipo));
 | |
|   switch (_tipo)
 | |
|   {
 | |
|   case 'C':
 | |
|     righelist.set_var("#TIPOCF", rec_head.get(RCONDV_TIPOCF));
 | |
|     righelist.set_var("#CODCF", rec_head.get(RCONDV_CODCF));
 | |
|     break;
 | |
|   case 'O':
 | |
|     break;
 | |
|   default:  //il default è 'L'
 | |
|     righelist.set_var("#CATVEN", rec_head.get(RCONDV_CATVEN));
 | |
|     break;
 | |
|   }
 | |
|   
 | |
|   righelist.set_var("#COD", rec_head.get(RCONDV_COD));
 | |
|   const long righelist_items = righelist.items();
 | |
|   TProgind pi(righelist_items, TR("Eliminazione righe listino..."), true, true);
 | |
|   //strage di righe!
 | |
|   for (bool ok = righelist.move_first(); ok; ok = righelist.move_next())
 | |
|   {
 | |
|     if (!pi.addstatus(1))
 | |
|       break;
 | |
|     righelist.cursor()->relation()->remove();
 | |
|   }
 | |
| 
 | |
|   //questa rimuove la testata
 | |
|   return (TRelation_application::remove());
 | |
| }
 | |
| 
 | |
| 
 | |
| //metodi per il caricamento e l'invio da files tipo .ini (transizioni)
 | |
| void TGestione_listini_semplice::ini2mask(TConfig& ini, TMask& m, bool query)
 | |
| {
 | |
|   TRelation_application::ini2mask(ini, m, query);
 | |
| 
 | |
|   if (!query)
 | |
|   {
 | |
|     TSheet_field& righe = m.sfield(FA_RIGHE);
 | |
|     righe.destroy();
 | |
|     TMask& rm = righe.sheet_mask();
 | |
| 
 | |
|     for (int r = 1;; r++)
 | |
|     {
 | |
|       TString8 paragraph;
 | |
|       paragraph.format("%d,%d", LF_RCONDV, r);
 | |
|       if (!ini.set_paragraph(paragraph))
 | |
|         break;
 | |
| 
 | |
|       TToken_string& row = righe.row(-1);
 | |
|       FOR_EACH_MASK_FIELD(rm, i, f)
 | |
|       {
 | |
|         const TFieldref* fr = f->field();
 | |
|         if (fr != NULL)
 | |
|         {
 | |
|           const int idx = righe.cid2index(f->dlg());
 | |
|           const TString& val = ini.get(fr->name());
 | |
|           row.add(val, idx);
 | |
|         }
 | |
|       }
 | |
|       righe.check_row(righe.items() - 1);
 | |
|     }
 | |
|     righe.force_update();
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TGestione_listini_semplice::mask2ini(const TMask& m, TConfig& ini)
 | |
| {
 | |
|   TRelation_application::mask2ini(m, ini);
 | |
| 
 | |
|   TString query;
 | |
|   query << "USE RCONDV";
 | |
|   query << "\nFROM TIPO=#TIPO CATVEN=#CATVEN TIPOCF=#TCF CODCF=#CODCF COD=#COD";
 | |
|   query << "\nTO TIPO=#TIPO CATVEN=#CATVEN TIPOCF=#TCF CODCF=#CODCF COD=#COD";
 | |
|   TISAM_recordset rcondv(query);
 | |
| 
 | |
|   TString4 tipo(_tipo);
 | |
|   rcondv.set_var("#TIPO", tipo);
 | |
|   if (_tipo == 'L')
 | |
|     rcondv.set_var("#CATVEN", m.get(CONDV_CATVEN));
 | |
|   else
 | |
|     rcondv.set_var("#CATVEN", "");
 | |
|   if (_tipo == 'C')
 | |
|   {
 | |
|     rcondv.set_var("#TCF", m.get(CONDV_TIPOCF));
 | |
|     rcondv.set_var("#CODCF", m.get(CONDV_CODCF));
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     rcondv.set_var("#TCF", "");
 | |
|     rcondv.set_var("#CODCF", "");
 | |
|   }
 | |
|   rcondv.set_var("#COD", m.get(CONDV_COD));
 | |
|   
 | |
|   const long items = rcondv.items();
 | |
|   TString16 paragraph;
 | |
|   int j = 0;
 | |
| 
 | |
|   for (bool ok = rcondv.move_first(); ok; ok = rcondv.move_next())
 | |
|   {
 | |
|     paragraph.format("%d,%d", LF_RCONDV, ++j);
 | |
|     ini.set_paragraph(paragraph);
 | |
| 
 | |
|     const TRectype& rec = rcondv.cursor()->curr();
 | |
|     const int nfields = rec.items();
 | |
|     for (int i = 0; i < nfields; i++)
 | |
|     {
 | |
|       const char* field_name = rec.fieldname(i);
 | |
|       ini.set(field_name, rec.get(field_name));
 | |
|     }
 | |
|   }
 | |
| 
 | |
| }
 | |
| 
 | |
| void TGestione_listini_semplice::init_query_mode(TMask& m)
 | |
| {
 | |
|   m.disable(DLG_CREA);
 | |
| }
 | |
| 
 | |
| void TGestione_listini_semplice::init_insert_mode(TMask& m)
 | |
| {
 | |
|   m.enable(DLG_CREA);
 | |
| }
 | |
| 
 | |
| void TGestione_listini_semplice::init_modify_mode(TMask& m)
 | |
| {
 | |
|   m.enable(DLG_CREA);
 | |
|   const bool ges_um = m.get_bool(FA_GESTUM);
 | |
| 
 | |
|   TSheet_field& righe = m.sfield(FA_RIGHE);
 | |
|   righe.enable_column(S_UM, ges_um);
 | |
| }
 | |
| 
 | |
| bool TGestione_listini_semplice::user_create()
 | |
| { 
 | |
|   //controlla se la chiave ha l'autorizzazione a questo programma
 | |
|   Tdninst dninst;
 | |
|   if (!dninst.can_I_run(true))
 | |
|     return error_box(TR("Programma non autorizzato!"));
 | |
| 
 | |
|   //decide il tipo di condizione di vendita: 'L'istino, 'C'ontratto 'O'fferta
 | |
|   _tipo = 'L';
 | |
|   if (argc() > 2) //se la chiamata ha un parametro ulteriore ('ve2 -4 c', ad esempio)..
 | |
|   {
 | |
|     TFilename trans = argv(2);  //..prende il parametro ulteriore
 | |
|     if (trans.len() == 1) //se è lungo 1 -> chiamata da menu...
 | |
|       _tipo = trans[0];
 | |
|     else
 | |
|     {
 | |
|       trans.ltrim(2);   //..sennò chiamata interattiva con file .ini
 | |
|       if (trans.exist())
 | |
|       {
 | |
|         TConfig ini(trans, "52");
 | |
|         _tipo = ini.get_char("TIPO");
 | |
|       }
 | |
|     }
 | |
|     _tipo = toupper(_tipo);
 | |
|   }
 | |
|   
 | |
|   _rel = new TRelation(LF_CONDV);
 | |
| 
 | |
|   //attenzione!! questo è il parametro per avere la lunghezza del numero riga sullo sheet
 | |
|   TSheet_field::set_line_number_width(5);
 | |
| 
 | |
|   //super-attenzione! la maschera da caricare viene decisa in base al tipo di condizione di vendita
 | |
|   TString16 mask_name;
 | |
|   mask_name << "ve2500a" << _tipo;
 | |
|   _mask = new  TGestione_listini_semplice_mask(mask_name);
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| bool TGestione_listini_semplice::user_destroy()
 | |
| {             
 | |
|   delete _mask;
 | |
|   delete _rel;
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| int ve2500(int argc, char* argv[])
 | |
| {
 | |
|   TGestione_listini_semplice a; 
 | |
|   a.run(argc, argv, "Gestione listini");
 | |
|   return 0;
 | |
| } |