示例#1
0
文件: Form1.cs 项目: luisfcolg/Clima
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.CurrentCell.ColumnIndex == 1 | dataGridView1.CurrentCell.ColumnIndex == 2 | dataGridView1.CurrentCell.ColumnIndex == 3 | dataGridView1.CurrentCell.ColumnIndex == 4)
            {
                return;
            }

            user_cities.RemoveAt(dataGridView1.CurrentCell.RowIndex);

            IProxyWeather     proxy     = new ProxyWeather();
            TotalCDegrees     degrees   = new TotalCDegrees();
            FDegreesConverter converter = new FDegreesConverter(degrees);

            dataGridView1.Rows.Clear();

            foreach (var i in user_cities)
            {
                var weather = proxy.Weather(i);
                converter.ConvertFDegreees(weather.main.temp);
                double temp = converter.GetCDegrees();
                converter.ConvertFDegreees(weather.main.temp_max);
                double temp_max = converter.GetCDegrees();
                converter.ConvertFDegreees(weather.main.temp_min);
                double      temp_min = converter.GetCDegrees();
                DisplayCity c        = new DisplayCity {
                    Name = i, Temp = temp, TempMax = temp_max, TempMin = temp_min
                };
                datagrid_cities.Add(c);
            }

            BindingSource source = new BindingSource();

            source.DataSource        = datagrid_cities;
            dataGridView1.DataSource = source;
        }
        public List <DisplayCity> Getcity()
        {
            SqlConnection connection = new SqlConnection(connectionString);
            string        query      = string.Format("Select Cities.Name,Cities.No_Of_Dwellers,Countries.Name AS Country From Countries INNER JOIN Cities ON Countries.Id=Cities.CountryId ORDER BY Cities.Name");

            connection.Open();
            SqlCommand command = new SqlCommand(query, connection);

            SqlDataReader      reader = command.ExecuteReader();
            List <DisplayCity> cities = new List <DisplayCity>();

            while (reader.Read())
            {
                DisplayCity displaycity = new DisplayCity();

                displaycity.CityName       = reader["Name"].ToString();
                displaycity.No_Of_Dwellers = int.Parse(reader["No_Of_Dwellers"].ToString());
                displaycity.CountryName    = reader["Country"].ToString();

                cities.Add(displaycity);
            }
            reader.Close();
            connection.Close();
            return(cities);
        }
示例#3
0
文件: Form1.cs 项目: luisfcolg/Clima
        private void home_button_Click(object sender, EventArgs e)
        {
            IProxyWeather     proxy     = new ProxyWeather();
            TotalCDegrees     degrees   = new TotalCDegrees();
            FDegreesConverter converter = new FDegreesConverter(degrees);

            dataGridView1.Rows.Clear();

            foreach (var i in user_cities)
            {
                var weather = proxy.Weather(i);
                if (weather.main != null)
                {
                    converter.ConvertFDegreees(weather.main.temp);
                    double temp = converter.GetCDegrees();
                    converter.ConvertFDegreees(weather.main.temp_max);
                    double temp_max = converter.GetCDegrees();
                    converter.ConvertFDegreees(weather.main.temp_min);
                    double      temp_min = converter.GetCDegrees();
                    DisplayCity c        = new DisplayCity {
                        Name = i, Temp = temp, TempMax = temp_max, TempMin = temp_min
                    };
                    datagrid_cities.Add(c);
                }
            }

            BindingSource source = new BindingSource();

            source.DataSource        = datagrid_cities;
            dataGridView1.DataSource = source;

            panel_add.Visible = false;
            panel4.Visible    = true;
        }