Files correlati : Ricompilazione Demo : [ ] Commento :accoppato vereplib e sostituito con il piu' avanzato velib07 in modo che funzioni CI git-svn-id: svn://10.65.10.50/trunk@14672 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			426 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			426 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <automask.h>
 | 
						||
#include <progind.h>
 | 
						||
#include <reprint.h>
 | 
						||
 | 
						||
#include "ci1200.h"
 | 
						||
 | 
						||
#include "../ca/calib01.h"
 | 
						||
#include "../ca/rmovana.h"
 | 
						||
#include "../ve/velib07.h"
 | 
						||
 | 
						||
#include "../include/doc.h"
 | 
						||
#include "../include/rdoc.h"
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TRiepiloghi_mask
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TRiepiloghi_mask : public TAutomask
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
 | 
						||
  int create_sheet_fields(int lf, int& y, short& dlg, bool required = false);
 | 
						||
  void create_sheet();
 | 
						||
 | 
						||
public:
 | 
						||
  TRiepiloghi_mask();
 | 
						||
};
 | 
						||
 | 
						||
int TRiepiloghi_mask::create_sheet_fields(int lf, int& y, short& dlg, bool required)
 | 
						||
{
 | 
						||
	TSheet_field& sf = sfield(F_COMMESSE);
 | 
						||
  TMask& sm = sf.sheet_mask();
 | 
						||
 | 
						||
  const char* field = NULL;
 | 
						||
  switch (lf)
 | 
						||
  {
 | 
						||
  case LF_CDC : field = RMOVANA_CODCCOSTO; break;
 | 
						||
  case LF_FASI: field = RMOVANA_CODFASE; break;
 | 
						||
  default     : field = RMOVANA_CODCMS; break;
 | 
						||
  }
 | 
						||
  const int h = ca_create_fields(sm, 0, lf, 1, y, dlg, dlg+50, 0, field);
 | 
						||
 | 
						||
  for (int i = 0; i < h; i++)
 | 
						||
  {
 | 
						||
    TEdit_field& fld = sm.efield(dlg+i);
 | 
						||
    fld.check_type(required ? CHECK_REQUIRED : CHECK_NORMAL);
 | 
						||
 | 
						||
    TEdit_field& dfld = sm.efield(dlg+50+i);
 | 
						||
    dfld.set_field(EMPTY_STRING); // Toglie campi che fan saltare gli output!
 | 
						||
  }
 | 
						||
 | 
						||
  y += h+1;
 | 
						||
  dlg += h;
 | 
						||
 | 
						||
  return h;
 | 
						||
}
 | 
						||
 | 
						||
