canalview.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  "canalview.h"
00022 #include  "empresa.h"
00023 #include  "selectcanalview.h"
00024 
00025 
00027 
00031 canalview::canalview(Empresa  *emp, QWidget *parent)
00032         : FichaBc(emp, parent) {
00033     _depura("canalview::canalview", 0);
00034 
00035     setTitleName(tr("Canal"));
00037     setDBTableName("canal");
00038 
00039     this->setAttribute(Qt::WA_DeleteOnClose);
00040     setupUi(this);
00041     mui_idcanal->setEmpresaBase(emp);
00042     mui_idcanal->setidcanal("0");
00043 
00044     m_nomcanal = new QLineEdit();
00045     m_nomcanal->setText("");
00046     m_desccanal = new QTextEdit();
00047     m_desccanal->setPlainText("");
00048 
00049     idcanal = 0;
00050     dialogChanges_setQObjectExcluido(mui_idcanal);
00051     dialogChanges_cargaInicial();
00052     on_mui_idcanal_valueChanged(0);
00053     empresaBase()->meteWindow(windowTitle(), this);
00054     _depura("END canalview::canalview", 0);
00055 }
00056 
00057 
00059 
00061 canalview::~canalview() {
00062     _depura("canalview::~canalview", 0);
00063     empresaBase()->sacaWindow(this);
00064     _depura("END canalview::~canalview", 0);
00065 }
00066 
00067 
00069 
00071 void canalview::pintar() {
00072     _depura("canalview::pintar", 0);
00074     if (idcanal != 0) {
00076         mui_nomcanal->setEnabled(TRUE);
00077         mui_desccanal->setEnabled(TRUE);
00078         mostrarplantilla();
00079     } else {
00080         idcanal = mui_idcanal->idcanal().toInt();
00081         mostrarplantilla();
00082     } // end if
00083 
00085     selectcanalview *scanal = empresaBase()->getselcanales();
00086     scanal->cargacanales();
00087     _depura("END canalview::pintar", 0);
00088 }
00089 
00090 
00092 
00095 void canalview::on_mui_idcanal_valueChanged(QString numcombo) {
00096     _depura("canalview::on_mui_idcanal_valueChanged", 0);
00097     int idcanal1 = numcombo.toInt();
00098     static bool flipflop = FALSE;
00099 
00100     if (dialogChanges_hayCambios() && flipflop) {
00101         if (QMessageBox::warning(this,
00102                                  tr("Guardar canal"),
00103                                  tr("Desea guardar los cambios."),
00104                                  tr("&Guardar"), tr("&Cancelar"), 0 , 0, 1) == 0)
00105             on_mui_guardar_clicked();
00106     } // end if
00107 
00110     if (idcanal1 == 0) {
00111         mui_nomcanal->setText("");
00112         mui_nomcanal->setEnabled(FALSE);
00113         mui_desccanal->setPlainText("");
00114         mui_desccanal->setEnabled(FALSE);
00115         flipflop = FALSE;
00116         return;
00117     } else {
00119         mui_nomcanal->setEnabled(TRUE);
00120         mui_desccanal->setEnabled(TRUE);
00121     } // end if
00122 
00123     flipflop = TRUE;
00124     idcanal = idcanal1;
00125     mostrarplantilla();
00126     _depura("END canalview::on_mui_idcanal_valueChanged", 0);
00127 }
00128 
00129 
00131 
00133 void canalview::mostrarplantilla() {
00134     _depura("canalview::mostrarplantilla", 0);
00135     QString query;
00136     QTextStream(&query) << "SELECT * from canal WHERE idcanal = '" << idcanal << "'";
00137     cursor2 *cursorcanal = empresaBase()->cargacursor(query);
00138     if (!cursorcanal->eof()) {
00139         mui_nomcanal->setText(cursorcanal->valor("nombre"));
00140         mui_desccanal->setPlainText(cursorcanal->valor("descripcion"));
00141     } // end if
00142     mui_idcanal->setidcanal(QString::number(idcanal));
00143     dialogChanges_cargaInicial();
00144     _depura("END canalview::mostrarplantilla", 0);
00145 
00146 }
00147 
00148 
00150 
00152 void canalview::on_mui_guardar_clicked() {
00153     _depura("canalview::on_mui_guardar_clicked", 0);
00154     QString nom = mui_nomcanal->text();
00155     QString desc = mui_desccanal->toPlainText();
00156     QString query;
00157     QTextStream(&query) << "UPDATE canal SET nombre = '"
00158                         << empresaBase()->sanearCadena(nom).toAscii().constData()
00159                         << "', descripcion = '"
00160                         << empresaBase()->sanearCadena(desc).toAscii().constData()
00161                         << "' WHERE idcanal = '" << idcanal << "'";
00162     empresaBase()->ejecuta(query);
00163     dialogChanges_cargaInicial();
00164     pintar();
00165     _depura("END canalview::on_mui_guardar_clicked", 0);
00166 }
00167 
00168 
00170 
00172 void canalview::on_mui_crear_clicked() {
00173     _depura("canalview::on_mui_crear_clicked", 0);
00175     if (dialogChanges_hayCambios()) {
00176         if (QMessageBox::warning(this,
00177                                  tr("Guardar canal"),
00178                                  tr("Desea guardar los cambios."),
00179                                  tr("&Guardar"), tr("&Cancelar"), 0 , 0, 1) == 0)
00180             on_mui_guardar_clicked();
00181     } // end if
00182     QString query = "";
00183     QTextStream(&query) << "INSERT INTO canal (nombre, descripcion) VALUES ('" << tr("Nuevo canal") << "', '" << tr("Escriba su descripcion") << "')";
00184     empresaBase()->begin();
00185     empresaBase()->ejecuta(query);
00186     query = "";
00187     QTextStream(&query) << "SELECT MAX(idcanal) AS id FROM canal";
00188     cursor2 *cur = empresaBase()->cargacursor(query, "queryy");
00189     idcanal = atoi(cur->valor("id").toAscii());
00190     delete cur;
00191     empresaBase()->commit();
00192     pintar();
00193     _depura("END canalview::on_mui_crear_clicked", 0);
00194 }
00195 
00196 
00198 
00200 void canalview::on_mui_borrar_clicked() {
00201     _depura("canalview::on_mui_borrar_clicked", 0);
00202     switch (QMessageBox::warning(this,
00203                                  tr("Borrar canal"),
00204                                  tr("Se va a borrar este canal.\nEsto puede ocasionar perdida de datos."),
00205                                  tr("&Borrar"), tr("&Cancelar"), 0 , 0, 1)) {
00206     case 0: 
00207         QString query;
00208         query.sprintf("DELETE FROM canal WHERE idcanal = %d", idcanal);
00209         empresaBase()->begin();
00210         empresaBase()->ejecuta(query);
00211         empresaBase()->commit();
00212         idcanal = 0;
00213         pintar();
00214     } // end switch
00215     _depura("END canalview::on_mui_borrar_clicked", 0);
00216 }
00217 
00218 
00220 
00223 void canalview::closeEvent(QCloseEvent *e) {
00224     _depura("ccosteview::closeEvent", 0);
00225     if (dialogChanges_hayCambios()) {
00226         int val = QMessageBox::warning(this,
00227                                        tr("Guardar canal"),
00228                                        tr("Desea guardar los cambios?"),
00229                                        tr("&Si"), tr("&No"), tr("&Cancelar"), 0, 2);
00230         if (val == 0)
00231             on_mui_guardar_clicked();
00232         if (val == 2)
00233             e->ignore();
00234     } // end if
00235     _depura("END ccosteview::closeEvent", 0);
00236 }
00237 

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