Files correlati : ps6362.exe ps6362100a.msk Commento : - Corretta importazione righe ordine. Andava a leggere nuovamente il 'figlio' datarow come se fosse una riga. - Sistemata maschera.
367 lines
13 KiB
C++
367 lines
13 KiB
C++
#include "flexform_xml.h"
|
|
|
|
#include <stack>
|
|
|
|
#include "config.h"
|
|
#include "date.h"
|
|
#include "progind.h"
|
|
#include "velib.h"
|
|
#include "sqlset.h"
|
|
|
|
#define CHECK_CONDXML_OR_RETURNFALSE(cond, msg) { \
|
|
TString str; \
|
|
if (!(cond)) { \
|
|
str << "Errore nella lettura dell'xml: " << (msg); \
|
|
warning_box(str); \
|
|
return false; } }
|
|
|
|
#define CHECK_NAMETAG_OR_RETURNFALSE(xml_element, name_tag) { \
|
|
TString name; name << (name_tag); \
|
|
TString msg; msg << "mi aspettavo di trovare il tag: " << name; \
|
|
CHECK_CONDXML_OR_RETURNFALSE((xml_element)->get_name() == name, msg); }
|
|
//if ((xml_element)->get_name() != name) { \
|
|
// msg.cut(0) << "Errore nella lettura dell'xml:" << name; \
|
|
// warning_box(msg); \
|
|
// return false; } }
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// ELEMENTI DDT
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Testata DDT
|
|
|
|
void TDDT_testata_xml::set_testata(const char* data_doc, const char* num_doc)
|
|
{
|
|
_datarow = new TXML_element("datarow", ""); add_child(*_datarow);
|
|
_dat_doc = new TXML_element("dat_doc", data_doc); _datarow->add_child(*_dat_doc);
|
|
_des_num = new TXML_element("des_num_doc", num_doc); _datarow->add_child(*_des_num);
|
|
}
|
|
|
|
TDDT_testata_xml::~TDDT_testata_xml()
|
|
{
|
|
delete _datarow;
|
|
delete _dat_doc;
|
|
delete _des_num;
|
|
}
|
|
|
|
// Riga DDT
|
|
|
|
void TDDT_riga_xml::set_datarow(const char* ind_tiporiga, const char* cod_art, const char* des_articolo_riga, const char* qta_merce, const char* des_campo_libero6)
|
|
{
|
|
const TString _cod_art = cod_art; _cod_art.left(25);
|
|
const TString _desc = des_articolo_riga; _desc.left(255);
|
|
const TString _libero6 = des_campo_libero6; _libero6.left(30);
|
|
_datarow = new TXML_element("datarow", ""); add_child(*_datarow);
|
|
_tiporiga = new TXML_element("ind_tiporiga", ind_tiporiga); _datarow->add_child(*_tiporiga);
|
|
_art = new TXML_element("cod_art", (const char*)_cod_art); _datarow->add_child(*_art);
|
|
_des_articolo = new TXML_element("des_articolo_riga", (const char*)_desc); _datarow->add_child(*_des_articolo);
|
|
_merce = new TXML_element("qta_merce", qta_merce); _datarow->add_child(*_merce);
|
|
_libero = new TXML_element("des_campo_libero6", (const char*)_libero6); _datarow->add_child(*_libero);
|
|
}
|
|
|
|
void TDDT_riga_xml::set_datarow(const char* ind_tiporiga, const char* cod_art, const wchar_t* des_articolo_riga, const char* qta_merce, const char* des_campo_libero6)
|
|
{
|
|
const TString _cod_art = cod_art; _cod_art.left(25);
|
|
const TString _libero6 = des_campo_libero6; _libero6.left(30);
|
|
_datarow = new TXML_element("datarow", ""); add_child(*_datarow);
|
|
_tiporiga = new TXML_element("ind_tiporiga", ind_tiporiga); _datarow->add_child(*_tiporiga);
|
|
_art = new TXML_element("cod_art", (const char*)_cod_art); _datarow->add_child(*_art);
|
|
_des_articolo = new TXML_element("des_articolo_riga", des_articolo_riga); _datarow->add_child(*_des_articolo);
|
|
_merce = new TXML_element("qta_merce", qta_merce); _datarow->add_child(*_merce);
|
|
_libero = new TXML_element("des_campo_libero6", (const char*)_libero6); _datarow->add_child(*_libero);
|
|
}
|
|
|
|
TDDT_riga_xml::~TDDT_riga_xml()
|
|
{
|
|
delete _datarow;
|
|
delete _tiporiga;
|
|
delete _art;
|
|
delete _des_articolo;
|
|
delete _merce;
|
|
delete _libero;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// ELEMENTI ORDINI
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Testata Ordini
|
|
|
|
void TOrdini_testata_xml::set_testata(const char* data_doc, const char* num_doc, const char* str)
|
|
{
|
|
_datarow = new TXML_element("datarow", ""); add_child(*_datarow);
|
|
|
|
_dat_doc = new TXML_element("dat_doc_esterno", data_doc); _datarow->add_child(*_dat_doc);
|
|
_des_num = new TXML_element("des_num_esterno", num_doc); _datarow->add_child(*_des_num);
|
|
_sig_serie = new TXML_element("sig_serie_esterno", str); _datarow->add_child(*_sig_serie);
|
|
}
|
|
|
|
TOrdini_testata_xml::~TOrdini_testata_xml()
|
|
{
|
|
delete _datarow;
|
|
delete _dat_doc;
|
|
delete _des_num;
|
|
delete _sig_serie;
|
|
}
|
|
|
|
|
|
// Riga Ordini
|
|
|
|
void TOrdini_riga_xml::set_datarow(const char* ind_tiporiga, const char* cod_art, const char* des_articolo_riga, const char* qta_merce, const char* des_campo_libero6)
|
|
{
|
|
_datarow = new TXML_element("datarow", ""); add_child(*_datarow);
|
|
|
|
_tiporiga = new TXML_element("ind_tiporiga", ind_tiporiga); _datarow->add_child(*_tiporiga);
|
|
_art = new TXML_element("cod_art", cod_art); _datarow->add_child(*_art);
|
|
_des_articolo = new TXML_element("des_articolo_riga", des_articolo_riga); _datarow->add_child(*_des_articolo);
|
|
_merce = new TXML_element("qta_merce", qta_merce); _datarow->add_child(*_merce);
|
|
_libero = new TXML_element("des_campo_libero6", des_campo_libero6); _datarow->add_child(*_libero);
|
|
}
|
|
|
|
TOrdini_riga_xml::~TOrdini_riga_xml()
|
|
{
|
|
delete _datarow;
|
|
delete _tiporiga;
|
|
delete _art;
|
|
delete _des_articolo;
|
|
delete _merce;
|
|
delete _libero;
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Flexform xml export
|
|
///////////////////////////////////////////////////////////
|
|
|
|
TFlexform_xml::TFlexform_xml(const char* xml_name, bool to_export) : _file_name(xml_name), _fout(nullptr), _export(to_export)
|
|
{
|
|
_esa_import.set_root();
|
|
if (_export)
|
|
_fout = new ofstream(xml_name);
|
|
else
|
|
_fin = new ifstream(xml_name);
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Flexform DDT export
|
|
///////////////////////////////////////////////////////////
|
|
|
|
int TFlexform_xml_ddt::add_doc()
|
|
{
|
|
const shared_ptr<TXML_element> doc = make_shared<TXML_element>("DOC_UNICO", "");
|
|
const shared_ptr<TDDT_testata_xml> test = make_shared<TDDT_testata_xml>();
|
|
_docs_unico.insert(_docs_unico.end(), doc);
|
|
_docs_unico.back()->set_parent(_esa_import);
|
|
|
|
_testate.insert(_testate.end(), test);
|
|
_testate.back()->set_parent(*_docs_unico.back());
|
|
return _docs_unico.size();
|
|
}
|
|
|
|
int TFlexform_xml_ddt::add_row(const shared_ptr<TDDT_riga_xml>& riga, const int which_doc)
|
|
{
|
|
int i = which_doc < 0 ? (int)_testate.size() - 1 : which_doc;
|
|
if (!_testate.empty() && i < (int)_testate.size())
|
|
riga->set_parent(*_testate[i]);
|
|
else
|
|
i = -1;
|
|
return i;
|
|
}
|
|
|
|
bool TFlexform_xml_ddt::print()
|
|
{
|
|
ofstream& out = *_fout;
|
|
out << R"(<?xml version="1.0" encoding="UTF-8"?>)" << endl;
|
|
const bool ok = _esa_import.print_on_file(_fout);
|
|
_fout->close();
|
|
return ok;
|
|
}
|
|
|
|
int TFlexform_xml_ddt::set_testata(const char* data_doc, const char* num_doc, const int which_doc)
|
|
{
|
|
int i = which_doc < 0 ? (int)_testate.size() - 1 : which_doc;
|
|
if (!_testate.empty() && i < (int)_testate.size())
|
|
_testate[i]->set_testata(data_doc, num_doc);
|
|
else
|
|
i = -1;
|
|
return i;
|
|
}
|
|
|
|
TFlexform_xml_ddt::TFlexform_xml_ddt(const char* xml_name) : TFlexform_xml(xml_name)
|
|
{
|
|
// <ESA_IMPORT Source=? CreationDate=? InstanceGuid=? FileVersion="1" />
|
|
_esa_import.set_attributes(TConfig(CONFIG_DITTA, "Main").get("RAGSOC"), TDate(TODAY), generate_GUID(), "1");
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Flexform Ordini export
|
|
///////////////////////////////////////////////////////////
|
|
|
|
void TFlexform_xml_ordini::add_doc()
|
|
{
|
|
/* const shared_ptr<TXML_element> doc = make_shared<TXML_element>("DOC_UNICO", "");
|
|
const shared_ptr<TDDT_testata_xml> test = make_shared<TDDT_testata_xml>();
|
|
_docs_unico.insert(_docs_unico.end(), doc);
|
|
_docs_unico.back()->set_parent(_esa_import);
|
|
|
|
_testate.insert(_testate.end(), test);
|
|
_testate.back()->set_parent(*_docs_unico.back());
|
|
return _docs_unico.size();*/
|
|
}
|
|
|
|
bool TFlexform_xml_ordini::print()
|
|
{
|
|
ofstream& out = *_fout;
|
|
out << R"(<?xml version="1.0" encoding="UTF-8"?>)" << endl;
|
|
const bool ok = _esa_import.print_on_file(_fout);
|
|
_fout->close();
|
|
return ok;
|
|
}
|
|
|
|
//bool TFlexform_xml_ordini::parse_ordine_xml(unique_ptr<char[]>& ford, const long len)
|
|
//{
|
|
// TXML_parser parser(ford.get(), len);
|
|
// TString name;
|
|
// vector<pair<TString, TString>> attributi;
|
|
// parser.get_xml_info(name, attributi);
|
|
// _info_xml = std::make_unique<TXML_element>(name, TString(""), true);
|
|
// TXML_tag tag = parser.get_xml_tag();
|
|
// // <ESA_IMPORT Source=? CreationDate=? InstanceGuid=? FileVersion="1" />
|
|
// bool ok = true;
|
|
// TString source, creation_date, instance_guid, file_version, tipo_operazione;
|
|
// ok &= tag.get_attribute(source, "Source")
|
|
// && tag.get_attribute(creation_date, "CreationDate")
|
|
// && tag.get_attribute(instance_guid, "InstanceGuid")
|
|
// && tag.get_attribute(file_version, "FileVersion");
|
|
// if (!ok)
|
|
// return false;
|
|
// _esa_import.set_attributes(source, TDate(creation_date), instance_guid, file_version);
|
|
// tag = parser.get_xml_tag();
|
|
// tag.get_name(name);
|
|
// ok = tag.get_attribute(tipo_operazione, "TipoOperazione");
|
|
// _ordine_impegno = std::make_unique<TXML_element>((const char*)name, "");
|
|
// _ordine_impegno->add_attribute("TipoOperazione", tipo_operazione);
|
|
// _ordine_impegno->set_parent(_esa_import);
|
|
// _testata.set_parent(*_ordine_impegno);
|
|
// tag = parser.get_xml_tag();
|
|
// tag.get_name(name);
|
|
// if(name != "OR_ORDINIT")
|
|
// {
|
|
// warning_box("Errore durante la lettura del tag \"OR_ORDINIT\".");
|
|
// return false;
|
|
// }
|
|
// tag = parser.get_xml_tag();
|
|
// if (name != "datarow")
|
|
// {
|
|
// warning_box("Errore durante la lettura del tag \"datarow\" della testata dell'ordine.");
|
|
// return false;
|
|
// }
|
|
// //parser.get_until_tag_close("datarow");
|
|
// return true;
|
|
//}
|
|
|
|
bool TFlexform_xml_ordini::convert() const
|
|
{
|
|
const std::vector<shared_ptr<TXML_element>>& imported = _importer._imported;
|
|
TProgress_monitor bar(imported.size(), "Conversione XML ...");
|
|
for(auto it = imported.begin(); it != imported.end(); ++it)
|
|
{
|
|
if (!bar.add_status())
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
TString TFlexform_xml_ordini::flexart2codart(const TString& cod_art_flexform)
|
|
{
|
|
TSQL_recordset sql("");
|
|
TString query; query << "SELECT * FROM ANAMAG WHERE COD_PMS = '" << cod_art_flexform << "'";
|
|
sql.set(query);
|
|
if(sql.items() == 1)
|
|
return sql.get(sql.find_column("CODART")).as_string();
|
|
return "";
|
|
}
|
|
|
|
bool TFlexform_xml_ordini::create_doc()
|
|
{
|
|
const shared_ptr<TXML_element> esa_import = _importer._imported[1];
|
|
CHECK_NAMETAG_OR_RETURNFALSE(esa_import, "ESA_IMPORT");
|
|
|
|
TXML_element* ordine_impegno = esa_import->get_childs()[0];
|
|
CHECK_NAMETAG_OR_RETURNFALSE(ordine_impegno, "ORDINE_IMPEGNO");
|
|
|
|
const auto it = ordine_impegno->find_attribute("TipoOperazione");
|
|
CHECK_CONDXML_OR_RETURNFALSE(it != ordine_impegno->get_attributes().end() && it->second == "Insert",
|
|
"il 'Tipo Operazione' deve essere 'Insert'.");
|
|
|
|
TXML_element* or_ordinit = ordine_impegno->get_childs()[0];
|
|
CHECK_NAMETAG_OR_RETURNFALSE(or_ordinit, "OR_ORDINIT");
|
|
|
|
TXML_element* datarow = or_ordinit->get_childs()[0];
|
|
CHECK_NAMETAG_OR_RETURNFALSE(datarow, "datarow");
|
|
|
|
const TDate dat_doc_esterno = (const char*)datarow->get_val_child("dat_doc_esterno");
|
|
const TString& des_num_esterno = datarow->get_val_child("des_num_esterno");
|
|
const TDate dat_evasione = (const char*)datarow->get_val_child("dat_evasione");
|
|
|
|
TDocumento doc('D', dat_doc_esterno.year(), _codnum, -1);
|
|
doc.put(DOC_TIPODOC, _codnum);
|
|
doc.put(DOC_STATO, "2");
|
|
doc.put(DOC_DATADOC, dat_doc_esterno);
|
|
doc.put(DOC_TIPOCF, "C");
|
|
doc.put(DOC_CODCF, _codcli_flex);
|
|
doc.put(DOC_DATACONS, dat_evasione);
|
|
|
|
vector<TXML_element*> childs_ordinit = or_ordinit->get_childs();
|
|
CHECK_CONDXML_OR_RETURNFALSE(!childs_ordinit.empty(), "non e' presente alcun ordine.");
|
|
|
|
auto it_child = childs_ordinit.begin();
|
|
if (childs_ordinit.size() > 1) // Ci sono effettivamente dei OR_ORDINIR (almeno 1) oltre al datarow (informazioni di testata ordine).
|
|
++it_child;
|
|
for (; it_child != childs_ordinit.end(); ++it_child)
|
|
{
|
|
const TXML_element& row = *(*it_child);
|
|
const TXML_element& datarow_r = *row.get_childs()[0];
|
|
|
|
const TString& ind_tiporiga = datarow_r.get_val_child("ind_tiporiga");
|
|
const TString& cod_art = datarow_r.get_val_child("cod_art");
|
|
const TString& des_articolo_riga = datarow_r.get_val_child("des_articolo_riga");
|
|
const TString& qta_merce = datarow_r.get_val_child("qta_merce");
|
|
const TDate dat_evas_riga = TDate(datarow_r.get_val_child("dat_evas_riga"));
|
|
const TString& des_campo_libero6 = datarow_r.get_val_child("des_campo_libero6");
|
|
|
|
TString cod_art_major = flexart2codart(cod_art);
|
|
|
|
TRiga_documento& d_row = doc.new_row(ind_tiporiga == "D" ? "05" : "01");
|
|
if (ind_tiporiga != "D")
|
|
d_row.put(RDOC_CODART, !cod_art_major.empty() ? cod_art_major : cod_art);
|
|
d_row.put(RDOC_DESCR, des_articolo_riga);
|
|
d_row.put(RDOC_QTA, qta_merce);
|
|
d_row.put("DATA_EVASIONE_RIGA", dat_evas_riga); // RG1 -> DATA_EVASIONE_RIGA
|
|
d_row.put("CODFLEX", des_campo_libero6); // RG1 -> CODFLEX
|
|
}
|
|
|
|
bool ok = doc.write() == NOERR;
|
|
ok = ok && doc.rewrite() == NOERR;
|
|
return ok;
|
|
}
|
|
|
|
bool TFlexform_xml_ordini::parse_and_import_ordine_xml(unique_ptr<char[]>& ford, long len)
|
|
{
|
|
_importer.parse(ford, len);
|
|
|
|
// Convertion to my Flexformstructure
|
|
//bool ok = convert();
|
|
|
|
// Creation of ORC in DOC
|
|
bool ok = create_doc();
|
|
return ok;
|
|
}
|
|
|
|
TFlexform_xml_ordini::TFlexform_xml_ordini(const char* xml_name, const char* codnum, int codcli_flex) : TFlexform_xml(xml_name, false), _codnum(codnum), _codcli_flex(codcli_flex)
|
|
{ }
|