Пример #1
0
        private async void WeatherApp_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var position = await LocationManager.GetPosition(); //Need. Don't change.

                double lat = position.Coordinate.Latitude;
                double lon = position.Coordinate.Longitude;

                RootObject myWeather = await WeatherClass.GetWeather(position.Coordinate.Latitude, position.Coordinate.Longitude);

                string icon = String.Format("http:{0}", myWeather.current.condition.icon);
                ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));

                CurrentLocation.Text  = myWeather.location.name;
                CurrentCondition.Text = myWeather.current.condition.text;
                CurrentTemp.Text      = myWeather.current.temp_f.ToString() + "ø";
                Humidity.Text         = myWeather.current.humidity.ToString() + "%";
                FeelsLike.Text        = myWeather.current.feelslike_f.ToString() + "ø";
                maxtemp.Text          = myWeather.forecast.forecastday[0].day.maxtemp_f.ToString() + "F";
                mintemp.Text          = myWeather.forecast.forecastday[0].day.mintemp_f.ToString() + "F";
                sunrise.Text          = myWeather.forecast.forecastday[0].astro.sunrise;
                sunset.Text           = myWeather.forecast.forecastday[0].astro.sunset;
            }
            catch
            {
                CurrentLocation.Text = "Unable to get weather at this time";
            }
        }
Пример #2
0
        // GET: Weather
        public JsonResult GetWeatherData()
        {
            WeatherClass s  = new WeatherClass();
            var          dd = s.GetWeatherNow("egypt");

            //WeatherClass.GetWeatherNow("egypt");

            return(Json(dd, JsonRequestBehavior.AllowGet));
        }
 public ActionResult GetJson(string name, string coutry)
 {
     using (WebClient wc = new WebClient())
     {
         wc.Encoding = Encoding.UTF8;
         string       json = wc.DownloadString(("http://api.openweathermap.org/data/2.5/weather?q=" + name + "," + coutry + "&appid=8e62cff8b7014d4615914d8b0c743c7e"));
         WeatherClass wthC = new WeatherClass(json);
         return(View(wthC));
     }
 }
Пример #4
0
        private async void WeatherApp_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //var position = await LocationManager.GetPosition(); //Need. Don't change.
                //double lat = position.Coordinate.Latitude;
                //double lon = position.Coordinate.Longitude;
                //Console.WriteLine(lat);
                //var textbox = lat.ToString();
                //Debug.Print(textbox);

                //var cli = new System.Net.WebClient();
                //var result = cli.DownloadString("https://api.apixu.com/v1/forecast.json?key=9038eee216524157bfb235747181807&q=31.2143,121.4324&days=7");
                //Console.WriteLine(result);
                //Debug.Print(result);
                //Console.WriteLine("TRY");
                //Debug.Print("TRY");

                //RootObject myWeather = await WeatherClass.GetWeather(position.Coordinate.Latitude, position.Coordinate.Longitude);

                var myWeather = await WeatherClass.GetWeather(37.335480, -121.893028);

                Console.WriteLine("KILLMONGO");
                Console.WriteLine(myWeather);

                string icon = String.Format("http:{0}", myWeather.current.condition.icon);
                ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));

                CurrentLocation.Text = myWeather.location.name;
                Console.WriteLine("HELLO");
                Console.WriteLine(CurrentLocation);
                CurrentCondition.Text = myWeather.current.condition.text;
                CurrentTemp.Text      = myWeather.current.temp_f.ToString() + "°F";
                Humidity.Text         = myWeather.current.humidity.ToString() + "%";
                FeelsLike.Text        = myWeather.current.feelslike_f.ToString() + "°F";
                maxtemp.Text          = myWeather.forecast.forecastday[0].day.maxtemp_f.ToString() + "°F";
                mintemp.Text          = myWeather.forecast.forecastday[0].day.mintemp_f.ToString() + "°F";
                sunrise.Text          = myWeather.forecast.forecastday[0].astro.sunrise;
                sunset.Text           = myWeather.forecast.forecastday[0].astro.sunset;
            }
            catch
            {
                CurrentLocation.Text = "Unable to get weather at this time";
            }
        }
