public WeatherNow loadWeatherNow(string _cityId)
 {
     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.weather.com.cn/data/sk/" + _cityId + ".html");
     //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.weather.com.cn/data/cityinfo/101010100.html");
     request.Timeout = 5000;
     request.Method = "GET";
     HttpWebResponse response = null;
     WeatherNow wn = null;
     try
     {
         response = (HttpWebResponse)request.GetResponse();
     }
     catch (WebException)
     {
         return wn;
     }
     StreamReader sr = new StreamReader(response.GetResponseStream());
     string jsonstr = sr.ReadLine();
     //MessageBox.Show(jsonstr);
     JavaScriptSerializer j = new JavaScriptSerializer();
     wn = new WeatherNow();
     wn = j.Deserialize<WeatherNow>(jsonstr);
     //MessageBox.Show(wn.weatherInfo.city);
     return wn;
 }
 /// <summary>
 /// 无参构造基本窗体
 /// </summary>
 public frmMain()
 {
     InitializeComponent();
     user = new User("piratf", -1, "-1");
     wn = null;
     wt = null;
 }
 /// <summary>
 /// 带参数构造窗体
 /// </summary>
 /// <param name="_user"></param>
 /// <param name="_supermarket"></param>
 public frmMain(Model.User _user, Supermarket _supermarket = null, WeatherNow _wn = null, WeatherToday _wt = null)
 {
     try
     {
         user = new Model.User(_user.UserID, _user.Level, _user.Supermarket);
         supermarket = new Supermarket(_supermarket.Name);
         wn = null;
         wt = null;
         if (_wn != null)
         {
             wn = _wn;
         }
         if (_wt != null)
         {
             wt = _wt;
         }
     }
     catch (NullReferenceException)
     {
         MessageBox.Show("用户信息加载失败,程序退出\n请联系管理员进行维护");
         Application.Exit();
     }
     InitializeComponent();
 }
 /// <summary>
 /// 联网获取天气
 /// </summary>
 private void loadWeather()
 {
     //显示天气
     string cityId = string.Empty;
         ipv4 = IpPostion.GetIp();
         if (ipv4 == null)
         {
             tssCity.Text = "网络连接失败";
             cityInfo = TssCity.FAILED;
             return;
         }
         //this.tablabelIPAddress.Text += ipv4;
         //get city id by ipv4
         cityId = IpPostion.getCityId(ipv4);
         if (cityId == null)
         {
             tssCity.Text = "网络连接失败";
             cityInfo = TssCity.FAILED;
             return;
         }
     wn = weatherBus.loadWeatherNow(cityId);
     wt = weatherBus.loadWeatherToday(cityId);
 }
 /// <summary>
 /// 根据天气信息刷新UI
 /// </summary>
 /// <param name="_wn"></param>
 public void setLable(WeatherNow _wn)
 {
     this.Invoke(new EventHandler(delegate
     {
         this.tab1labelCityName.Text += _wn.weatherInfo.city;
         this.tab1labelRelativeHumidity.Text += _wn.weatherInfo.SD;
         this.tab1labelTemperature.Text += _wn.weatherInfo.temp + "℃";
         this.tab1labelWindDirection.Text += _wn.weatherInfo.WD;
         this.tab1labelWindPower.Text += _wn.weatherInfo.WS;
         this.tab1labelTime.Text += _wn.weatherInfo.time;
     }));
 }