Exemplo n.º 1
0
        public void GetMonenPuntos(int idUsuaio)
        {
            List <Monumentos> listMonumentos = new List <Monumentos>();

            var             json     = "";
            MySqlConnection conexion = new MySqlConnection(ruta);

            conexion.Open();

            MySqlCommand command = conexion.CreateCommand();

            if (idUsuaio == 1)
            {
                command.CommandText = ("SELECT p.idPun_Patr, p.lat, p.long, p.url_img_punto, p.nombre, p.descripcion  FROM punto_patrimonial p where p.publicado = 1");
            }
            else
            {
                command.CommandText = ("SELECT p.idPun_Patr, p.lat, p.long, p.url_img_punto, p.nombre, p.descripcion  FROM punto_patrimonial p where p.publicado = 0");
            }


            command.Connection = conexion;

            MySqlDataReader reader = command.ExecuteReader();


            while (reader.Read())
            {
                Monumentos mou = new Monumentos();

                mou.Idmonumento = reader.GetInt32(0);
                mou.Latitud     = reader.GetDecimal(1);
                mou.Longitud    = reader.GetDecimal(2);
                mou.Url_img     = reader.GetString(3);
                mou.Nombre      = reader.GetString(4);
                mou.Descripcion = reader.GetString(5);



                listMonumentos.Add(mou);
            }

            command.Connection.Close();

            //json = jss.Serialize(listMonumentos);
            Context.Response.Clear();
            Context.Response.ContentType = "application/json";

            JavaScriptSerializer jss = new JavaScriptSerializer();

            Context.Response.Write(jss.Serialize(listMonumentos));
            // return json;
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            try{
                switch (context.Request.HttpMethod)
                {
                case "POST":

                    break;

                case "GET":

                    string ruta = "server=sql5.freesqldatabase.com; database=sql5126778; Uid=sql5126778; pwd=RIv77yWahZ;";

                    List <Monumentos> listMonumentos = new List <Monumentos>();

                    var             json     = "";
                    MySqlConnection conexion = new MySqlConnection(ruta);
                    conexion.Open();

                    MySqlCommand command = conexion.CreateCommand();
                    command.CommandText = ("SELECT p.idPun_Patr, p.lat, p.long  FROM punto_patrimonial p");
                    command.Connection  = conexion;

                    MySqlDataReader reader = command.ExecuteReader();


                    while (reader.Read())
                    {
                        Monumentos mou = new Monumentos();

                        //mou.Idmonumento = reader.GetString(0).ToString();
                        mou.Latitud  = reader.GetDecimal(1);
                        mou.Longitud = reader.GetDecimal(2);

                        listMonumentos.Add(mou);
                    }

                    command.Connection.Close();

                    JavaScriptSerializer jss = new JavaScriptSerializer();
                    //json = jss.Serialize(listMonumentos);

                    HttpContext.Current.Response.Write(jss.Serialize(listMonumentos));
                    break;

                default:

                    break;
                }
            }catch (Exception e) {
                HttpContext.Current.Response.Write("Error en el Web Service");
            }
        }