Files correlati :ba1.exe Ricompilazione Demo : [ ] Commento : Correzione minima (tolto GTK da Linux in ba1500.cpp) Sostituito "selezionati" con "presenti" in una message box di ba1700.cpp (indicazioni by Cinzia) git-svn-id: svn://10.65.10.50/trunk@12040 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1530 lines
		
	
	
		
			38 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1530 lines
		
	
	
		
			38 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <date.h>
 | 
						||
#include <form.h>
 | 
						||
#include <modaut.h>
 | 
						||
#include <msksheet.h>
 | 
						||
#include <prefix.h>
 | 
						||
#include <printer.h>
 | 
						||
#include <utility.h>
 | 
						||
#include <urldefid.h>
 | 
						||
#include <dongle.h>
 | 
						||
 | 
						||
#define  BITTEST(w,p) (((w) & (0x0001 << (p))) != 0)
 | 
						||
#define  BITSET(w,p,v)  ((v) ? ((w) |= (0x0001 << (p))) : ((w) &= (~(0x0001 << (p)))))
 | 
						||
 | 
						||
#include "ba1.h"
 | 
						||
#include "ba1500.h"
 | 
						||
#include "ba1500a.h"
 | 
						||
#include "ba1500b.h"
 | 
						||
#include "ba1600.h"
 | 
						||
 | 
						||
#define K1         0x4500
 | 
						||
#define LBYTEMASK  0x00FF
 | 
						||
