Esempio n. 1
0
        public Sitios obtener_datos(string CellID)
        {
            Sitios bar = new Sitios();

            MySqlConnection conexion = Database.obtenerConexion(true);

            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection  = conexion;
            cmd.Transaction = Database.obtenerTransaccion();
            cmd.CommandText = "select * from sitios where CellID = @filtro";
            cmd.Parameters.AddWithValue("@filtro", CellID);

            try
            {
                if (Database.obtenerTransaccion() == null)
                {
                    conexion.Open();
                }

                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    bar.Codigo       = reader["CellID"].ToString();
                    bar.Nombre       = reader["Nombre"].ToString();
                    bar.Viatico_ID   = reader["Codigo Viatico"].ToString();
                    bar.Longitud     = reader["longitud"].ToString();
                    bar.Latitud      = reader["latitud"].ToString();
                    bar.Pais         = reader["pais"].ToString();
                    bar.Provincia    = reader["provincia"].ToString();
                    bar.Departamento = reader["departamento"].ToString();
                    bar.Localidad    = reader["localidad"].ToString();

                    bar.IDNombre = bar.Codigo + " - " + bar.Nombre;
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                UltimoMensaje = GestionErrores.obtenerError(ex);
                UltimoMensaje.cargar(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),
                    System.Reflection.MethodBase.GetCurrentMethod().ToString(),
                    new System.Diagnostics.StackFrame(0, true).GetFileLineNumber());
                UltimoMensaje.EsError = true;
                Notify(UltimoMensaje);
            }
            finally
            {
                cmd.Parameters.Clear();
                if (Database.obtenerTransaccion() == null)
                {
                    if (conexion.State != ConnectionState.Closed)
                    {
                        conexion.Close();
                    }
                }
            }

            return(bar);
        }
Esempio n. 2
0
 private static void cargarDatos(Sitios objeto, MySqlDataReader dr)
 {
     objeto.Codigo = dr[dbCampoCodigo].ToString();
     objeto.Nombre = dr[dbCampoNombre].ToString();
 }
Esempio n. 3
0
        public List <Sitios> obtener(string busqueda = "")
        {
            List <Sitios> ret = new List <Sitios>();

            MySqlConnection conexion = Database.obtenerConexion(true);

            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection  = conexion;
            cmd.Transaction = Database.obtenerTransaccion();
            cmd.CommandText = "select * from sitios where CellID like @filtro OR Nombre like @filtro order by CellID";
            cmd.Parameters.AddWithValue("@filtro", "%" + busqueda + "%");

            try
            {
                if (Database.obtenerTransaccion() == null)
                {
                    conexion.Open();
                }

                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Sitios bar = new Sitios();

                    bar.Subscribe(this);

                    bar.Codigo     = reader["CellID"].ToString();
                    bar.Nombre     = reader["Nombre"].ToString();
                    bar.Viatico_ID = reader["Codigo Viatico"].ToString();
                    bar.IDNombre   = bar.Codigo + " - " + bar.Nombre;
                    ret.Add(bar);
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                UltimoMensaje = GestionErrores.obtenerError(ex);
                UltimoMensaje.cargar(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),
                    System.Reflection.MethodBase.GetCurrentMethod().ToString(),
                    new System.Diagnostics.StackFrame(0, true).GetFileLineNumber());
                UltimoMensaje.EsError = true;
                Notify(UltimoMensaje);
            }
            finally
            {
                cmd.Parameters.Clear();
                if (Database.obtenerTransaccion() == null)
                {
                    if (conexion.State != ConnectionState.Closed)
                    {
                        conexion.Close();
                    }
                }
            }

            return(ret);
        }
Esempio n. 4
0
        } // Unsubscribe

        #endregion

        public List <Sitios> obtenerFiltrado(ItemFiltro[] itemFiltro,
                                             ItemOrden[] orden, bool busquedaAnd, double inicio, double fin, out double totalRegistros)
        {
            List <Sitios> ret = new List <Sitios>();

            UltimoMensaje = null;
            MySqlConnection conexion = Database.obtenerConexion(true);

            MySqlCommand comando = new MySqlCommand();

            comando.Connection  = conexion;
            comando.Transaction = Database.obtenerTransaccion();

            totalRegistros = 0;
            int parameterCount = 0;

            string where = "";
            string tipoBusqueda = " AND ";

            if (!busquedaAnd)
            {
                tipoBusqueda = " OR  ";
            }


            Varios.armarConsultaFiltros(itemFiltro, comando, ref parameterCount, ref where, tipoBusqueda);

            string cadenaOrden = "";

            comando.CommandText = "SELECT count(*) FROM " + dbTabla + " " + where;
            try
            {
                if (Database.obtenerTransaccion() == null)
                {
                    conexion.Open();
                }
                double.TryParse(comando.ExecuteScalar().ToString(), out totalRegistros);

                if (inicio < 0)
                {
                    inicio = 0;
                }

                if (inicio > totalRegistros)
                {
                    inicio = totalRegistros - 1;
                }


                if (fin > totalRegistros || fin == -1)
                {
                    fin = totalRegistros;
                }

                if (inicio < 1)
                {
                    inicio = 1;
                }

                if (fin < 1)
                {
                    fin = 1;
                }

                cadenaOrden = Varios.armarCadenaOrden(orden, cadenaOrden, dbCampoNombre);

                //TODO: Hacer Paginacion

                double rowcount = fin - (inicio - 1);

                comando.CommandText = "  SELECT *   FROM " + dbTabla + " " + where + " "
                                      + cadenaOrden
                                      + " LIMIT " + (inicio - 1) + ", " + rowcount;

                MySqlDataReader dr = comando.ExecuteReader();

                while (dr.Read())
                {
                    Sitios bar = new Sitios();
                    bar.Subscribe(this);

                    cargarDatos(bar, dr);

                    ret.Add(bar);
                }

                dr.Close();
            }
            catch (Exception ex)
            {
                UltimoMensaje = GestionErrores.obtenerError(ex);
                UltimoMensaje.cargar(
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(),
                    System.Reflection.MethodBase.GetCurrentMethod().ToString(),
                    new System.Diagnostics.StackFrame(0, true).GetFileLineNumber());
                UltimoMensaje.EsError = true;
                Notify(UltimoMensaje);
            }
            finally
            {
                comando.Parameters.Clear();
                if (Database.obtenerTransaccion() == null)
                {
                    if (conexion.State != ConnectionState.Closed)
                    {
                        conexion.Close();
                    }
                }
            }

            return(ret);
        }