コード例 #1
0
        public void getSeteDiasPrevisaoLatLon(string lat, string lon)
        {
            DataSet ds  = new DataSet();
            string  url = "http://servicos.cptec.inpe.br/XML/cidade/7dias/" + lat + "/" + lon + "/previsaoLatLon.xml";

            ds.ReadXml(url);

            int       count = ds.Tables[0].Rows.Count;
            DataTable dt    = ds.Tables[0];

            cidade c = new cidade();

            //try
            //{
            if (ds != null)
            {
                if (count > 0)
                {
                    CptecDAL.LuaDAL objLua = new CptecDAL.LuaDAL();

                    for (int i = 0; i < count; i++)
                    {
                        c.nome        = dt.Rows[i]["nome"].ToString().Trim();
                        c.uf          = dt.Rows[i]["uf"].ToString().Trim();
                        c.atualizacao = dt.Rows[i]["atualizacao"].ToString().Trim();
                    }

                    count = ds.Tables[1].Rows.Count;
                    dt    = ds.Tables[1];

                    List <cidade.previsao> pr = new List <cidade.previsao>();

                    for (int i = 0; i < count; i++)
                    {
                        cidade.previsao p = new cidade.previsao();
                        p.dia    = dt.Rows[i]["dia"].ToString().Trim();
                        p.tempo  = dt.Rows[i]["tempo"].ToString().Trim();
                        p.maxima = dt.Rows[i]["maxima"].ToString().Trim();
                        p.minima = dt.Rows[i]["minima"].ToString().Trim();
                        p.iuv    = dt.Rows[i]["iuv"].ToString().Trim();
                        p.lua    = objLua.getLua(p.dia).Rows[0]["descricao"].ToString();
                        pr.Add(p);
                    }

                    c.previsoes = pr;
                }
            }

            //}
            //catch (Exception)
            //{

            //}

            //return c;
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

            this.Context.Response.ContentType = "application/json; charset=utf-8";
            this.Context.Response.Write(jsSerializer.Serialize(c));
        }
コード例 #2
0
        public cidade getSeteDiasPrevisao(string cod)
        {
            DataSet ds  = new DataSet();
            string  url = "http://servicos.cptec.inpe.br/XML/cidade/7dias/" + cod + "/previsao.xml";

            ds.ReadXml(url);

            int       count = ds.Tables[0].Rows.Count;
            DataTable dt    = ds.Tables[0];

            cidade c = new cidade();

            //try
            //{
            if (ds != null)
            {
                if (count > 0)
                {
                    CptecDAL.LuaDAL objLua = new CptecDAL.LuaDAL();


                    for (int i = 0; i < count; i++)
                    {
                        c.nome        = dt.Rows[i]["nome"].ToString().Trim();
                        c.uf          = dt.Rows[i]["uf"].ToString().Trim();
                        c.atualizacao = dt.Rows[i]["atualizacao"].ToString().Trim();
                    }

                    count = ds.Tables[1].Rows.Count;
                    dt    = ds.Tables[1];

                    List <cidade.previsao> pr = new List <cidade.previsao>();

                    for (int i = 0; i < count; i++)
                    {
                        cidade.previsao p = new cidade.previsao();
                        p.dia    = dt.Rows[i]["dia"].ToString().Trim();
                        p.tempo  = dt.Rows[i]["tempo"].ToString().Trim();
                        p.maxima = dt.Rows[i]["maxima"].ToString().Trim();
                        p.minima = dt.Rows[i]["minima"].ToString().Trim();
                        p.iuv    = dt.Rows[i]["iuv"].ToString().Trim();
                        p.lua    = objLua.getLua(p.dia).Rows[0]["descricao"].ToString();
                        pr.Add(p);
                    }

                    c.previsoes = pr;
                }
            }

            //}
            //catch (Exception)
            //{

            //}

            return(c);
        }
コード例 #3
0
ファイル: JSON.asmx.cs プロジェクト: rodrigosabreu/Cptec
        public void getSeteDiasPrevisao(string cod)
        {
            try
            {
                DataSet ds  = new DataSet();
                string  url = "http://servicos.cptec.inpe.br/XML/cidade/7dias/" + cod + "/previsao.xml";
                ds.ReadXml(url);

                int       count = ds.Tables[0].Rows.Count;
                DataTable dt    = ds.Tables[0];

                Cidade c = new Cidade();


                if (ds != null)
                {
                    if (count > 0)
                    {
                        CptecDAL.LuaDAL objLua = new CptecDAL.LuaDAL();

                        for (int i = 0; i < count; i++)
                        {
                            c.nome = dt.Rows[i]["nome"].ToString().Trim();
                            if (c.nome == "null")
                            {
                                throw new Exception("Registros com valores nulo.");
                            }
                            c.uf          = dt.Rows[i]["uf"].ToString().Trim();
                            c.atualizacao = dt.Rows[i]["atualizacao"].ToString().Trim();
                        }

                        count = ds.Tables[1].Rows.Count;
                        dt    = ds.Tables[1];

                        List <Cidade.Previsao> pr = new List <Cidade.Previsao>();

                        for (int i = 0; i < count; i++)
                        {
                            Cidade.Previsao p = new Cidade.Previsao();
                            p.dia    = dt.Rows[i]["dia"].ToString().Trim();
                            p.tempo  = dt.Rows[i]["tempo"].ToString().Trim();
                            p.maxima = dt.Rows[i]["maxima"].ToString().Trim();
                            p.minima = dt.Rows[i]["minima"].ToString().Trim();
                            p.iuv    = dt.Rows[i]["iuv"].ToString().Trim();
                            p.lua    = objLua.getLua(p.dia).Rows[0]["descricao"].ToString();
                            pr.Add(p);
                        }

                        c.previsoes = pr;
                    }
                }

                _DATA d = new _DATA();
                d.dados = c;

                _JSON j = new _JSON();
                j.data   = d;
                j.error  = "";
                j.sucess = "true";

                JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
                this.Context.Response.ContentType = "application/json; charset=utf-8";
                this.Context.Response.Write(jsSerializer.Serialize(j));
            }
            catch (Exception ex)
            {
                _ERROR e = new _ERROR();
                e.error  = ex.Message;
                e.sucess = "false";

                JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
                this.Context.Response.ContentType = "application/json; charset=utf-8";
                this.Context.Response.Write(jsSerializer.Serialize(e));
            }
        }