void TRiepiloghi_mask::create_sheet()
 | 
						||
{
 | 
						||
	TSheet_field& sf = sfield(F_COMMESSE);
 | 
						||
  TMask& sm = sf.sheet_mask();
 | 
						||
  sm.hide(-1);
 | 
						||
 | 
						||
  const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
 | 
						||
 | 
						||
  TConfig & ini = ca_config();
 | 
						||
 | 
						||
  int y = 1;
 | 
						||
  short dlg = S_CDC1 + 100; // id del primo campo da generare
 | 
						||
 | 
						||
  for (int i = 0; i < 2; i++)
 | 
						||
  {
 | 
						||
    const TString& level = ini.get("Level", NULL, i+1);  // Legge il livello 1 o 2
 | 
						||
    if (level == "CDC")                                  // Crea centro di costo 
 | 
						||
    {
 | 
						||
      if (fasinfo.parent() == LF_CDC)
 | 
						||
        create_sheet_fields(LF_FASI, y, dlg);
 | 
						||
      else
 | 
						||
      {
 | 
						||
        const bool cdc_req = ini.get_bool("CdcRequired");
 | 
						||
        create_sheet_fields(LF_CDC, y, dlg);
 | 
						||
      }
 | 
						||
    } else
 | 
						||
    if (level == "CMS")                                   // Crea commessa
 | 
						||
    {
 | 
						||
      if (fasinfo.parent() == LF_COMMESSE)
 | 
						||
        create_sheet_fields(LF_FASI, y, dlg);
 | 
						||
      else
 | 
						||
      {
 | 
						||
        create_sheet_fields(LF_COMMESSE, y, dlg);
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
 | 
						||
  if (fasinfo.levels() > 0 && fasinfo.parent() <= 0)
 | 
						||
    create_sheet_fields(LF_FASI, y, dlg);
 | 
						||
 | 
						||
	for (short id = S_CDC12; id >= S_CDC1; id--)
 | 
						||
  {
 | 
						||
    const int pos = sm.id2pos(id+100);
 | 
						||
    if (pos >= 0)
 | 
						||
    {
 | 
						||
      TMask_field& f = sm.fld(pos);
 | 
						||
      const int size = f.size();
 | 
						||
      const TString& prompt = f.prompt();
 | 
						||
      sf.set_column_header(id, prompt);
 | 
						||
      sf.set_column_justify(id, f.is_kind_of(CLASS_REAL_FIELD));
 | 
						||
      sf.set_column_width(id, (max(3+size, prompt.len()+1)) * CHARX);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      sf.delete_column(id);
 | 
						||
    sm.hide(id); // Nasconde il campo "segnaposto"
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
bool TRiepiloghi_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						||
{
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
TRiepiloghi_mask::TRiepiloghi_mask() :  TAutomask("ci1200") 
 | 
						||
{ 
 | 
						||
  create_sheet();
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TRiepiloghi_recordset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TRiepiloghi_recordset : public TDocument_recordset
 | 
						||
{
 | 
						||
  TDate _da_data, _a_data;
 | 
						||
  long _da_clifo, _a_clifo;
 | 
						||
  TString _da_codart, _a_codart;
 | 
						||
  TString _codcosto, _codcms, _codfas;
 | 
						||
  TString_array _tipidoc;
 | 
						||
 | 
						||
protected:
 | 
						||
  static bool rdoc_filter(const TRelation* rel);
 | 
						||
  bool valid_record(const TRelation& rel) const;
 | 
						||
 | 
						||
  bool has_doc_reference(const char* str) const;
 | 
						||
  virtual void set_custom_filter(TCursor& cur) const;
 | 
						||
 | 
						||
public:
 | 
						||
  void set_filter(const TRiepiloghi_mask& msk, int cms_row);
 | 
						||
  TRiepiloghi_recordset(const TString& sql) : TDocument_recordset(sql) { }
 | 
						||
};
 | 
						||
 | 
						||
static const TRiepiloghi_recordset* myself = NULL;
 | 
						||
 | 
						||
bool TRiepiloghi_recordset::valid_record(const TRelation& rel) const
 | 
						||
{
 | 
						||
  const TRectype& doc = rel.curr(LF_DOC);
 | 
						||
  
 | 
						||
  const TDate data = doc.get(DOC_DATADOC);
 | 
						||
  if (data < _da_data || (_a_data.ok() && data > _a_data))
 | 
						||
    return false;
 | 
						||
 | 
						||
  const long clifo = doc.get_long(DOC_CODCF);
 | 
						||
  if (clifo < _da_clifo || (_a_clifo > 0 && clifo > _a_clifo))
 | 
						||
    return false;
 | 
						||
    
 | 
						||
  const TRectype& rdoc = rel.curr(LF_RIGHEDOC);
 | 
						||
  const TString& codart = rdoc.get(RDOC_CODART);
 | 
						||
  if (codart < _da_codart || (_a_codart.not_empty() && codart.compare(_a_codart, _a_codart.len()) > 0))
 | 
						||
    return false;
 | 
						||
 | 
						||
  if (!_tipidoc.empty())
 | 
						||
  {
 | 
						||
    const TString4 codnum = doc.get(DOC_CODNUM);
 | 
						||
    const TString4 tipodoc = doc.get(DOC_TIPODOC);
 | 
						||
    const TString4 stato = doc.get(DOC_STATO);
 | 
						||
 | 
						||
    bool found = false;
 | 
						||
    FOR_EACH_ARRAY_ROW(_tipidoc, i, row)
 | 
						||
    {
 | 
						||
      const TString4 cn = row->get(0);
 | 
						||
      const TString4 td = row->get();
 | 
						||
      if ((cn.blank() || cn == codnum) && (td.blank() || td == tipodoc))
 | 
						||
      {
 | 
						||
				const TString4 si = row->get();
 | 
						||
				const TString4 sf = row->get();
 | 
						||
 | 
						||
				if ((si.blank() || stato >= si) && (sf.blank() || stato <= sf))
 | 
						||
				{
 | 
						||
					found = true;
 | 
						||
					break;
 | 
						||
				}
 | 
						||
      }
 | 
						||
    }
 | 
						||
    if (!found)
 | 
						||
      return false;
 | 
						||
  }
 | 
						||
 | 
						||
  if (_codcosto.not_empty())
 | 
						||
  {
 | 
						||
    const TString& cos = rdoc.get(RDOC_CODCOSTO);
 | 
						||
    if (cos != _codcosto)
 | 
						||
      return false;
 | 
						||
  }
 | 
						||
  if (_codcms.not_empty())
 | 
						||
  {
 | 
						||
    const TString& cms = rdoc.get(RDOC_CODCMS);
 | 
						||
    if (cms != _codcms)
 | 
						||
      return false;
 | 
						||
  }
 | 
						||
  if (_codfas.not_empty())
 | 
						||
  {
 | 
						||
    const TString& fas = rdoc.get(RDOC_FASCMS);
 | 
						||
    if (fas != _codfas)
 | 
						||
      return false;
 | 
						||
  }
 | 
						||
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
bool TRiepiloghi_recordset::rdoc_filter(const TRelation* rel)
 | 
						||
{
 | 
						||
  return myself->valid_record(*rel);
 | 
						||
}
 | 
						||
 | 
						||
bool TRiepiloghi_recordset::has_doc_reference(const char* str) const
 | 
						||
{
 | 
						||
  TString expr(str); expr.upper();
 | 
						||
  return expr.find("DOC.") >= 0 || expr.find("DOC->") >= 0 || 
 | 
						||
         expr.find("33.") >= 0 || expr.find("33->") >=0;
 | 
						||
}
 | 
						||
 | 
						||
void TRiepiloghi_recordset::set_custom_filter(TCursor& cur) const
 | 
						||
{
 | 
						||
  // Quanto segue potrebbe essere una magia degli TISAM_recordset
 | 
						||
  // o quanto meno dei TDocument_recordset
 | 
						||
  TString filter = cur.filter();
 | 
						||
  bool has_doc = false;
 | 
						||
  if (has_doc_reference(filter))
 | 
						||
    has_doc = true; else
 | 
						||
  if (cur.is_sorted() && has_doc_reference(((TSorted_cursor&)cur).get_order()))
 | 
						||
    has_doc = true;
 | 
						||
 | 
						||
  myself = this;
 | 
						||
  cur.set_filterfunction(rdoc_filter, true); // Acc. il true e' obbligatorio :-(
 | 
						||
  cur.setfilter(filter, has_doc, 1);
 | 
						||
 | 
						||
  int nkey = 6;
 | 
						||
  const TMultilevel_code_info* mci = ca_multilevel_code_info_by_index(0);
 | 
						||
  if (mci != NULL && mci->logic() == LF_CDC)
 | 
						||
    nkey = 7;
 | 
						||
  cur.setkey(nkey);
 | 
						||
  
 | 
						||
  TRectype filtrec(LF_RIGHEDOC);
 | 
						||
  if (_codcosto.full())
 | 
						||
    filtrec.put(RDOC_CODCOSTO, _codcosto);
 | 
						||
  if (_codcms.full())
 | 
						||
    filtrec.put(RDOC_CODCMS, _codcms);
 | 
						||
  cur.setregion(filtrec, filtrec);
 | 
						||
}
 | 
						||
 | 
						||
void TRiepiloghi_recordset::set_filter(const TRiepiloghi_mask& msk, int cms_row)
 | 
						||
{
 | 
						||
  _codcosto = _codcms = _codfas = "";
 | 
						||
  if (cms_row >= 0)
 | 
						||
  {
 | 
						||
    TSheet_field& sf = msk.sfield(F_COMMESSE);
 | 
						||
    TMask& sm = sf.sheet_mask();
 | 
						||
    sf.update_mask(cms_row);
 | 
						||
    TRelation rel(LF_RMOVANA);
 | 
						||
    sm.autosave(rel);
 | 
						||
    _codcosto = rel.curr().get(RMOVANA_CODCCOSTO);
 | 
						||
    _codcms   = rel.curr().get(RMOVANA_CODCMS);
 | 
						||
    _codfas   = rel.curr().get(RMOVANA_CODFASE);
 | 
						||
  } 
 | 
						||
  set_var("#S_CDC", TVariant(_codcosto), true);
 | 
						||
  set_var("#S_CMS", TVariant(_codcms), true);
 | 
						||
  set_var("#S_FAS", TVariant(_codfas), true);
 | 
						||
 | 
						||
  TToken_string td(80, ',');
 | 
						||
  _tipidoc.destroy();
 | 
						||
  TSheet_field& sf = msk.sfield(F_TIPI);
 | 
						||
  FOR_EACH_SHEET_ROW(sf, i, row)
 | 
						||
  {
 | 
						||
    TToken_string str;
 | 
						||
 | 
						||
    const TString8 num = row->get(0);
 | 
						||
    const TString8 tip = row->get(2);
 | 
						||
    str.add(num, 0);
 | 
						||
    str.add(tip, 1);
 | 
						||
    str.add(row->get(4), 2);
 | 
						||
    str.add(row->get(5), 3);
 | 
						||
    _tipidoc.add(str);
 | 
						||
    
 | 
						||
    if (!num.blank() || !tip.blank())
 | 
						||
    {
 | 
						||
      td.add(num);
 | 
						||
      if (!num.blank())
 | 
						||
        td << '/' << tip;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  set_var("#S_TIPIDOC", TVariant(td), true);
 | 
						||
 | 
						||
  _da_data = msk.get_date(F_DA_DATA);
 | 
						||
  _a_data = msk.get_date(F_A_DATA);
 | 
						||
  set_var("#S_DATEFROM", TVariant(_da_data), true);
 | 
						||
  set_var("#S_DATETO", TVariant(_a_data), true);
 | 
						||
 | 
						||
  _da_clifo = msk.get_long(F_DA_CLIFO);
 | 
						||
  _a_clifo = msk.get_long(F_A_CLIFO);
 | 
						||
  set_var("#S_DACLIFO", TVariant(_da_clifo), true);
 | 
						||
  set_var("#S_ACLIFO", TVariant(_a_clifo), true);
 | 
						||
 | 
						||
  _da_codart = msk.get(F_DA_CODART);
 | 
						||
  _a_codart = msk.get(F_A_CODART);
 | 
						||
  set_var("#S_DACODART", TVariant(_da_codart), true);
 | 
						||
  set_var("#S_ACODART", TVariant(_a_codart), true);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TRiepiloghi_report
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TRiepiloghi_report : public TReport
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual bool set_recordset(const TString& sql);
 | 
						||
 | 
						||
public:
 | 
						||
  void set_filter(const TRiepiloghi_mask& msk, int cms_row);
 | 
						||
  TRiepiloghi_report() { }
 | 
						||
};
 | 
						||
 | 
						||
bool TRiepiloghi_report::set_recordset(const TString& sql)
 | 
						||
{
 | 
						||
  TRiepiloghi_recordset* rs = new TRiepiloghi_recordset(sql);
 | 
						||
  return TReport::set_recordset(rs);
 | 
						||
}
 | 
						||
 | 
						||
void TRiepiloghi_report::set_filter(const TRiepiloghi_mask& msk, int cms_row)
 | 
						||
{
 | 
						||
  TRiepiloghi_recordset* rs = (TRiepiloghi_recordset*)recordset();
 | 
						||
  rs->set_filter(msk, cms_row);
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TRiepiloghi_app
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TRiepiloghi_app : public TSkeleton_application
 | 
						||
{
 | 
						||
protected:
 | 
						||
	const TMultilevel_code_info& get_first_level() const;
 | 
						||
  virtual void main_loop();
 | 
						||
};
 | 
						||
 | 
						||
 | 
						||
//metodo per accattarsi o' primo livello della configurazione CA
 | 
						||
const TMultilevel_code_info& TRiepiloghi_app::get_first_level() const
 | 
						||
{
 | 
						||
	TConfig& cfg = ca_config();
 | 
						||
	const TString& first_lev = cfg.get("Level(1)");
 | 
						||
	const int logic = first_lev == "CDC" ? LF_CDC : LF_COMMESSE;
 | 
						||
	return ca_multilevel_code_info(logic);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
void TRiepiloghi_app::main_loop()
 | 
						||
{
 | 
						||
  TRiepiloghi_mask mask;
 | 
						||
  while (mask.run() != K_QUIT)
 | 
						||
  {
 | 
						||
    TReport_book book;
 | 
						||
    TRiepiloghi_report rep;
 | 
						||
    const TString& repname = mask.get(F_REPORT);
 | 
						||
    rep.load(repname);
 | 
						||
 | 
						||
    TSheet_field& sheet = mask.sfield(F_COMMESSE);
 | 
						||
		TString video_string;	//stringa che compare nella progind
 | 
						||
    if (sheet.empty())	//se non ci sono righe sullo sheet (selezione su tutte le cms/cdc)...
 | 
						||
		{
 | 
						||
			TToken_string& row = sheet.row(-1);	//crea la prima riga dello sheet
 | 
						||
 | 
						||
			const TMultilevel_code_info& liv1 = get_first_level();	//stabilisce quale <20> il primo livello (tra CDC e CMS)..
 | 
						||
			TISAM_recordset set(liv1.logic() == LF_CDC ? "USE CDC" : "USE COMMESSE");	//..e di conseguenza scrive la use giusta
 | 
						||
 | 
						||
			TProgind pi(set.items(), video_string, true, true);
 | 
						||
			for (int i = 0; set.move_to(i); i++)	//fighissimo metodo per scandire un file in 1 riga!
 | 
						||
			{
 | 
						||
				pi.addstatus(1);
 | 
						||
				if (pi.iscancelled())
 | 
						||
					break;
 | 
						||
				row = set.get((unsigned int)0).as_string();	//prende il valore del primo campo del file (CDC o CMS code)
 | 
						||
 | 
						||
				video_string = TR("Scansione");
 | 
						||
				video_string << " " << row;	//completa la stringa da visualizzare sulla progind
 | 
						||
				pi.set_text(video_string);
 | 
						||
 | 
						||
				for (int l = liv1.levels()-2; l >= 0; l--)	//se la struttura <20> a pi<70> livelli costruisce la tokenstring
 | 
						||
					row.insert("|", liv1.total_len(l));
 | 
						||
 | 
						||
				rep.set_filter(mask, 0);	//fa la set filter sulla prima riga (che <20> quella usata)	
 | 
						||
				book.add(rep);
 | 
						||
			}
 | 
						||
			sheet.destroy();	//cancella le commesse aggiunte in automatico sullo sheet
 | 
						||
		}
 | 
						||
		else	//se ha almeno una riga sullo sheet delle cms/cdc...
 | 
						||
		{
 | 
						||
			FOR_EACH_SHEET_ROW(sheet, r, row)	//per ogni cdc/cms che appare nello sheet di pag.1 della msk..
 | 
						||
			{
 | 
						||
				rep.set_filter(mask, r);	//..chiama il metodone globale che crea e compila il file.. 
 | 
						||
  																	//..temporaneo i cui dati riempiranno il report
 | 
						||
				book.add(rep);	//aggiunge il report relativo alla cdc/cms corrente al book
 | 
						||
			}
 | 
						||
		}
 | 
						||
 | 
						||
    book.print_or_preview();
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
int ci1200(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TRiepiloghi_app sd;
 | 
						||
  sd.run(argc, argv, "Stampa riepiloghi");
 | 
						||
  return 0;
 | 
						||
}
 |