コード例 #1
0
 //Update the result box
 private void UpdateUpdateBox()
 {
     editBox.Items.Clear();
     for (int i = 0; i < Weather.GetCityNameCount(); i++)
     {
         editBox.Items.Add(Weather.GetCityName(i) + " - " + Weather.GetWeatherDate(i));
     }
 }
コード例 #2
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);
 }
コード例 #3
0
        //Update currently selected result with new details in textboxes
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("This will update the selected forecast with the new information you have entered.\nAre you sure?", "Update Forecast?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                CheckValues();
                if (valuesGood == true && cityBox.Text != "")
                {
                    PasswordCheck newPasswordCheck = new PasswordCheck();
                    newPasswordCheck.ShowDialog();
                    if (PasswordCheck.allowUser == true)
                    {
                        if (Weather.UpdateWeatherDatabase(cityBox.Text, dateInputBox.Value, minTempBox.Text, maxTempBox.Text, precipBox.Text, humidBox.Text, windBox.Text, Weather.GetCityName(editBox.SelectedIndex), Weather.GetWeatherDate(editBox.SelectedIndex)) == true)
                        {
                            MessageBox.Show("You have successfully updated this weather entry.");
                            int oldIndex = editBox.SelectedIndex;
                            UpdateUpdateBox();
                            editBox.SelectedIndex = oldIndex;
                        }
                        else
                        {
                            MessageBox.Show("There was an error performing this action.\nDatabase likely not connected correctly.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("The data you have entered is incorrect. \nPlease make sure that: \n- No fields are empty.\n- There are no numbers in the city input field.\n- There are no letters in the in the number fields.");
                }
            }
            else
            {
            }
        }
コード例 #4
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;
                 }
             }
         }
     }
 }
コード例 #5
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.");
            }
        }