Files correlati : Ricompilazione Demo : [ ] Commento : Eliminati include inutili git-svn-id: svn://10.65.10.50/trunk@18504 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			309 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			309 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <automask.h>
 | 
						||
#include <reprint.h>
 | 
						||
#include <textset.h>
 | 
						||
 
 | 
						||
#include "lv2300a.h"
 | 
						||
 | 
						||
class TGiri_recordset: public TCSV_recordset
 | 
						||
{
 | 
						||
public:
 | 
						||
  TGiri_recordset(): TCSV_recordset("CSV(\"\t\")") {}
 | 
						||
};
 | 
						||
 | 
						||
//Variabili del singolo giorno contrenenti il codice cliente;
 | 
						||
//ordine fermata e eventualmente l'ora
 | 
						||
struct TPassaggio: public TObject
 | 
						||
{
 | 
						||
  long _codcf;
 | 
						||
  int _ordfer;
 | 
						||
  int _ora;
 | 
						||
  TString4 _iter;
 | 
						||
 | 
						||
  TPassaggio() :_codcf(0),_ordfer(0),_ora(0) {}
 | 
						||
  TPassaggio(long codcf, int ordfer, int ora, const TString& iter) :_codcf(codcf),_ordfer(ordfer),_ora(ora),_iter(iter) {}
 | 
						||
};
 | 
						||
 | 
						||
class TPassaggi: public TArray
 | 
						||
{
 | 
						||
  int _count;
 | 
						||
public:
 | 
						||
  void add(TPassaggio* p);
 | 
						||
  TPassaggio& passaggio(int p);
 | 
						||
};
 | 
						||
 | 
						||
TPassaggio& TPassaggi:: passaggio(int p)
 | 
						||
{
 | 
						||
  TPassaggio* h = (TPassaggio*)objptr(p);
 | 
						||
 | 
						||
  if(h==NULL)
 | 
						||
  {
 | 
						||
    h = new TPassaggio();
 | 
						||
    TArray::add(h,p);
 | 
						||
  }  
 | 
						||
  return *h;
 | 
						||
}
 | 
						||
 | 
						||