Пример #5
0
        private async void WelcomePage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //var welcometext = String.Format("Welcome, {0}!", visitorName);
                string now_time = DateTime.Now.ToString("h:mm:ss tt");

                time.Text = now_time + " ";
                //Debug.Print(time);
                string now_date = DateTime.Now.ToString("M/d/yyyy");
                date.Text = now_date + " ";
                var myWeather = await WeatherClass.GetWeather(37.335480, -121.893028);

                CurrentTemp.Text = myWeather.current.temp_f.ToString() + "°F";
            }
            catch
            {
                var welcometext = String.Format("Welcome, {0}!", visitorName);
                var time        = DateTime.Now.ToString("h:mm:ss tt");
                Debug.Print(time);
                Debug.Print("WHATUP");
            }
            //Greetings.Text = welcometext;
        }
Пример #6
0
        public JsonResult GetWeather()
        {
            WeatherClass myWeather = new WeatherClass();

            return(Json(myWeather.GetCurrentWeather(), JsonRequestBehavior.AllowGet));
        }
Пример #7
0
    /// <summary>
    /// gridview行数据绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gv_citydata_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (mRecordeData == null)
        {
            return;
        }

        try
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Text = rowHeaderName(e.Row.Cells[1].Text);

                int index = 1;
                if (gridShowSX(mRecordeData[0].DataType))
                {
                    e.Row.Cells[1].Text = rowHeaderName(e.Row.Cells[3].Text);
                    index++;
                }


                for (int i = 0; i < mElementRelation.Length; i++)
                {
                    e.Row.Cells[index].Text = mElementRelation[i].ElementNameCN;
                    index++;
                }

                for (int i = index; i < e.Row.Cells.Count; i++)
                {
                    e.Row.Cells[i].Visible = false;
                }
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[4].Text == "&nbsp;")
                {
                    e.Row.Visible = false;
                    ExpStationMessage.NoDataStationName.Add(e.Row.Cells[1].Text + "(" + e.Row.Cells[0].Text + ")");
                }
                else
                {
                    int rowIndex = e.Row.RowIndex;
                    e.Row.Cells[0].Text = e.Row.Cells[1].Text + "(" + e.Row.Cells[0].Text + ")";

                    int index = 1;
                    if (gridShowSX(mRecordeData[0].DataType))
                    {
                        e.Row.Cells[1].Text = e.Row.Cells[3].Text;
                        index = 2;
                    }
                    //20120220 syy增加最高温度和最低温度判断,如果出现最高温度和最低温度相等,则给出城市名称提示
                    //20120220 syy最高温度、最低温度变量,以便对比
                    //20130702 syy记录天气现象
                    //20130704 syy记录天气现象(转)
                    //20130702 syy记录风力
                    //20130702 syy记录风向
                    //20130704 syy记录风力(转)
                    //20130704 syy记录风向(转)
                    //统一记录在WeatherClass中
                    WeatherClass weather = new WeatherClass();

                    for (int i = 0; i < mElementRelation.Length; i++)
                    {
                        string elementName = mElementRelation[i].ElementName;

                        string valueElement_Code = valueElement(elementName, mRecordeData[rowIndex]);

                        e.Row.Cells[index].Text = decodeEl(mElementRelation[i].ElementCodeType, valueElement_Code);

                        index++;


                        //20120220 syy如果是最高温度,则保存到maxTem变量中,以便一行完成后与最低气温进行对比
                        if (mElementRelation[i].ElementCodeType == 2)
                        {
                            if (mElementRelation[i].ElementNameCN == "最高气温")
                            {
                                weather.HighTem     = valueElement_Code;
                                weather.HighTemElID = mElementRelation[i].ElementName.ToString();
                                continue;
                            }
                            //20120220 syy如果是最低气温,则保存到minTem变量中,以便一行完成后与最高气温进行对比
                            if (mElementRelation[i].ElementNameCN == "最低气温")
                            {
                                weather.LowTem     = valueElement_Code;
                                weather.LowTemElID = mElementRelation[i].ElementName.ToString();
                                continue;
                            }
                        }

                        //20120220 syy如果是天气现象,则保存到weather变量中,以便一行完成后与最低气温进行交叉查看,如果出现冻雨等天气现象,则提示
                        if (mElementRelation[i].ElementCodeType == 1)
                        {
                            if (mElementRelation[i].ElementNameCN == "天气")
                            {
                                weather.Weather01 = valueElement_Code;
                                continue;
                            }
                            else
                            {
                                weather.Weather02 = valueElement_Code;
                                continue;
                            }
                        }
                        //20120220 syy如果是风向,以便一行完成后与风力进行交叉查看,如果出现风力》=3级,无风向则提示
                        //风力id=3
                        if (mElementRelation[i].ElementCodeType == 3)
                        {
                            if (mElementRelation[i].ElementNameCN == "风向")
                            {
                                weather.WindDir01 = valueElement_Code;
                                continue;
                            }
                            else
                            {
                                weather.WindDir02 = valueElement_Code;
                                continue;
                            }
                        }
                        //20120220 syy如果是风力,以便一行完成后与风向进行交叉查看,如果出现风力》=3级,无风向则提示
                        //风力id=4
                        if (mElementRelation[i].ElementCodeType == 4)
                        {
                            if (mElementRelation[i].ElementNameCN == "风力")
                            {
                                weather.WindPower01 = valueElement_Code;
                                continue;
                            }
                            else
                            {
                                weather.WindPower02 = valueElement_Code;
                                continue;
                            }
                        }
                    }

                    for (int i = index; i < e.Row.Cells.Count; i++)
                    {
                        e.Row.Cells[i].Visible = false;
                    }

                    //20120220 syy增加最高温度和最低温度判断,如果出现最高温度和最低温度相等,则给出城市名称提示
                    //20120220 syy如果是最高温度,则保存到maxTem变量中,以便一行完成后与最低气温进行对比
                    if (equalTem(weather.HighTem, weather.LowTem))
                    {
                        //EqualMaxMinTemStationName.Add(e.Row.Cells[0].Text);
                        ExpStationMessage.EqualMaxMinTemStationName.Add(e.Row.Cells[0].Text);
                        e.Row.BackColor = System.Drawing.Color.LightSalmon;
                    }

                    //20130702 syy最高温》=45 || 最低温《=-40
                    if (highTem(weather.HighTem) || lowTem(weather.LowTem))
                    {
                        //LimitTemStationName.Add(e.Row.Cells[0].Text);
                        ExpStationMessage.LimitTemStationName.Add(e.Row.Cells[0].Text);
                        e.Row.BackColor = System.Drawing.Color.LightSalmon;
                    }

                    //20120702 syy最高温和最低温与前一天数据对比,如果相差8度则提示。
                    if (subTemExp(weather.HighTemElID, weather.HighTem, weather.LowTemElID, weather.LowTem, mRecordeData[rowIndex]))
                    {
                        e.Row.BackColor = System.Drawing.Color.LightSalmon;
                        //提示信息在函数subTemExp进行加载赋值,因为要显示前一天具体的温度,以便进行对比
                    }

                    //20130702 syy,最低温度》5,天气现象有冻雨、雨夹雪、小雪、中雪、大雪、暴雪
                    if (lTemWethExp(weather.LowTem, weather.Weather01) || lTemWethExp(weather.LowTem, weather.Weather02))
                    {
                        e.Row.BackColor = System.Drawing.Color.LightSalmon;
                        ExpStationMessage.TempWethExpStationName.Add(e.Row.Cells[0].Text);
                    }

                    //20130702 syy数据中有风力(》3级)且无风向
                    if (windNExp(weather.WindDir01, weather.WindPower01))
                    {
                        e.Row.BackColor = System.Drawing.Color.LightSalmon;
                        ExpStationMessage.WinNStationName.Add(e.Row.Cells[0].Text);
                    }

                    //20130702 syy数据中有风力(》3级)且无风向(转)
                    if (windNExp(weather.WindDir02, weather.WindPower02))
                    {
                        e.Row.BackColor = System.Drawing.Color.LightSalmon;
                        ExpStationMessage.WinNStationName.Add(e.Row.Cells[0].Text);
                    }

                    //20130702 syy天气现象为大暴雨
                    if (wethExp(weather.Weather01) || wethExp(weather.Weather02))
                    {
                        e.Row.BackColor = System.Drawing.Color.LightSalmon;
                        ExpStationMessage.WethExpStationName.Add(e.Row.Cells[0].Text);
                    }
                }

                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    //当鼠标停留时更改背景色
                    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E2DED6'");
                    //当鼠标移开时还原背景色
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                }
            }
        }
        catch
        {
        }
    }
Пример #8
0
        public JsonResult GetWeather()
        {
            WeatherClass weath = new WeatherClass();

            return(Json(weath.getWeatherForecast(), JsonRequestBehavior.AllowGet));
        }