Files correlati :si0.exe Ricompilazione Demo : [ ] Commento :messo un if (anno !=0) git-svn-id: svn://10.65.10.50/trunk@10752 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			248 lines
		
	
	
		
			6.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			248 lines
		
	
	
		
			6.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
//////////////////////////////////////////////////////////////
 | 
						|
// Stampa documenti
 | 
						|
//////////////////////////////////////////////////////////////
 | 
						|
 | 
						|
#include <applicat.h>
 | 
						|
#include <config.h>
 | 
						|
#include <defmask.h>
 | 
						|
#include <form.h>
 | 
						|
#include <printer.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <sheet.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include <doc.h>
 | 
						|
#include <rdoc.h>
 | 
						|
#include "../ve/velib.h"
 | 
						|
 | 
						|
#include "si0200a.h"
 | 
						|
 | 
						|
class TDocisamfile : public TLocalisamfile
 | 
						|
{
 | 
						|
  TDocumento _doc;
 | 
						|
 | 
						|
public:
 | 
						|
  virtual TRectype& curr() const { return (TRectype&) _doc; }
 | 
						|
  virtual int readat(TRecnotype nrec, word lockop = _nolock);
 | 
						|
  TDocisamfile() : TLocalisamfile(LF_DOC) {}
 | 
						|
  virtual ~TDocisamfile() {};
 | 
						|
};
 | 
						|
 | 
						|
int TDocisamfile::readat(TRecnotype nrec, word lockop)
 | 
						|
{
 | 
						|
  int err = TBaseisamfile::readat(nrec, _nolock);
 | 
						|
  if (err == NOERR)
 | 
						|
    err = _doc.read(TBaseisamfile::curr());
 | 
						|
  return err;
 | 
						|
}
 | 
						|
 | 
						|
class TListe_form : public TForm
 | 
						|
{
 | 
						|
 | 
						|
// @access Protected Member
 | 
						|
protected:
 | 
						|
 | 
						|
public:               
 | 
						|
  virtual bool validate(TForm_item& fld, TToken_string& val);
 | 
						|
  TListe_form(const char* form, const char * code = "", int editlevel = 0, const char* desc = "");
 | 
						|
  virtual ~TListe_form() {}
 | 
						|
};
 | 
						|
 | 
						|
bool TListe_form::validate(TForm_item& fld, TToken_string& val)
 | 
						|
{   
 | 
						|
  return TForm::validate(fld, val);
 | 
						|
}
 | 
						|
 | 
						|
TListe_form::TListe_form(const char* form, const char* code, int editlevel, const char* desc) 
 | 
						|
           : TForm(form, code, editlevel, desc) 
 | 
						|
{
 | 
						|
  const int num = relation()->lfile().num();
 | 
						|
  
 | 
						|
  if (num == LF_DOC)
 | 
						|
    relation()->lfile().set_curr(new TDocumento);
 | 
						|
}
 | 
						|
 | 
						|
class TListe_application: public TSkeleton_application
 | 
						|
{            
 | 
						|
  TMask * _select_mask;
 | 
						|
  TListe_form * _form;              
 | 
						|
  TFilename _formname;   
 | 
						|
  
 | 
						|
protected:
 | 
						|
  virtual bool create();
 | 
						|
  virtual bool destroy();
 | 
						|
  char tipo_lista() const { return _formname[6]; }
 | 
						|
  void set_limits();
 | 
						|
  virtual void main_loop();
 | 
						|
  virtual const char * extra_modules() const { return "BA"; }
 | 
						|
 | 
						|
public:
 | 
						|
  TListe_application() : _select_mask(NULL), _form(NULL) {};
 | 
						|
  virtual ~TListe_application() {};
 | 
						|
};
 | 
						|
 | 
						|
inline TListe_application& app() { return (TListe_application&) main_app(); }
 | 
						|
 | 
						|