void TPassaggi::add(TPassaggio* p)
 | 
						||
{
 | 
						||
  const int of = p->_ordfer;
 | 
						||
  if(of>0 && of<1000)
 | 
						||
  {
 | 
						||
    int first=0;
 | 
						||
    int last=_count-1;
 | 
						||
    int guess=0;
 | 
						||
    while(first<=last)
 | 
						||
    {
 | 
						||
      guess=(first+last)/2;
 | 
						||
      TPassaggio& h = passaggio(guess);
 | 
						||
      if(h._ordfer==p->_ordfer)
 | 
						||
        break;
 | 
						||
 | 
						||
      if(h._ordfer>p->_ordfer)
 | 
						||
        last=guess-1;
 | 
						||
      else
 | 
						||
        first=guess+1;
 | 
						||
    }
 | 
						||
    TArray::insert(p,guess);
 | 
						||
    _count++;
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    TArray::add(p);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
//Tutti i passaggi settimanali di un singolo itinerario
 | 
						||
class TSettimana: public TArray
 | 
						||
{
 | 
						||
public:
 | 
						||
  void add(int g,TPassaggio* p);
 | 
						||
  TPassaggio& passaggio(int g, int p);//giorno, fermata
 | 
						||
  int passaggi(int g) const;
 | 
						||
  int passaggi() const;
 | 
						||
  TSettimana():TArray(7){}//7 gg = settimana
 | 
						||
};
 | 
						||
 | 
						||
//Tutti i records all'interno del giorno
 | 
						||
int TSettimana::passaggi(int g) const
 | 
						||
{
 | 
						||
  int n=0;
 | 
						||
  TArray* p= (TArray* ) objptr(g);
 | 
						||
  if(p!=NULL) n=p->items();
 | 
						||
 | 
						||
  return n;
 | 
						||
}
 | 
						||
 | 
						||
//Ritorno il numero di elementi con + passaggi
 | 
						||
int TSettimana::passaggi() const
 | 
						||
{
 | 
						||
  int n=0;
 | 
						||
  FOR_EACH_ARRAY_ITEM((*this), i, obj)
 | 
						||
  {
 | 
						||
    TArray* p = (TArray*) obj;
 | 
						||
    const int e = p->items();
 | 
						||
    if(e>n) n=e;
 | 
						||
  }
 | 
						||
  return n;
 | 
						||
}
 | 
						||
 | 
						||
void TSettimana::add(int g,TPassaggio* p)
 | 
						||
{
 | 
						||
  TPassaggi* a= (TPassaggi*) objptr(g);
 | 
						||
  if(a==NULL)
 | 
						||
  {
 | 
						||
    a=new TPassaggi();
 | 
						||
    TArray::add(a,g);
 | 
						||
  }
 | 
						||
  a->add(p);
 | 
						||
  
 | 
						||
}
 | 
						||
 | 
						||
TPassaggio& TSettimana ::passaggio(int g,int p)
 | 
						||
{
 | 
						||
  TPassaggi* a= (TPassaggi*) objptr(g);
 | 
						||
  if(a==NULL)
 | 
						||
  {
 | 
						||
    a=new TPassaggi();
 | 
						||
    TArray::add(a,g);
 | 
						||
  }
 | 
						||
  return a->passaggio(p);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
class TItinerari: public TArray
 | 
						||
{
 | 
						||
public:
 | 
						||
  void add(long i,int g,TPassaggio* p);
 | 
						||
  void add(long i,int g,long codcf, int ordfer, int ora,TString iter);
 | 
						||
  TSettimana& settimana(long codIti);
 | 
						||
};
 | 
						||
 | 
						||
void TItinerari::add(long i,int g,TPassaggio* p)
 | 
						||
{
 | 
						||
  settimana(i).add(g,p);
 | 
						||
}
 | 
						||
 | 
						||
void TItinerari::add(long i,int g,long codcf, int ordfer, int ora, TString iter)
 | 
						||
{
 | 
						||
  TPassaggio* p = new TPassaggio(codcf,ordfer,ora,iter);
 | 
						||
  add(i,g,p);
 | 
						||
}
 | 
						||
TSettimana& TItinerari::settimana(long codIti)
 | 
						||
{
 | 
						||
  TSettimana* a = (TSettimana*)objptr(codIti);
 | 
						||
  if(a==NULL)
 | 
						||
  {
 | 
						||
    a = new TSettimana;
 | 
						||
    TArray::add(a,codIti);
 | 
						||
  }
 | 
						||
  return *a;
 | 
						||
}
 | 
						||
 | 
						||
class TGiri_mask: public TAutomask
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
public:
 | 
						||
  TGiri_mask():TAutomask("lv2300a"){}
 | 
						||
};
 | 
						||
 | 
						||
bool TGiri_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						||
{
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
class TGiri_report : public TReport
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual bool use_mask() { return false; }
 | 
						||
 | 
						||
public:
 | 
						||
  TGiri_report(bool settimanale) { load(settimanale ? "lv2300a" : "lv2200z"); }
 | 
						||
};
 | 
						||
 | 
						||
class TGiri_app: public TSkeleton_application
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual void main_loop();
 | 
						||
  void elabora(const TMask& mask) const;
 | 
						||
};
 | 
						||
 | 
						||
void TGiri_app::elabora(const TMask& mask) const
 | 
						||
{
 | 
						||
  TISAM_recordset giri("USE LVRCONSPLAN KEY 2\n"
 | 
						||
                       "SELECT (BETWEEN(CODITI,#FROM_CODITI,#TO_CODITI))"
 | 
						||
                       "&&(BETWEEN(CODCF,#FROM_CODCF,#TO_CODCF))"
 | 
						||
                       "&&(BETWEEN(CODAUT,#FROM_CODAUT,#TO_CODAUT))\n"
 | 
						||
                       "FROM DTCONS=#FROM_DATA\n "
 | 
						||
                       "TO DTCONS=#TO_DATA"
 | 
						||
                       );
 | 
						||
 | 
						||
  //inserire parametri filtri
 | 
						||
  giri.set_var("#FROM_DATA",mask.get_date(F_DATA_FROM));
 | 
						||
  giri.set_var("#TO_DATA",mask.get_date(F_DATA_TO));  
 | 
						||
  giri.set_var("#FROM_CODITI", TVariant(mask.get(F_CODITI_FROM)));
 | 
						||
  giri.set_var("#TO_CODITI",TVariant(mask.get(F_CODITI_TO)));
 | 
						||
  giri.set_var("#FROM_CODAUT",TVariant(mask.get(F_CODAUT_FROM)));
 | 
						||
  giri.set_var("#TO_CODAUT",TVariant(mask.get(F_CODAUT_TO)));
 | 
						||
  giri.set_var("#FROM_CODCF",TVariant(mask.get(F_CODCF_FROM)));
 | 
						||
  giri.set_var("#TO_CODCF",TVariant(mask.get(F_CODCF_TO)));
 | 
						||
 | 
						||
  TItinerari iti;
 | 
						||
 | 
						||
  for(bool ok = giri.move_first();ok;ok=giri.move_next())
 | 
						||
  {
 | 
						||
    TDate giorno = giri.get("DTCONS").as_date();  
 | 
						||
    int wday = giorno.wday();//1=luned<65>
 | 
						||
    long itinerario=giri.get("CODITI").as_int();
 | 
						||
    TString iter=giri.get("CODITI").as_string();
 | 
						||
    long cliente=giri.get("CODCF").as_int();
 | 
						||
    int ordfer=giri.get("ORDFER").as_int();
 | 
						||
    int ora = 0;//in attesa che venga inserito
 | 
						||
 | 
						||
    iti.add(itinerario,wday,cliente,ordfer,ora,iter);
 | 
						||
  }
 | 
						||
 | 
						||
 
 | 
						||
  TGiri_report r(true);
 | 
						||
  TGiri_recordset* giri_set = new TGiri_recordset();
 | 
						||
  r.set_recordset(giri_set);
 | 
						||
  FOR_EACH_ARRAY_ITEM(iti,i,obj)//scandisce itinerario e tiene
 | 
						||
    //buoni solo quelli valorizzati
 | 
						||
  {
 | 
						||
    TSettimana& s = *(TSettimana*) obj;
 | 
						||
    const int max = s.passaggi();
 | 
						||
 | 
						||
    for(int j=0; j<max;j++)
 | 
						||
    {
 | 
						||
      giri_set->new_rec();
 | 
						||
 | 
						||
      TString4 str_iti;
 | 
						||
      str_iti.format("%03d", i);
 | 
						||
      giri_set->set(0,TVariant(str_iti));
 | 
						||
      
 | 
						||
      for(int g=1; g<=7;g++)
 | 
						||
      {
 | 
						||
        const TPassaggio& pass = s.passaggio(g,j);
 | 
						||
        const int column = (g-1)*3+1;
 | 
						||
        
 | 
						||
        giri_set->set(column,pass._codcf);
 | 
						||
        giri_set->set(column + 1,TVariant(long (pass._ordfer)));
 | 
						||
        giri_set->set(column + 2,TVariant(long (pass._ora)));
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
 | 
						||
  // riporta tutte le variabili del report.
 | 
						||
  const TString_array& vars = giri.variables();
 | 
						||
  FOR_EACH_ARRAY_ROW(vars, v, var)
 | 
						||
  {
 | 
						||
    const char* varname = var->get(0);
 | 
						||
    giri_set->set_var(varname, giri.get_var(varname), true);
 | 
						||
  }
 | 
						||
 | 
						||
  TReport_book b;
 | 
						||
  bool ok = b.add(r);// Richiede parametri di stampa in base alla maschera omonima
 | 
						||
  if (ok)
 | 
						||
  {
 | 
						||
    if (b.pages() > 0)
 | 
						||
      b.print_or_preview(); // Stampa effettivamente
 | 
						||
    else
 | 
						||
      warning_box (TR("Nessun record estratto per i parametri inseriti"));
 | 
						||
  } 
 | 
						||
}
 | 
						||
 | 
						||
void TGiri_app::main_loop()
 | 
						||
{
 | 
						||
  TGiri_mask m;
 | 
						||
  while(m.run()==K_ENTER)
 | 
						||
  {
 | 
						||
    if(m.get(F_CHOICE)=="S")
 | 
						||
    {
 | 
						||
      elabora(m);  //Stampa Giro Settimanale
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      TGiri_report r(false); //Stampa Giro Giornaliero
 | 
						||
      r.mask2report(m);
 | 
						||
      TReport_book b;
 | 
						||
      bool ok = b.add(r);          // Richiede parametri di stampa in base alla maschera omonima
 | 
						||
      if (ok)
 | 
						||
      {
 | 
						||
        if (b.pages() > 0)
 | 
						||
          b.print_or_preview(); // Stampa effettivamente
 | 
						||
        else
 | 
						||
          warning_box (TR("Nessun record estratto per i parametri inseriti"));
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }  
 | 
						||
}
 | 
						||
 | 
						||
int lv2300(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TGiri_app app;
 | 
						||
  app.run(argc, argv, TR("Stampa Giri"));
 | 
						||
  return 0;
 | 
						||
}
 |