From f28826dc39ceaa67b90651fcceae0c3d2b5b73c1 Mon Sep 17 00:00:00 2001 From: Simone Palacino Date: Thu, 5 Mar 2020 13:01:01 +0100 Subject: [PATCH] Patch level : 12.0 no-patch Files correlati : ps6362.exe Commento : - Personalizzazione Major: - Modificato percorso default esportazione - Corretto salvataggio dati maschera - Introduzione smart pointer per getione sicura dei puntatori; tolti delete per i puntatori --- src/ps/flexform_xml.cpp | 17 +++------- src/ps/flexform_xml.h | 16 +++++----- src/ps/ps6362100.cpp | 71 +++++++++++++++++++++++++---------------- src/ps/xml_element.cpp | 6 ++-- 4 files changed, 59 insertions(+), 51 deletions(-) diff --git a/src/ps/flexform_xml.cpp b/src/ps/flexform_xml.cpp index 9865a39ff..8881ef9d3 100644 --- a/src/ps/flexform_xml.cpp +++ b/src/ps/flexform_xml.cpp @@ -153,16 +153,17 @@ TFlexform_xml::TFlexform_xml(const char* xml_name) : _file_name(xml_name), _fout int TFlexform_xml_ddt::add_doc() { - TXML_element* doc = new TXML_element("DOC_UNICO", ""); + const shared_ptr doc = make_shared("DOC_UNICO", ""); + const shared_ptr test = make_shared(); _docs_unico.insert(_docs_unico.end(), doc); _docs_unico.back()->set_parent(_esa_import); - TDDT_testata_xml* test = new TDDT_testata_xml; + _testate.insert(_testate.end(), test); _testate.back()->set_parent(*_docs_unico.back()); return _docs_unico.size(); } -int TFlexform_xml_ddt::add_row(TDDT_riga_xml* riga, int which_doc) +int TFlexform_xml_ddt::add_row(shared_ptr riga, int which_doc) { int i = which_doc < 0 ? (int)_testate.size() - 1 : which_doc; if (!_testate.empty() && i < (int)_testate.size()) @@ -191,16 +192,6 @@ int TFlexform_xml_ddt::set_testata(const char* data_doc, const char* num_doc, co return i; } -TFlexform_xml_ddt::~TFlexform_xml_ddt() -{ - for (auto doc : _docs_unico) - delete doc; - for (auto testata : _testate) - delete testata; - for (auto row : _rows) - delete row; -} - /////////////////////////////////////////////////////////// // Flexform Ordini export diff --git a/src/ps/flexform_xml.h b/src/ps/flexform_xml.h index 9f76fb000..3bb2b10d2 100644 --- a/src/ps/flexform_xml.h +++ b/src/ps/flexform_xml.h @@ -164,19 +164,19 @@ public: */ class TFlexform_xml_ddt final : public TFlexform_xml { - vector _docs_unico; // Tanti doc_unico, figli di _esa_import - vector _testate; // _testata contiene i dati di testata, piu' tutte gli ordini riga come figli + vector> _docs_unico; // Tanti doc_unico, figli di _esa_import + vector> _testate; // _testata contiene i dati di testata, piu' tutte gli ordini riga come figli - vector _rows; + vector> _rows; 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. */ - int add_row(TDDT_riga_xml* riga, int which_doc = -1); - bool print() override; - TDDT_riga_xml* new_row() { _rows.push_back(new TDDT_riga_xml); return _rows.back(); } + int add_row(shared_ptr riga, int which_doc = -1); + bool print() override; + shared_ptr new_row() { _rows.insert(_rows.end(), make_shared()); return _rows.back(); } /** Setto testata al documento n. \a which_riga, altrimenti se non specificato setta l'ultimo doc presente. * \returns indice documento settato. @@ -185,7 +185,7 @@ public: int set_testata(const char* data_doc, const char* num_doc, int which_doc = -1); TFlexform_xml_ddt(const char* xml_name = "") : TFlexform_xml(xml_name) { } - ~TFlexform_xml_ddt(); + ~TFlexform_xml_ddt() = default; }; @@ -205,4 +205,4 @@ public: TFlexform_xml_ordini(const char* xml_name = ""); }; -#endif // __MAJORXML_H__ \ No newline at end of file +#endif // __MAJORXML_H__ diff --git a/src/ps/ps6362100.cpp b/src/ps/ps6362100.cpp index ca49ed6bc..a9df0b3ac 100644 --- a/src/ps/ps6362100.cpp +++ b/src/ps/ps6362100.cpp @@ -1,3 +1,5 @@ +#include + #include "ps6362.h" #include "ps6362100a.h" @@ -37,21 +39,36 @@ TMajor_export_mask::TMajor_export_mask() : TAutomask("ps6362100a") void TMajor_export_mask::save_all() const { - ini_set_string(CONFIG_DITTA, "ps6362", "flddest", get(F_FLDDEST)); - ini_set_bool(CONFIG_DITTA, "ps6362", "fldroot_b", get(F_SUBFLD)); - ini_set_string(CONFIG_DITTA, "ps6362", "numddt", get(F_NUMDDT)); - ini_set_string(CONFIG_DITTA, "ps6362", "numord", get(F_NUMORD)); + ini_set_string(CONFIG_DITTA, "ps6362", "flddest", get(F_FLDDEST)); + ini_set_bool (CONFIG_DITTA, "ps6362", "fldroot_b", get_bool(F_SUBFLD)); + ini_set_string(CONFIG_DITTA, "ps6362", "fldyear", get(F_ANNO_ELAB)); + ini_set_string(CONFIG_DITTA, "ps6362", "numddt", get(F_NUMDDT)); + ini_set_string(CONFIG_DITTA, "ps6362", "numord", get(F_NUMORD)); + ini_set_string(CONFIG_DITTA, "ps6362", "num_da", get(F_NUMDDT_DA)); + ini_set_string(CONFIG_DITTA, "ps6362", "num_a", get(F_NUMDDT_A)); } void TMajor_export_mask::load_all() { - TFilename temp; - temp.tempdir(); - set(F_FLDDEST, ini_get_string(CONFIG_DITTA, "ps6362", "flddest", temp)); - set(F_SUBFLD, ini_get_bool(CONFIG_DITTA, "ps6362", "fldroot_b")); - set(F_ANNO_ELAB, TDate(TODAY).year()); - set(F_NUMDDT, ini_get_string(CONFIG_DITTA, "ps6362", "numddt", "")); - set(F_NUMORD, ini_get_string(CONFIG_DITTA, "ps6362", "numord", "")); + TFilename dir; + PWSTR szPath[MAX_PATH]; + char dest[MAX_PATH]; + if ((HRESULT)SHGetKnownFolderPath(FOLDERID_Desktop, 0, NULL, szPath) >= 0) + { + size_t size; + wcstombs_s(&size, dest, MAX_PATH, szPath[0], MAX_PATH); + dir = dest; + } + else + dir.tempdir(); + TString y; y << TDate(TODAY).year(); + set(F_FLDDEST, ini_get_string(CONFIG_DITTA, "ps6362", "flddest", dir)); + set(F_SUBFLD, ini_get_bool (CONFIG_DITTA, "ps6362", "fldroot_b", true)); + set(F_ANNO_ELAB, ini_get_string(CONFIG_DITTA, "ps6362", "fldyear", y)); + set(F_NUMDDT, ini_get_string(CONFIG_DITTA, "ps6362", "numddt", "")); + set(F_NUMORD, ini_get_string(CONFIG_DITTA, "ps6362", "numord", "")); + set(F_NUMDDT_DA, ini_get_string(CONFIG_DITTA, "ps6362", "num_da", "")); + set(F_NUMDDT_A, ini_get_string(CONFIG_DITTA, "ps6362", "num_a", "")); if(get(F_NUMDDT).empty() || get(F_NUMORD).empty()) { TTable num("%NUM"); @@ -83,13 +100,13 @@ class TMajor_export_app : public TSkeleton_application { TString _fld_dest; - bool create() override; + bool create() override; + static TFilename check_name_file(const TString& dir, bool sub_fld, int from, int to, bool ddt = true); + static const char* get_riferimento_flexform(const TSQL_recordset& righe_doc); + static bool export_ddt(TMask& msk); + static bool export_ordini() { return false; } + void main_loop() override; - static TFilename check_name_file(const TString& dir, bool sub_fld, int from, int to, bool ddt = true); - static const char* get_riferimento_flexform(const TSQL_recordset& righe_doc); - static bool export_ddt(TMask& msk); - static bool export_ordini() { return false; } - void main_loop() override; public: TMajor_export_app() = default; }; @@ -108,7 +125,7 @@ TFilename TMajor_export_app::check_name_file(const TString& dir, const bool sub_ da.format("%07d", from); a.format("%07d", to); - TString name; name << (ddt ? "ddt" : "ord") << TDate(TODAY).year() << da << a; + TString name; name << (ddt ? "ddt" : "ord") << TDate(TODAY).year() << da << a; TFilename xml(cartella); if (!xvt_fsys_dir_exists(xml)) xvt_fsys_mkdir(xml); @@ -163,10 +180,10 @@ bool TMajor_export_app::export_ddt(TMask& msk) const int to = msk.get_int(F_NUMDDT_A); const TString& codnum = msk.get(F_NUMDDT); - TFilename xml = check_name_file(dir, sub_fld, from, to); - if (xml.empty()) + TFilename path_xml = check_name_file(dir, sub_fld, from, to); + if (path_xml.empty()) return false; - TFlexform_xml_ddt ddt(xml); + TFlexform_xml_ddt xml_ddts(path_xml); TString query_doc; query_doc << "SELECT DATADOC, NDOC FROM doc WHERE CODNUM = '" << codnum << "' AND ANNO = " << year << " AND PROVV = 'D' AND NDOC >= " << from << " AND NDOC <= " << to; TSQL_recordset doc(query_doc); @@ -176,10 +193,10 @@ bool TMajor_export_app::export_ddt(TMask& msk) { if (!bar.add_status()) break; - ddt.add_doc(); + xml_ddts.add_doc(); TFormatted_date day(doc.get(0).as_date()); day.set_format("1444/"); const TString& n_doc = doc.get(1).as_string(); - ddt.set_testata(day.string(), n_doc); + xml_ddts.set_testata(day.string(), n_doc); // Righe documento TString query_righe; query_righe << "SELECT CODART, DESCR, QTA, RG1, DESCLUNGA, DESCEST\n" @@ -187,7 +204,7 @@ bool TMajor_export_app::export_ddt(TMask& msk) TSQL_recordset righe_doc(query_righe); for (bool ok_r = righe_doc.move_first(); ok_r; ok_r = righe_doc.move_next()) { - TDDT_riga_xml* riga = ddt.new_row(); + shared_ptr riga = xml_ddts.new_row(); const TString& cod_art = righe_doc.get(0).as_string(); TString descr = righe_doc.get(1).as_string(); @@ -197,12 +214,12 @@ bool TMajor_export_app::export_ddt(TMask& msk) descr << righe_doc.get(5).as_string(); riga->set_datarow("C", cod_art, descr, qta, desccampolibero6); - ddt.add_row(riga); + xml_ddts.add_row(riga); } } bool ok = true; - if (ok &= ddt.ok()) - ok &= ddt.print(); + if (ok &= xml_ddts.ok()) + ok &= xml_ddts.print(); return ok; } diff --git a/src/ps/xml_element.cpp b/src/ps/xml_element.cpp index 788dcfe1d..29b021587 100644 --- a/src/ps/xml_element.cpp +++ b/src/ps/xml_element.cpp @@ -13,14 +13,14 @@ TString escape_chars (const TString& str); bool TXML_element::print_on_file(ofstream* fout, const int deep, const char* indent) { - const TString ind = indent; + const TString ind = indent; const TString _indent = this->_parent == XML_ROOT_TAG ? this->_indent : ind; if (fout == nullptr || !fout->is_open() || _name.empty()) return false; ofstream& out = *fout; - bool ok = true; + bool ok = true; // Stampo prima la riga con tag e attributi for (int i = 0; i < deep; ++i) // Indentazione @@ -144,4 +144,4 @@ TString escape_chars(const TString& str) } } return text; -} \ No newline at end of file +}