コード例 #1
0
 //Display details of entry on click
 private void EditBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     cityBox.Text       = Weather.GetCityName(editBox.SelectedIndex);
     dateInputBox.Value = Weather.GetWeatherDate(editBox.SelectedIndex);
     minTempBox.Text    = Weather.GetMinTemp(editBox.SelectedIndex);
     maxTempBox.Text    = Weather.GetMaxTemp(editBox.SelectedIndex);
     precipBox.Text     = Weather.GetPrecipitation(editBox.SelectedIndex);
     humidBox.Text      = Weather.GetHumidity(editBox.SelectedIndex);
     windBox.Text       = Weather.GetWindSpeed(editBox.SelectedIndex);
 }
コード例 #2
0
 //Update database with new values based on if it was in the database before or not
 public static void AddWeatherDatabase()
 {
     if (newEntry.Contains(true))
     {
         SetConnectionString();
         con.Open();
         using (con)
         {
             for (int i = 0; i < newEntry.Count; i++)
             {
                 if (Convert.ToBoolean(newEntry[i]) == true)
                 {
                     String     command    = String.Format("INSERT INTO TBL_WEATHER VALUES ('{0}','{1}',{2},{3},{4},{5},{6})", Weather.GetCityName(i), Weather.GetWeatherDate(i), Weather.GetMinTemp(i), Weather.GetMaxTemp(i), Weather.GetPrecipitation(i), Weather.GetHumidity(i), Weather.GetWindSpeed(i));
                     SqlCommand sqlWeather = new SqlCommand(command, con);
                     sqlWeather.ExecuteNonQuery();
                     newEntry[i] = false;
                 }
             }
         }
     }
 }
コード例 #3
0
        //Retrieve and compare the results for the weather report
        private void PopulateReportTable()
        {
            int lowMinTemp  = 0;
            int highMinTemp = 0;
            int lowMaxTemp  = 0;
            int highMaxTemp = 0;
            int lowPrecip   = 0;
            int highPrecip  = 0;
            int lowHumid    = 0;
            int highHumid   = 0;
            int lowSpeed    = 0;
            int highSpeed   = 0;

            reportTable.Rows.Clear();
            if (citiesSelected.Count != 0)
            {
                for (int i = 0; i < citiesSelected.Count; i++)
                {
                    for (int j = 0; j < Weather.GetCityNameCount(); j++)
                    {
                        if (Weather.GetCityName(j) == Convert.ToString(citiesSelected[i]))
                        {
                            if (Weather.GetWeatherDate(j) >= startDateBox.Value && Weather.GetWeatherDate(j) <= endDateBox.Value)
                            {
                                if (reportTable.Rows.Count == 0)
                                {
                                    //Initiate values in the lowest and highest section
                                    lowMinTemp  = Convert.ToInt32(Weather.GetMinTemp(j));
                                    highMinTemp = Convert.ToInt32(Weather.GetMinTemp(j));
                                    lowMaxTemp  = Convert.ToInt32(Weather.GetMaxTemp(j));
                                    highMaxTemp = Convert.ToInt32(Weather.GetMaxTemp(j));
                                    lowPrecip   = Convert.ToInt32(Weather.GetPrecipitation(j));
                                    highPrecip  = Convert.ToInt32(Weather.GetPrecipitation(j));
                                    lowHumid    = Convert.ToInt32(Weather.GetHumidity(j));
                                    highHumid   = Convert.ToInt32(Weather.GetHumidity(j));
                                    lowSpeed    = Convert.ToInt32(Weather.GetWindSpeed(j));
                                    highSpeed   = Convert.ToInt32(Weather.GetWindSpeed(j));
                                }
                                else
                                {
                                    //Update values if lowest and highest section not empty
                                    if (Convert.ToInt32(Weather.GetMinTemp(j)) < lowMinTemp)
                                    {
                                        lowMinTemp = Convert.ToInt32(Weather.GetMinTemp(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetMinTemp(j)) > highMinTemp)
                                    {
                                        highMinTemp = Convert.ToInt32(Weather.GetMinTemp(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetMaxTemp(j)) < lowMaxTemp)
                                    {
                                        lowMaxTemp = Convert.ToInt32(Weather.GetMaxTemp(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetMaxTemp(j)) > highMaxTemp)
                                    {
                                        highMaxTemp = Convert.ToInt32(Weather.GetMaxTemp(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetPrecipitation(j)) < lowPrecip)
                                    {
                                        lowPrecip = Convert.ToInt32(Weather.GetPrecipitation(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetPrecipitation(j)) > highPrecip)
                                    {
                                        highPrecip = Convert.ToInt32(Weather.GetPrecipitation(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetHumidity(j)) < lowHumid)
                                    {
                                        lowHumid = Convert.ToInt32(Weather.GetHumidity(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetHumidity(j)) > highHumid)
                                    {
                                        highHumid = Convert.ToInt32(Weather.GetHumidity(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetWindSpeed(j)) < lowSpeed)
                                    {
                                        lowSpeed = Convert.ToInt32(Weather.GetWindSpeed(j));
                                    }

                                    if (Convert.ToInt32(Weather.GetWindSpeed(j)) > highSpeed)
                                    {
                                        highSpeed = Convert.ToInt32(Weather.GetWindSpeed(j));
                                    }
                                }
                                //Populate the table with the report
                                reportTable.Rows.Add(Weather.GetCityName(j), Weather.GetWeatherDate(j).ToShortDateString(), Weather.GetMinTemp(j) + "°C", Weather.GetMaxTemp(j) + "°C", Weather.GetPrecipitation(j) + "%", Weather.GetHumidity(j) + "%", Weather.GetWindSpeed(j) + "km/h");

                                lowestMinTemp.Text  = Convert.ToString(lowMinTemp) + " °C";
                                highestMinTemp.Text = Convert.ToString(highMinTemp) + " °C";

                                lowestMaxTemp.Text  = Convert.ToString(lowMaxTemp) + " °C";
                                highestMaxTemp.Text = Convert.ToString(highMaxTemp) + " °C";

                                lowestPrecip.Text  = Convert.ToString(lowPrecip) + " %";
                                highestPrecip.Text = Convert.ToString(highPrecip) + " %";

                                lowestHumid.Text  = Convert.ToString(lowHumid) + " %";
                                highestHumid.Text = Convert.ToString(highHumid) + " %";

                                lowestWind.Text  = Convert.ToString(lowSpeed) + " km/h";
                                highestWind.Text = Convert.ToString(highSpeed) + " km/h";
                            }
                        }
                    }
                }
                //Reset report and display error
                if (reportTable.Rows.Count == 0)
                {
                    lowestMinTemp.Text  = "";
                    highestMinTemp.Text = "";
                    lowestMaxTemp.Text  = "";
                    highestMaxTemp.Text = "";
                    lowestPrecip.Text   = "";
                    highestPrecip.Text  = "";
                    lowestHumid.Text    = "";
                    highestHumid.Text   = "";
                    lowestWind.Text     = "";
                    highestWind.Text    = "";
                    MessageBox.Show("No Results Found.");
                }
            }
            else
            {
                MessageBox.Show("You have not selected any cities. \nTo obtain results, please select one or more cities.");
            }
        }