2019-12-03 10:36:43 +01:00
|
|
|
#include "f90.h"
|
|
|
|
#include "applicat.h"
|
|
|
|
#include "automask.h"
|
|
|
|
#include "f90200a.h"
|
|
|
|
#include "tsdb.h"
|
|
|
|
#include "../fp/fplib.h"
|
|
|
|
#include "f901tab.h"
|
2020-04-01 21:26:49 +02:00
|
|
|
#include "f90100.h"
|
2019-12-03 10:36:43 +01:00
|
|
|
|
2020-04-08 14:28:26 +02:00
|
|
|
TString escape(const char* str);
|
|
|
|
|
2019-12-03 10:36:43 +01:00
|
|
|
///////////////////////////////////////////////////////////////
|
2020-04-06 19:25:21 +02:00
|
|
|
// TF9_categorie_doc_msk
|
2019-12-03 10:36:43 +01:00
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
class TF9_categorie_doc_msk : public TAutomask
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly) override;
|
|
|
|
bool on_key(KEY key) override;
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
void check_spell() const;
|
|
|
|
void load_table() const;
|
|
|
|
void salva_tabella() const;
|
2019-12-03 10:36:43 +01:00
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
public:
|
|
|
|
TF9_categorie_doc_msk() : TAutomask("f90200a") { load_table(); }
|
2019-12-03 10:36:43 +01:00
|
|
|
};
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
bool TF9_categorie_doc_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
|
|
|
switch(o.dlg())
|
|
|
|
{
|
|
|
|
case DLG_OK:
|
|
|
|
if (e == fe_button)
|
2020-04-06 19:25:21 +02:00
|
|
|
salva_tabella();
|
|
|
|
break;
|
|
|
|
case B_DELETE:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
|
|
|
TSheet_field& sf = sfield(S_CLASSDOC);
|
|
|
|
sf.hide();
|
|
|
|
FOR_EACH_SHEET_ROW(sf, nr, row)
|
|
|
|
{
|
|
|
|
if (row->starts_with("X"))
|
|
|
|
{
|
|
|
|
sf.destroy(nr);
|
|
|
|
--nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sf.show();
|
|
|
|
}
|
2019-12-03 10:36:43 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-04-06 19:25:21 +02:00
|
|
|
/*if(o.dlg() >= F_SELCLASS && o.dlg() <= F_OPERCEE && (e == fe_init || e == fe_modify) && jolly >= 1)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}*/
|
2019-12-03 10:36:43 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
bool TF9_categorie_doc_msk::on_key(KEY key)
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
|
|
|
if (key == K_DEL)
|
|
|
|
{
|
|
|
|
TSheet_field& sf = sfield(S_CLASSDOC);
|
|
|
|
sf.hide();
|
|
|
|
int row = sf.selected();
|
|
|
|
TString_array& arr = sf.rows_array();
|
|
|
|
arr.destroy(row, true);
|
|
|
|
sf.force_update();
|
|
|
|
sf.show();
|
|
|
|
}
|
|
|
|
return TAutomask::on_key(key);
|
|
|
|
}
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
void TF9_categorie_doc_msk::check_spell() const
|
|
|
|
{
|
|
|
|
TSheet_field& sf = sfield(S_CLASSDOC);
|
|
|
|
FOR_EACH_SHEET_ROW(sf, nr, row)
|
|
|
|
{
|
|
|
|
TString start;
|
|
|
|
TString catdoc = start = row->get(F_CATDOC - 101);
|
|
|
|
catdoc.trim();
|
|
|
|
catdoc.upper();
|
|
|
|
std::string ss = (const char*)catdoc;
|
|
|
|
for (size_t i = 0; i < ss.size(); ++i)
|
|
|
|
{
|
|
|
|
if (!(ss[i] >= 'A' && ss[i] <= 'Z' || ss[i] >= '0' && ss[i] <= '9' || ss[i] == '_'))
|
|
|
|
ss.erase(i--, 1);
|
|
|
|
}
|
|
|
|
catdoc = ss.c_str();
|
|
|
|
row->add(catdoc, 1);
|
|
|
|
if (catdoc != start)
|
|
|
|
sf.force_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TF9_categorie_doc_msk::load_table() const
|
|
|
|
{
|
|
|
|
TSheet_field& sf = sfield(S_CLASSDOC);
|
|
|
|
sf.hide();
|
|
|
|
sf.destroy();
|
|
|
|
|
|
|
|
int idx = 0;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
const TString& appo = ini_get_string(CONFIG_DITTA, "F9", "CATDOC", "", idx++);
|
|
|
|
if (appo == "STOP" || appo.empty()) /* STOP: Riga terminatrice */
|
|
|
|
break;
|
|
|
|
TToken_string& row = sf.row(-1);
|
|
|
|
row = appo;
|
|
|
|
}
|
|
|
|
|
|
|
|
sf.show();
|
|
|
|
sf.force_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TF9_categorie_doc_msk::salva_tabella() const
|
|
|
|
{
|
|
|
|
check_spell();
|
|
|
|
int idx = 0;
|
|
|
|
TString iget = "start";
|
|
|
|
while (iget != "STOP" && !iget.empty())
|
|
|
|
{
|
|
|
|
iget = ini_get_string(CONFIG_DITTA, "F9", "CATDOC", "", idx);
|
|
|
|
ini_remove(CONFIG_DITTA, "F9", "CATDOC", idx++);
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
TSheet_field& sf = sfield(S_CLASSDOC);
|
|
|
|
FOR_EACH_SHEET_ROW(sf, nr, row)
|
|
|
|
{
|
2020-04-08 14:28:26 +02:00
|
|
|
if(row->get(1) && TString(row->get(1)).full())
|
2020-04-06 19:25:21 +02:00
|
|
|
ini_set_string(CONFIG_DITTA, "F9", "CATDOC", *row, idx++);
|
|
|
|
}
|
|
|
|
ini_set_string(CONFIG_DITTA, "F9", "CATDOC", "STOP", idx); // Riga terminatrice
|
|
|
|
|
|
|
|
// Reload
|
|
|
|
load_table();
|
|
|
|
}
|
|
|
|
|
2019-12-03 10:36:43 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
2020-04-06 19:25:21 +02:00
|
|
|
// TF9_categorie_doc
|
2019-12-03 10:36:43 +01:00
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
class TF9_categorie_doc : public TSkeleton_application
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
|
|
|
TString _log;
|
|
|
|
void add_error_log(TString& query);
|
|
|
|
void main_loop() override;
|
|
|
|
|
|
|
|
public:
|
2020-04-06 19:25:21 +02:00
|
|
|
TF9_categorie_doc() = default;
|
2019-12-03 10:36:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
void TF9_categorie_doc::add_error_log(TString& query)
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
2020-04-01 21:26:49 +02:00
|
|
|
_log << "\n" << query << "\n" << fp_db().sq_get_text_error() << "\n" << fp_db().sq_get_string_error();
|
2019-12-03 10:36:43 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
void TF9_categorie_doc::main_loop()
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
2020-04-06 19:25:21 +02:00
|
|
|
TF9_categorie_doc_msk msk;
|
2019-12-03 10:36:43 +01:00
|
|
|
while(msk.run() == K_ENTER)
|
|
|
|
{
|
|
|
|
TSheet_field& sf = msk.sfield(S_CLASSDOC);
|
|
|
|
TString query;
|
2020-04-06 19:25:21 +02:00
|
|
|
query << "TRUNCATE TABLE " F9_DRT ";\n";
|
|
|
|
bool ok = fp_db().sq_set_exec(query, false) && fp_db().sq_commit();
|
|
|
|
if (ok)
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
2020-04-06 19:25:21 +02:00
|
|
|
FOR_EACH_SHEET_ROW(sf, nr, row)
|
|
|
|
{
|
|
|
|
query.cut(0);
|
|
|
|
query << "INSERT INTO " F9_DRT "("
|
|
|
|
DRT_CODSOC ", "
|
|
|
|
DRT_CATDOC ", "
|
|
|
|
DRT_DESCR ", "
|
|
|
|
DRT_CLASSO ", "
|
|
|
|
DRT_CAUSSO ", "
|
|
|
|
DRT_CAUSCON ", "
|
|
|
|
DRT_TIPOCAU ", "
|
2020-04-08 14:28:26 +02:00
|
|
|
DRT_TIPOMOV ", "
|
2020-04-06 19:25:21 +02:00
|
|
|
DRT_OPCEE ")\nVALUES('" <<
|
|
|
|
ini_get_string(CONFIG_DITTA, PAR_MOD, AMBIENTE_F9) << "', '" <<
|
2020-04-08 14:28:26 +02:00
|
|
|
row->get(1) << "', '" << // Catdoc
|
|
|
|
escape(row->get(2)) << "', '" << // Descr
|
|
|
|
row->get(3) << "', '" << // Classe doc sost.
|
|
|
|
row->get(4) << "', '" << // Causale sost.
|
|
|
|
escape(row->get(5)) << "', '" << // Causale cont
|
|
|
|
escape(row->get(6)) << "', '" << // Tipo caus. cont
|
|
|
|
escape(row->get(7)) << "', '" << // Tipo mov.
|
|
|
|
row->get(8) << "');\n"; // "Operat. CEE"
|
2020-04-06 19:25:21 +02:00
|
|
|
ok &= fp_db().sq_set_exec(query, false) && fp_db().sq_commit();
|
|
|
|
if (!ok)
|
|
|
|
break;
|
|
|
|
}
|
2019-12-03 10:36:43 +01:00
|
|
|
}
|
2020-04-06 19:25:21 +02:00
|
|
|
|
|
|
|
if (!ok)
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
|
|
|
add_error_log(query);
|
|
|
|
ofstream fout;
|
2020-04-06 19:25:21 +02:00
|
|
|
fout.open("f9.catdoc.dberror.txt");
|
2019-12-03 10:36:43 +01:00
|
|
|
fout << _log << "\n";
|
2020-04-06 19:25:21 +02:00
|
|
|
error_box("Errore nel salvataggio dei dati.\nControllare file di errore f9.catdoc.dberror.txt");
|
2019-12-03 10:36:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:28:26 +02:00
|
|
|
TString escape(const char* str)
|
|
|
|
{
|
|
|
|
TString string; string << str;
|
|
|
|
for (int pos = string.find('\''); pos != -1; pos = string.find('\'', pos + 2))
|
|
|
|
string.insert("'", pos);
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2020-04-06 19:25:21 +02:00
|
|
|
int f90200(const int argc, char* argv[])
|
2019-12-03 10:36:43 +01:00
|
|
|
{
|
2020-04-06 19:25:21 +02:00
|
|
|
TF9_categorie_doc app;
|
|
|
|
app.run(argc, argv, TR("Configurazione Categorie Documentali."));
|
2019-12-03 10:36:43 +01:00
|
|
|
return 0;
|
|
|
|
}
|