Пример #1
0
 public WeatherToday loadWeatherToday(string _cityId)
 {
     //HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.weather.com.cn/data/sk/101010100.html");
     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.weather.com.cn/data/cityinfo/" + _cityId  + ".html");
     request.Timeout = 5000;
     request.Method = "GET";
     HttpWebResponse response = null;
     WeatherToday wt = null;
     try
     {
         response = (HttpWebResponse)request.GetResponse();
     }
     catch (WebException)
     {
         return wt;
     }
     StreamReader sr = new StreamReader(response.GetResponseStream());
     string jsonstr = sr.ReadLine();
     //MessageBox.Show(jsonstr);
     JavaScriptSerializer j = new JavaScriptSerializer();
     wt = new WeatherToday();
     wt = j.Deserialize<WeatherToday>(jsonstr);
     //MessageBox.Show(wt.weatherInfo.city);
     return wt;
 }
Пример #2
0
 /// <summary>
 /// 无参构造基本窗体
 /// </summary>
 public frmMain()
 {
     InitializeComponent();
     user = new User("piratf", -1, "-1");
     wn = null;
     wt = null;
 }
Пример #3
0
 /// <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();
 }
Пример #4
0
 /// <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);
 }
Пример #5
0
 /// <summary>
 /// 更新ToolStatusStrip地址信息
 /// </summary>
 /// <param name="_wt"></param>
 private void setTss(WeatherToday _wt)
 {
     if (_wt != null)
     {
         // bgwWeather.ReportProgress(50, _wt);
         this.Invoke(new EventHandler(delegate
         {
             tssCity.Text = _wt.weatherInfo.city + " " + _wt.weatherInfo.weather + " ";
         }));
     }
     else
     {
         tssCity.Text = "加载失败";
     }
 }
Пример #6
0
 /// <summary>
 /// 根据天气数据刷新UI
 /// </summary>
 /// <param name="_wt"></param>
 public void setLable(WeatherToday _wt)
 {
     this.Invoke(new EventHandler(delegate
     {
         this.tablabelIPAddress.Text = ipv4;
         this.tab2lableCityName.Text += _wt.weatherInfo.city;
         this.tab2labelTemperature.Text += _wt.weatherInfo.temp2 + "~" + _wt.weatherInfo.temp1;
         this.tab2lableWeather.Text += _wt.weatherInfo.weather;
         this.tab2lableUpdateTime.Text += _wt.weatherInfo.ptime;
     }));
 }