Esempio n. 1
0
        private void buttonCitySearch_Click(object sender, EventArgs e)
        {
            // Disable add button
            buttonAddCity.Enabled = false;

            try
            {
                // Perform actual search
                WeatherChannel weather = new WeatherChannel();
                ArrayList      cities  = weather.SearchCity(searchTextBox.Text);

                // Clear previous results
                listBoxCityResults.Items.Clear();

                foreach (WeatherChannel.City city in cities)
                {
                    listBoxCityResults.Items.Add(city);

                    if (listBoxCityResults.Items.Count == 1)
                    {
                        listBoxCityResults.SelectedItem = listBoxCityResults.Items[0];
                    }
                }
                if (listBoxCityResults.Items.Count > 0)
                {
                    groupBoxCityDetails.Visible = true;
                    buttonCancelCity.Visible    = true;
                    buttonAddCity.Visible       = true;
                    this.Height = 488 + 40;
                }
                else
                {
                    if (MessageBox.Show("No cities found", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) ==
                        DialogResult.OK)
                    {
                        searchTextBox.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    private void OnTempCity()
    {
      string city = "";
      if (!GetKeyboard(ref city) || String.IsNullOrEmpty(city))
      {
        return;
      }
      try
      {
        // Perform actual search        
        WeatherChannel weather = new WeatherChannel();
        ArrayList cities = weather.SearchCity(city);

        if (cities.Count <= 0)
        {
          GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
          dlg.SetHeading(8);
          dlg.SetLine(1, 412);
          dlg.SetLine(2, "");
          dlg.DoModal(GetID);
          return;
        }

        GUIDialogMenu dialogCitySelect =
          (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
        if (dialogCitySelect != null)
        {
          dialogCitySelect.Reset();
          dialogCitySelect.SetHeading(8); //my weather
          foreach (WeatherChannel.City _city in cities)
          {
            dialogCitySelect.Add(_city.Name + " (" + _city.Id + ")");
          }

          dialogCitySelect.DoModal(GetID);
          if (dialogCitySelect.SelectedLabel >= 0)
          {
            WeatherChannel.City citytemp = (WeatherChannel.City)cities[dialogCitySelect.SelectedLabel];
            _locationCode = citytemp.Id;
            _nowLabelLocation = citytemp.Name;
            _urlSatellite = "";
            _urlTemperature = "";
            _urlUvIndex = "";
            _urlWinds = "";
            _urlHumidity = "";
            _urlPreciptation = "";

            UpdateDetailImages();

            _dayNum = -2;
            _selectedDayName = "All";

            //refresh clicked so do a complete update (not an autoUpdate)
            BackgroundUpdate(false);
          }
        }
      }
      catch (Exception ex)
      {
        Log.Error("MyWeather (Quick Weather) error: {0}", ex.ToString());
      }
    }
    private void AddLocation()
    {
      string city = "";
      if (!GetKeyboard(ref city) || String.IsNullOrEmpty(city))
      {
        return;
      }
      try
      {
        // Perform actual search        
        WeatherChannel weather = new WeatherChannel();
        ArrayList cities = weather.SearchCity(city);

        if (cities.Count <= 0)
        {
          GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
          dlg.SetHeading(8);
          dlg.SetLine(1, 412);
          dlg.SetLine(2, "");
          dlg.DoModal(GetID);
          return;
        }

        GUIDialogMenu dialogCitySelect = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
        if (dialogCitySelect != null)
        {
          dialogCitySelect.Reset();
          dialogCitySelect.ShowQuickNumbers = false;
          dialogCitySelect.SetHeading(396); // Select Location
          foreach (WeatherChannel.City _city in cities)
          {
            dialogCitySelect.Add(_city.Name + " (" + _city.Id + ")");
          }

          dialogCitySelect.DoModal(GetID);
          if (dialogCitySelect.SelectedLabel >= 0)
          {
            WeatherChannel.City newcity = (WeatherChannel.City)cities[dialogCitySelect.SelectedLabel];
            LocationInfo loc = new LocationInfo();
            loc.City = newcity.Name;
            loc.CityCode = newcity.Id;
            loc.UrlSattelite = "";
            loc.UrlTemperature = "";
            loc.UrlUvIndex = "";
            loc.UrlWinds = "";
            loc.UrlHumidity = "";
            loc.UrlPrecip = "";
            availableLocations.Add(loc);

            SaveLocations();
            SetDefaultLocation(); // Reset the default location as necessary
            InitDefaultLocation(); // Refresh default location button as necessary
          }
        }
      }
      catch (Exception ex)
      {
        Log.Error("MyWeather settings error: {0}", ex.ToString());
      }
    }