From 50a0c712770274a8d87f4fa29996d9f10cecb8ec Mon Sep 17 00:00:00 2001 From: rmontanana Date: Mon, 24 Feb 2014 13:28:43 +0100 Subject: [PATCH] =?UTF-8?q?ref#=203=20#6=20Terminada=20la=20importaci?= =?UTF-8?q?=C3=B3n=20de=20datos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Csv.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Csv.php b/Csv.php index 220f84a..dc51f96 100644 --- a/Csv.php +++ b/Csv.php @@ -226,22 +226,29 @@ class Csv { return $mensaje; } - private function escribeFic($comando) { - $fp = fopen("tmp/comandos", "a"); - fputs($fp, $comando . "\n"); + private function escribeLog($comando) { + $fp = fopen($this->nombre.".log", "a"); + $linea = strftime("%Y/%m/%d")."|".$this->nombre."|".$comando; + fputs($fp, $linea . "\n"); fclose($fp); } private function bajaElemento($i) { $id = $this->datosFichero[$i][$this->idElemento]; $comando = 'delete from Elementos where id="' . $id . '";'; - $this->escribeFic($comando); + $this->escribeLog($comando); + if (!$this->bdd->ejecuta($comando)) { + throw new Exception("Baja-".$this->bdd->mensajeError, $this->bdd->error); + } } private function modificaElemento($i) { $id = $this->datosFichero[$i][$this->idElemento]; $comando = 'update Elementos set Cantidad=' . $this->datosFichero[$i][$this->cantidadReal] . ' where id="' . $id . '";'; - $this->escribeFic($comando); + $this->escribeLog($comando); + if (!$this->bdd->ejecuta($comando)) { + throw new Exception("Modifica-".$this->bdd->mensajeError, $this->bdd->error); + } } private function altaElemento($i) { @@ -256,7 +263,10 @@ class Csv { $idArt = $datosFichero[$i]; $comando = 'insert into Elementos () values (null,' . $idArticulo . ',' . $idUbicacion . ',"' . $this->datosFichero[$i][$this->nSerie]; $comando .= '",' . $this->datosFichero[$i][$this->cantidadReal] . ',"' . $this->datosFichero[$i][$this->fechaCompra] . '");'; - $this->escribeFic($comando); + $this->escribeLog($comando); + if (!$this->bdd->ejecuta($comando)) { + throw new Exception("Alta-".$this->bdd->mensajeError, $this->bdd->error); + } } private function cargaIndices($campos) { @@ -278,8 +288,8 @@ class Csv { break; } } - $this->EscribeFic("Cantreal=[$this->cantidadReal] fechacompra=[$this->fechaCompra] ubicacion=[$this->idUbicacion] articulo=[$this->idArticulo]"); - $this->EscribeFic("idElemento=[$this->idElemento] Cantidad=[$this->cantidad] nserie=[$this->nserie]"); + //$this->EscribeFic("Cantreal=[$this->cantidadReal] fechacompra=[$this->fechaCompra] ubicacion=[$this->idUbicacion] articulo=[$this->idArticulo]"); + //$this->EscribeFic("idElemento=[$this->idElemento] Cantidad=[$this->cantidad] nserie=[$this->nserie]"); } /** @@ -311,6 +321,7 @@ class Csv { } } $mensaje = "Se han procesado correctamente $acciones acciones en la Base de Datos."; + $this->bdd->confirmaTransaccion(); return $this->panelMensaje($mensaje,"success", "Información"); } catch (Exception $e) { $this->bdd->abortaTransaccion();