Files correlati : ba0 ba1 Ricompilazione Demo : [ ] Commento : Corretta gestione immagini in menu "vecchio" stile git-svn-id: svn://10.65.10.50/trunk@18317 c028cbd2-c16b-5b4b-a496-9718f37d4682
245 lines
6.5 KiB
C++
Executable File
245 lines
6.5 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <config.h>
|
|
#include <dongle.h>
|
|
#include <isam.h>
|
|
#include <modaut.h>
|
|
#include <prefix.h>
|
|
#include <netsock.h>
|
|
#include <recset.h>
|
|
#include <utility.h>
|
|
#include <xml.h>
|
|
|
|
#include "ba1103.h"
|
|
|
|
#include <doc.h>
|
|
#include <mov.h>
|
|
#include <nditte.h>
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TFirm_isamfile
|
|
// Prossimamente nelle migliori librerie:
|
|
// praticamente un TLocalisamfile di un ditta qualsiasi,
|
|
// normalmente diversa dalla corrente.
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TFirm_isamfile : public TIsamtempfile
|
|
{
|
|
protected:
|
|
static const TString& build_file_name(int logicnum, long firm);
|
|
|
|
public:
|
|
TFirm_isamfile(int logicnum, long firm = -1);
|
|
};
|
|
|
|
const TString& TFirm_isamfile::build_file_name(int logicnum, long codditta)
|
|
{
|
|
// Se codditta < 0 allora usa la ditta corrente;
|
|
// Se codditta = 0 allora usa i dati comuni
|
|
if (codditta < 0)
|
|
codditta = main_app().get_firm();
|
|
TFilename path = firm2dir(codditta);
|
|
path.add(logic2table(logicnum));
|
|
path.lower(); path.ext("dbf");
|
|
if (!path.exist() && codditta > 0)
|
|
{
|
|
NFCHECK(path, "Impossibile aprire ", (const char*)path);
|
|
path = firm2dir(0L);
|
|
path.add(logic2table(logicnum));
|
|
path.lower(); path.ext("dbf");
|
|
}
|
|
path.insert("%");
|
|
return get_tmp_string() = path;
|
|
}
|
|
|
|
TFirm_isamfile::TFirm_isamfile(int lf, long codditta)
|
|
: TIsamtempfile(lf, build_file_name(lf, codditta), false, false)
|
|
{ }
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Utilities
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Costruisce il nome del file xml locale o remoto
|
|
static void build_xml_filename(TFilename& name, bool remote)
|
|
{
|
|
const long n = dongle().number();
|
|
name.format("%05ld", n);
|
|
if (n == 0) // Le chiavi di sviluppo sono tutte 0, uso il nome della stazione
|
|
{
|
|
char host[80];
|
|
xvt_sys_get_host_name(host, sizeof(host));
|
|
name << host;
|
|
name.replace(' ', '_');
|
|
}
|
|
if (remote)
|
|
{
|
|
const TDate oggi(TODAY);
|
|
name << '_' << oggi.date2ansi();
|
|
}
|
|
name.ext("xml");
|
|
}
|
|
|
|
// Cerca un tag figlio e se non lo trova lo crea. Opzionalmente lo svuota anche.
|
|
static TXmlItem& find_or_create_child(TXmlItem& root, const char* tag, bool reset = false)
|
|
{
|
|
TXmlItem* pitem = root.FindFirstChild(tag);
|
|
if (pitem == NULL)
|
|
pitem = &root.AddChild(tag);
|
|
else
|
|
{
|
|
if (reset)
|
|
{
|
|
pitem->Destroy();
|
|
pitem->SetTag(tag);
|
|
}
|
|
}
|
|
return *pitem;
|
|
}
|
|
|
|
static const TString& get_last(long codditta, int lf, const char* field)
|
|
{
|
|
TFirm_isamfile file(lf, codditta);
|
|
if (file.last() == NOERR)
|
|
return file.get(field);
|
|
return EMPTY_STRING;
|
|
}
|
|
|
|
static int is_active_firm(long codditta)
|
|
{
|
|
if (main_app().get_firm() == codditta)
|
|
return 2;
|
|
|
|
if (prefix().exist(codditta))
|
|
{
|
|
int anno = 0;
|
|
if (dongle().active(CGAUT))
|
|
{
|
|
const TDate datareg = get_last(codditta, LF_MOV, MOV_DATAREG);
|
|
anno = datareg.year();
|
|
}
|
|
|
|
if (anno == 0 && dongle().active(VEAUT))
|
|
anno = atoi(get_last(codditta, LF_DOC, DOC_ANNO));
|
|
|
|
if (anno > 0)
|
|
{
|
|
const TDate oggi(TODAY);
|
|
const int annoscorso = oggi.year()-1;
|
|
const int annoprossimo = annoscorso+2;
|
|
if (anno >= annoscorso && anno <= annoprossimo)
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Salva o aggiorna il file xml coi dati di installazione
|
|
bool save_campo_xml()
|
|
{
|
|
TFilename filename; build_xml_filename(filename, false);
|
|
|
|
TXmlItem root;
|
|
if (!root.Load(filename))
|
|
root.SetTag("Campo");
|
|
|
|
TXmlItem& system = find_or_create_child(root, "system");
|
|
char host[_MAX_PATH];
|
|
xvt_sys_get_host_name(host, sizeof(host));
|
|
system.SetAttr("Host", host);
|
|
xvt_sys_get_user_name(host, sizeof(host));
|
|
system.SetAttr("User", host);
|
|
time_t t; time(&t);
|
|
system.SetAttr("Time", ctime(&t));
|
|
xvt_sys_get_version(host, NULL, sizeof(host));
|
|
system.SetAttr("O.S.", host);
|
|
|
|
if (prefix_valid())
|
|
{
|
|
TXmlItem& study = find_or_create_child(root, "study", true);
|
|
TRecordset* recset = create_recordset("USE NDITTE");
|
|
for (bool ok = recset->move_first(); ok; ok = recset->move_next())
|
|
{
|
|
const long codditta = recset->get(NDT_CODDITTA).as_int();
|
|
const int flag = is_active_firm(codditta);
|
|
if (flag != 0)
|
|
{
|
|
TXmlItem& firm = study.AddChild("firm");
|
|
firm.SetAttr(NDT_CODDITTA, codditta);
|
|
firm.SetAttr(NDT_RAGSOC, recset->get(NDT_RAGSOC).as_string());
|
|
firm.SetAttr("Current", flag == 2);
|
|
}
|
|
}
|
|
delete recset;
|
|
}
|
|
|
|
TXmlItem& study = find_or_create_child(root, "study");
|
|
xvt_sys_get_host_name(host, sizeof(host));
|
|
study.SetAttr("DataPath", firm2dir(-1));
|
|
study.SetAttr("ExePath", main_app().argv(0));
|
|
|
|
const TDongle& d = dongle();
|
|
TXmlItem& chiavetta = find_or_create_child(root, "dongle", true);
|
|
chiavetta.SetAttr("Number", d.number());
|
|
chiavetta.SetAttr("Users", d.max_users());
|
|
chiavetta.SetAttr("Year", d.year_assist());
|
|
chiavetta.SetAttr("Update", d.last_update().string());
|
|
switch (d.hardware())
|
|
{
|
|
case _dongle_hardlock: chiavetta.SetAttr("Model", "Hardlock"); break;
|
|
case _dongle_eutron : chiavetta.SetAttr("Model", "Eutron"); break;
|
|
case _dongle_network :
|
|
chiavetta.SetAttr("Model", "Network server");
|
|
xvt_sys_get_profile_string(NULL, "Server", "Dongle", "", host, sizeof(host));
|
|
chiavetta.SetAttr("Server", host);
|
|
break;
|
|
default: chiavetta.SetAttr("Model", "Unknown"); break;
|
|
}
|
|
|
|
TConfig ini("install.ini", "Main");
|
|
for (word m = 1; m < ENDAUT; m++) if (d.active(m))
|
|
{
|
|
const TString4 name = d.module_code2name(m);
|
|
const TString& version = ini.get("Versione", name);
|
|
if (version.full())
|
|
{
|
|
TXmlItem& module = chiavetta.AddChild("module");
|
|
module.SetAttr("Code", name);
|
|
module.SetAttr("Version", version);
|
|
module.SetAttr("Patch", ini.get("Patch"));
|
|
module.SetAttr("Date", ini.get("Data"));
|
|
}
|
|
}
|
|
|
|
root.Save(filename);
|
|
return filename.exist();
|
|
}
|
|
|
|
// Aggiorna il file xml coi dati di installazione e lo spedisce qua
|
|
bool send_campo_xml()
|
|
{
|
|
bool ok = is_power_station();
|
|
|
|
if (!ok) // Non salvare attivazioni di prova interne
|
|
{
|
|
TWait_cursor waiter;
|
|
if (save_campo_xml())
|
|
{
|
|
if (xvt_net_get_status() & 0x7)
|
|
{
|
|
TSocketClient aga;
|
|
CONNID id = aga.QueryConnection("21", "www.aga.it");
|
|
if (id > 0)
|
|
{
|
|
TFilename local, remote;
|
|
build_xml_filename(local, false);
|
|
build_xml_filename(remote, true);
|
|
ok = aga.FtpSendFile(id, remote, local, "attivazioni", "viagra");
|
|
aga.RemoveConnection(id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ok;
|
|
}
|