bool TListe_application::create()
 | 
						|
{             
 | 
						|
  if (argc() < 3)
 | 
						|
    return error_box("manca il nome del form di stampa");
 | 
						|
 | 
						|
  open_files(LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG, LF_SCONTI, LF_UMART, 
 | 
						|
             LF_TAB, LF_TABCOM, LF_CLIFO, LF_CFVEN, LF_INDSP, LF_OCCAS, LF_PCON,
 | 
						|
             LF_MOVMAG, LF_RMOVMAG, LF_MAG, LF_SVRIEP, LF_AGENTI, LF_PERCPROV, LF_ATTIV, LF_CAUSALI, 0);
 | 
						|
  _formname = argv(2);                                 
 | 
						|
  _select_mask = new TMask("si0200a");
 | 
						|
  _form = new TListe_form(_formname);
 | 
						|
  
 | 
						|
  return TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
void TListe_application::set_limits()
 | 
						|
{     
 | 
						|
  TCursor * c = _form->cursor(); 
 | 
						|
  TRelation * r = c->relation(); 
 | 
						|
  const int headlnum = r->lfile().num();
 | 
						|
  TString16 tipo(_select_mask->get(F_TIPOCF));
 | 
						|
  TString16 cli_fr(_select_mask->get(F_CODFR));
 | 
						|
  TString16 cli_to(_select_mask->get(F_CODTO));
 | 
						|
  TRectype from(LF_CLIFO);
 | 
						|
  from.put("TIPOCF", tipo);
 | 
						|
  TRectype to(from);           
 | 
						|
  
 | 
						|
  TString filter("(");   
 | 
						|
  if (headlnum == LF_DOC)
 | 
						|
  {
 | 
						|
    if (cli_fr.empty() && cli_to.empty())
 | 
						|
    {      
 | 
						|
      TString16 rag_fr(_select_mask->get(F_RAGSOCFR));
 | 
						|
      if (rag_fr.not_empty())
 | 
						|
        filter << format("&&(20->RAGSOC>=\"%s\")", (const char *) rag_fr);
 | 
						|
      TString16 rag_to(_select_mask->get(F_RAGSOCTO));
 | 
						|
      if (rag_to.not_empty())
 | 
						|
        filter << format("&&(20->RAGSOC<=\"%s\")", (const char *) rag_to);
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      TString16 cli_fr(_select_mask->get(F_CODFR));
 | 
						|
      if (cli_fr.not_empty())
 | 
						|
        from.put("CODCF", cli_fr);
 | 
						|
      TString16 rag_to(_select_mask->get(F_CODTO));
 | 
						|
      if (rag_to.not_empty())
 | 
						|
        to.put("CODCF", cli_to);
 | 
						|
      c->setkey(2);
 | 
						|
    }                  
 | 
						|
    c->setregion(from, to);
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    if (cli_fr.empty() && cli_to.empty())
 | 
						|
    {      
 | 
						|
      TString16 rag_fr(_select_mask->get(F_RAGSOCFR));
 | 
						|
      if (rag_fr.not_empty())
 | 
						|
        filter << format("&&(20->RAGSOC>=\"%s\")", (const char *) rag_fr);
 | 
						|
      TString16 rag_to(_select_mask->get(F_RAGSOCTO));
 | 
						|
      if (rag_to.not_empty())
 | 
						|
        filter << format("&&(20->RAGSOC<=\"%s\")", (const char *) rag_to);
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      TString16 cli_fr(_select_mask->get(F_CODFR));
 | 
						|
      if (cli_fr.not_empty())
 | 
						|
        from.put("CODCF", cli_fr);
 | 
						|
      TString16 rag_to(_select_mask->get(F_CODTO));
 | 
						|
      if (rag_to.not_empty())
 | 
						|
        to.put("CODCF", cli_to);
 | 
						|
    }                  
 | 
						|
  }
 | 
						|
  if (filter != "(")
 | 
						|
    filter << "&&";
 | 
						|
  if (_select_mask->get_int(F_ANNO) != 0)
 | 
						|
    filter << format("(ANNO==%d)", _select_mask->get_int(F_ANNO));
 | 
						|
  filter << format("&&(PROVV==\"%c\")", _select_mask->get(F_PROVV)[0]);   
 | 
						|
  
 | 
						|
  TSheet_field & s = _select_mask->sfield(F_SHEETNUMS);   
 | 
						|
  const int rows = s.items();
 | 
						|
  
 | 
						|
  if (rows > 0)
 | 
						|
  { 
 | 
						|
    TString sw, e1, e2;
 | 
						|
    
 | 
						|
    for (int j=0; j<rows; j++)
 | 
						|
    {
 | 
						|
      TToken_string& riga = s.row(j);
 | 
						|
 | 
						|
      sw = riga.get(0);sw.trim();
 | 
						|
      if (riga.empty_items() || sw.empty())
 | 
						|
        break; // Interrompe alla prima riga vuota...
 | 
						|
      
 | 
						|
      e1.format("(CODNUM==\"%s\"", (const char*)sw);
 | 
						|
      e2 = "";
 | 
						|
      for (int k=1; k<=6; k++) // Famme vede' li stati generali... Aho' A BURINO! Che e' la Rivoluzione Francese?
 | 
						|
      {
 | 
						|
        const char c = riga.get(k)[0];
 | 
						|
        if (c == '\0' || c == ' ')
 | 
						|
          break; // Interrompe al primo blank... 
 | 
						|
        e2.format("(33->STATO==\"%c\")",c);
 | 
						|
        // Se k vale 2 o piu' significa ke gli stati prec erano != "" no!?
 | 
						|
        if (k == 1)
 | 
						|
          e1 << "&&(";
 | 
						|
        else
 | 
						|
          e1 << "||";
 | 
						|
        e1 << e2;
 | 
						|
      }
 | 
						|
      if (e2.not_empty())
 | 
						|
        e1 << ")";
 | 
						|
      e1 << ")";   // Piazza la parentesi finale
 | 
						|
      
 | 
						|
      if (j == 0)
 | 
						|
        filter << "&&(";
 | 
						|
      else
 | 
						|
        filter << "||";
 | 
						|
        
 | 
						|
      filter << e1;
 | 
						|
    }
 | 
						|
    filter << ")";      // Parentesi finale
 | 
						|
  }
 | 
						|
  TDate data_fr(_select_mask->get(F_DA_DATADOC));
 | 
						|
  if (data_fr.ok())
 | 
						|
    filter << format("&&(ANSI(33->DATADOC)>=\"%s\")", (const char *) data_fr.string(ANSI));
 | 
						|
  TDate data_to(_select_mask->get(F_A_DATADOC));
 | 
						|
  if (data_to.ok())
 | 
						|
    filter << format("&&(ANSI(33->DATADOC)<=\"%s\")", (const char *) data_to.string(ANSI));
 | 
						|
  TString80 art_fr(_select_mask->get(F_SERVFR));
 | 
						|
  if (art_fr.not_empty())
 | 
						|
    filter << format("&&(34->CODARTMAG>=\"%s\")", (const char *) art_fr);
 | 
						|
  TString80 art_to(_select_mask->get(F_SERVTO));
 | 
						|
  if (art_to.not_empty())
 | 
						|
    filter << format("&&(34->CODARTMAG<=\"%s\")", (const char *) art_to);
 | 
						|
  filter << ")";     
 | 
						|
  
 | 
						|
  c->setfilter(filter, TRUE);
 | 
						|
}
 | 
						|
 | 
						|
bool TListe_application::destroy()
 | 
						|
{
 | 
						|
  delete _select_mask;
 | 
						|
  delete _form;
 | 
						|
  return TApplication::destroy();
 | 
						|
}
 | 
						|
 | 
						|
void TListe_application::main_loop()
 | 
						|
{
 | 
						|
  while (_select_mask->run() != K_ESC)
 | 
						|
  {                         
 | 
						|
    set_limits();
 | 
						|
    _form->print();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
// Do all the work!
 | 
						|
int si0200(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TListe_application a;
 | 
						|
  a.run(argc, argv, "Lista documenti");
 | 
						|
  return (0);
 | 
						|
}
 | 
						|
 |