cuadranteqtablewidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.com                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <QKeyEvent>
00022 #include <QEvent>
00023 #include <QLineEdit>
00024 #include <QTextEdit>
00025 #include <QMenu>
00026 
00027 #include "cuadranteqtablewidget.h"
00028 #include "configuracion.h"
00029 #include "funcaux.h"
00030 #include "company.h"
00031 #include "cuadrante1view.h"
00032 #include "cuadranteview.h"
00033 
00040 CuadranteQTableWidget::CuadranteQTableWidget(QWidget *parent) : QTableWidget(parent) {
00041     _depura("CuadranteQTableWidget::CuadranteQTableWidget", 0);
00042     connect(this, SIGNAL(contextMenuRequested ( int, int, const QPoint &)), this, SLOT(on_contextMenuRequested ( int, int, const QPoint & )));
00043     _depura("END CuadranteQTableWidget::CuadranteQTableWidget", 0);
00044 }
00045 
00046 
00048 
00050 CuadranteQTableWidget::~CuadranteQTableWidget() {
00051     _depura("END ~CuadranteQTableWidget", 0);
00052 }
00053 
00054 
00056 
00059 void CuadranteQTableWidget::dragEnterEvent(QDragEnterEvent *event) {
00060     _depura("CuadranteQTableWidget::dragEnterEvent", 0);
00061     event->acceptProposedAction();
00062     _depura("END CuadranteQTableWidget::dragEnterEvent", 0);
00063 }
00064 
00065 
00067 
00070 void CuadranteQTableWidget::dragMoveEvent(QDragMoveEvent *event) {
00071     _depura("CuadranteQTableWidget::dragMoveEvent", 0);
00072     event->acceptProposedAction();
00073     _depura("END CuadranteQTableWidget::dragMoveEvent", 0);
00074 }
00075 
00077 
00080 void CuadranteQTableWidget::dropEvent(QDropEvent *event) {
00081     _depura("CuadranteQTableWidget::dropEvent", 0);
00082     QTableWidget::dropEvent(event);
00083     _depura("END CuadranteQTableWidget::dropEvent", 0);
00084 }
00085 
00086 
00088 
00094 bool CuadranteQTableWidget::dropMimeData (int row, int column,const QMimeData *data, Qt::DropAction ) {
00095     _depura("CuadranteQTableWidget::dropMimeData", 0  );
00096 
00097     if (data->hasText()) {
00098         ((CuadranteQTextDocument *)cellWidget(row, column))->addTrabajador(data->text());
00099     }
00100     _depura("END CuadranteQTableWidget::dropMimeData", 0  );
00101     return (TRUE);
00102 }
00103 
00104 
00105 void CuadranteQTableWidget::on_contextMenuRequested ( int , int , const QPoint &  ) {
00106     _depura("CuadranteQTableWidget::contextMenuRequested", 2);
00107 }
00108 
00109 
00112 
00113 
00115 
00119 CuadranteQTextDocument::CuadranteQTextDocument(Company *emp, QWidget *parent) :QLabel(parent), QTableWidgetItem(QTableWidgetItem::UserType),  PEmpresaBase(emp) {
00120     _depura("CuadranteQTextDocument::CuadranteQTextDocument", 0);
00121     setContextMenuPolicy(Qt::CustomContextMenu);
00122     connect(this, SIGNAL(customContextMenuRequested ( const QPoint &  )), this, SLOT(on_customContextMenuRequested ( const QPoint &  )));
00123     _depura("END CuadranteQTextDocument::CuadranteQTextDocument", 0);
00124 }
00125 
00126 
00127 void CuadranteQTextDocument::on_customContextMenuRequested ( const QPoint & pos ) {
00128     QMap<QAction *, QString> horarios;
00129     QMenu menu(this);
00130     QAction *at = menu.addAction("Vaciar Personal");
00131     QAction *com = menu.addAction("Quitar Comentarios");
00132     QAction *fest = menu.addAction("Festivo");
00133     QAction *nofest = menu.addAction("No Festivo");
00134     QMenu *menu1 = menu.addMenu("Eliminar Personal");
00135     cursor2 *cur1 = empresaBase()->cargacursor("SELECT * FROM horario, trabajador, tipotrabajo WHERE horario.idtrabajador = trabajador.idtrabajador AND trabajador.idtipotrabajo = tipotrabajo.idtipotrabajo AND idcuadrante = "+mdb_idcuadrante +" ORDER BY nomtipotrabajo, nomtrabajador, horainhorario");
00136     if (!cur1) throw -1;
00137     while (!cur1->eof()) {
00138         QAction *ac = menu1->addAction(cur1->valor("nomtrabajador") + "(" + cur1->valor("horainhorario") + ":" + cur1->valor("horafinhorario") + ")");
00139         horarios[ac] = cur1->valor("idhorario");
00140         cur1->siguienteregistro();
00141     } // end while
00142     delete cur1;
00143 
00144     QAction *sel = menu.exec(mapToGlobal(pos), at);
00145 
00147     if (sel == at) {
00148         QString query = "DELETE FROM horario WHERE idcuadrante = " + mdb_idcuadrante;
00149         empresaBase()->ejecuta(query);
00150     } // end if
00151 
00152     if (horarios.contains(sel)) {
00153         QString query = "DELETE FROM horario WHERE idhorario = " + horarios[sel];
00154         empresaBase()->ejecuta(query);
00155     } // end if
00156 
00157     if (sel == fest) {
00158         QString query = "UPDATE cuadrante SET fiestacuadrante = TRUE WHERE idcuadrante = " + mdb_idcuadrante;
00159         empresaBase()->ejecuta(query);
00160     } // end if
00161 
00162     if (sel == nofest) {
00163         QString query = "UPDATE cuadrante SET fiestacuadrante = FALSE WHERE idcuadrante = " + mdb_idcuadrante;
00164         empresaBase()->ejecuta(query);
00165     } // end if
00166 
00167 
00168     if (sel == com) {
00169         QString query = "UPDATE cuadrante SET comentcuadrante = '' WHERE idcuadrante = " + mdb_idcuadrante;
00170         empresaBase()->ejecuta(query);
00171     } // end if
00172     pintaCuadrante(mdb_idalmacen, mdb_fechacuadrante);
00173     /*
00174 
00175         QObject *wid = parent();
00176         while (wid
00177                 && (wid->objectName() != "CuadranteBase")
00178               ) {
00179             wid = wid->parent();
00180         } // end if
00181         if (wid)
00182             ((CuadranteView *)wid)->on_mui_actualizar_clicked();
00183     */
00184     return;
00185 
00186 }
00187 
00189 
00192 void CuadranteQTextDocument::contextMenuEvent ( QContextMenuEvent *  ) {
00193     QTableWidgetItem::setSelected(TRUE);
00194 }
00195 
00196 
00198 
00201 void CuadranteQTextDocument::mouseDoubleClickEvent ( QMouseEvent *  ) {
00202     Cuadrante1View *cuad = new Cuadrante1View((Company *)empresaBase(), 0);
00203     empresaBase()->pWorkspace()->addWindow(cuad);
00204     cuad->show();
00205 //    CuadranteQTextDocument *newItem = (CuadranteQTextDocument *) mui_cuadrante->cellWidget(mui_cuadrante->currentRow(), mui_cuadrante->currentColumn());
00206     connect (cuad, SIGNAL(save()), this, SLOT(refresh()));
00207     cuad->cargar(idcuadrante());
00208 }
00209 
00210 
00211 
00213 
00215 CuadranteQTextDocument::~CuadranteQTextDocument() {
00216     _depura("~CuadranteQTextDocument", 0);
00217 }
00218 
00219 
00221 
00224 void CuadranteQTextDocument::addTrabajador(QString idtrabajador) {
00225     _depura("CuadranteQTextDocument::addTrabajador", 0);
00226     cursor2 *cur = NULL;
00227     try {
00228         QString horain = "08:00";
00229         QString horafin = "13:00";
00230         QString horain1 = "16:00";
00231         QString horafin1 = "20:00";
00232 
00233         QString querycuad = "SELECT * FROM cuadrante WHERE idcuadrante=" + mdb_idcuadrante;
00234         cursor2 *cur = empresaBase()->cargacursor(querycuad);
00235         if (!cur) throw -1;
00236         if (!cur->eof()) {
00237             if (cur->valor("aperturacuadrante") != "")
00238                 horain = cur->valor("aperturacuadrante");
00239             if (cur->valor("cierrecuadrante") != "")
00240                 horafin = cur->valor("cierrecuadrante");
00241             if (cur->valor("apertura1cuadrante") != "")
00242                 horain1 = cur->valor("apertura1cuadrante");
00243             if (cur->valor("cierre1cuadrante") != "")
00244                 horafin1 = cur->valor("cierre1cuadrante");
00245         } // end if
00246 
00247         QString query = "INSERT INTO horario (idtrabajador, idcuadrante, horainhorario, horafinhorario) VALUES (" +idtrabajador +","+ mdb_idcuadrante +",'"+horain+"','"+horafin+"')";
00248         QString query1 = "INSERT INTO horario (idtrabajador, idcuadrante, horainhorario, horafinhorario) VALUES (" +idtrabajador +","+ mdb_idcuadrante +",'"+horain1+"','"+horafin1+"')";
00249         empresaBase()->begin();
00250         empresaBase()->ejecuta(query);
00251         empresaBase()->ejecuta(query1);
00252         empresaBase()->commit();
00253         pintaCuadrante(mdb_idalmacen, mdb_fechacuadrante);
00254         _depura("END CuadranteQTextDocument::addTrabajador", 0);
00255     } catch (...) {
00256         empresaBase()->rollback();
00257         if (cur) delete cur;
00258         mensajeInfo("Error al agregar el trabajador al cuadrante");
00259     } // end try
00260     _depura("END CuadranteQTextDocument::addTrabajador", 0);
00261 }
00262 
00263 
00265 
00270 void CuadranteQTextDocument::setAlmFecha(QString idalmacen, const QDate &date) {
00271     _depura("CuadranteQTextDocument::setAlmFecha", 0);
00272     cursor2 *cur1 = NULL;
00273     try {
00275         cur1 = empresaBase()->cargacursor("SELECT * FROM cuadrante WHERE fechacuadrante = '" + date.toString("dd/MM/yyyy") + "' AND idalmacen="+idalmacen);
00276         if (!cur1) throw -1;
00277         if (cur1->eof()) {
00278             QString query = "INSERT INTO cuadrante (idalmacen, fechacuadrante) VALUES ("+idalmacen+",'"+ date.toString("dd/MM/yyyy") +"')";
00279             empresaBase()->begin();
00280             empresaBase()->ejecuta(query);
00281             empresaBase()->commit();
00282         } // end if
00283         delete cur1;
00284         pintaCuadrante(idalmacen, date);
00285     } catch (...) {
00286         empresaBase()->rollback();
00287         mensajeInfo("Error en la carga");
00288         if (cur1) delete cur1;
00289         return;
00290     } // end try
00291     _depura("END CuadranteQTextDocument::setAlmFecha", 0);
00292 }
00293 
00294 
00296 
00300 void CuadranteQTextDocument::pintaCuadrante(QString idalmacen, const QDate &date) {
00301     _depura("CuadranteQTextDocument::pintaCuadrante", 0, idalmacen);
00302     mdb_idalmacen = idalmacen;
00303     mdb_fechacuadrante = date;
00304 
00305     ImpCuadrante *imp = new ImpCuadrante((Company *)empresaBase());
00306     imp->mdb_idalmacen = idalmacen;
00307     imp->mdb_fechacuadrante = date;
00308     imp->generar();
00309     QLabel::setText(imp->m_html);
00310     mdb_idcuadrante = imp->mdb_idcuadrante;
00311     _depura("END CuadranteQTextDocument::pintaCuadrante", 0);
00312     return;
00313 }
00314 
00315 
00317 
00320 QString CuadranteQTextDocument::idcuadrante() {
00321     _depura("CuadranteQTextDocument::idcuadrante", 0);
00322     _depura("END CuadranteQTextDocument::idcuadrante", 0);
00323     return mdb_idcuadrante;
00324 }
00325 
00326 
00328 
00331 QDate CuadranteQTextDocument::fechacuadrante() {
00332     _depura("CuadranteQTextDocument::fechacuadrante", 0);
00333     _depura("END CuadranteQTextDocument::fechacuadrante", 0);
00334     return mdb_fechacuadrante;
00335 }
00336 
00337 
00339 
00342 QString CuadranteQTextDocument::idalmacen() {
00343     _depura("CuadranteQTextDocument::idalmacen", 0);
00344     _depura("END CuadranteQTextDocument::idalmacen", 0);
00345     return mdb_idalmacen;
00346 }
00347 
00348 
00350 
00352 void CuadranteQTextDocument::refresh() {
00353     _depura("CuadranteQTextDocument::refresh", 0);
00354     pintaCuadrante(mdb_idalmacen, mdb_fechacuadrante);
00355     _depura("END CuadranteQTextDocument::refresh", 0);
00356 }
00357 
00358 
00360 
00362 void CuadranteQTextDocument::setText(QString text) {
00363     _depura("CuadranteQTextDocument::setText", 0);
00364     QLabel::setText(text);
00365     _depura("END CuadranteQTextDocument::setText", 0);
00366 }
00367 
00368 
00370 
00372 void CuadranteQTextDocument::setidcuadrante(QString text) {
00373     _depura("CuadranteQTextDocument::setidcuadrante", 0);
00374     mdb_idcuadrante = text;
00375     _depura("END CuadranteQTextDocument::setidcuadrante", 0);
00376 }
00377 
00379 
00382 const QString CuadranteQTextDocument::impresion() {
00383     _depura("CuadranteQTextDocument::impresion", 0);
00384 
00385     QString html = "";
00386     html += "<td>\n";
00387     QString style="";
00388     cursor2 *cur = empresaBase()->cargacursor("SELECT * FROM cuadrante, almacen WHERE cuadrante.idalmacen = almacen.idalmacen AND almacen.idalmacen="+mdb_idalmacen+" AND cuadrante.fechacuadrante ='" +mdb_fechacuadrante.toString("dd/MM/yyyy")+ "'");
00389     if (!cur) throw -1;
00390     if (!cur->eof()) {
00391         if (cur->valor("fiestacuadrante") == "t") {
00392             style = " style=\"festivo\"";
00393         }
00394         html += "<para "+style+"> <b>" + cur->valor("nomalmacen") + "</b>: " + mdb_fechacuadrante.toString("dd/MM/yyyy")+"</para><spacer length=\"0.1cm\"/>\n";
00395     } // end if
00396 
00397 
00398     QString oldnomtipotrabajo = "";
00399 
00400     cursor2 *cur1 = empresaBase()->cargacursor("SELECT * FROM horario, trabajador, tipotrabajo WHERE horario.idtrabajador = trabajador.idtrabajador AND trabajador.idtipotrabajo = tipotrabajo.idtipotrabajo AND idcuadrante = "+mdb_idcuadrante +" ORDER BY nomtipotrabajo, horainhorario, nomtrabajador");
00401     if (!cur1) throw -1;
00402     while (!cur1->eof()) {
00403         if (oldnomtipotrabajo != cur1->valor("nomtipotrabajo") ) {
00404             html +=  "<para "+style+"><font color=\"red\" size=\"5\">" + cur1->valor("nomtipotrabajo") + ":</font></para><spacer length=\"0.1cm\"/>\n";
00405             oldnomtipotrabajo = cur1->valor("nomtipotrabajo");
00406         } // end if
00407         html += "<para "+style+"><font face=\"Helvetica\" size=\"6\" color=\"" + cur1->valor("colortipotrabajo") + "\">" + cur1->valor("nomtrabajador") + " " + cur1->valor("apellidostrabajador");
00408         html += "<sup>(" + cur1->valor("horainhorario").left(5) + "--" + cur1->valor("horafinhorario").left(5) + ")</sup></font></para><spacer length=\"0.1cm\"/>\n";
00409 
00410         cur1->siguienteregistro();
00411     } // end while
00412     delete cur1;
00413 
00414     if (cur->valor("comentcuadrante") != "") {
00415         html += "<para "+style+"><font face=\"Helvetica\" size=\"5\" color=\"black\">" + cur->valor("comentcuadrante").replace("\n", "<spacer length=\"0.1cm\"/>\n") + "</font></para>";
00416     } // end if
00417 
00418     delete cur;
00419 
00420     html += "</td>\n";
00421     _depura("END CuadranteQTextDocument::impresion", 0);
00422     return html;
00423 }
00424 
00425 
00427 
00429 
00433 ImpCuadrante::ImpCuadrante(Company *emp) :  PEmpresaBase(emp) {
00434     _depura("ImpCuadrante::ImpCuadrante", 0);
00435     _depura("END ImpCuadrante::ImpCuadrante", 0);
00436 }
00437 
00438 
00440 
00442 ImpCuadrante::~ImpCuadrante() {
00443     _depura("~ImpCuadrante", 0);
00444 }
00445 
00446 
00448 
00452 void ImpCuadrante::generar() {
00453     _depura("ImpCuadrante::generar", 0, mdb_idalmacen);
00454     cursor2 *cur = NULL;
00455     cursor2 *cur1 = NULL;
00456 
00458     int res = g_plugins->lanza("ImpCuadrante_generar", this);
00459     if (res != 0) {
00460         return;
00461     } // end if
00462 
00463     try {
00464         QString html = "";
00465         cur = empresaBase()->cargacursor("SELECT * FROM cuadrante, almacen WHERE cuadrante.idalmacen = almacen.idalmacen AND almacen.idalmacen="+mdb_idalmacen+" AND cuadrante.fechacuadrante ='" +mdb_fechacuadrante.toString("dd/MM/yyyy")+ "'");
00466         if (!cur) throw -1;
00467         if (!cur->eof()) {
00468             if (cur->valor("fiestacuadrante") == "t") {
00469                 html += "<table width=\"240\" height=\"300\" bgcolor=\"#999999\"><tr><td>";
00470             } else {
00471                 html += "<table width=\"240\" height=\"300\" bgcolor=\"#FFFFFF\"><tr><td>";
00472             }
00473             html += "<font size=\"2\" color=\"#660000\"><B>" + cur->valor("nomalmacen") + "</B>: " + mdb_fechacuadrante.toString("dd/MM/yyyy")+"</font><BR>";
00474             mdb_idcuadrante = cur->valor("idcuadrante");
00475         } // end if
00476 
00477         QString oldnomtipotrabajo = "";
00478 
00479         cur1 = empresaBase()->cargacursor("SELECT * FROM horario, trabajador, tipotrabajo WHERE horario.idtrabajador = trabajador.idtrabajador AND trabajador.idtipotrabajo = tipotrabajo.idtipotrabajo AND idcuadrante = "+mdb_idcuadrante +" ORDER BY nomtipotrabajo, nomtrabajador, horainhorario ");
00480         if (!cur1) throw -1;
00481         while (!cur1->eof()) {
00482 
00483 
00484             if (oldnomtipotrabajo != cur1->valor("nomtipotrabajo") ) {
00485                 html += "<font size=\"2\" color=\"#00FF00\" >" + cur1->valor("nomtipotrabajo") + ":</font><BR>";
00486                 oldnomtipotrabajo = cur1->valor("nomtipotrabajo");
00487             } // end if
00488 
00490             if (buscaConflictos(cur1->valor("idtrabajador"), mdb_fechacuadrante, cur1->valor("horainhorario").left(5), cur1->valor("horafinhorario").left(5))) {
00491                 html += "<font size=\"3\" color=\"#FF0000\">ERROR</FONT> ";
00492             }
00493 
00494             html += "<font size=\"3\" color=\"" + cur1->valor("colortipotrabajo") + "\">" + cur1->valor("nomtrabajador") + " " + cur1->valor("apellidostrabajador");
00495             html += " (" + cur1->valor("horainhorario").left(5) + "--" + cur1->valor("horafinhorario").left(5) + ") </font><BR>";
00496 
00497             cur1->siguienteregistro();
00498         } // end while
00499         delete cur1;
00500 
00501         if (cur->valor("comentcuadrante") != "") {
00502             html += "<HR><font size=\"2\" color=\"#000000\">" + cur->valor("comentcuadrante").replace("\n", "<BR>")+"</font>";
00503         } // end if
00504         delete cur;
00505 
00506         html += "</td></tr></table>";
00507 
00508 //        QLabel::setText(html);
00509         m_html = html;
00510         _depura("END ImpCuadrante::generar", 0);
00511     } catch (...) {
00512         mensajeInfo("Error en el pintado");
00513         if (cur) delete cur;
00514         if (cur1) delete cur1;
00515         return;
00516     } // end try
00517 }
00518 
00519 
00521 
00528 bool ImpCuadrante::buscaConflictos(QString idtrabajador, const QDate &date, QString horain, QString horafin) {
00529     _depura ("ImpCuadrante::buscaConflictos", 0);
00530     bool conflicto = FALSE;
00531     QString query = "SELECT * FROM horario NATURAL LEFT JOIN cuadrante  WHERE idtrabajador = " + idtrabajador + " AND NOT (( horafinhorario < '" + horain + "') OR (horainhorario > '" + horafin +"')) AND fechacuadrante = '" + date.toString("dd/MM/yyyy") + "'";
00532     cursor2 *cur = empresaBase()->cargacursor(query);
00533     if (cur) {
00534         if (cur->numregistros() > 1) {
00535             conflicto = TRUE;
00536         } // end if
00537         delete cur;
00538     }
00539 
00540     query = "SELECT * FROM ausencia WHERE idtrabajador = " + idtrabajador + " AND fechainausencia <= '" + date.toString("dd/MM/yyyy") + "' AND fechafinausencia >= '" + date.toString("dd/MM/yyyy") + "'";
00541     cur = empresaBase()->cargacursor(query);
00542     if (cur) {
00543         if (!cur->eof()) {
00544             conflicto = TRUE;
00545         } // end if
00546         delete cur;
00547     } // end if
00548 
00549     _depura ("END ImpCuadrante::buscaConflictos", 0);
00550     return conflicto;
00551 }

Generated on Sat Dec 15 00:01:06 2007 for BulmaGes by  doxygen 1.5.1