Beispiel #1
0
        private void CrearParametros(OdbcCommand command, LocalidadEntity entidad)
        {
            OdbcParameter parameter = null;

            parameter       = command.Parameters.Add("?", OdbcType.Int);
            parameter.Value = entidad.Provincia.IdProvincia;

            parameter       = command.Parameters.Add("?", OdbcType.VarChar);
            parameter.Value = entidad.Nombre;

            parameter       = command.Parameters.Add("?", OdbcType.Int);
            parameter.Value = entidad.IdLocalidad;
        }
Beispiel #2
0
        private void EjecutarComando(daComun.TipoComandoEnum sqlCommandType, LocalidadEntity entidad)
        {
            OdbcConnection connection = null;
            OdbcCommand    command    = null;

            try {
                connection = (OdbcConnection)connectionDA.GetOpenedConnection();
                IDataParameter paramId = new OdbcParameter("?", OdbcType.Int);
                paramId.Value = entidad.IdLocalidad;

                switch (sqlCommandType)
                {
                case daComun.TipoComandoEnum.Insertar:
                    command = new OdbcCommand(SQLInsert, connection);
                    command.Parameters.Add(paramId);
                    CrearParametros(command, entidad);
                    break;

                case daComun.TipoComandoEnum.Actualizar:
                    command = new OdbcCommand(SQLUpdate, connection);
                    command.Parameters.Add(paramId);
                    CrearParametros(command, entidad);
                    break;

                case daComun.TipoComandoEnum.Eliminar:
                    command = new OdbcCommand(SQLDelete, connection);
                    command.Parameters.Add(paramId);
                    CrearParametros(command, entidad);
                    break;
                }

                command.ExecuteNonQuery();
                connection.Close();
            } catch (Exception ex) {
                throw new daException(ex);
            } finally {
                if (command != null)
                {
                    command.Dispose();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Beispiel #3
0
        public LocalidadEntity ObtenerLocalidadPorId(int idlocalidad)
        {
            OdbcConnection  connection = null;
            OdbcCommand     command    = null;
            OdbcDataReader  dr         = null;
            LocalidadEntity localidad;

            try {
                connection = (OdbcConnection)connectionDA.GetOpenedConnection();
                command    = new OdbcCommand(SQLSearchByPrimaryKey, connection);
                command.Parameters.Add("?", OdbcType.Int);
                command.Parameters[0].Value = idlocalidad;
                dr = command.ExecuteReader();

                localidad = new LocalidadEntity();

                while (dr.Read())
                {
                    localidad = CrearEntidad(dr);
                }

                dr.Close();
                connection.Close();
            } catch (Exception ex) {
                throw new daException(ex);
            } finally {
                dr = null;
                if (command != null)
                {
                    command.Dispose();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
            }

            return(localidad);
        }
Beispiel #4
0
 public void Actualizar(LocalidadEntity entidad)
 {
     EjecutarComando(daComun.TipoComandoEnum.Actualizar, entidad);
 }
Beispiel #5
0
 public void Insertar(LocalidadEntity entidad)
 {
     EjecutarComando(daComun.TipoComandoEnum.Insertar, entidad);
 }