00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ficha.h"
00022 #include "fichacfg.h"
00023 #include "qcombobox2.h"
00024 #include "plugins.h"
00025 #include "qradiobutton2.h"
00026 #include "busquedafecha.h"
00027
00028 #include <QMenu>
00029 #include <QToolButton>
00030 #include <QTextEdit>
00031 #include <QCheckBox>
00032 #include <QFile>
00033 #include <QTextStream>
00034 #include <QDomDocument>
00035 #include <QDomNode>
00036
00038
00043 Ficha::Ficha(QWidget *parent, Qt::WFlags f, edmode modo) : BLWidget(parent, f), DBRecord(NULL), dialogChanges(this) {
00044 _depura("Ficha::Ficha", 0);
00045
00047 int res = g_plugins->lanza("Ficha_Ficha", this);
00048 if (res != 0) {
00049 return;
00050 }
00051
00052 m_title = windowTitle();
00053 setContextMenuPolicy(Qt::CustomContextMenu);
00054 connect (this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_customContextMenuRequested(const QPoint &)));
00055 m_modo = modo;
00056 dialogChanges_cargaInicial();
00057 _depura("END Ficha::Ficha", 0);
00058 }
00059
00060
00062
00068 Ficha::Ficha(EmpresaBase *emp, QWidget *parent, Qt::WFlags f, edmode modo) : BLWidget(emp, parent, f), DBRecord(emp), dialogChanges(this) {
00069 _depura("Ficha::Ficha", 0);
00070
00072 int res = g_plugins->lanza("Ficha_Ficha", this);
00073 if (res != 0) {
00074 return;
00075 }
00076
00077 setContextMenuPolicy(Qt::CustomContextMenu);
00078 connect (this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_customContextMenuRequested(const QPoint &)));
00079 m_modo = modo;
00080 dialogChanges_cargaInicial();
00081 _depura("END Ficha::Ficha", 0);
00082 }
00083
00084
00086
00088 Ficha::~Ficha() {
00089 _depura("Ficha::~Ficha", 0, this->windowTitle());
00090 sacaWindow();
00091 _depura("END Ficha::~Ficha", 0);
00092 }
00093
00094
00095
00097
00099 void Ficha::cargaSpecs() {
00100 _depura("SubForm3::cargaSpecs", 0 );
00101 _depura(objectName(), 2);
00102
00103 QFile file("/etc/bulmages/" + objectName() + "_" + empresaBase()->nameDB() + "_spec.spc");
00104 QDomDocument doc("mydocument");
00105 if (!file.open(QIODevice::ReadOnly))
00106 return;
00107 if (!doc.setContent(&file)) {
00108 file.close();
00109 return;
00110 }
00111 file.close();
00112
00113 QDomElement docElem = doc.documentElement();
00114 QDomElement principal = docElem.firstChildElement("FICHA");
00116 QString tablename = principal.firstChildElement("TABLENAME").toElement().text();
00117 QString campoid = principal.firstChildElement("CAMPOID").toElement().text();
00118
00119 QDomNodeList nodos = docElem.elementsByTagName("CAMPO");
00120 for (int i = 0; i < nodos.count(); i++) {
00121 QDomNode ventana = nodos.item(i);
00122 QDomElement e1 = ventana.toElement();
00123 if ( !e1.isNull() ) {
00124 DBCampo::dbtype type= DBCampo::DBvarchar;
00125 QString nomheader = e1.firstChildElement("NOMCAMPO").toElement().text();
00126 if (exists(nomheader)) return;
00127 QString nompheader = e1.firstChildElement("NOMPCAMPO").toElement().text();
00128 QString typeheader = e1.firstChildElement("DBTYPECAMPO").toElement().text();
00129 if (typeheader == "DBVARCHAR") {
00130 type = DBCampo::DBvarchar;
00131 } else if (typeheader == "DBINT") {
00132 type = DBCampo::DBint;
00133 } else if (typeheader == "DBNUMERIC") {
00134 type = DBCampo::DBnumeric;
00135 } else if (typeheader == "DBBOOLEAN") {
00136 type = DBCampo::DBboolean;
00137 } else if (typeheader == "DBDATE") {
00138 type = DBCampo::DBdate;
00139 }
00140
00141 int restricciones = (int) DBCampo::DBNothing;
00142 QDomElement restrict = e1.firstChildElement("RESTRICTIONSCAMPO");
00143 while (!restrict.isNull()) {
00144 QString trestrict = restrict.text();
00145 if (trestrict == "DBNOTHING") {
00146 restricciones |= DBCampo::DBvarchar;
00147 } else if (trestrict == "DBNOTNULL") {
00148 restricciones |= DBCampo::DBNotNull;
00149 } else if (trestrict == "DBPRIMARYKEY") {
00150 restricciones |= DBCampo::DBPrimaryKey;
00151 } else if (trestrict == "DBNOSAVE") {
00152 restricciones |= DBCampo::DBNoSave;
00153 } else if (trestrict == "DBAUTO") {
00154 restricciones |= DBCampo::DBAuto;
00155 } else if (trestrict == "DBAUTO") {
00156 restricciones |= DBCampo::DBAuto;
00157 } else if (trestrict == "DBDUPPRIMARYKEY") {
00158 restricciones |= DBCampo::DBDupPrimaryKey;
00159 } else if (trestrict == "DBREQUIRED") {
00160 restricciones |= DBCampo::DBRequired;
00161 } else if (trestrict == "DBNOLOAD") {
00162 restricciones |= DBCampo::DBNoLoad;
00163 }
00164 restrict = restrict.nextSiblingElement("RESTRICTIONSCAMPO");
00165 }
00166
00167 addDBCampo(nomheader, type, (DBCampo::dbrestrict) restricciones, nompheader);
00168 generaCampo(nomheader, nompheader, typeheader);
00169 }
00170 }
00171
00172 _depura("END SubForm3::cargaSpecs", 0);
00173 }
00174
00175
00176 void Ficha::generaCampo(const QString &objname, const QString &textname, const QString &type) {
00177
00179 QFrame *frame = findChild<QFrame *>("m_frameplugin");
00181 if (!frame) {
00182 frame = findChild<QFrame *>("m_frameplugin");
00183 }
00184 if (!frame) return;
00185
00186 QVBoxLayout *vboxl = frame->findChild<QVBoxLayout *>();
00187 if (!vboxl) {
00188 vboxl = new QVBoxLayout(frame);
00189 vboxl->setSpacing(0);
00190 vboxl->setMargin(0);
00191 vboxl->setObjectName(QString::fromUtf8("m_framevboxlayout"));
00192 }
00193
00194
00195 QHBoxLayout *hboxLayout160 = new QHBoxLayout();
00196 hboxLayout160->setSpacing(2);
00197 hboxLayout160->setMargin(0);
00198 hboxLayout160->setObjectName(QString::fromUtf8("hboxLayout16"));
00199
00200 QLabel *textLabel2_9_26 = new QLabel(frame);
00201 textLabel2_9_26->setObjectName(QString::fromUtf8("textLabel2_9_2"));
00202 hboxLayout160->addWidget(textLabel2_9_26);
00203 textLabel2_9_26->setText(textname);
00204
00205 if (type == "DBDATE") {
00206 BusquedaFecha *bus = new BusquedaFecha(frame);
00207 bus->setObjectName(objname);
00208 hboxLayout160->addWidget(bus);
00209 } else {
00210 QLineEdit *bus = new QLineEdit(frame);
00211 bus->setObjectName(objname);
00212 hboxLayout160->addWidget(bus);
00213 }
00214 vboxl->addLayout(hboxLayout160);
00215 }
00216
00218
00220 void Ficha::setModoConsulta() {
00221 _depura("Ficha::setModoConsulta", 0);
00222 m_modo = SelectMode;
00223 _depura("END Ficha::setModoConsulta", 0);
00224 }
00225
00226
00228
00230 void Ficha::setModoEdicion() {
00231 _depura("Ficha::setModoEdicion", 0);
00232 m_modo = EditMode;
00233 _depura("END Ficha::setModoEdicion", 0);
00234 }
00235
00236
00238
00241 bool Ficha::modoEdicion() {
00242 _depura("Ficha::modoEdicion", 0);
00243 _depura("END Ficha::modoEdicion", 0);
00244 return m_modo == EditMode;
00245 }
00246
00247
00249
00252 bool Ficha::modoConsulta() {
00253 _depura("Ficha::modoConsulta", 0);
00254 _depura("END Ficha::modoConsulta", 0);
00255 return m_modo == SelectMode;
00256 }
00257
00258
00260
00262 void Ficha::on_mui_cancelar_clicked() {
00263 _depura("Ficha::on_mui_cancelar_clicked", 0);
00264 close();
00265 _depura("END Ficha::on_mui_cancelar_clicked", 0);
00266 }
00267
00268
00270
00272 void Ficha::on_mui_guardar_clicked() {
00273 _depura("Ficha::on_mui_guardar_clicked", 0);
00274 guardar();
00275 _depura("END Ficha::on_mui_guardar_clicked", 0);
00276 }
00277
00278
00280
00282 void Ficha::on_mui_aceptar_clicked() {
00283 _depura("Ficha::on_mui_aceptar_clicked", 0);
00284 try {
00285 if (guardar()) {
00286 throw -1;
00287 }
00288 close();
00289 } catch (...) {
00290 _depura("Error al guardar la ficha", 2);
00291 }
00292 _depura("Ficha::on_mui_aceptar_clicked", 0);
00293 }
00294
00295
00297
00299 void Ficha::on_mui_imprimir_clicked() {
00300 _depura("Ficha::on_mui_imprimir_clicked", 0);
00301 imprimir();
00302 _depura("END Ficha::on_mui_imprimir_clicked", 0);
00303 }
00304
00305
00307
00309 void Ficha::on_mui_eliminar_clicked() {
00310 on_mui_borrar_clicked();
00311 }
00312
00314
00316 void Ficha::on_mui_borrar_clicked() {
00317 _depura("Ficha::on_mui_borrar_clicked", 0);
00318
00319 int val = QMessageBox::question(this,
00320 tr("Borrar") + " " + windowTitle(),
00321 tr("Desea eliminar '") + " " + windowTitle() + "' ?",
00322 QMessageBox::Yes,
00323 QMessageBox::Cancel | QMessageBox::Escape | QMessageBox::Default);
00324
00325 if (val == QMessageBox::Yes) {
00326 if (!borrar()) {
00327 dialogChanges_cargaInicial();
00328 _depura(windowTitle() + " " + "borrado satisfactoriamente.", 10);
00329 close();
00330 } else {
00331 mensajeInfo(windowTitle() + tr("No se ha podido borrar"));
00332 }
00333 }
00334 _depura("END Ficha::on_mui_borrar_clicked", 0);
00335 }
00336
00337
00339
00343 void Ficha::closeEvent(QCloseEvent *e) {
00344 _depura("Ficha::closeEvent", 0, windowTitle());
00345 try {
00346 if (dialogChanges_hayCambios()) {
00347 int val = QMessageBox::warning(this,
00348 tr("Guardar") + " " + windowTitle(),
00349 tr("Desea guardar los cambios?"),
00350 tr("&Si"), tr("&No"), tr("&Cancelar"), 0, 2);
00351 if (val == 0) {
00352 guardar();
00353 }
00354 if (val == 2) {
00355 e->ignore();
00356 return;
00357 }
00358 }
00361
00362 } catch (...) {
00363 mensajeInfo(tr("No se pudo cerrar la ventana debido a un error"));
00364 e->ignore();
00365 }
00366 _depura("END Ficha::closeEvent", 0);
00367 }
00368
00369
00371
00374 int Ficha::sacaWindow() {
00375 _depura("Ficha::sacaWindow", 0);
00376 if (empresaBase() != NULL) {
00377 empresaBase()->sacaWindow(this);
00378 }
00379 _depura("END Ficha::sacaWindow", 0);
00380 return 0;
00381 }
00382
00383
00385
00390 void Ficha::meteWindow(QString nom, QObject *obj, bool compdup) {
00391 _depura("Ficha::meteWindow", 0);
00392 if (empresaBase() != NULL) {
00393 empresaBase()->meteWindow(nom, obj, compdup);
00394 }
00395
00397 setDBTableName(tableName());
00400 cargaSpecs();
00401 _depura("END Ficha::meteWindow", 0);
00402 }
00403
00404
00406
00408 void Ficha::on_customContextMenuRequested(const QPoint &) {
00409 _depura("Ficha::on_customContextMenuRequested", 0);
00410 QMenu *popup = new QMenu(this);
00411
00413 emit pintaMenu(popup);
00414
00416 creaMenu(popup);
00417
00418
00419 QAction *avconfig = popup->addAction(tr("Opciones Avanzadas de Ficha"));
00420 QAction *avprint = popup->addAction(tr("Imprimir Ficha"));
00421 QAction *opcion = popup->exec(QCursor::pos());
00422
00423 if (opcion) {
00424 if (opcion == avconfig) {
00425 new FichaCfg(empresaBase(), this, 0);
00426 } else if (opcion == avprint) {
00427 Ficha::imprimir();
00428 }
00429
00430 emit trataMenu(opcion);
00431
00433 procesaMenu(opcion);
00434 }
00435
00436 delete popup;
00437 _depura("END Ficha::on_customContextMenuRequested", 0);
00438 }
00439
00440
00442
00444 void Ficha::creaMenu(QMenu *) {
00445 _depura("SubForm3:: CreaMenu", 0, "funcion para ser sobreescrita");
00446 }
00447
00448
00450
00452 void Ficha::procesaMenu(QAction *) {
00453 _depura("SubForm3:: procesaMenu", 0, "funcion para ser sobreescrita");
00454 }
00455
00456
00458
00461 void Ficha::setDBTableName(QString nom) {
00462 _depura("Ficha::setDBTableName", 0);
00463 DBRecord::setDBTableName(nom);
00464
00465 if (!empresaBase()->has_table_privilege(nom, "INSERT")) {
00467 QToolButton *b = findChild<QToolButton *>("mui_guardar");
00468 if (b) b->setDisabled(TRUE);
00469 b = findChild<QToolButton *>("mui_borrar");
00470 if (b) b->setDisabled(TRUE);
00471 }
00472
00473 _depura("END Ficha::setDBTableName", 0);
00474 }
00475
00476
00478
00481 void Ficha::setTitleName(QString nom) {
00482 _depura("Ficha::setTitleName");
00483 m_title = nom;
00484 _depura("END Ficha::setTitleName");
00485 }
00486
00487
00489
00491 void Ficha::pintar() {
00492 _depura("Ficha::pintar", 0);
00493 DBCampo *campo;
00495 for (int i = 0; i < m_lista.size(); ++i) {
00496 campo = m_lista.at(i);
00498 QLineEdit *l = findChild<QLineEdit *>("mui_" + campo->nomcampo());
00499 if (l) {
00500 l->setText(campo->valorcampo());
00501 }
00503 QTextEdit *l3 = findChild<QTextEdit *>("mui_" + campo->nomcampo());
00504 if (l3) {
00505 l3->setText(campo->valorcampo());
00506 }
00509 BLWidget *l1 = findChild<BLWidget *>("mui_" + campo->nomcampo());
00510 if (l1) {
00511 l1->setValorCampo(campo->valorcampo());
00512 }
00515 QComboBox2 *l2 = findChild<QComboBox2 *>("mui_" + campo->nomcampo());
00516 if (l2) {
00517 l2->setValorCampo(campo->valorcampo());
00518 }
00519 QCheckBox *l5 = findChild<QCheckBox *>("mui_" + campo->nomcampo());
00520 if (l5) {
00521 if (campo->valorcampo() == "t") {
00522 l5->setChecked(TRUE);
00523 } else {
00524 l5->setChecked(FALSE);
00525 }
00526 }
00527
00529 QList<QRadioButton2 *> l6 = findChildren<QRadioButton2 *>(QRegExp("mui_"+campo->nomcampo()+"_*"));
00530 for (int i = 0; i < l6.size(); ++i) {
00531 if (l6.at(i)->valorCampo() == campo->valorcampo()) {
00532 l6.at(i)->setChecked(TRUE);
00533 } else {
00534 l6.at(i)->setChecked(FALSE);
00535 }
00536 }
00537 }
00538 pintarPost();
00539 }
00540
00541
00549 void Ficha::recogeValores() {
00550 _depura("Ficha::recogeValores", 0);
00551 DBCampo *campo;
00553 for (int i = 0; i < m_lista.size(); ++i) {
00554 campo = m_lista.at(i);
00556 QLineEdit *l = findChild<QLineEdit *>("mui_" + campo->nomcampo());
00557 if (l)
00558 campo->set(l->text());
00559
00561 QTextEdit *l3 = findChild<QTextEdit *>("mui_" + campo->nomcampo());
00562 if (l3)
00563 campo->set(l3->toPlainText());
00564
00566 BLWidget *l1 = findChild<BLWidget *>("mui_" + campo->nomcampo());
00567 if (l1)
00568 campo->set(l1->valorCampo());
00569
00571 QComboBox2 *l2 = findChild<QComboBox2 *>("mui_" + campo->nomcampo());
00572 if (l2)
00573 campo->set(l2->valorCampo());
00574
00575 QCheckBox *l5 = findChild<QCheckBox *>("mui_" + campo->nomcampo());
00576 if (l5) {
00577 if (l5->isChecked()) {
00578 campo->set("TRUE");
00579 } else {
00580 campo->set("FALSE");
00581 }
00582 }
00583
00585 QList<QRadioButton2 *> l6 = findChildren<QRadioButton2 *>(QRegExp("mui_"+campo->nomcampo()+"_*"));
00586 if (l6.size() > 0) {
00587 int aux = 0;
00588 for (int i = 0; i < l6.size(); ++i) {
00589 if (l6.at(i)->isChecked()) {
00590 campo->set(l6.at(i)->valorCampo());
00591 aux = 1;
00592 }
00593 }
00594 if (aux == 0) {
00595 campo->set("");
00596 }
00597 }
00598
00599 }
00600 _depura("END Ficha::recogeValores", 0);
00601 }
00602
00603
00605
00609 int Ficha::cargar(QString id) {
00610 _depura("Ficha::cargar", 0, id);
00611 try {
00612 if (DBRecord::cargar(id)) {
00613 throw -1;
00614 }
00616 if (g_plugins->lanza("Ficha_cargar", this)) return 0;
00617 cargarPost(id);
00618 setWindowTitle(m_title + " " + DBvalue(m_campoid));
00619 pintar();
00620 dialogChanges_cargaInicial();
00621 meteWindow(windowTitle(), this);
00622 } catch (...) {
00623 return -1;
00624 }
00625 _depura("END Ficha::cargar", 0);
00626 return 0;
00627 }
00628
00629
00631
00637 int Ficha::guardar() {
00638 _depura("Ficha::guardar", 0);
00639
00640 try {
00641 QString id;
00642 recogeValores();
00643 empresaBase()->begin();
00644 DBsave(id);
00645 setDBvalue(m_campoid, id);
00646 empresaBase()->commit();
00647
00649 if (g_plugins->lanza("Ficha_guardar_Post", this)) return 0;
00650
00651 guardarPost();
00652
00654 cargar(id);
00655
00656 _depura("END Ficha::guardar", 0);
00657 return 0;
00658 } catch (...) {
00659 mensajeInfo("Error inesperado al guardar");
00660 empresaBase()->rollback();
00661 return -1;
00662 }
00663 }
00664
00665
00666 int Ficha::borrarPre() {
00667 _depura("Ficha::borrarPre", 0);
00668 _depura("END Ficha::borrarPre", 0);
00669 return 0;
00670 }
00671
00672
00679 int Ficha::borrar() {
00680 _depura("Ficha::borrar existe solo para ser derivado", 0);
00682 if (g_plugins->lanza("Ficha_borrar", this)) return 0;
00683 borrarPre();
00684 return DBRecord::borrar();
00685 }
00686
00687
00689
00692 int Ficha::guardarPost() {
00693 _depura("Ficha::guardarPost", 0);
00694 _depura("END Ficha::guardarPost", 0);
00695 return 0;
00696 }
00697
00698
00700
00703 int Ficha::cargarPost(QString ) {
00704 _depura("Ficha::cargarPost", 0);
00705 _depura("END Ficha::cargarPost", 0);
00706 return 0;
00707 }
00708
00710
00713 void Ficha::pintarPost() {
00714 _depura("Ficha::pintarPost", 0);
00715 _depura("END Ficha::pintarPost", 0);
00716 }
00717
00718
00719
00720
00723
00726 void Ficha::trataTags(QString &buff) {
00727 _depura("Ficha::trataTags", 0);
00728 int pos = 0;
00729
00731 QRegExp rx("\\[(\\w*)\\]");
00732 while ((pos = rx.indexIn(buff, pos)) != -1) {
00733 if (exists(rx.cap(1))) {
00734 buff.replace(pos, rx.matchedLength(), DBvalue(rx.cap(1)));
00735 pos = 0;
00736 } else {
00737 pos += rx.matchedLength();
00738 }
00739 }
00740
00742 pos = 0;
00743 QRegExp rx9("<!--\\s*EXISTS\\s*FILE\\s*=\\s*\"([^\"]*)\"\\s*-->(.*)<!--\\s*END\\s*EXISTS\\s*-->");
00744 rx9.setMinimal(TRUE);
00745 while ((pos = rx9.indexIn(buff, pos)) != -1) {
00746 QString ldetalle = trataExists(rx9.cap(1), rx9.cap(2));
00747 buff.replace(pos, rx9.matchedLength(), ldetalle);
00748 pos = 0;
00749 }
00750
00752 pos = 0;
00753 QRegExp rx4("<!--\\s*IF\\s*QUERY\\s*=\\s*\"([^\"]*)\"\\s*-->(.*)<!--\\s*END\\s*IF\\s*QUERY\\s*-->");
00754 rx4.setMinimal(TRUE);
00755 while ((pos = rx4.indexIn(buff, pos)) != -1) {
00756 QString ldetalle = trataIfQuery(rx4.cap(1), rx4.cap(2));
00757 buff.replace(pos, rx4.matchedLength(), ldetalle);
00758 pos = 0;
00759 }
00760
00762 pos = 0;
00763 QRegExp rx1("<!--\\s*QUERY\\s*=\\s*\"([^\"]*)\"\\s*-->(.*)<!--\\s*END\\s*QUERY\\s*-->");
00764 rx1.setMinimal(TRUE);
00765 while ((pos = rx1.indexIn(buff, pos)) != -1) {
00766 QString ldetalle = trataQuery(rx1.cap(1), rx1.cap(2));
00767 buff.replace(pos, rx1.matchedLength(), ldetalle);
00768 pos = 0;
00769 }
00770
00771
00773 pos = 0;
00774 QRegExp rx7("<!--\\s*SUBQUERY\\s*=\\s*\"([^\"]*)\"\\s*-->(.*)<!--\\s*END\\s*SUBQUERY\\s*-->");
00775 rx7.setMinimal(TRUE);
00776 while ((pos = rx7.indexIn(buff, pos)) != -1) {
00777 QString ldetalle = trataQuery(rx7.cap(1), rx7.cap(2));
00778 buff.replace(pos, rx7.matchedLength(), ldetalle);
00779 pos = 0;
00780 }
00781
00782 _depura("END Ficha::trataTags", 0);
00783 }
00784
00785
00787
00791 QString Ficha::trataIfQuery(const QString &query, const QString &datos) {
00792 _depura("Ficha::trataIfQuery", 0);
00793 QString result="";
00794 QString query1 = query;
00795
00797 QRegExp rx("\\[(\\w*)\\]");
00798 int pos = 0;
00799 while ((pos = rx.indexIn(query1, pos)) != -1) {
00800 if (exists(rx.cap(1))) {
00801 query1.replace(pos, rx.matchedLength(), DBvalue(rx.cap(1)));
00802 pos = 0;
00803 } else {
00804 pos += rx.matchedLength();
00805 }
00806 }
00808 cursor2 *cur = empresaBase()->cargacursor(query1);
00809 if (!cur) return "";
00810 if (!cur->eof()) {
00811 result = datos;
00812 }
00813 delete cur;
00814 _depura("END Ficha::trataIfQuery", 0);
00815 return result;
00816 }
00817
00818
00820
00824 QString Ficha::trataQuery(const QString &query, const QString &datos) {
00825 _depura("Ficha::trataQuery", 0);
00826 QString result="";
00827 QString query1 = query;
00828
00830 QRegExp rx("\\[(\\w*)\\]");
00831 int pos = 0;
00832 while ((pos = rx.indexIn(query1, pos)) != -1) {
00833 if (exists(rx.cap(1))) {
00834 query1.replace(pos, rx.matchedLength(), DBvalue(rx.cap(1)));
00835 pos = 0;
00836 } else {
00837 pos += rx.matchedLength();
00838 }
00839 }
00840
00842 cursor2 *cur = empresaBase()->cargacursor(query1);
00843 if (!cur) return "";
00844 while (!cur->eof()) {
00845 QString salidatemp = datos;
00846
00848 QRegExp rx("\\[(\\w*)\\]");
00849 int pos = 0;
00850 while ((pos = rx.indexIn(salidatemp, pos)) != -1) {
00851 if (cur->numcampo(rx.cap(1)) != -1) {
00852 salidatemp.replace(pos, rx.matchedLength(), cur->valor(rx.cap(1)));
00853 pos = 0;
00854 } else {
00855 pos += rx.matchedLength();
00856 }
00857 }
00858
00859 result += salidatemp;
00860 cur->siguienteregistro();
00861 }
00862 delete cur;
00863 _depura("END Ficha::trataQuery", 0);
00864 return result;
00865 }
00866
00867
00869
00873 QString Ficha::trataExists(const QString &query, const QString &datos) {
00874 _depura("Ficha::trataExists", 0);
00875
00876 QString result="";
00877 QString query1 = query;
00878
00880 QRegExp rx("\\[(\\w*)\\]");
00881 int pos = 0;
00882 while ((pos = rx.indexIn(query1, pos)) != -1) {
00883 if (exists(rx.cap(1))) {
00884 query1.replace(pos, rx.matchedLength(), DBvalue(rx.cap(1)));
00885 pos = 0;
00886 } else {
00887 pos += rx.matchedLength();
00888 }
00889 }
00890
00891 QFile file(query1);
00892 if (file.exists())
00893 result = datos;
00894 _depura("END Ficha::trataExists", 0);
00895
00896 return result;
00897 }
00898
00899
00901
00903 void Ficha::generaRML(const QString &arch) {
00904 _depura("Ficha::generaRML", 0);
00905
00907 int res = g_plugins->lanza("Ficha_generaRML", this);
00908 if (res != 0) {
00909 return;
00910 }
00911 QString archivo = confpr->valor(CONF_DIR_OPENREPORTS) + arch;
00912 QString archivod = confpr->valor(CONF_DIR_USER) + arch;
00913 QString archivologo = confpr->valor(CONF_DIR_OPENREPORTS) + "logo.jpg";
00914
00915
00917 #ifdef WINDOWS
00918
00919 archivo = "copy " + archivo + " " + archivod;
00920 #else
00921
00922 archivo = "cp " + archivo + " " + archivod;
00923 #endif
00924
00925 system (archivo.toAscii().constData());
00927 #ifdef WINDOWS
00928
00929 archivologo = "copy " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00930 #else
00931
00932 archivologo = "cp " + archivologo + " " + confpr->valor(CONF_DIR_USER) + "logo.jpg";
00933 #endif
00934
00935 system(archivologo.toAscii().constData());
00936 QFile file;
00937 file.setFileName(archivod);
00938 file.open(QIODevice::ReadOnly);
00939 QTextStream stream(&file);
00940 QString buff = stream.readAll();
00941 file.close();
00942
00944 trataTags(buff);
00945
00946 if (file.open(QIODevice::WriteOnly)) {
00947 QTextStream stream(&file);
00948 stream << buff;
00949 file.close();
00950 }
00951
00952 _depura("END Ficha::generaRML", 0);
00953 }
00954
00955
00956