#include #include /////////////////////////////////////////////////////////// // TReport_application /////////////////////////////////////////////////////////// bool TReport_application::create() { bool ok = user_create(); if (ok) return TSkeleton_application::create(); return false; } bool TReport_application::destroy() { user_destroy(); return TSkeleton_application::destroy(); } void TReport_application::ini2mask(TConfig& ini, TMask& m, bool query) { const TString16 defpar = ini.get_paragraph(); TString tmp; for (int f = m.fields()-1; f >= 0; f--) { TMask_field& campo = m.fld(f); const TFieldref* fref = campo.field(); if (fref) { if (!query || campo.in_key(0)) { const TString& str = fref->read(ini, defpar); if (str.not_empty()) { campo.set(str); if (query) { tmp.format("%d=%s", campo.dlg(), (const char *) str); } } } } } ini.set_paragraph(defpar); } void TReport_application::mask2ini(const TMask& m, TConfig& ini) { ini.set("Firm", get_firm(), "Transaction"); ini.set("User", user()); ini.set("HostName", get_hostname()); int year, release, tag, patch; if (get_version_info(year, release, tag, patch)) { TString80 ver; ver.format("%d %d.%d-%d", year, release, tag, patch); ini.set("Version", ver); } for (int f = 0; f < m.fields(); f++) { TMask_field& campo = m.fld(f); if (campo.shown()) { const TFieldref* fr = campo.field(); if (fr) { if (campo.empty()) fr->write(ini, "Main", " "); else { if (campo.class_id() == CLASS_DATE_FIELD && campo.right_justified()) { const TDate d(campo.get()); fr->write(ini, "Main", d.string(ANSI)); } else fr->write(ini, "Main", campo.get()); } } } } ini.set_paragraph("Main"); // Reimposta paragrafo standard } // @cmember Esegue la stampa void TReport_application::execute_print(TReport_book & book, TAutomask & mask, TReport & rep, export_type type) { book.add(rep, type); } TTrec * TReport_application::get_dbase_recdesc(TReport & rep) { TTrec * desc = new TTrec; TReport_section * head = rep.find_section('H', 0); int header_row = -1; TToken_string key; int nfields = 0; int hrow = 0; if (head != nullptr) { int secfields = head->items(); for (int i = secfields - 1; hrow == 0 && i >= 0; i--) { const TReport_field & fld = head->field(i); const TReport_rct& r = fld.get_rect(); if ((r.x < 1500) && (fld.type() == 'T')) hrow = r.y; } TString fieldname; for (int i = 0; i < secfields; i++) { const TReport_field & fld = head->field(i); const TReport_rct& r = fld.get_rect(); if ((r.y >= hrow - 50) && (r.y <= hrow + 50) && (fld.type() == 'T')) { fieldname = fld.formatted_text(); fieldname.cut(9); fieldname.strip_spaces(); fieldname.upper(); if (nfields == 0) key = fieldname; const int nf = desc->fields(); TString f; TToken_string def; bool found = false; for (int n = nf - 1; !found && n >= 0; n--) { def = desc->fielddef(n); f = def.get(0); if (f.starts_with(fieldname)) { fieldname << atoi(f.mid(fieldname.len())) + 1; found = true; } } def = fieldname; def.add(_alfafld); def.add(80); desc->set_fields(nfields); desc->update_fielddef(nfields++, def); } } desc->set_keys(1); desc->update_keydef(0, key); } return desc; } // @cmember Ciclo principale void TReport_application::main_loop() { TAutomask & m = get_mask(); KEY k; while ((k = m.run()) != K_QUIT) { TReport & rep = get_report(m); TReport_book b(title()); TFilename name = get_filename(rep); bool ask_filename = name.blank(); export_type type = _export_printer; switch (k) { case K_EXCEL: type = _export_excel; break; case K_PDF: type = _export_pdf; break; case K_TEXT: type = _export_text; break; case K_DBF: type = _export_dbase; break; case K_VISUALIZE: type = _export_visualize; break; default: break; } execute_print(b, m, rep, type); switch (k) { case K_ENTER: case K_PRINT: b.print_or_preview(); break; case K_EXPORT: b.esporta(); break; case K_EXCEL: b.export_excel(name, false, true, ask_filename); break; case K_PDF: b.export_pdf(name, false, true, ask_filename); break; case K_TEXT: b.export_text(name, false, true, ask_filename); break; case K_DBF : b.export_dbase(name, false, get_dbase_recdesc(rep), true, ask_filename); break; case K_VISUALIZE: b.preview(); break; default: break; } } } const char * TReport_application::get_filename(const TReport & rep) { short id = output_id(); TFilename output; if (id > 0) output = get_mask().get(id); else output.tempdir(); output.add(output_name(rep)); TString & str = get_tmp_string(output.len()); str = output; return str; }