Files correlati : ca?.exe Ricompilazione Demo : [ ] Commento : Aggiunto supporto per la creazione di campi analitici dinamicamente sulle pagine successive alla prima git-svn-id: svn://10.65.10.50/trunk@12965 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			422 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			422 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <automask.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <relapp.h>
 | 
						|
 | 
						|
#include "ca0800a.h"
 | 
						|
#include "calib01.h"
 | 
						|
 | 
						|
#include "rrip.h"
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TRiparti_msk 
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TRiparti_msk : 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);
 | 
						|
  void create_sheet();
 | 
						|
 | 
						|
public:
 | 
						|
  TRiparti_msk();
 | 
						|
};
 | 
						|
 | 
						|
bool TRiparti_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case F_TIPORIP:
 | 
						|
    if (e == fe_init || e == fe_modify)
 | 
						|
    {
 | 
						|
      TSheet_field& sf = sfield(F_SHEET);
 | 
						|
      TMask& sm = sf.sheet_mask();
 | 
						|
      const int t = atoi(o.get());
 | 
						|
      sm.show(101, t < 2);   // Percentuale
 | 
						|
      sm.show(201, t == 2);  // Parti
 | 
						|
      sm.enable(101, t != 1);
 | 
						|
      sf.enable_column(0, t != 1);
 | 
						|
      sf.force_update();
 | 
						|
    }
 | 
						|
    if (e == fe_close && atoi(o.get()) == 0)
 | 
						|
    {
 | 
						|
      TSheet_field& sf = sfield(F_SHEET);
 | 
						|
      real tot;
 | 
						|
      FOR_EACH_SHEET_ROW(sf, i, row)
 | 
						|
        tot += real(row->get(0));
 | 
						|
      tot.round(2);
 | 
						|
      if (tot != CENTO)
 | 
						|
        return error_box(TR("Il totale delle percentuali di riparto deve essere 100"));
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  case F_SHEET:
 | 
						|
    if (e == fe_init)
 | 
						|
    {
 | 
						|
      TSheet_field& sf = sfield(F_SHEET);
 | 
						|
      TMask& sm = sf.sheet_mask();
 | 
						|
      const bool on = get(F_TIPO)[0] != 'C';
 | 
						|
      for (short id = 202; id < 214; id++)
 | 
						|
      {
 | 
						|
        if (sm.id2pos(id) > 0)
 | 
						|
        {
 | 
						|
          sf.enable_column(id, on);
 | 
						|
          sm.enable(id, on);
 | 
						|
        }
 | 
						|
        if (sm.id2pos(id+50) > 0)
 | 
						|
          sm.enable(id+50, on);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    if (e == fe_modify || e == fe_close)
 | 
						|
    {
 | 
						|
/*
 | 
						|
      const short id = o.dlg();
 | 
						|
      int level = -1;
 | 
						|
      if (id >= 202 && id <= 217)
 | 
						|
      {
 | 
						|
        level = (o.dlg()-202) % 4;  
 | 
						|
      } else
 | 
						|
      if (id >= F_CODCDC_1 && id <= F_CODCDC_4) 
 | 
						|
      {
 | 
						|
        level = id-F_CODCDC_1;
 | 
						|
      } else
 | 
						|
      if (id >= F_CODCMS_1 && id <= F_CODCMS_4) 
 | 
						|
      {
 | 
						|
        level = id-F_CODCMS_1;
 | 
						|
      }
 | 
						|
      if (level >= 0)
 | 
						|
      {
 | 
						|
        TEdit_field& fld = (TEdit_field&)o;
 | 
						|
        return ca_test_multilevel_field(fld, level);
 | 
						|
      }
 | 
						|
*/
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
int TRiparti_msk::create_sheet_fields(int lf, int& y, short& dlg)
 | 
						|
{
 | 
						|
  TSheet_field& sf = sfield(F_SHEET);
 | 
						|
  TMask& sm = sf.sheet_mask();
 | 
						|
  const int h = ca_create_fields(sm, 0, lf, 1, y, dlg, dlg+50);
 | 
						|
 | 
						|
  for (int i = 0; i < h; i++)
 | 
						|
  {
 | 
						|
    TEdit_field& fld = sm.efield(dlg+i);
 | 
						|
    int logic = lf;
 | 
						|
    if (logic == LF_FASI)
 | 
						|
    {
 | 
						|
      const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
 | 
						|
      if (fasinfo.parent() != 0)
 | 
						|
      {
 | 
						|
        const TMultilevel_code_info& parinfo = ca_multilevel_code_info(fasinfo.parent());
 | 
						|
        if (i < parinfo.levels())
 | 
						|
          logic = fasinfo.parent();
 | 
						|
      }
 | 
						|
    }
 | 
						|
 | 
						|
    if (logic == LF_PCON)
 | 
						|
    {
 | 
						|
      const TFieldref* f = fld.field();
 | 
						|
      const TString16 fieldname = f->name();
 | 
						|
 | 
						|
      if (fieldname == "GRUPPO") 
 | 
						|
        fld.set_field("CODCONTO[1,3]"); else
 | 
						|
      if (fieldname == "CONTO") 
 | 
						|
        fld.set_field("CODCONTO[4,6]"); else
 | 
						|
      if (fieldname == "SOTTOCONTO") 
 | 
						|
        fld.set_field("CODCONTO[7,12]");
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      const char* fieldname = NULL;
 | 
						|
      switch(logic)
 | 
						|
      {
 | 
						|
      case LF_CDC     : fieldname = RRIP_CODCOSTO; break;
 | 
						|
      case LF_COMMESSE: fieldname = RRIP_CODCMS;   break;
 | 
						|
      case LF_FASI    : fieldname = RRIP_CODFASE;  break;
 | 
						|
      default         : fieldname = RRIP_CODCONTO; break;
 | 
						|
      }
 | 
						|
      TFieldref* f = (TFieldref*)fld.field();
 | 
						|
      f->set_name(fieldname);
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  y += h+1;
 | 
						|
  dlg += h;
 | 
						|
  return h;
 | 
						|
}
 | 
						|
 | 
						|
void TRiparti_msk::create_sheet()
 | 
						|
{
 | 
						|
  TSheet_field& sf = sfield(F_SHEET);
 | 
						|
  TMask& sm = sf.sheet_mask();
 | 
						|
  sm.hide(-1);
 | 
						|
 | 
						|
  const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
 | 
						|
 | 
						|
  TConfig_anal ini;
 | 
						|
 | 
						|
  int y = 1;
 | 
						|
  short dlg = 202;
 | 
						|
 | 
						|
  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
 | 
						|
        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);
 | 
						|
 | 
						|
  const bool use_pdc = ini.get_bool("UsePdcc");
 | 
						|
  create_sheet_fields(use_pdc ? LF_PCON : LF_PCONANA, y, dlg);
 | 
						|
  
 | 
						|
  for (short id = 217; id >= 202; id--)
 | 
						|
  {
 | 
						|
    const int pos = sm.id2pos(id);
 | 
						|
    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);
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
TRiparti_msk::TRiparti_msk() : TAutomask("ca0800a") 
 | 
						|
{  
 | 
						|
  TConfig_anal ini;
 | 
						|
 | 
						|
  // Crea gli eventuali campi per commessa e centro di costo
 | 
						|
 | 
						|
  int y = 5;
 | 
						|
  for (int i = 0; i < 2; i++)
 | 
						|
  {
 | 
						|
    const char* prompt = NULL;
 | 
						|
    int h = 0;
 | 
						|
    const TString& level = ini.get("Level", NULL, i+1);  // Legge il livello 1 o 2
 | 
						|
    if (level == "CDC")                                  // Crea centro di costo 
 | 
						|
    {
 | 
						|
      h = ca_create_fields(*this, 0, LF_CDC, 2,  y, F_CODCDC_1, F_DESCDC_1);
 | 
						|
      prompt = TR("@bCentro di costo");
 | 
						|
    } else
 | 
						|
    if (level == "CMS")                                   // Crea commessa
 | 
						|
    {
 | 
						|
      h = ca_create_fields(*this, 0, LF_COMMESSE, 2, y, F_CODCMS_1, F_DESCMS_1);
 | 
						|
      prompt = TR("@bCommessa");
 | 
						|
    }
 | 
						|
 | 
						|
    if (prompt != NULL)                                   // Crea groupbox
 | 
						|
    {
 | 
						|
      const int last = fields()-1;
 | 
						|
      for (int j = 0; j < 2*h; j++)
 | 
						|
        fld(last-j).set_group(2);
 | 
						|
 | 
						|
      h += 2;
 | 
						|
      TGroup_field& grp = add_groupbox(F_LEVEL_1+i, 0, prompt, 1, y-1, 78, h);
 | 
						|
      grp.set_group(2);
 | 
						|
      y += h;
 | 
						|
    }
 | 
						|
  }
 | 
						|
  create_sheet();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TRiparti_app
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TRiparti_app : public TRelation_application
 | 
						|
{  
 | 
						|
  TRelation* _rel;
 | 
						|
  TRiparti_msk* _msk;
 | 
						|
 | 
						|
  virtual const char * extra_modules() const {return "cm";} //funziona anche con autorizzazione CM
 | 
						|
 | 
						|
  const TString& somma_campi(TToken_string& row, int first, bool pdc = false) const;
 | 
						|
  void write_rows();
 | 
						|
 | 
						|
  void spezza_campo(const TString& str, TToken_string& row, int first) const;
 | 
						|
  void read_rows();
 | 
						|
 | 
						|
protected:    
 | 
						|
  virtual bool user_create();
 | 
						|
  virtual bool user_destroy();
 | 
						|
  virtual int write(const TMask& m);
 | 
						|
  virtual int rewrite(const TMask& m);
 | 
						|
  virtual int read(TMask& m);
 | 
						|
 | 
						|
  virtual TRelation* get_relation() const { return _rel; }
 | 
						|
  virtual TMask* get_mask(int) { return _msk; }
 | 
						|
};
 | 
						|
 | 
						|
const TString& TRiparti_app::somma_campi(TToken_string& row, int first, bool pdc) const
 | 
						|
{
 | 
						|
  TSheet_field& sheet = _msk->sfield(F_SHEET);
 | 
						|
  TMask& m = sheet.sheet_mask();
 | 
						|
  
 | 
						|
  const short id = 201 + first;
 | 
						|
 | 
						|
  TString& str = get_tmp_string(20);
 | 
						|
  for (int i = 0; i < 4; i++)
 | 
						|
  {
 | 
						|
    TString80 token = row.get(first+i);
 | 
						|
    if (m.id2pos(id+i) < 0)
 | 
						|
      break;
 | 
						|
    const TEdit_field& fld = m.efield(id+i);
 | 
						|
    if (pdc)
 | 
						|
      token.right_just(fld.size(), '0');
 | 
						|
    else
 | 
						|
      token.left_just(fld.size());
 | 
						|
    str << token;
 | 
						|
  }
 | 
						|
  return str;
 | 
						|
}
 | 
						|
 | 
						|
void TRiparti_app::spezza_campo(const TString& str, TToken_string& row, int first) const
 | 
						|
{
 | 
						|
  TSheet_field& sheet = _msk->sfield(F_SHEET);
 | 
						|
  TMask& m = sheet.sheet_mask();
 | 
						|
  TString80 token;
 | 
						|
 | 
						|
  const short id = 201 + first;
 | 
						|
  int start = 0;
 | 
						|
  for (int i = 0; i < 4; i++)
 | 
						|
  {
 | 
						|
    if (m.id2pos(id+i) < 0)
 | 
						|
      break;
 | 
						|
    const TEdit_field& fld = m.efield(id+i);
 | 
						|
    const int len = fld.size();
 | 
						|
    token = str.mid(start, len); token.trim();
 | 
						|
    row.add(token, first+i);
 | 
						|
    start += len;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TRiparti_app::write_rows()
 | 
						|
{
 | 
						|
  TRectype* key = new TRectype(LF_RRIP);
 | 
						|
  const char tipo = _msk->get(F_TIPO)[0];
 | 
						|
  key->put("TIPO", tipo);
 | 
						|
  key->put("CODICE", _msk->get(tipo == 'B' ? F_CODICE_B : F_CODICE_I));
 | 
						|
 | 
						|
  TRecord_array a(LF_RRIP, "NRIGA");
 | 
						|
  a.set_key(key);
 | 
						|
  
 | 
						|
  TSheet_field& sheet = _msk->sfield(F_SHEET);
 | 
						|
  TMask& sm = sheet.sheet_mask();
 | 
						|
 | 
						|
  FOR_EACH_SHEET_ROW(sheet, i, row)
 | 
						|
  {
 | 
						|
    TRectype& rec = a.row(i+1, true);  // Crea una riga nuova
 | 
						|
    for (int i = sm.fields()-1; i >= 0; i--)
 | 
						|
    {
 | 
						|
      TMask_field& mf = sm.fld(i);
 | 
						|
      if (mf.field() != NULL)
 | 
						|
      {
 | 
						|
        const int idx = sheet.cid2index(mf.dlg());
 | 
						|
        if (idx < 17)
 | 
						|
          mf.field()->write(row->get(idx), rec);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
  a.rewrite();
 | 
						|
}
 | 
						|
 | 
						|
void TRiparti_app::read_rows()
 | 
						|
{
 | 
						|
  const char tipo = _msk->get(F_TIPO)[0];
 | 
						|
  TToken_string key;
 | 
						|
  key << tipo << '|' << _msk->get(tipo == 'B' ? F_CODICE_B : F_CODICE_I);
 | 
						|
  TRecord_array a(key, LF_RRIP);
 | 
						|
  
 | 
						|
  TSheet_field& sheet = _msk->sfield(F_SHEET);
 | 
						|
  TMask& sm = sheet.sheet_mask();
 | 
						|
  sheet.destroy();
 | 
						|
  for (int i = 1; i <= a.rows(); i++)
 | 
						|
  {
 | 
						|
    TToken_string& row = sheet.row(i-1);
 | 
						|
    const TRectype& rec = a.row(i);
 | 
						|
    for (int i = sm.fields()-1; i >= 0; i--)
 | 
						|
    {
 | 
						|
      TMask_field& mf = sm.fld(i);
 | 
						|
      if (mf.field() != NULL)
 | 
						|
      {
 | 
						|
        const int idx = sheet.cid2index(mf.dlg());
 | 
						|
        if (idx < 17)
 | 
						|
          row.add(mf.field()->read(rec), idx);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int TRiparti_app::write(const TMask& m)
 | 
						|
{
 | 
						|
  const int err = TRelation_application::write(m);
 | 
						|
  if (err == NOERR)
 | 
						|
    write_rows();
 | 
						|
  return err;
 | 
						|
}
 | 
						|
 | 
						|
int TRiparti_app::rewrite(const TMask& m)
 | 
						|
{
 | 
						|
  const int err = TRelation_application::rewrite(m);
 | 
						|
  if (err == NOERR)
 | 
						|
    write_rows();
 | 
						|
  return err;
 | 
						|
}
 | 
						|
 | 
						|
int TRiparti_app::read(TMask& m)
 | 
						|
{
 | 
						|
  const int err = TRelation_application::read(m);
 | 
						|
  if (err == NOERR)
 | 
						|
    read_rows();
 | 
						|
  return err;
 | 
						|
}
 | 
						|
 | 
						|
bool TRiparti_app::user_create()
 | 
						|
{
 | 
						|
  _rel = new TRelation(LF_RIP);
 | 
						|
  _msk = new TRiparti_msk;
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool TRiparti_app::user_destroy()
 | 
						|
{
 | 
						|
  delete _rel;
 | 
						|
  delete _msk;
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
int ca0800(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TRiparti_app a;
 | 
						|
  a.run(argc, argv, TR("Tabella di ripartizione"));
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 |