2020-06-19 12:30:10 +02:00
|
|
|
#ifndef __MAJORXML_H
|
|
|
|
#define __MAJORXML_H
|
2020-03-05 10:44:33 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include "strings.h"
|
|
|
|
#include "xml_element.h"
|
|
|
|
#include "date.h"
|
|
|
|
|
|
|
|
#define XML_ESCAPE_CHAR '&'
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TEsa_import_xml
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief \a TXML_element Contenitore Importazione Flexform.
|
|
|
|
*/
|
|
|
|
struct TEsa_import_xml : TXML_element
|
|
|
|
{
|
|
|
|
void set_attributes(const TString& source, const TDate& creation_date, const TString& instance_guid, const TString& file_version)
|
|
|
|
{
|
|
|
|
add_attribute("Source", source);
|
|
|
|
add_attribute("CreationDate", creation_date.string(full, '/'));
|
|
|
|
add_attribute("InstanceGuid", instance_guid);
|
|
|
|
add_attribute("FileVersion", file_version);
|
|
|
|
}
|
|
|
|
TEsa_import_xml() : TXML_element("ESA_IMPORT", "") { }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// ELEMENTI DDT
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief \a TXML_element Testata DDT.
|
|
|
|
*/
|
|
|
|
class TDDT_testata_xml : public TXML_element
|
|
|
|
{
|
|
|
|
friend class TDDT_riga_xml;
|
|
|
|
TXML_element* _datarow;
|
|
|
|
|
|
|
|
// Figli di _datarow: campi della testata
|
|
|
|
|
|
|
|
TXML_element* _dat_doc;
|
|
|
|
TXML_element* _des_num;
|
|
|
|
public:
|
|
|
|
void add_row(TDDT_riga_xml& riga) { add_child((TXML_element&)riga); }
|
|
|
|
void set_testata(const char* data_doc, const char* num_doc);
|
|
|
|
|
|
|
|
TDDT_testata_xml() : TXML_element("MG_MOVMAGT", ""), _datarow(nullptr), _dat_doc(nullptr), _des_num(nullptr) { }
|
|
|
|
~TDDT_testata_xml();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief \a TXML_element Riga DDT.
|
|
|
|
*/
|
|
|
|
class TDDT_riga_xml : public TXML_element
|
|
|
|
{
|
|
|
|
TXML_element* _datarow; // Unico figlio di OR_ORDINIR contenenti i campi campi dell'ordine
|
|
|
|
|
|
|
|
// Figli di _datarow: campi dell'ordine
|
|
|
|
|
|
|
|
TXML_element* _tiporiga;
|
|
|
|
TXML_element* _art;
|
|
|
|
TXML_element* _des_articolo;
|
|
|
|
TXML_element* _merce;
|
|
|
|
TXML_element* _libero;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_datarow(const char* ind_tiporiga, const char* cod_art, const char* des_articolo_riga, const char* qta_merce, const char* des_campo_libero6);
|
|
|
|
void 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);
|
|
|
|
|
|
|
|
TDDT_riga_xml() : TXML_element("MG_MOVMAGR", ""), _datarow(nullptr), _tiporiga(nullptr), _art(nullptr), _des_articolo(nullptr), _merce(nullptr), _libero(nullptr) { }
|
|
|
|
~TDDT_riga_xml();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// ELEMENTI ORDINI
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief \a TXML_element Testata Ordine.
|
|
|
|
*/
|
|
|
|
class TOrdini_testata_xml : public TXML_element
|
|
|
|
{
|
|
|
|
friend class TOrdini_riga_xml;
|
|
|
|
|
|
|
|
TXML_element* _datarow;
|
|
|
|
|
|
|
|
// Figli di _datarow: campi della testata
|
|
|
|
|
|
|
|
TXML_element* _dat_doc;
|
|
|
|
TXML_element* _des_num;
|
|
|
|
TXML_element* _sig_serie;
|
|
|
|
public:
|
|
|
|
void add_row(TOrdini_riga_xml& riga) { add_child((TXML_element&)riga); }
|
|
|
|
void set_testata(const char* data_doc, const char* num_doc, const char* str = "CCL");
|
|
|
|
|
|
|
|
TOrdini_testata_xml() : TXML_element("OR_ORDINIT", ""), _datarow(nullptr), _dat_doc(nullptr), _des_num(nullptr), _sig_serie(nullptr) { }
|
|
|
|
~TOrdini_testata_xml();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief \a TXML_element Riga Ordine.
|
|
|
|
*/
|
|
|
|
class TOrdini_riga_xml : public TXML_element
|
|
|
|
{
|
|
|
|
TXML_element* _datarow; // Unico figlio di OR_ORDINIR contenenti i campi campi dell'ordine
|
|
|
|
|
|
|
|
// Figli di _datarow: campi dell'ordine
|
|
|
|
|
|
|
|
TXML_element* _tiporiga;
|
|
|
|
TXML_element* _art;
|
|
|
|
TXML_element* _des_articolo;
|
|
|
|
TXML_element* _merce;
|
|
|
|
TXML_element* _libero;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_datarow(const char* ind_tiporiga, const char* cod_art, const char* des_articolo_riga, const char* qta_merce, const char* des_campo_libero6);
|
|
|
|
TOrdini_riga_xml() : TXML_element("OR_ORDINIR", ""), _datarow(nullptr), _tiporiga(nullptr), _art(nullptr), _des_articolo(nullptr), _merce(nullptr), _libero(nullptr) { }
|
|
|
|
~TOrdini_riga_xml();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Flexform export xml
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Main FLEXFORM XML Class.
|
|
|
|
*/
|
|
|
|
class TFlexform_xml
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
TString _file_name;
|
|
|
|
ofstream* _fout;
|
2020-06-19 12:30:10 +02:00
|
|
|
ifstream* _fin;
|
2020-03-05 10:44:33 +01:00
|
|
|
TEsa_import_xml _esa_import;
|
2020-06-19 12:30:10 +02:00
|
|
|
bool _export;
|
2020-03-05 10:44:33 +01:00
|
|
|
|
2020-06-19 12:30:10 +02:00
|
|
|
void set_indentation(const bool use_tab, const short n_spaces) { _esa_import.set_indentation(use_tab, n_spaces); }
|
|
|
|
virtual bool print() pure;
|
2020-03-05 10:44:33 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool ok() const { return _fout != nullptr && _fout->is_open(); }
|
|
|
|
|
2020-06-19 12:30:10 +02:00
|
|
|
TFlexform_xml(const char* xml_name = "", bool to_export = true);
|
2020-03-05 10:44:33 +01:00
|
|
|
virtual ~TFlexform_xml() { delete _fout; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Esportatore XML DDT Flexform.
|
|
|
|
*/
|
|
|
|
class TFlexform_xml_ddt final : public TFlexform_xml
|
|
|
|
{
|
2020-03-05 13:01:01 +01:00
|
|
|
vector<shared_ptr<TXML_element>> _docs_unico; // Tanti doc_unico, figli di _esa_import
|
|
|
|
vector<shared_ptr<TDDT_testata_xml>> _testate; // _testata contiene i dati di testata, piu' tutte gli ordini riga come figli
|
2020-03-05 10:44:33 +01:00
|
|
|
|
2020-03-05 13:01:01 +01:00
|
|
|
vector<shared_ptr<TDDT_riga_xml>> _rows;
|
2020-03-05 10:44:33 +01:00
|
|
|
public:
|
|
|
|
int add_doc();
|
|
|
|
/** Aggiungo la riga al documento n. \a which_riga, altrimenti se non specificato mette sull'ultimo doc presente.
|
|
|
|
* \returns indice documento in cui e' stata inserita la riga.
|
|
|
|
* \returns -1 se non e' mai stato inserito alcun documento o l'indice (\a which_doc) non e' corretto.
|
|
|
|
*/
|
2020-03-10 15:15:19 +01:00
|
|
|
int add_row(const shared_ptr<TDDT_riga_xml>& riga, int which_doc = -1);
|
2020-03-05 13:01:01 +01:00
|
|
|
bool print() override;
|
|
|
|
shared_ptr<TDDT_riga_xml> new_row() { _rows.insert(_rows.end(), make_shared<TDDT_riga_xml>()); return _rows.back(); }
|
2020-03-05 10:44:33 +01:00
|
|
|
|
2020-03-10 15:15:19 +01:00
|
|
|
/** Setto testata al documento n. \a which_doc, altrimenti se non specificato setta l'ultimo doc presente.
|
2020-03-05 10:44:33 +01:00
|
|
|
* \returns indice documento settato.
|
|
|
|
* \returns -1 se non e' mai stato inserito alcun documento o l'indice (\a which_doc) non e' corretto.
|
|
|
|
*/
|
|
|
|
int set_testata(const char* data_doc, const char* num_doc, int which_doc = -1);
|
|
|
|
|
2020-06-19 12:30:10 +02:00
|
|
|
TFlexform_xml_ddt(const char* xml_name = "");
|
2020-03-05 13:01:01 +01:00
|
|
|
~TFlexform_xml_ddt() = default;
|
2020-03-05 10:44:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2020-06-19 12:30:10 +02:00
|
|
|
* \brief Classe dell'ordine xml importato
|
2020-03-05 10:44:33 +01:00
|
|
|
*/
|
|
|
|
class TFlexform_xml_ordini final : public TFlexform_xml
|
|
|
|
{
|
2020-06-19 12:30:10 +02:00
|
|
|
unique_ptr<TXML_element> _info_xml;
|
|
|
|
unique_ptr<TXML_element> _ordine_impegno; // Unico ordine, figlio di _esa_import
|
|
|
|
TOrdini_testata_xml _testata; // _testata contiene i dati di testata, piu' tutte gli ordini riga come figli, figlio di _ordine_impegno
|
|
|
|
TXML_importer _importer;
|
|
|
|
TString _codnum;
|
|
|
|
int _codcli_flex;
|
2020-03-05 10:44:33 +01:00
|
|
|
|
|
|
|
public:
|
2020-06-19 12:30:10 +02:00
|
|
|
void add_doc();
|
|
|
|
void add_row(const shared_ptr<TOrdini_riga_xml>& riga) { riga->set_parent(_testata); }
|
2020-03-05 10:44:33 +01:00
|
|
|
bool print() override;
|
|
|
|
void set_testata(const char* data_doc, const char* num_doc, const char* str) { _testata.set_testata(data_doc, num_doc, str); }
|
2020-06-19 12:30:10 +02:00
|
|
|
bool parse_and_import_ordine_xml(unique_ptr<char[]>& ford, long len);
|
|
|
|
bool convert() const;
|
|
|
|
bool create_doc();
|
2020-03-05 10:44:33 +01:00
|
|
|
|
2020-08-20 12:37:35 +02:00
|
|
|
static TString flexart2codart(const TString& string);
|
|
|
|
|
2020-06-19 12:30:10 +02:00
|
|
|
TFlexform_xml_ordini(const char* xml_name = "", const char* codnum = "", int codcli_flex = 12);
|
2020-03-05 10:44:33 +01:00
|
|
|
};
|
|
|
|
|
2020-06-19 12:30:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
// Utils
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//class TXML_parser
|
|
|
|
//{
|
|
|
|
// long _last_pos;
|
|
|
|
// const long _len;
|
|
|
|
// const char* _xml;
|
|
|
|
//public:
|
|
|
|
// bool get_xml_info(TString& name, vector<pair<TString, TString>>& attributi)
|
|
|
|
// {
|
|
|
|
// bool end = false;
|
|
|
|
// bool ok = true;
|
|
|
|
// TToken_string line("", ' ');
|
|
|
|
// if (_xml[_last_pos++] == '<' && _xml[_last_pos++] == '?')
|
|
|
|
// {
|
|
|
|
// for (int i = _last_pos; !end && i < _len; ++i)
|
|
|
|
// {
|
|
|
|
// bool text = false;
|
|
|
|
// TString tag;
|
|
|
|
// if (_xml[i] == '\"')
|
|
|
|
// text = !text;
|
|
|
|
// else if (!text && _xml[i] == '?' && i + 1 < _len && _xml[i + 1] == '>')
|
|
|
|
// {
|
|
|
|
// end = true;
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// else if (!text && _xml[i] == '?' && !(i + 1 < _len && _xml[i + 1] == '>'))
|
|
|
|
// {
|
|
|
|
// warning_box("tag info XML non chiuso correttamente!");
|
|
|
|
// ok = false;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// line << _xml[i];
|
|
|
|
// }
|
|
|
|
// name = line.get(0);
|
|
|
|
// TToken_string tok("", '=');
|
|
|
|
// for (int i = 1; line.get(-1, tok) && i < line.items(); ++i)
|
|
|
|
// {
|
|
|
|
// if (tok.items() != 2)
|
|
|
|
// {
|
|
|
|
// warning_box("Errore durante la lettura degli attributi delle info XML.");
|
|
|
|
// ok = false;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// attributi.push_back({ tok.get(0), tok.get(1) });
|
|
|
|
// }
|
|
|
|
// return ok;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// error_box("XML mal formattato: mi aspettavo la riga di info xml.");
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// void get_single_tag(TString& str) const
|
|
|
|
// {
|
|
|
|
// str.cut(0);
|
|
|
|
// bool end = false;
|
|
|
|
// bool open = false;
|
|
|
|
// for (int i = _last_pos; !end && i < _len; ++i)
|
|
|
|
// {
|
|
|
|
// if (!open)
|
|
|
|
// {
|
|
|
|
// if (_xml[i] != '<')
|
|
|
|
// continue;
|
|
|
|
// open = true;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// bool text = false;
|
|
|
|
// TString tag;
|
|
|
|
// if (_xml[i] == '\"')
|
|
|
|
// text = !text;
|
|
|
|
// else if (!text && _xml[i] == '>')
|
|
|
|
// end = true;
|
|
|
|
// str << _xml[i];
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// TXML_tag get_xml_tag() const
|
|
|
|
// {
|
|
|
|
// TXML_tag xml_tag;
|
|
|
|
// TString tag;
|
|
|
|
// get_single_tag(tag);
|
|
|
|
// xml_tag.import_tag(tag);
|
|
|
|
// return xml_tag;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// TXML_parser(const char* xml, const long len) : _last_pos(0), _len(len), _xml(xml) { }
|
|
|
|
//};
|
|
|
|
|
|
|
|
#endif // __MAJORXML_H
|