/// <summary> /// 获取天气展示类别的信息 /// </summary> /// <param name="id">城市ID</param> /// <param name="name">城市名字</param> /// <returns></returns> private async Task GetWeatherByCity(int id, string name, string urlcode) { weatherDictionary = null; //先初始化为空。 await weatherHandler.GetWeatherByUrl(urlcode); List <IWeatherMsg> list = weatherHandler.WeatherMsgs; Dictionary <string, object> dic = new Dictionary <string, object>(); List <WeatherItem> weatherLists = new List <WeatherItem>(); WeatherItem weatherItem = new WeatherItem(); if (list.Count == 0) { MessageBox.Show("暂无天气数据"); return; } for (int i = 0; i < list.Count; i++) { if (list[i].flag == 2) //每天的数据 { WeatherDayMsg dayMsg = list[i] as WeatherDayMsg; if (dayMsg.time == DateTime.Today) //今天的数据 { if (string.IsNullOrEmpty(dayMsg.maxTemp)) //如果只有半天数据 { OnlyDayWeatherInfo od = new OnlyDayWeatherInfo(); od.city = name; od.date = dayMsg.time.ToString("MM月dd日"); od.week = dayMsg.time.ToString("dddd"); od.weatherStatus = dayMsg.weatherStatus; od.imgSrc = "Images/night/晚间" + GetWeatherImgSrcByWeatherStatus(dayMsg.weatherStatus); od.temperature = dayMsg.minTemp; od.wind = dayMsg.wind; od.windL = dayMsg.windL; dic.Add("onlyday", od); } else { DayAndNightWeatherInfo dn = new DayAndNightWeatherInfo(); dn.city = name; dn.date = dayMsg.time.ToString("MM月dd日"); dn.week = dayMsg.time.ToString("dddd"); dn.weatherStatus_day = dayMsg.weatherStatus.Split('转')[0].Trim(); dn.weatherStatus_night = dayMsg.weatherStatus.Split('转')[1].Trim(); dn.imgSrc_day = "Images/day/日间" + GetWeatherImgSrcByWeatherStatus(dn.weatherStatus_day); dn.imgSrc_night = "Images/night/晚间" + GetWeatherImgSrcByWeatherStatus(dn.weatherStatus_night); dn.maxTemperature = dayMsg.maxTemp; dn.minTemperature = dayMsg.minTemp; dn.wind_day = dayMsg.wind.Split('转')[0].Trim(); dn.wind_night = dayMsg.wind.Split('转')[1].Trim(); dn.windL_day = dayMsg.windL.Split('转')[0].Trim(); dn.windL_night = dayMsg.windL.Split('转')[1].Trim(); dic.Add("dayandnight", dn); } } else //之后7几天的数据 { weatherItem = new WeatherItem(); weatherItem.areaID = id; weatherItem.date = dayMsg.time.ToString("MM月dd日"); weatherItem.maxTemperature = dayMsg.maxTemp; weatherItem.minTemperature = dayMsg.minTemp; string weatherStatus = dayMsg.weatherStatus.Split('转')[0].Trim(); weatherItem.weatherStatus = weatherStatus; weatherItem.imageSrc = "../Images/night/晚间" + GetWeatherImgSrcByWeatherStatus(weatherStatus); weatherLists.Add(weatherItem); } } } dic.Add("weatherItem", weatherLists); weatherDictionary = dic; }