Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 patch 1092 git-svn-id: svn://10.65.10.50/trunk@16352 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			171 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			171 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <diction.h>
 | 
						|
#include <reputils.h>
 | 
						|
#include <textset.h>
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TAS400_report
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
TRecordset* TAS400_report::recordset() const
 | 
						|
{
 | 
						|
  return _set != NULL ? _set : TReport::recordset();
 | 
						|
}
 | 
						|
 | 
						|
bool TAS400_report::set_recordset(TRecordset* rs)
 | 
						|
{
 | 
						|
  if (_set != NULL && _owned)
 | 
						|
    delete _set;
 | 
						|
  _set = rs;
 | 
						|
  _owned = true;
 | 
						|
  
 | 
						|
  const TAS400_recordset& recset = *(TAS400_recordset*)_set;
 | 
						|
 | 
						|
  TReport_section& body = section('B', 1);
 | 
						|
  body.destroy();
 | 
						|
 | 
						|
  const int reclen = recset.record_length();
 | 
						|
  const int keypos = recset.key_position();
 | 
						|
  const int keylen = recset.key_length();
 | 
						|
  const int tabstop = 10;
 | 
						|
 | 
						|
  // Genera sfondo solo per colonne dispari
 | 
						|
  for (int x = tabstop; x < reclen; x += 2*tabstop)
 | 
						|
  {
 | 
						|
    TReport_field* b = new TReport_field(&body);
 | 
						|
    b->set_type('R');
 | 
						|
    b->set_pos(x*100, 0);
 | 
						|
    b->set_size(tabstop*100, 100);
 | 
						|
    b->set_pattern(PAT_SOLID);
 | 
						|
    b->set_back_color(XVT_MAKE_COLOR(192,255,255)); // Light Cyan
 | 
						|
    body.add(b);
 | 
						|
  }
 | 
						|
  
 | 
						|
  // Genera sfondo per la chiave se presente
 | 
						|
  if (keylen > 0)
 | 
						|
  {
 | 
						|
    TReport_field* b = new TReport_field(&body);
 | 
						|
    b->set_type('R');
 | 
						|
    b->set_pos(keypos*100, 0);
 | 
						|
    b->set_size(keylen*100, 100);
 | 
						|
    b->set_pattern(PAT_SOLID);
 | 
						|
    b->set_back_color(XVT_MAKE_COLOR(255,192,192)); // Light Fucsia
 | 
						|
    body.add(b);
 | 
						|
  }
 | 
						|
 | 
						|
  // Genera campi a passo fisso per evitare errori di arrotondamento font
 | 
						|
  TString16 src; // Nome della sorgente di ogni colonna
 | 
						|
  for (int k = 0; k < reclen; k += tabstop)
 | 
						|
  {
 | 
						|
    TReport_field* f = new TReport_field(&body);
 | 
						|
    f->set_type('S');
 | 
						|
    src.format("A[%d,%d]", k+1, k+tabstop);
 | 
						|
    f->set_field(src);
 | 
						|
    f->set_pos(k*100, 0);
 | 
						|
    f->set_size(tabstop*100, 100);
 | 
						|
    body.add(f);
 | 
						|
  }
 | 
						|
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool TAS400_report::set_recordset(const TString& query)
 | 
						|
{
 | 
						|
  TAS400_recordset* rs = (TAS400_recordset*)recordset();
 | 
						|
  if (rs == NULL || !_owned)
 | 
						|
  {
 | 
						|
    rs = new TAS400_recordset(query);
 | 
						|
    TAS400_report::set_recordset(rs);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    rs->exec(query);
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
TAS400_report::TAS400_report(const char* query) 
 | 
						|
             : _set(NULL), _owned(false)
 | 
						|
{
 | 
						|
  set_recordset(TFixed_string(query));
 | 
						|
}
 | 
						|
 | 
						|
TAS400_report::TAS400_report(TRecordset& asr) 
 | 
						|
             : _set(NULL), _owned(false)
 | 
						|
{
 | 
						|
  set_recordset(&asr);
 | 
						|
  _owned = false; // il metodo precedente forza _owned = true
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TLog_report
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
void TLog_report::set_title(const char* title)
 | 
						|
{
 | 
						|
  _title = title;
 | 
						|
}
 | 
						|
 | 
						|
bool TLog_report::get_usr_val(const TString& name, TVariant& var) const
 | 
						|
{
 | 
						|
  if (name == "#TITLE")
 | 
						|
  {
 | 
						|
    var = _title;
 | 
						|
    return true;
 | 
						|
  }
 | 
						|
  return TReport::get_usr_val(name, var);
 | 
						|
}
 | 
						|
 | 
						|
bool TLog_report::set_usr_val(const TString& name, const TVariant& var)
 | 
						|
{
 | 
						|
  if (name == "#TITLE")
 | 
						|
  {
 | 
						|
    set_title(var.as_string());
 | 
						|
    return true;
 | 
						|
  }
 | 
						|
  
 | 
						|
  return TReport::set_usr_val(name, var);
 | 
						|
}
 | 
						|
 | 
						|
void TLog_report::reset()
 | 
						|
{
 | 
						|
  TText_recordset* csv = (TText_recordset*)recordset();
 | 
						|
  if (csv)
 | 
						|
    csv->destroy();
 | 
						|
}
 | 
						|
 | 
						|
bool TLog_report::log(int sev, const char* msg)
 | 
						|
{
 | 
						|
  TText_recordset* csv = (TText_recordset*)recordset();
 | 
						|
  bool ok = csv != NULL;
 | 
						|
  if (ok)
 | 
						|
  {
 | 
						|
    //controlla se la stringa esiste gia'
 | 
						|
    if (_kill_duplicates)
 | 
						|
    {
 | 
						|
      for (bool go = csv->move_last(); go; go = csv->move_prev())
 | 
						|
      {
 | 
						|
        const TString& m = csv->get(1).as_string();
 | 
						|
        if (m == msg)
 | 
						|
          return true;  // ignoro messaggio duplicato
 | 
						|
      }
 | 
						|
    }
 | 
						|
    //aggiunge il messaggio
 | 
						|
    ok = csv->new_rec() >= 0;
 | 
						|
    if (ok)
 | 
						|
    {
 | 
						|
      csv->set(0u, TVariant((long)sev));
 | 
						|
      csv->set(1, TVariant(msg));
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
TLog_report::TLog_report(const char* title, const char* name)
 | 
						|
{
 | 
						|
  load(name);
 | 
						|
  if (recordset() == NULL)
 | 
						|
  {
 | 
						|
    TCSV_recordset* csv = new TCSV_recordset("CSV(\"\t\")"); // tab separated
 | 
						|
    set_recordset(csv);
 | 
						|
  }
 | 
						|
  set_title(title);
 | 
						|
}
 |