public override int EjecutarCmdPreparado(List <CamposTabla> unRegistro) { int resultado = 0; try { foreach (CamposTabla item in unRegistro) { if (this.comandoPreparado.Parameters.Count > 0) { if (this.comandoPreparado.Parameters.Contains("@" + item.Nombre)) { this.comandoPreparado.Parameters[item.Nombre].Value = item.Valor; } } } //EJECUCION DE COMANDO if (exeAutoNum) { //CAPTURAMOS VALOR AUTONUMERICO DE TIPO SEQUENCE CUANDO EXEAUTONUM == TRUE IfxDataReader rd = (IfxDataReader)ExecuteReader(this.comandoPreparado); rd.Read(); resultado = Convert.ToInt32(rd["valorActual"]); rd.Close(); rd.Dispose(); rd = null; } else { //DEVOLVEMOS EL NUMERO DE REGISTROS AFECTADOS CUANDO EXEAUTONUM == FALSE resultado = ExecuteNonQuery(this.comandoPreparado); } } catch (IfxException) { //throw new Exception("Error " + mensaje + " Registro \nDetalle: ", ex); throw; } catch (Exception) { //throw new Exception("Error " + mensaje + " Registro \nDetalle: ", ex); throw; } //DEVOLUCION DE RESULTADO return(resultado); }
private int EjecutarSQLAutonumerico(string cadenaSQL, List <CamposTabla> lp, object unaConexion = null, object unaTransaccion = null) { bool exeAutoNumerico = false; //OBJETO PARA MANIPULACION DE CADENA SQL StringBuilder sqlNueva = new StringBuilder(cadenaSQL); //VERIFICACION DE CAMPOS DEFINIDOS COMO AUTONUMERICOS if (lp.Count(x => x.Autonumerico == true) == 1) { exeAutoNumerico = true; } else { exeAutoNumerico = false; } //DETERMINAMOS NOMBRE DE TABLA /*if (cadenaSQL.Contains("insert into")) * { * mensaje = "agregando"; * } * if (cadenaSQL.Contains("update ")) * { * mensaje = "actualizando"; exeAutoNumerico = false; * } * if (cadenaSQL.Contains("delete from")) * { * mensaje = "eliminando"; exeAutoNumerico = false; * }*/ //CREAMOS OBJETO COMANDO IfxCommand command = new IfxCommand(); command.CommandType = System.Data.CommandType.Text; //SI ES EJECUCION DE AUTONUMERICO ESTABLECE LA DEVOLUCION DEL VALOR DE LA SECUENCIA if (exeAutoNumerico) { sqlNueva.Replace("{%}", "coalesce"); } //CREACION DE PARAMETROS EN EL COMANDO Y DESCARTE DE CAMPOS AUTONUMERICOS foreach (CamposTabla item in lp) { if (!item.Nombre.Contains("#")) { IfxParameter parametro = new IfxParameter(); parametro.ParameterName = "@" + item.Nombre; if (item.TipoEstablecido) { parametro.DbType = item.Tipo; parametro.Size = item.Tamaño; } parametro.Direction = item.Direccion; parametro.Value = item.Valor; command.Parameters.Add(parametro); } } //command.CommandText = sqlNueva.Replace("@", ":").ToString(); command.CommandText = sqlNueva.ToString(); //ASIGNACION DE CONEXION Y TRANSACCION if (unaConexion == null) { command.Connection = this.Conexion; } else { command.Connection = (IfxConnection)unaConexion; } if (unaConexion != null && unaTransaccion != null) { command.Transaction = (IfxTransaction)unaTransaccion; } //RESULTADO DEVUELTO int resultado = 0; try { if (unaConexion == null) { if (Conexion.State == System.Data.ConnectionState.Closed) { Conexion.Open(); } } //EJECUCION DE COMANDO if (exeAutoNumerico) { //CAPTURAMOS VALOR AUTONUMERICO DE TIPO SEQUENCE CUANDO EXEAUTONUM == TRUE IfxDataReader rd = (IfxDataReader)ExecuteReader(command); rd.Read(); resultado = Convert.ToInt32(rd["valorActual"]); rd.Close(); rd.Dispose(); rd = null; } else { //DEVOLVEMOS EL NUMERO DE REGISTROS AFECTADOS CUANDO EXEAUTONUM == FALSE resultado = ExecuteNonQuery(command); } } catch (IfxException) { //throw new Exception("Error " + mensaje + " Registro \nDetalle: " + ex.ToString(), ex); throw; } /*catch (Exception) * { * //throw new Exception("Error " + mensaje + " Registro \nDetalle: " + ex.ToString(), ex); * throw; * }*/ finally { //DESTRUCCION DE OBJETOS Y CIERRE DE CONEXION command.Dispose(); if (unaConexion == null) { if (conexionLocal != null) { if (Conexion.State == System.Data.ConnectionState.Open) { Conexion.Close(); conexionLocal = null; } } } //mensaje = null; sqlNueva = null; } //DEVOLUCION DE RESULTADO return(resultado); }