#define UBYTEMASK  0xFF00
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
TInformazione_moduli::TInformazione_moduli()
 | 
						||
                    : _unassigned_modules(0)
 | 
						||
{
 | 
						||
  int mod = 0;
 | 
						||
  TString s(256);
 | 
						||
  TToken_string t;
 | 
						||
  TString_array descs;
 | 
						||
  
 | 
						||
  ifstream  in(AUT_FILE);
 | 
						||
  while (!in.eof() && in.good())
 | 
						||
  {
 | 
						||
    in.getline(s.get_buffer(), s.size());
 | 
						||
    s.trim();
 | 
						||
    if (s.empty()) 
 | 
						||
      break;
 | 
						||
    const int l = s.len();
 | 
						||
    if (l >= 3 && s[3] > ' ')
 | 
						||
    {
 | 
						||
      t = s.mid(3);
 | 
						||
      t.add(s.left(2));
 | 
						||
    } else {
 | 
						||
      t = "{Modulo Sconosciuto}";
 | 
						||
      t.add(s.left(2));
 | 
						||
    }
 | 
						||
    t.add(mod++); 
 | 
						||
    s = t.get(0);
 | 
						||
    descs.add(s);
 | 
						||
    s.upper();
 | 
						||
    t.add(s, 0);
 | 
						||
    _infos.add(t);
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (in.bad() && !in.eof())
 | 
						||
    error_box(TR("Si e' verificato un errore leggendo il file di descrizione moduli."));
 | 
						||
  
 | 
						||
  _infos.sort();
 | 
						||
  for (int i=0;i<mod;i++)
 | 
						||
  {
 | 
						||
    TToken_string& riga = _infos.row(i);
 | 
						||
    const int mod = riga.get_int(2);
 | 
						||
    _index[mod] = i;         
 | 
						||
    s = descs.row(mod).get(0);
 | 
						||
    riga.add(s, 0);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
const char* TInformazione_moduli::get_description_by_order(int index)
 | 
						||
{ 
 | 
						||
  if (index >= 0 && index < _infos.items())
 | 
						||
    return _infos.row(index).get(0);
 | 
						||
  else
 | 
						||
    return "";
 | 
						||
}
 | 
						||
 | 
						||
const char* TInformazione_moduli::get_description_by_name(const char* code) const
 | 
						||
{
 | 
						||
  FOR_EACH_ARRAY_ROW_BACK(_infos, i, info)
 | 
						||
  {
 | 
						||
    if (stricmp(info->get(1), code) == 0)
 | 
						||
      return info->get(0);
 | 
						||
  }
 | 
						||
  return "{MODULO SCONOSCIUTO}";
 | 
						||
}
 | 
						||
 | 
						||
const char* TInformazione_moduli::get_name_by_order(int index)
 | 
						||
{ 
 | 
						||
  if (index >= 0 && index < _infos.items())
 | 
						||
    return _infos.row(index).get(1);
 | 
						||
  else 
 | 
						||
    return "";
 | 
						||
}
 | 
						||
 | 
						||
int TInformazione_moduli::get_module_by_order(int index)
 | 
						||
{
 | 
						||
  if (index >= 0 && index < _infos.items())
 | 
						||
    return _infos.row(index).get_int(2);
 | 
						||
  else
 | 
						||
    return -1;
 | 
						||
}
 | 
						||
 | 
						||
// Calcola il produttore ufficiale di module
 | 
						||
TDongleType TInformazione_moduli::get_owner(int module) const
 | 
						||
{   
 | 
						||
  const int aut[] = { CMAUT, ATAUT, POAUT, AFAUT, TCAUT, TMAUT, 
 | 
						||
                      VEAUT, MGAUT, ORAUT, EFAUT, DBAUT, PRAUT, SVAUT, -1 };
 | 
						||
  for (int a = 0; aut[a] >= 0; a++)
 | 
						||
    if (module == aut[a])
 | 
						||
      return _aga_dongle;
 | 
						||
      
 | 
						||
  return _prassi_dongle;
 | 
						||
}
 | 
						||
 | 
						||
// Testa se module appartiene al produttore owner
 | 
						||
// N.B. L'AGA possiede anche tutti i moduli PRASSI
 | 
						||
bool TInformazione_moduli::test_owner(int module, TDongleType owner) const
 | 
						||
{
 | 
						||
  TDongleType ow = get_owner(module);
 | 
						||
  bool yes = owner == ow || (owner == _aga_dongle && ow == _prassi_dongle);
 | 
						||
  return yes;
 | 
						||
}
 | 
						||
 | 
						||
const char* TInformazione_moduli::get_description(int module)
 | 
						||
{ return get_description_by_order(_index[module]); }
 | 
						||
 | 
						||
const char* TInformazione_moduli::get_name(int module)
 | 
						||
{ return get_name_by_order(_index[module]); }
 | 
						||
 | 
						||
int TInformazione_moduli::get_index(int module) const
 | 
						||
{ return _index[module]; }
 | 
						||
 | 
						||
int TInformazione_moduli::get_index_by_name(const char* code) const
 | 
						||
{
 | 
						||
  FOR_EACH_ARRAY_ROW_BACK(_infos, i, info)
 | 
						||
  {
 | 
						||
    if (stricmp(info->get(1), code) == 0)
 | 
						||
      break;
 | 
						||
  }
 | 
						||
  return i >= 0 ? get_index(i) : i;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TForm richiesta attivazione
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TRequest_form : public TForm
 | 
						||
{ 
 | 
						||
public:             
 | 
						||
  void update_serno(const TString& serno);
 | 
						||
  void update_dongle(const TDongle& dongle);
 | 
						||
  void update_os();
 | 
						||
  void print_footer();
 | 
						||
 | 
						||
  TRequest_form(const char* name);
 | 
						||
  virtual ~TRequest_form() { }
 | 
						||
}; 
 | 
						||
 | 
						||
TRequest_form::TRequest_form(const char* name)
 | 
						||
             : TForm(name)
 | 
						||
{                                   
 | 
						||
  const TPrint_section& header = section('H', odd_page);
 | 
						||
  const TPrint_section& footer = section('F', odd_page);
 | 
						||
  
 | 
						||
  int riga[66];
 | 
						||
  int y1 = header.height()-2;
 | 
						||
  int y2 = printer().formlen() - footer.height();
 | 
						||
  if ((y2-y1) & 0x1) y2--; // Forza un numero pari di righe
 | 
						||
  
 | 
						||
  for (int i = 0; ; i++)
 | 
						||
  {
 | 
						||
    riga[i] = y1 + 2*(i+1);
 | 
						||
    if (riga[i] >= y2-1)
 | 
						||
    {
 | 
						||
      riga[i] = 0;
 | 
						||
      break;
 | 
						||
    }
 | 
						||
  }      
 | 
						||
  genera_intestazioni(odd_page, y1+1);
 | 
						||
  genera_fincatura(odd_page, y1, y2, riga);
 | 
						||
} 
 | 
						||
 | 
						||
void TRequest_form::update_serno(const TString& num)
 | 
						||
{
 | 
						||
  const TDate today(TODAY);
 | 
						||
  TForm_item& data = find_field('H', odd_page, FF_DATARICH);
 | 
						||
  data.set(today.string());
 | 
						||
  switch (::dongle().hardware() )
 | 
						||
  {
 | 
						||
    case _dongle_eutron:
 | 
						||
      find_field('H',odd_page,FF_DONGLE_HW).set("EUTRON"); break;
 | 
						||
    default:
 | 
						||
      find_field('H',odd_page,FF_DONGLE_HW).set("HARDLOCK"); break;
 | 
						||
  }
 | 
						||
  TForm_item& serno = find_field('H', odd_page, FF_DONGLE_SN);
 | 
						||
  serno.set(num);
 | 
						||
}
 | 
						||
 | 
						||
void TRequest_form::update_dongle(const TDongle& dongle)
 | 
						||
{
 | 
						||
  TForm_item& year = find_field('H', odd_page, FF_YEAR);
 | 
						||
  TString str; 
 | 
						||
  str << "31-12-" << (int)dongle.year_assist();
 | 
						||
  year.set(str);
 | 
						||
  
 | 
						||
  TForm_item& user = find_field('H', odd_page, FF_NUTENTI);
 | 
						||
  str.format("%d", dongle.max_users());
 | 
						||
  user.set(str);
 | 
						||
}
 | 
						||
 | 
						||
void TRequest_form::update_os()
 | 
						||
{
 | 
						||
  TForm_item& os = find_field('H', odd_page, FF_OS);
 | 
						||
  const char* stros = NULL;
 | 
						||
  switch (xvt_sys_get_os_version())
 | 
						||
  {       
 | 
						||
  case XVT_WS_LINUX : stros = "Linux"; break;
 | 
						||
  case XVT_WS_WIN_95: stros = "Windows 95"; break;
 | 
						||
  case XVT_WS_WIN_98: stros = "Windows 98"; break;
 | 
						||
  default           : stros = "Windows NT/XP"; break;
 | 
						||
  }
 | 
						||
  os.set(stros);
 | 
						||
}
 | 
						||
 | 
						||
void TRequest_form::print_footer()
 | 
						||
{
 | 
						||
  set_footer(odd_page, TRUE);
 | 
						||
  printer().formfeed();
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TAttivazione_moduli
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TAttivazione_moduli : public TSkeleton_application
 | 
						||
{
 | 
						||
  TMask* _msk;
 | 
						||
  TInformazione_moduli* _im;
 | 
						||
 | 
						||
  word _serno;
 | 
						||
  word _wanted_users, _wanted_assist;
 | 
						||
 | 
						||
protected:
 | 
						||
  virtual bool create() ;                         
 | 
						||
  virtual bool destroy() ;                        
 | 
						||
  virtual void main_loop();
 | 
						||
  virtual bool use_files() const { return FALSE; }
 | 
						||
  virtual bool test_assistance_year() const;
 | 
						||
  
 | 
						||
  void garble(word k[4]) const;
 | 
						||
  void garble(word n, TString& str) const;
 | 
						||
  void garble_user(word u, TString& str) const;
 | 
						||
  void garble_year(word u, TString& str) const;
 | 
						||
 | 
						||
  word& serno() { return _serno; }
 | 
						||
  
 | 
						||
  void init_mask();
 | 
						||
  void update_listino();
 | 
						||
  void load_masklistino(TMask & m);
 | 
						||
  void save_masklistino(TMask & m);
 | 
						||
  int build_sheet(bool on = TRUE);
 | 
						||
  void build_key_column();
 | 
						||
  
 | 
						||
  bool burn_dongle();
 | 
						||
  
 | 
						||
  static void keyext(const TString & s, word * v);
 | 
						||
  static void encode_second_key();
 | 
						||
  
 | 
						||
  static bool user_hnd(TMask_field& f, KEY k);
 | 
						||
  static bool date_hnd(TMask_field& f, KEY k);
 | 
						||
  static bool serno_hnd(TMask_field& f, KEY k);
 | 
						||
  static bool decode_hnd(TMask_field& f, KEY k);
 | 
						||
  static bool activate_hnd(TMask_field& f, KEY k);
 | 
						||
  
 | 
						||
  static bool k_notify(TSheet_field& f, int r, KEY k);
 | 
						||
  static bool change_users_handler(TMask_field&, KEY key);
 | 
						||
  static bool maxuser_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool change_assist_handler(TMask_field&, KEY key);
 | 
						||
  static bool assist_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool print_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool printlist_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool aggiorna_listino_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool modifica_listino_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool aga_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool sh_nposti_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool sh_acquisto_handler(TMask_field& fld, KEY key);
 | 
						||
  static bool sh_aggiornamento_handler(TMask_field& fld, KEY key);
 | 
						||
  
 | 
						||
protected:
 | 
						||
  bool new_module_requested();
 | 
						||
  
 | 
						||
  void print_request();  
 | 
						||
  void print_answer();
 | 
						||
  void print_status();
 | 
						||
  void print_listino();
 | 
						||
 | 
						||
public:                       
 | 
						||
  virtual void print();
 | 
						||
 | 
						||
  TAttivazione_moduli() : _msk(NULL), _wanted_users(0), _wanted_assist(0) { }
 | 
						||
  virtual ~TAttivazione_moduli() { }
 | 
						||
};
 | 
						||
 | 
						||
 | 
						||
HIDDEN TAttivazione_moduli& app() { return (TAttivazione_moduli &)main_app(); }
 | 
						||
 | 
						||
int round_price(int val)
 | 
						||
{
 | 
						||
  if (val>50000) 
 | 
						||
    val=int((val+9)/10000)*10000;
 | 
						||
  else
 | 
						||
    val=int((val+9)/10)*10;
 | 
						||
  return val;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::sh_nposti_handler(TMask_field& fld, KEY key)       
 | 
						||
{
 | 
						||
  if (key == K_TAB && fld.focusdirty())
 | 
						||
  {
 | 
						||
    // default
 | 
						||
    int posti = atoi(fld.get());
 | 
						||
    if (posti<=1)
 | 
						||
      return TRUE;
 | 
						||
    int val = fld.mask().get_int(F_ACQ1);
 | 
						||
    switch (posti)
 | 
						||
    {
 | 
						||
      case 2:
 | 
						||
        val = int(val * .30);     break;
 | 
						||
      case 3:
 | 
						||
        val = int(val * .20);     break;
 | 
						||
      case 5:
 | 
						||
        val = int(val * .15);    break;
 | 
						||
      case 9:
 | 
						||
        val = int(val * .10);     break;
 | 
						||
      case 30:
 | 
						||
        val = int(val * .05);    break;
 | 
						||
      default:
 | 
						||
        val=0;
 | 
						||
    }
 | 
						||
    val = round_price(val);
 | 
						||
    if (fld.mask().field(fld.dlg()+1).empty())
 | 
						||
      fld.mask().field(fld.dlg()+1).set(val) ;  // costo di acquisto
 | 
						||
    val=fld.mask().get_int(fld.dlg()+1);
 | 
						||
    val = int (val * .35);
 | 
						||
    val = round_price(val);
 | 
						||
    fld.mask().field(fld.dlg()+2).set(val) ;     // costo di aggiornamento
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::sh_acquisto_handler(TMask_field& fld, KEY key)
 | 
						||
{
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
bool TAttivazione_moduli::sh_aggiornamento_handler(TMask_field& fld, KEY key)
 | 
						||
{
 | 
						||
  if (key == K_TAB && fld.empty())
 | 
						||
  {
 | 
						||
  }
 | 
						||
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
void TAttivazione_moduli::update_listino()
 | 
						||
{
 | 
						||
  TMask msklistino("ba1500b") ;
 | 
						||
  TMask &smask = msklistino.sfield(F_MODULILIST).sheet_mask();
 | 
						||
  for (int c=0; c<6; c++)
 | 
						||
  {
 | 
						||
    smask.set_handler(F_POSTI1+3*c,  sh_nposti_handler    );
 | 
						||
    smask.set_handler(F_ACQ1+3*c,    sh_acquisto_handler  );
 | 
						||
    smask.set_handler(F_AGG1+3*c,    sh_aggiornamento_handler);
 | 
						||
  }
 | 
						||
  load_masklistino(msklistino);
 | 
						||
  if (msklistino.run()==K_ENTER)
 | 
						||
  {
 | 
						||
    save_masklistino(msklistino);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
 | 
						||
void TAttivazione_moduli::load_masklistino(TMask &msklistino)
 | 
						||
{
 | 
						||
  TWait_cursor hourglass;
 | 
						||
  TInstall_ini ini;
 | 
						||
  TDate dt(ini.get("Listino","Main"));
 | 
						||
  if (!dt.empty())
 | 
						||
    msklistino.set(F_DATALIST,dt);
 | 
						||
 | 
						||
  TSheet_field& sf = msklistino.sfield(F_MODULILIST);
 | 
						||
  for (int i = 0; i < MAX_AUT; i++)
 | 
						||
  {
 | 
						||
    const TString16 modname(_im->get_name_by_order(i));
 | 
						||
    if (modname.empty())
 | 
						||
      break;
 | 
						||
    
 | 
						||
    TToken_string& riga = sf.row(i);
 | 
						||
    riga=modname;
 | 
						||
 | 
						||
    const TFixed_string d(_im->get_description_by_order(i));
 | 
						||
    riga.add(d); 
 | 
						||
    riga.trim();
 | 
						||
    riga.add("1"); // prima colonna = monoutenza
 | 
						||
 | 
						||
    TString_array prices;
 | 
						||
    ini.set_paragraph(modname);
 | 
						||
    ini.list_variables(prices, TRUE,modname,TRUE); // get array sorted by var name
 | 
						||
    FOR_EACH_ARRAY_ROW(prices, v, key)
 | 
						||
    {
 | 
						||
      const TFixed_string price(key->get(0));
 | 
						||
      if (price.compare("Prezzo", 6, TRUE) == 0)
 | 
						||
      {
 | 
						||
        TString16 colonna(price.sub(7,price.len()-1));
 | 
						||
        if (atoi(colonna) != 1)
 | 
						||
          riga.add(colonna);
 | 
						||
        TToken_string valori(key->get(1),',');
 | 
						||
        riga.add(valori.get(0));
 | 
						||
        riga.add(valori.get(1));
 | 
						||
      }
 | 
						||
    }
 | 
						||
    sf.check_row(i);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::save_masklistino(TMask &msklistino)
 | 
						||
{
 | 
						||
  TWait_cursor hourglass;
 | 
						||
  TInstall_ini ini;
 | 
						||
  ini.set_paragraph("Main");  
 | 
						||
  ini.set("Listino",msklistino.get(F_DATALIST));
 | 
						||
  TSheet_field& sf = (TSheet_field&)msklistino.field(F_MODULILIST);
 | 
						||
  const int items=sf.items();
 | 
						||
  for (int i = 0; i < items; i++)
 | 
						||
  {
 | 
						||
    TToken_string& riga = sf.row(i);
 | 
						||
    TString tmpstr(riga.get(0));
 | 
						||
    ini.set_paragraph(tmpstr);
 | 
						||
    
 | 
						||
    int nposti;
 | 
						||
    for (int col=0; col < 6; col++)
 | 
						||
    {
 | 
						||
      const char * p=riga.get(3*col+2);
 | 
						||
      if (p==NULL || (nposti=atoi(p))==0 )
 | 
						||
        break;
 | 
						||
      tmpstr = riga.get(3*col+3);
 | 
						||
      if (tmpstr.blank())
 | 
						||
        continue;
 | 
						||
      tmpstr << ',' << riga.get(3*col+4);
 | 
						||
      TString16 varname("Prezzo");
 | 
						||
      varname << '(' << nposti << ')';
 | 
						||
      ini.set(varname,tmpstr);
 | 
						||
      if (ini.new_paragraph())
 | 
						||
        ini.set("Descrizione",riga.get(1));
 | 
						||
    }
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
int TAttivazione_moduli::build_sheet(bool on)
 | 
						||
{
 | 
						||
  int nmod = 0;
 | 
						||
  TSheet_field& sf = (TSheet_field&)_msk->field(F_MODULI);
 | 
						||
  for (int i = 0; i < MAX_AUT; i++)
 | 
						||
  {
 | 
						||
    if (*_im->get_name_by_order(i)=='\0')
 | 
						||
      break;
 | 
						||
    
 | 
						||
    const TFixed_string d(_im->get_description_by_order(i));
 | 
						||
    TToken_string& riga = sf.row(i);
 | 
						||
    riga = d; 
 | 
						||
    riga.trim();
 | 
						||
    const int module = _im->get_module_by_order(i);
 | 
						||
    
 | 
						||
    const bool ics = module == 0 || (on && ::dongle().active(module));
 | 
						||
    if (ics)
 | 
						||
    {
 | 
						||
      riga.add("X");
 | 
						||
      if (module != 0) 
 | 
						||
        nmod++;     
 | 
						||
      else
 | 
						||
        sf.disable_cell(i, -1);  // Disabilita la riga della base
 | 
						||
    } 
 | 
						||
    else 
 | 
						||
      riga.add(" ");
 | 
						||
    riga.add(module);
 | 
						||
  }
 | 
						||
  return nmod;
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::garble(word k[4]) const
 | 
						||
{
 | 
						||
  ::dongle().garble(k);
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::garble(word n, TString& str) const
 | 
						||
{
 | 
						||
  const TDate today(_msk->get(F_DT));
 | 
						||
  const long val = today.date2julian();
 | 
						||
  
 | 
						||
  word data[4];
 | 
						||
  data[0] = word(_msk->get_int(F_SN));
 | 
						||
  data[1] = n;
 | 
						||
  data[2] = word(val >> 16);
 | 
						||
  data[3] = word(val & 0xFFFF);
 | 
						||
  garble(data);
 | 
						||
  str.format("%04X%04X", data[0], data[1]);
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::garble_user(word u, TString& str) const
 | 
						||
{
 | 
						||
  const TDate today(_msk->get(F_DT));
 | 
						||
  const long val = today.date2julian();
 | 
						||
  
 | 
						||
  word data[4];
 | 
						||
  data[0] = word(_msk->get_int(F_SN));
 | 
						||
  data[1] = u;
 | 
						||
  data[2] = word(val >> 16);
 | 
						||
  data[3] = word(val & 0xFFFF);
 | 
						||
  garble(data);
 | 
						||
  str.format("%04X%04X", data[0], data[1]);
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::garble_year(word y, TString& str) const
 | 
						||
{
 | 
						||
  const TDate today(_msk->get(F_DT));
 | 
						||
  const long val = today.date2julian();
 | 
						||
  
 | 
						||
  word data[4];
 | 
						||
  data[0] = y;
 | 
						||
  data[1] = word(_msk->get_int(F_SN));
 | 
						||
  data[2] = word(val >> 16);
 | 
						||
  data[3] = word(val & 0xFFFF);
 | 
						||
  garble(data);
 | 
						||
  str.format("%04X%04X", data[0], data[1]);
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::build_key_column()
 | 
						||
{       
 | 
						||
  TSheet_field& sf = _msk->sfield(F_MODULI);
 | 
						||
  sf.enable_column(F_KEY, FALSE);
 | 
						||
 | 
						||
  TString16 tmp;
 | 
						||
  FOR_EACH_SHEET_ROW_BACK(sf, i, riga)
 | 
						||
  {   
 | 
						||
    if (!sf.cell_disabled(i, 1))
 | 
						||
    {
 | 
						||
      int module = riga->get_int(2);
 | 
						||
      garble(module, tmp);
 | 
						||
      riga->add(tmp, 3);
 | 
						||
    }  
 | 
						||
  }
 | 
						||
  sf.force_update();
 | 
						||
  
 | 
						||
  _msk->set(F_USERS, ::dongle().max_users());
 | 
						||
  _msk->set(F_ASSIST, ::dongle().year_assist());
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::burn_dongle()
 | 
						||
{   
 | 
						||
  TDongle& din = ::dongle();
 | 
						||
  bool ok = din.type() == _user_dongle;
 | 
						||
  if (ok)
 | 
						||
  {
 | 
						||
    TString16 str, key;
 | 
						||
  
 | 
						||
    TSheet_field& sf = _msk->sfield(F_MODULI);
 | 
						||
    FOR_EACH_SHEET_ROW(sf, i, riga)
 | 
						||
    {
 | 
						||
      key = riga->get(3); key.trim();
 | 
						||
      if (key.not_empty())
 | 
						||
      {
 | 
						||
        const int module = riga->get_int(2);
 | 
						||
        garble(module, str);
 | 
						||
        const bool good = key == str;
 | 
						||
        if (good)
 | 
						||
        {
 | 
						||
          if (!din.active(module) &&
 | 
						||
              yesno_box(FR("Confermare l'attivazione del modulo %d:\n%s"), 
 | 
						||
                        module, riga->get(0)))
 | 
						||
            din.activate(module);
 | 
						||
        }
 | 
						||
        else
 | 
						||
        {
 | 
						||
          if (din.active(module) &&
 | 
						||
              yesno_box(FR("Confermare la disattivazione del modulo %d:\n%s"), 
 | 
						||
                        module, riga->get(0)))
 | 
						||
            din.deactivate(module);
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }  
 | 
						||
    
 | 
						||
    if (din.dirty())
 | 
						||
    {
 | 
						||
      ok = din.burn();
 | 
						||
      if (!ok)
 | 
						||
        error_box(TR("Impossibile riprogrammare la chiave"));
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  return ok;  
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::maxuser_handler(TMask_field& fld, KEY key)
 | 
						||
{         
 | 
						||
  bool ok = TRUE;
 | 
						||
  if (key == K_TAB && fld.focusdirty())
 | 
						||
  {
 | 
						||
    const int utenti = atoi(fld.get());
 | 
						||
    if (utenti > 0 && utenti < 10000)
 | 
						||
    {                             
 | 
						||
      TString16 str;
 | 
						||
      app().garble_user(utenti, str);
 | 
						||
      fld.mask().set(102, str);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      ok = fld.error_box(TR("Numero di utenti errato"));  
 | 
						||
  }  
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::change_users_handler(TMask_field& fld, KEY key)
 | 
						||
{             
 | 
						||
  if (key == K_SPACE)
 | 
						||
  {                                   
 | 
						||
    TMask m(TR("Utenti"), 1, 40, 5);
 | 
						||
    m.add_number(101, 0, PR("Utenti "), 1, 1, 4, "U");
 | 
						||
    m.add_string(102, 0, PR("Codice "), 1, 2, 8, "U");
 | 
						||
    m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
 | 
						||
    m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
 | 
						||
    
 | 
						||
    TDongle& dongle = ::dongle();
 | 
						||
    if (dongle.type() == _user_dongle)
 | 
						||
      m.set(101, dongle.max_users());  
 | 
						||
    else
 | 
						||
    {
 | 
						||
      m.set_handler(101, maxuser_handler);
 | 
						||
      m.disable(102);
 | 
						||
    }  
 | 
						||
    
 | 
						||
    if (m.run() == K_ENTER)
 | 
						||
    {
 | 
						||
      const int utenti = m.get_int(101);
 | 
						||
      if (dongle.type() == _user_dongle)
 | 
						||
      {
 | 
						||
        if (utenti > 0 && utenti < 10000)
 | 
						||
        {                  
 | 
						||
          if (m.field(102).empty())
 | 
						||
          {
 | 
						||
            app()._wanted_users = utenti; 
 | 
						||
            if (utenti > 0)
 | 
						||
              fld.message_box(TR("Premere il bottone '%s'\nper richiedere l'attivazione di %d utenti."),
 | 
						||
                              fld.mask().field(F_PRINT).prompt(), utenti);
 | 
						||
          }
 | 
						||
          else
 | 
						||
          {
 | 
						||
            TString16 str;
 | 
						||
            app().garble_user(utenti, str);
 | 
						||
            if (str == m.get(102))
 | 
						||
            { 
 | 
						||
              dongle.set_max_users(utenti);
 | 
						||
              fld.mask().set(F_USERS, utenti);
 | 
						||
            }  
 | 
						||
            else
 | 
						||
              fld.error_box(TR("Codice errato"));
 | 
						||
          }    
 | 
						||
        }  
 | 
						||
        else
 | 
						||
          fld.error_box(TR("Numero di utenti errato"));
 | 
						||
      }                                           
 | 
						||
      else
 | 
						||
        app()._wanted_users = utenti;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::assist_handler(TMask_field& fld, KEY key)
 | 
						||
{         
 | 
						||
  bool ok = TRUE;
 | 
						||
  if (key == K_TAB && fld.focusdirty())
 | 
						||
  {
 | 
						||
    const int year = atoi(fld.get());
 | 
						||
    if (year >= 1997 && year <= 2997)
 | 
						||
    {                             
 | 
						||
      TString16 str;
 | 
						||
      app().garble_year(year, str);
 | 
						||
      fld.mask().set(102, str);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      ok = fld.error_box(TR("Anno errato"));  
 | 
						||
  }  
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::change_assist_handler(TMask_field& fld, KEY key)
 | 
						||
{             
 | 
						||
  if (key == K_SPACE)
 | 
						||
  {                                   
 | 
						||
    TMask m(TR("Assistenza"), 1, 40, 5);
 | 
						||
    m.add_number(101, 0, PR("Anno   "), 1, 1, 4, "U");
 | 
						||
    m.add_string(102, 0, PR("Codice "), 1, 2, 8, "U");
 | 
						||
    m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
 | 
						||
    m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
 | 
						||
    
 | 
						||
    TDongle& dongle = ::dongle();
 | 
						||
    if (dongle.type() == _user_dongle)
 | 
						||
      m.set(101, dongle.year_assist());  
 | 
						||
    else
 | 
						||
    {
 | 
						||
      m.set_handler(101, assist_handler);
 | 
						||
      m.disable(102);
 | 
						||
    }  
 | 
						||
    
 | 
						||
    if (m.run() == K_ENTER)
 | 
						||
    {
 | 
						||
      word year = m.get_int(101);
 | 
						||
      if (dongle.type() == _user_dongle)
 | 
						||
      {
 | 
						||
        if (year >= 1997 && year <= 2997)
 | 
						||
        {      
 | 
						||
          if (m.field(102).empty())
 | 
						||
          {
 | 
						||
            app()._wanted_assist = year;
 | 
						||
            fld.message_box(FR("Premere il bottone '%s'\nper rinnovare il contratto di assistenza per l'anno %u."),
 | 
						||
                            fld.mask().field(F_PRINT).prompt(), year);
 | 
						||
          }
 | 
						||
          else
 | 
						||
          {
 | 
						||
            TString16 str;
 | 
						||
            app().garble_year(year, str);
 | 
						||
            bool ok = str == m.get(102);
 | 
						||
            if (ok)
 | 
						||
            { 
 | 
						||
              if (year <= 1997)
 | 
						||
                year = 0;
 | 
						||
              dongle.set_year_assist(year);
 | 
						||
              fld.mask().set(F_ASSIST, year);
 | 
						||
            }  
 | 
						||
            else
 | 
						||
              fld.error_box(TR("Codice errato"));
 | 
						||
          }    
 | 
						||
        }  
 | 
						||
        else
 | 
						||
          fld.error_box(TR("Anno errato"));
 | 
						||
      }                                           
 | 
						||
      else
 | 
						||
        app()._wanted_assist = year;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::print_handler(TMask_field& fld, KEY key)
 | 
						||
{
 | 
						||
  if (key == K_SPACE)
 | 
						||
    app().print();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::printlist_handler(TMask_field& fld, KEY key)
 | 
						||
{
 | 
						||
  if (key == K_SPACE)
 | 
						||
    app().print_listino();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
bool TAttivazione_moduli::aga_handler(TMask_field& fld, KEY key)
 | 
						||
{
 | 
						||
  if (key == K_SPACE)        
 | 
						||
  {
 | 
						||
    TMask mask(TR("Produttore"), 1, 50, 6);
 | 
						||
    mask.add_string(101, 0, PR("Ditta "), 1, 1, 40);
 | 
						||
    mask.add_string(102, 0, PR("Amministratore di sistema  "), 1, 2, 8, "U");
 | 
						||
    mask.add_string(103, 0, PR("Password di amministratore "), 1, 3, 8, "*");
 | 
						||
 | 
						||
    mask.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
 | 
						||
    mask.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
 | 
						||
    
 | 
						||
    TConfig ini("install.ini", "Main");
 | 
						||
    mask.set(101, ::decode(ini.get("Producer")));
 | 
						||
    mask.set(102, ::decode(ini.get("Administrator")));
 | 
						||
    mask.set(103, ::decode(ini.get("Password")));
 | 
						||
    if (mask.run() == K_ENTER)
 | 
						||
    {
 | 
						||
      ini.set("Producer",      ::encode(mask.get(101)));
 | 
						||
      ini.set("Administrator", ::encode(mask.get(102)));
 | 
						||
      ini.set("Password",      ::encode(mask.get(103)));
 | 
						||
    }
 | 
						||
  }  
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::init_mask()
 | 
						||
{
 | 
						||
  const TDate oggi(TODAY);
 | 
						||
  const int nmod  = build_sheet();
 | 
						||
 | 
						||
  if (::dongle().hardware() == _dongle_hardlock)
 | 
						||
  {
 | 
						||
    word ud[4];
 | 
						||
    ::dongle().read_words(48, 4, ud);
 | 
						||
    _msk->set(F_K2, format("%04X%04X%04X%04X", ud[0], ud[1], ud[2], ud[3]));
 | 
						||
 | 
						||
    ud[0] = ::dongle().number();
 | 
						||
    ud[1] = K1 | (nmod & LBYTEMASK);
 | 
						||
    long& l = (long&)ud[2];
 | 
						||
    l = oggi.year()*10000L + oggi.month()*100L + oggi.day();
 | 
						||
  
 | 
						||
    garble(ud);
 | 
						||
    _msk->set(F_K1, format("%04X%04X%04X%04X", ud[0], ud[1], ud[2], ud[3]));
 | 
						||
    _msk->set_caption(TR("Attivazione HARDLOCK"));
 | 
						||
  }  
 | 
						||
  else
 | 
						||
  {
 | 
						||
    _msk->hide(F_K1);
 | 
						||
    _msk->hide(F_K2);
 | 
						||
    _msk->hide(F_K3);
 | 
						||
    _msk->hide(F_K4);
 | 
						||
    _msk->set_caption(TR("Attivazione EUTRON"));
 | 
						||
  }
 | 
						||
  
 | 
						||
  _msk->set(F_SN, ::dongle().number());
 | 
						||
  _msk->set(F_DT, oggi);      
 | 
						||
  _msk->set(F_USERS, ::dongle().max_users());
 | 
						||
  _msk->set(F_ASSIST, ::dongle().year_assist());
 | 
						||
}
 | 
						||
 | 
						||
int hexdigit(char c)
 | 
						||
{
 | 
						||
  return c >= 'A' ? (c - 'A' + 10) : (c - '0');
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::keyext(const TString& s, word * val)
 | 
						||
{
 | 
						||
  for (int i = 0 ; i < 4; i++)
 | 
						||
  {
 | 
						||
    const int off = i * 4;
 | 
						||
    word & l = val[i];
 | 
						||
    
 | 
						||
    l = 0;
 | 
						||
    for (int j = 0; j < 4; j++)
 | 
						||
      l = l * 16 + hexdigit(s[off + j]);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::user_hnd(TMask_field & f, KEY k)
 | 
						||
{
 | 
						||
  const TString16 k4(f.get());
 | 
						||
  if (!f.to_check(k) || k4.empty()) 
 | 
						||
    return TRUE;
 | 
						||
  
 | 
						||
  TMask & m = f.mask();
 | 
						||
  word ud1[4], ud2[4];
 | 
						||
  const TString16 k3(m.get(F_K3));
 | 
						||
  
 | 
						||
  keyext(k3, ud1);
 | 
						||
  keyext(k4, ud2);
 | 
						||
  
 | 
						||
  app().garble(ud1);
 | 
						||
  const long & l = (long &) ud1[0];
 | 
						||
  TDate d(l), d1(TODAY);
 | 
						||
 | 
						||
  d.addmonth(3);
 | 
						||
  if (d < d1)
 | 
						||
  {
 | 
						||
    f.error_box(TR("Data non valida"));
 | 
						||
    return k != K_ENTER;
 | 
						||
  }
 | 
						||
  if ((ud1[2] & UBYTEMASK) != K1 || ud1[3] != app().serno()) 
 | 
						||
  {
 | 
						||
    f.error_box(TR("Primo codice errato"));
 | 
						||
    return k != K_ENTER;
 | 
						||
  }
 | 
						||
    
 | 
						||
  app().garble(ud2);
 | 
						||
  for (int i = 0; i < 4; i++) ud2[i] ^= app().serno();
 | 
						||
  if (ud2[3] != 0) 
 | 
						||
  {
 | 
						||
    f.error_box(TR("Secondo codice errato"));
 | 
						||
    return k != K_ENTER;
 | 
						||
  }
 | 
						||
  TSheet_field& sf = (TSheet_field&) m.field(F_MODULI);
 | 
						||
  const int un = app()._im->unassigned();
 | 
						||
  for (i = un; i < MAX_AUT; i++)
 | 
						||
  {
 | 
						||
    const int af = app()._im->get_module_by_order(i) - 1;
 | 
						||
    if (af < 0) continue;
 | 
						||
    TToken_string& tt = sf.row(i-un);
 | 
						||
    tt.add(BITTEST(ud2[af / 16], af % 16) ? "X" : " ", 1);
 | 
						||
  }
 | 
						||
  if (k == K_ENTER)
 | 
						||
  {
 | 
						||
    keyext(k4, ud2);
 | 
						||
    if (::dongle().write_words(48, 4, ud2))
 | 
						||
      message_box(TR("Programmazione effettuata con successo"));
 | 
						||
  } 
 | 
						||
  else
 | 
						||
    sf.force_update();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::serno_hnd(TMask_field& f, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_TAB && f.focusdirty())
 | 
						||
  {
 | 
						||
    app().build_key_column();
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::date_hnd(TMask_field& f, KEY k)
 | 
						||
{    
 | 
						||
  if (k == K_TAB && f.focusdirty())
 | 
						||
  {       
 | 
						||
    const TDate data(f.get());
 | 
						||
    const TDate oggi(TODAY);
 | 
						||
    if (data > oggi)
 | 
						||
      return f.error_box(FR("La data deve essere antecedente a quella di sistema"));
 | 
						||
      
 | 
						||
    const TDate& last_update = ::dongle().last_update();
 | 
						||
    if (data < last_update)
 | 
						||
      return f.error_box(FR("La data deve essere successiva al %s"), last_update.string());
 | 
						||
    
 | 
						||
    const int year_assist = ::dongle().year_assist()+1;
 | 
						||
    if (data.year() > year_assist)  
 | 
						||
      return f.error_box(FR("La data deve essere antecedente al 31-12-%d"), year_assist);
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::encode_second_key()
 | 
						||
{
 | 
						||
  TMask * m = app()._msk;
 | 
						||
  word    ud1[4], ud2[4];
 | 
						||
  int     nmod = 0;
 | 
						||
  
 | 
						||
  for (int i = 0; i < 4; i++) ud2[i] = 0;
 | 
						||
  TSheet_field& sf = (TSheet_field&) m->field(F_MODULI);
 | 
						||
  const int un = app()._im->unassigned();
 | 
						||
  for (i = un; i < MAX_AUT; i++)
 | 
						||
  {
 | 
						||
    const int af = app()._im->get_module_by_order(i) -1;
 | 
						||
    if (af < 0) continue;
 | 
						||
    TToken_string& tt = sf.row(i-un);
 | 
						||
    if (tt.get(1)[0] == 'X')
 | 
						||
    {
 | 
						||
      BITSET(ud2[af / 16], af % 16, TRUE);
 | 
						||
      nmod++;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  for (i = 0; i < 4; i++) ud2[i] ^= app().serno();
 | 
						||
 | 
						||
  const TDate d(m->get(F_DT));
 | 
						||
  long & l = (long &) ud1[0];
 | 
						||
  
 | 
						||
  l = d.year()*10000L + d.month()*100L + d.day();
 | 
						||
  ud1[2] = K1 | (nmod & UBYTEMASK);
 | 
						||
  ud1[3] = app().serno();
 | 
						||
  
 | 
						||
  app().garble(ud1);
 | 
						||
  m->set(F_K3, format("%04X%04X%04X%04X", ud1[0], ud1[1], ud1[2], ud1[3]));
 | 
						||
 | 
						||
  app().garble(ud2);
 | 
						||
  m->set(F_K4, format("%04X%04X%04X%04X", ud2[0], ud2[1], ud2[2], ud2[3]));
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::decode_hnd(TMask_field & f, KEY k)
 | 
						||
{
 | 
						||
  const TString16 k2(f.get());
 | 
						||
  if (!f.to_check(k) || k2.empty()) 
 | 
						||
    return TRUE;
 | 
						||
  
 | 
						||
  TMask& m = f.mask();
 | 
						||
  word ud1[4], ud2[4];
 | 
						||
  const TString16 k1(m.get(F_K1));
 | 
						||
  
 | 
						||
  keyext(k1, ud1);
 | 
						||
  keyext(k2, ud2);
 | 
						||
 | 
						||
  app().garble(ud1);
 | 
						||
  long & l = (long &) ud1[2];
 | 
						||
  const TDate  d(l);
 | 
						||
  app().serno() = ud1[0];
 | 
						||
  if ((ud1[1] & UBYTEMASK) != K1)
 | 
						||
    return f.error_box(TR("Primo codice errato"));
 | 
						||
  
 | 
						||
  app().garble(ud2);
 | 
						||
  for (int i = 0; i < 4; i++) ud2[i] ^= app().serno();
 | 
						||
  if (ud2[3] != 0)
 | 
						||
    return f.error_box(TR("Secondo codice errato"));
 | 
						||
  m.set(F_SN, app().serno());
 | 
						||
  m.set(F_DT, d);
 | 
						||
  m.set(F_K3,k1);
 | 
						||
  m.set(F_K4,k2);
 | 
						||
  TSheet_field& sf = (TSheet_field&) m.field(F_MODULI);
 | 
						||
  const int un = app()._im->unassigned();
 | 
						||
  for (i = un; i < MAX_AUT; i++)
 | 
						||
  {
 | 
						||
    const int af = app()._im->get_module_by_order(i) -1;
 | 
						||
    if (af < 0) continue;
 | 
						||
    TToken_string& tt = sf.row(i-un);
 | 
						||
    tt.add(BITTEST(ud2[af / 16], af % 16) ? "X" : " ", 1);
 | 
						||
  }
 | 
						||
  encode_second_key();
 | 
						||
  sf.force_update();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::activate_hnd(TMask_field & f, KEY k)
 | 
						||
{
 | 
						||
  encode_second_key();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::k_notify(TSheet_field& f, int r, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_INS || k == K_DEL)
 | 
						||
    return FALSE;
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
bool TAttivazione_moduli::modifica_listino_handler(TMask_field& fld, KEY key)
 | 
						||
{       
 | 
						||
  bool ok = TRUE;
 | 
						||
  if (key == K_SPACE)
 | 
						||
  {
 | 
						||
    app().update_listino();
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
bool TAttivazione_moduli::aggiorna_listino_handler(TMask_field& fld, KEY key)
 | 
						||
{       
 | 
						||
  bool ok = TRUE;
 | 
						||
  if (key == K_SPACE)
 | 
						||
  {
 | 
						||
    TInstall_ini ini;    
 | 
						||
    TFilename name = ini.get("DiskPath");
 | 
						||
    name.add(ini.default_name());
 | 
						||
    while (!name.exist())
 | 
						||
    {
 | 
						||
      TMask msk(TR("Aggiornamento listino"), 1, -1, -1, 60, 4);
 | 
						||
      msk.add_string(DLG_USER, 0, PR("Percorso "), 1, 1, 50);
 | 
						||
      msk.add_button(DLG_CANCEL, 0, "", -12, -1, 10, 2);
 | 
						||
      msk.add_button(DLG_OK, 0, "", -22, -1, 10, 2);
 | 
						||
      msk.set(DLG_USER, name);
 | 
						||
      if (msk.run() == K_ENTER)
 | 
						||
        name = msk.get(DLG_USER);
 | 
						||
      else
 | 
						||
      {
 | 
						||
        ok = FALSE;
 | 
						||
        break;
 | 
						||
      }
 | 
						||
    }
 | 
						||
    if (ok)
 | 
						||
    {
 | 
						||
      if (ok = ini.update_prices(name))
 | 
						||
        message_box(TR("Listino aggiornato"));
 | 
						||
      else
 | 
						||
        message_box(TR("Listino gi<67> aggiornato"));
 | 
						||
    }
 | 
						||
  }  
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::print_request()
 | 
						||
{
 | 
						||
  TRequest_form form("ba1500a");
 | 
						||
  TForm_item& num    = form.find_field('B', odd_page, 101);
 | 
						||
  TForm_item& descr  = form.find_field('B', odd_page, 102);
 | 
						||
  TForm_item& codice = form.find_field('B', odd_page, 103);
 | 
						||
  TForm_item& price  = form.find_field('B', odd_page, 104);
 | 
						||
  TForm_item& manut  = form.find_field('B', odd_page, 105);
 | 
						||
      
 | 
						||
  TInstall_ini ini;    
 | 
						||
  ini.write_protect();
 | 
						||
 | 
						||
  const bool special = _wanted_assist > ::dongle().year_assist() || _wanted_users != 0;
 | 
						||
  const word users = max(_wanted_users, ::dongle().max_users());
 | 
						||
 | 
						||
  TWait_cursor hourglass;
 | 
						||
  TSheet_field& sheet = _msk->sfield(F_MODULI);
 | 
						||
  for (TDongleType owner = _aga_dongle; 
 | 
						||
       owner <= _prassi_dongle; 
 | 
						||
       owner = TDongleType(owner+1))
 | 
						||
  {
 | 
						||
    int found = 0;
 | 
						||
    TString str;
 | 
						||
    
 | 
						||
    FOR_EACH_SHEET_ROW(sheet, r, row)
 | 
						||
    { 
 | 
						||
      //const int module = _im->get_module_by_order(r);
 | 
						||
      const int module = row->get_int(2) ;
 | 
						||
      const bool active = ::dongle().active(module);
 | 
						||
      const bool wanted = *row->get(1) > ' ';
 | 
						||
 | 
						||
      if (!special && active)
 | 
						||
        continue;
 | 
						||
      if (!wanted && !active)  
 | 
						||
        continue;
 | 
						||
      if (_im->get_owner(module) != owner)
 | 
						||
        continue;
 | 
						||
      
 | 
						||
      if (found == 0)
 | 
						||
      {
 | 
						||
        printer().open();      
 | 
						||
        switch (owner)
 | 
						||
        {
 | 
						||
          case _prassi_dongle:
 | 
						||
            form.find_field('H',odd_page,1).set("Partners"); break;
 | 
						||
          default: //case _aga_dongle:
 | 
						||
            form.find_field('H',odd_page,1).set("A.G.A."); break;
 | 
						||
        }
 | 
						||
        form.update_serno(_msk->get(F_SN));
 | 
						||
        form.update_dongle(::dongle());
 | 
						||
        form.update_os();
 | 
						||
      }
 | 
						||
        
 | 
						||
      str.format("%3d", ++found);
 | 
						||
      num.set(str);
 | 
						||
        
 | 
						||
      str = row->get(0);
 | 
						||
      descr.set(str);
 | 
						||
        
 | 
						||
      str = active ? TR("*ATTIVO*") : "";
 | 
						||
      codice.set(str);
 | 
						||
      
 | 
						||
      str = _im->get_name(module);
 | 
						||
      real full, assist;    
 | 
						||
      ini.prices(str, users, full, assist);
 | 
						||
      if (active)
 | 
						||
      {
 | 
						||
        real old_full, old_assist;
 | 
						||
        ini.prices(str, ::dongle().max_users(), old_full, old_assist);
 | 
						||
        full -= old_full;
 | 
						||
        assist -= old_assist;
 | 
						||
      }
 | 
						||
      else
 | 
						||
        assist = 0.0;
 | 
						||
      
 | 
						||
      price.set(full.string());
 | 
						||
      manut.set(assist.string());
 | 
						||
 | 
						||
      form.print(-1);
 | 
						||
    }   
 | 
						||
 | 
						||
    if (special && found > 0)
 | 
						||
    {    
 | 
						||
      codice.set("");
 | 
						||
      price.set("");
 | 
						||
      manut.set("");
 | 
						||
      if (_wanted_users != 0)
 | 
						||
      {
 | 
						||
        str.format("%3d", ++found);
 | 
						||
        num.set(str);
 | 
						||
         
 | 
						||
        str.format(FR("Variazione del numero utenti da %u a %u"),
 | 
						||
                   ::dongle().max_users(), _wanted_users);
 | 
						||
        descr.set(str);
 | 
						||
        form.print(-1);
 | 
						||
      }
 | 
						||
      if (_wanted_assist > ::dongle().year_assist())
 | 
						||
      {
 | 
						||
        str.format("%3d", ++found);
 | 
						||
        num.set(str);
 | 
						||
        str.format(FR("Contratto di assistenza per l'anno %u"), _wanted_assist);
 | 
						||
        descr.set(str);
 | 
						||
        form.print(-1);
 | 
						||
      }
 | 
						||
    }
 | 
						||
    
 | 
						||
    if (found)
 | 
						||
    {
 | 
						||
      form.print_footer();
 | 
						||
      printer().close();
 | 
						||
    }  
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::print_status()
 | 
						||
{
 | 
						||
  TRequest_form form("ba1500a");
 | 
						||
  TForm_item& descr  = form.find_field('B', odd_page, 102);
 | 
						||
  TForm_item& codice = form.find_field('B', odd_page, 103);
 | 
						||
 | 
						||
  form.find_field('H',odd_page,1).set("PR.A.S.S.I.");
 | 
						||
  form.update_serno(_msk->get(F_SN));
 | 
						||
  form.update_dongle(::dongle());
 | 
						||
  form.update_os();
 | 
						||
      
 | 
						||
  TWait_cursor hourglass;
 | 
						||
  printer().open();      
 | 
						||
 | 
						||
  TSheet_field& sheet = _msk->sfield(F_MODULI);
 | 
						||
  FOR_EACH_SHEET_ROW(sheet, r, row)
 | 
						||
  { 
 | 
						||
    //const int module = _im->get_module_by_order(r);
 | 
						||
    const int module = row->get_int(2) ;
 | 
						||
    const bool active = ::dongle().active(module);
 | 
						||
 
 | 
						||
    if (!active)
 | 
						||
      continue;
 | 
						||
      
 | 
						||
    descr.set(row->get(0));
 | 
						||
    codice.set(TR("*ATTIVO*"));
 | 
						||
    form.print(-1);
 | 
						||
  }
 | 
						||
 | 
						||
  printer().close();
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::print_answer()
 | 
						||
{               
 | 
						||
  TString str;
 | 
						||
  int found = 0;
 | 
						||
  
 | 
						||
  TRequest_form form("ba1500a");
 | 
						||
  TForm_item& num = form.find_field('B', odd_page, 101);
 | 
						||
  TForm_item& descr = form.find_field('B', odd_page, 102);
 | 
						||
  TForm_item& codice = form.find_field('B', odd_page, 103);
 | 
						||
  
 | 
						||
  TSheet_field& sheet = _msk->sfield(F_MODULI);
 | 
						||
  FOR_EACH_SHEET_ROW(sheet, r, row) if (*row->get(1) > ' ')
 | 
						||
  { 
 | 
						||
    const int module = _im->get_module_by_order(r);
 | 
						||
    if (module != BAAUT)
 | 
						||
    {
 | 
						||
      if (found == 0)
 | 
						||
      {
 | 
						||
        printer().open();      
 | 
						||
        form.update_serno(_msk->get(F_SN));
 | 
						||
        form.update_dongle(::dongle());
 | 
						||
        form.update_os();
 | 
						||
      }
 | 
						||
 | 
						||
      str.format("%3d", ++found);
 | 
						||
      num.set(str);
 | 
						||
        
 | 
						||
      str = row->get(0);
 | 
						||
      descr.set(str);
 | 
						||
      
 | 
						||
      str = row->get(3);
 | 
						||
      codice.set(str);
 | 
						||
 | 
						||
      form.print(-1);
 | 
						||
    }
 | 
						||
  }             
 | 
						||
  
 | 
						||
  if (_wanted_users != 0 || _wanted_assist != 0)
 | 
						||
  {
 | 
						||
    if (found == 0)
 | 
						||
    {
 | 
						||
      printer().open();      
 | 
						||
      form.update_serno(_msk->get(F_SN));
 | 
						||
      form.update_dongle(::dongle());
 | 
						||
    }
 | 
						||
    if (_wanted_users != 0)
 | 
						||
    {
 | 
						||
      str.format("%3d", ++found);
 | 
						||
      num.set(str);
 | 
						||
      str.format(FR("Variazione del numero utenti da %u a %u"),
 | 
						||
                 ::dongle().max_users(), _wanted_users);
 | 
						||
      descr.set(str);
 | 
						||
      garble_user(_wanted_users, str);
 | 
						||
      codice.set(str);
 | 
						||
      form.print(-1);
 | 
						||
    }
 | 
						||
    if (_wanted_assist != 0)
 | 
						||
    {
 | 
						||
      str.format("%3d", ++found);
 | 
						||
      num.set(str);
 | 
						||
      str.format(FR("Contratto di assistenza per l'anno %u"), _wanted_assist);
 | 
						||
      descr.set(str);
 | 
						||
      garble_year(_wanted_assist, str);
 | 
						||
      codice.set(str);
 | 
						||
      form.print(-1);
 | 
						||
    }
 | 
						||
  }
 | 
						||
 | 
						||
  if (found)
 | 
						||
  {
 | 
						||
    form.print_footer();
 | 
						||
    printer().close();
 | 
						||
  }  
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
void TAttivazione_moduli::print_listino()
 | 
						||
{
 | 
						||
  TRequest_form form("ba1500a");
 | 
						||
  TForm_item& num    = form.find_field('B', odd_page, 101);
 | 
						||
  TForm_item& descr  = form.find_field('B', odd_page, 102);
 | 
						||
  TForm_item& codice = form.find_field('B', odd_page, 103);
 | 
						||
  TForm_item& price  = form.find_field('B', odd_page, 104);
 | 
						||
  TForm_item& manut  = form.find_field('B', odd_page, 105);
 | 
						||
      
 | 
						||
  TInstall_ini ini;    
 | 
						||
  ini.write_protect();
 | 
						||
 | 
						||
  const bool special = _wanted_assist > ::dongle().year_assist() || _wanted_users != 0;
 | 
						||
  const word users = max(_wanted_users, ::dongle().max_users());
 | 
						||
 | 
						||
  TWait_cursor hourglass;
 | 
						||
  TSheet_field& sheet = _msk->sfield(F_MODULI);
 | 
						||
  {
 | 
						||
    int found = 0;
 | 
						||
    TString str;
 | 
						||
    real full, assist;    
 | 
						||
    
 | 
						||
    FOR_EACH_SHEET_ROW(sheet, r, row)
 | 
						||
    { 
 | 
						||
      const int module = row->get_int(2) ;
 | 
						||
      const bool active = ::dongle().active(module);
 | 
						||
 | 
						||
      str = _im->get_name(module);
 | 
						||
      ini.prices(str, users, full, assist, FALSE);
 | 
						||
      if (!full.is_zero() || ! assist.is_zero())
 | 
						||
      {
 | 
						||
        if (found++ == 0)
 | 
						||
        {
 | 
						||
          printer().open();      
 | 
						||
          form.find_field('H',odd_page,1).set(TR("LISTINO"));
 | 
						||
  
 | 
						||
          num.set("");
 | 
						||
          str.format(TR("Numero utenti: %u"), users );
 | 
						||
          descr.set(str);
 | 
						||
          form.print(-1);
 | 
						||
        }
 | 
						||
          
 | 
						||
        price.set(full.string());
 | 
						||
        manut.set(assist.string());
 | 
						||
 | 
						||
        str.format("%3d", found);
 | 
						||
        num.set(str);
 | 
						||
          
 | 
						||
        str = row->get(0);
 | 
						||
        descr.set(str);
 | 
						||
          
 | 
						||
        str = "";
 | 
						||
        codice.set(str);
 | 
						||
        
 | 
						||
        form.print(-1);
 | 
						||
      }   
 | 
						||
    }   
 | 
						||
    
 | 
						||
    if (found)
 | 
						||
    {
 | 
						||
      form.print_footer();
 | 
						||
      printer().close();
 | 
						||
    }  
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::new_module_requested()
 | 
						||
{
 | 
						||
  TSheet_field& sheet = _msk->sfield(F_MODULI);            
 | 
						||
  bool found = FALSE;
 | 
						||
  FOR_EACH_SHEET_ROW(sheet, r, row) 
 | 
						||
  {
 | 
						||
    if (*row->get(1) > ' ')              // Wanted!
 | 
						||
    {
 | 
						||
      const int module = row->get_int(2);
 | 
						||
      if (!::dongle().active(module))   // Not active yet?
 | 
						||
      {
 | 
						||
        found = TRUE;
 | 
						||
        break;
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return found;
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::print()
 | 
						||
{
 | 
						||
  if (::dongle().type() == _user_dongle)
 | 
						||
  {
 | 
						||
    if (new_module_requested())
 | 
						||
      print_request();
 | 
						||
    else
 | 
						||
      print_status();
 | 
						||
  }
 | 
						||
  else              
 | 
						||
    print_answer();
 | 
						||
}
 | 
						||
 | 
						||
// Questo programma non deve bloccarsi per l'anno di assistenza!
 | 
						||
bool TAttivazione_moduli::test_assistance_year() const 
 | 
						||
{ 
 | 
						||
  return TRUE; 
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::create()
 | 
						||
{
 | 
						||
  bool ok = ::dongle().login(TRUE);
 | 
						||
  if (!ok)
 | 
						||
    return FALSE;
 | 
						||
    
 | 
						||
  ok = TApplication::test_assistance_year();
 | 
						||
  if (!ok)
 | 
						||
  {
 | 
						||
    ok = update_assistance_year();
 | 
						||
    if (ok)
 | 
						||
      return FALSE;
 | 
						||
  }
 | 
						||
 | 
						||
  _im = new TInformazione_moduli;
 | 
						||
  
 | 
						||
  disable_menu_item(M_FILE_NEW);
 | 
						||
  disable_menu_item(M_FILE_PG_SETUP);
 | 
						||
 | 
						||
  _msk = new TMask("ba1500a") ;
 | 
						||
  
 | 
						||
  _msk->set_handler(F_CHANGEUSERS, change_users_handler);
 | 
						||
  _msk->set_handler(F_CHANGEASSIST, change_assist_handler);
 | 
						||
  _msk->set_handler(F_PRINT, print_handler);
 | 
						||
  _msk->set_handler(F_PRINTLIST, printlist_handler);
 | 
						||
  _msk->set_handler(F_AGGLISTINO, aggiorna_listino_handler);
 | 
						||
 | 
						||
  const TDongleType mydongle = ::dongle().type();
 | 
						||
#ifdef DBG
 | 
						||
  if (::dongle().number() == 0)
 | 
						||
#else
 | 
						||
  if (mydongle == _aga_dongle)
 | 
						||
#endif
 | 
						||
  {                                  
 | 
						||
    _msk->show(F_AGA);
 | 
						||
    _msk->set_handler(F_AGA, aga_handler);
 | 
						||
    _msk->show(F_MODLISTINO);
 | 
						||
    _msk->set_handler(F_MODLISTINO, modifica_listino_handler);
 | 
						||
  }
 | 
						||
  
 | 
						||
  TSheet_field& sf = _msk->sfield(F_MODULI);
 | 
						||
  sf.set_notify(k_notify);
 | 
						||
 | 
						||
  //const int un = _im->unassigned();
 | 
						||
  switch (mydongle)
 | 
						||
  {
 | 
						||
  case _user_dongle:
 | 
						||
    _msk->enable(F_DT);
 | 
						||
    _msk->set_handler(F_DT, date_hnd);
 | 
						||
  case _developer_dongle:
 | 
						||
  {
 | 
						||
    if (::dongle().hardware() == _dongle_hardlock)
 | 
						||
    {
 | 
						||
      _msk->disable(F_K1);
 | 
						||
      _msk->disable(F_K2);
 | 
						||
      _msk->set_handler(F_K4, user_hnd);
 | 
						||
    }
 | 
						||
    
 | 
						||
    init_mask();
 | 
						||
    
 | 
						||
    _serno=_msk->get_int(F_SN);
 | 
						||
    sf.enable_column(F_ENABLE, serno() != 0);
 | 
						||
    sf.enable_column(F_KEY, serno() != 0);
 | 
						||
  }
 | 
						||
  break;
 | 
						||
  case _prassi_dongle: 
 | 
						||
  case _aga_dongle:
 | 
						||
  {
 | 
						||
    if (::dongle().hardware() == _dongle_hardlock)
 | 
						||
    {
 | 
						||
      _msk->set_handler(F_K2, decode_hnd);
 | 
						||
      _msk->disable(F_K3);
 | 
						||
      _msk->disable(F_K4); 
 | 
						||
    }
 | 
						||
    _msk->set_handler(F_SN, serno_hnd);
 | 
						||
    _msk->enable(F_SN);
 | 
						||
    init_mask();
 | 
						||
    _serno=_msk->get_int(F_SN);
 | 
						||
        
 | 
						||
    sf.sheet_mask().field(F_ENABLE).set_handler(activate_hnd);
 | 
						||
    build_sheet(FALSE);  
 | 
						||
    
 | 
						||
    for (int i = 0; i < MAX_AUT; i++)
 | 
						||
    {
 | 
						||
      const int af = _im->get_module_by_order(i);
 | 
						||
      if (af == 0)
 | 
						||
        sf.disable_cell(i,1);            
 | 
						||
      else  
 | 
						||
        sf.enable_cell(i,1,_im->test_owner(af, mydongle));            
 | 
						||
    }
 | 
						||
    
 | 
						||
    build_key_column();
 | 
						||
  }
 | 
						||
  break;
 | 
						||
  default:
 | 
						||
  break;
 | 
						||
  }                      
 | 
						||
             
 | 
						||
  enable_menu_item(M_FILE_PG_SETUP);
 | 
						||
  enable_menu_item(M_FILE_PRINT);
 | 
						||
  return TSkeleton_application::create();
 | 
						||
}
 | 
						||
 | 
						||
bool TAttivazione_moduli::destroy()
 | 
						||
{
 | 
						||
  if (_msk != NULL) delete _msk;
 | 
						||
  if (_im  != NULL) delete _im;
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
void TAttivazione_moduli::main_loop()
 | 
						||
{
 | 
						||
  KEY res = _msk->run();
 | 
						||
  if (res == K_ENTER)
 | 
						||
    burn_dongle();
 | 
						||
 | 
						||
}
 | 
						||
 | 
						||
int ba1500(int argc, char** argv)
 | 
						||
{
 | 
						||
  // dipende dalla check_parameters fatta in main()
 | 
						||
  if (user() == ::dongle().administrator())
 | 
						||
  {
 | 
						||
    TAttivazione_moduli a ;
 | 
						||
    a.run(argc, argv, FR("Attivazione moduli"));
 | 
						||
  }
 | 
						||
  else 
 | 
						||
    error_box(FR("L'utente %s non e' abilitato all'esecuzione di questo programma"), (const char*)user());
 | 
						||
  return 0;
 | 
						||
}
 |