Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 650 git-svn-id: svn://10.65.10.50/trunk@14148 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			283 lines
		
	
	
		
			7.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			283 lines
		
	
	
		
			7.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <automask.h>
 | |
| #include <browfile.h>
 | |
| #include <filetext.h>
 | |
| #include <prefix.h>
 | |
| #include <progind.h>
 | |
| #include <recarray.h>
 | |
| #include <tabutil.h>
 | |
| #include <utility.h>
 | |
| #include <viswin.h>
 | |
| 
 | |
| #include "ps0816.h"
 | |
| #include "ps0816100a.h"
 | |
| 
 | |
| class TMaskPs0816 : public TAutomask
 | |
| {
 | |
| protected:
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
| public:
 | |
|   TMaskPs0816() : TAutomask("ps0816100a") { }
 | |
|   virtual ~TMaskPs0816() { }
 | |
| };
 | |
| 
 | |
| bool TMaskPs0816::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | |
| {
 | |
|   const short id = o.dlg();
 | |
|   switch(id)
 | |
|   {
 | |
|     case F_SFILE: 
 | |
|     case F_FFILE:
 | |
|     {
 | |
|       if (e == fe_modify || e == fe_close)
 | |
|       {
 | |
|         TFilename name = o.get();
 | |
|         if (!name.exist())
 | |
|           return error_box("File non valido");
 | |
|       }
 | |
|       break;
 | |
|     }
 | |
|     case F_LISTINO: 
 | |
|     {
 | |
|       if (e == fe_modify || e == fe_close)
 | |
|       {
 | |
|         char listino = o.get()[0];
 | |
|       }
 | |
|       break;
 | |
|     }
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| class TListinoPs0816 : public TSkeleton_application  
 | |
| {
 | |
| 	virtual bool check_autorization() const {return false;}
 | |
|   virtual const char * extra_modules() const {return "ve";}
 | |
| 
 | |
| protected:
 | |
|   virtual void main_loop();
 | |
| 
 | |
| public:
 | |
|   void mask2ini(TMask& m, bool load = FALSE);
 | |
|   void ini2mask(TMask& m) { mask2ini(m, TRUE); }
 | |
|   void import_listino(const TMask& m);
 | |
| };
 | |
| 
 | |
| void TListinoPs0816::import_listino(const TMask& m)
 | |
| {
 | |
|   TString msg;
 | |
|   TString16 marca;
 | |
|   TString80 codart, campo;
 | |
|   TFilename filetxt;
 | |
|   bool caricalistino = TRUE;
 | |
|   
 | |
|   const char listino = m.get(F_LISTINO)[0];
 | |
|   TAssoc_array marche;
 | |
|   if (listino == 'S')
 | |
|   {
 | |
|     for (short id = F_SMARCA1; id <= F_SMARCA12; id++)
 | |
|     { 
 | |
|       TString16 marca = m.field(id).get();
 | |
|       if (!marca.blank())
 | |
|         marche.add((const char*) marca);
 | |
|     }   
 | |
|     filetxt = m.get(F_SFILE);
 | |
|   }  
 | |
|   else
 | |
|   {
 | |
|     for (short id = F_FMARCA1; id <= F_FMARCA12; id++)
 | |
|     { 
 | |
|       TString16 marca = m.field(id).get();
 | |
|       if (!marca.blank())
 | |
|         marche.add((const char*) marca);
 | |
|     }   
 | |
|     filetxt = m.get(F_FFILE);
 | |
|   } 
 | |
|   msg = "Importazione listino ";
 | |
|   msg << filetxt;
 | |
|   TProgind pi(::fsize(filetxt), msg, TRUE, TRUE);
 | |
|   TString16 fileini, confini;
 | |
|   fileini = "ps0816102";  // contiene la descrizione del file di testo
 | |
|   fileini << listino;
 | |
|   fileini << ".ini";
 | |
|   TFile_text file(filetxt, fileini);
 | |
|   confini  = "ps0816101"; // contiene i valori standard dei campi
 | |
|   confini << listino;
 | |
|   confini << ".ini";
 | |
|   TConfig config(confini);
 | |
|   TAssoc_array var_anamag = config.list_variables("LF_ANAMAG");
 | |
|   TAssoc_array var_umart = config.list_variables("LF_UMART");
 | |
|   TAssoc_array var_condv = config.list_variables("LF_CONDV");
 | |
|   TAssoc_array var_rcondv = config.list_variables("LF_RCONDV");
 | |
|   
 | |
|   file.kill_zero_only();
 | |
| 
 | |
|   long valid = 0;
 | |
| 
 | |
|   //msg.insert("@b", 0);
 | |
| 
 | |
|   TRelation rel(LF_RCONDV);
 | |
|   rel.add(LF_CONDV,"TIPO==TIPO|CATVEN==CATVEN|TIPOCF==TIPOCF|CODCF==CODCF|COD==COD");
 | |
|   rel.add(LF_ANAMAG,"CODART==CODART");
 | |
|   rel.add(LF_UMART,"CODART==CODART|UM==UM");
 | |
|   TLocalisamfile& rcondv = rel.lfile();
 | |
|   TLocalisamfile& condv = rel.lfile(LF_CONDV);
 | |
|   TLocalisamfile& anamag = rel.lfile(LF_ANAMAG);
 | |
|   TLocalisamfile& umart = rel.lfile(LF_UMART);
 | |
|   const int numcar = config.get_int("MARCA", "MAIN");
 | |
|   const char carattere = config.get_char("CARATTEREMARCA", "MAIN");
 | |
|   caricalistino = (config.get("LISTINO", "MAIN")[0] == 'S');
 | |
|   const TString80 campomarca = config.get("CAMPOMARCA", "MAIN");
 | |
|   TRecord_text curr;
 | |
|   while (file.read(curr) == NOERR)
 | |
|   {
 | |
|     pi.setstatus(file.read_file()->tellg());
 | |
|     if (pi.iscancelled())
 | |
|       break;
 | |
|     codart = file.get_field(curr, "CODICE ARTICOLO");
 | |
|     marca = file.get_field(curr, campomarca).sub(0,numcar);
 | |
|     if (listino == 'S')
 | |
|     {
 | |
|       TString80 strtmp = codart.sub(marca.len());
 | |
|       while (marca.len() < 3)
 | |
|         marca << ' ';
 | |
|       codart = marca;
 | |
|       codart << strtmp;
 | |
|     } 
 | |
|     else                   
 | |
|     {               
 | |
|       TString80 strtmp = marca;
 | |
|       strtmp << codart;
 | |
|       codart = strtmp;
 | |
|     } 
 | |
|     marca.trim();     
 | |
|     if (marche.is_key(marca))
 | |
|     {
 | |
|       while (marca.len() < 3)
 | |
|       {
 | |
|         TString80 strtmp = "";
 | |
|         strtmp << carattere << marca;
 | |
|         marca = strtmp;
 | |
|       } 
 | |
|       if (caricalistino)
 | |
|       {
 | |
|         rcondv.zero();
 | |
|         rcondv.put("TIPO", "L");
 | |
|         rcondv.put("CATVEN", config.get("CATVEN","LF_RCONDV"));
 | |
|         rcondv.put("TIPOCF", "");
 | |
|         rcondv.put("CODCF", "");
 | |
|         rcondv.put("COD", config.get("COD","LF_RCONDV"));
 | |
|         rcondv.put("TIPORIGA", config.get("TIPORIGA","LF_RCONDV"));
 | |
|         rcondv.put("CODRIGA", codart);
 | |
|         rcondv.put("UM", config.get("UM","LF_RCONDV"));
 | |
|         rcondv.put("NSCAGL", config.get("NSCAGL","LF_RCONDV"));
 | |
|         if (!rcondv.read() == NOERR)
 | |
|         {
 | |
|           FOR_EACH_ASSOC_STRING(var_rcondv, obj, key, val)
 | |
|             rcondv.put(key,val);
 | |
|         }           
 | |
|         if (listino == 'F')
 | |
|         {
 | |
|           const real divisore(file.get_field(curr, "DIVISORE")); 
 | |
|           if (divisore > 1.00)
 | |
|           {
 | |
|             real prezzo = rcondv.get("PREZZO");
 | |
|             prezzo /= divisore;
 | |
|             rcondv.put("PREZZO", prezzo);
 | |
|           }
 | |
|         }
 | |
|         const int err = file.autosave(rel, curr);
 | |
|         valid++;
 | |
|         condv.zero();
 | |
|         FOR_EACH_ASSOC_STRING(var_condv, obj, key, val)
 | |
|           condv.put(key,val);
 | |
|         TRectype condv_curr = condv.curr();
 | |
|         if (!condv.read() == NOERR)
 | |
|           condv.write(condv_curr);
 | |
|       }   
 | |
|       anamag.zero();
 | |
|       anamag.put("CODART", codart);
 | |
|       if (!anamag.read() == NOERR)
 | |
|       {
 | |
|         FOR_EACH_ASSOC_STRING(var_anamag, obj, key, val)
 | |
|           anamag.put(key,val);
 | |
|         anamag.put("CODART", codart);
 | |
|         anamag.put("DESCR", file.get_field(curr, "DESCRIZIONE ARTICOLO"));
 | |
|         anamag.put("GRMERC", marca);
 | |
|         anamag.write();
 | |
|       }       
 | |
|       //config.set_paragraph("LF_UMART");
 | |
|       umart.zero();
 | |
|       umart.put("CODART", codart);
 | |
|       umart.put("NRIGA", 1);
 | |
|       int err = umart.read();
 | |
|       if (!err == NOERR)
 | |
|       {   
 | |
|         FOR_EACH_ASSOC_STRING(var_umart, obj, key, val)
 | |
|           umart.put(key,val);
 | |
|         umart.put("CODART", codart);
 | |
|         umart.put("NRIGA", 1);    
 | |
|         TString16 um = file.get_field(curr, "UNITA DI MISURA");
 | |
|         um.upper();
 | |
|         umart.put("UM", um);
 | |
|         umart.write();
 | |
|         err=NOERR;
 | |
|       }          
 | |
|       if (!caricalistino)
 | |
|         if (err==NOERR)
 | |
|         {
 | |
|           real prezzo = file.get_field(curr, "PREZZO");
 | |
|           if (listino == 'F')
 | |
|           {
 | |
|             const real divisore(file.get_field(curr, "DIVISORE")); 
 | |
| 
 | |
|             if (divisore > 1.00)
 | |
|               prezzo /= divisore;
 | |
|           }
 | |
|           umart.put("PREZZO", prezzo);
 | |
|           umart.rewrite();
 | |
|           valid++;
 | |
|         } 
 | |
|     }
 | |
|   }                    
 | |
|   warning_box("Operazione terminata: %d prezzi aggiornati", valid);
 | |
| }
 | |
| 
 | |
| void TListinoPs0816::mask2ini(TMask& m, bool load)
 | |
| {
 | |
|   TConfig cfg(CONFIG_DITTA, "ps0816");
 | |
|   TString16 id;
 | |
|   
 | |
|   for (int f = m.fields()-1; f >= 0; f--)
 | |
|   {
 | |
|     TMask_field& fld = m.fld(f);
 | |
|     if (fld.is_edit())
 | |
|     {
 | |
|       id.format("%d", fld.dlg());
 | |
|       if (load)
 | |
|         fld.set(cfg.get(id));
 | |
|       else
 | |
|         cfg.set(id, fld.get());
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TListinoPs0816::main_loop()
 | |
| {
 | |
|   TMaskPs0816 m;
 | |
|   ini2mask(m);
 | |
|   while (m.run() == K_ENTER)
 | |
|   {
 | |
|     import_listino(m);
 | |
|     mask2ini(m);
 | |
|   }
 | |
| }
 | |
| 
 | |
| int ps0816100(int argc, char* argv[])
 | |
| {
 | |
|   TListinoPs0816 a;
 | |
|   a.run(argc, argv, "Caricamento listino personalizzato per AeC");
 | |
|   return 0;
 | |
| }
 |