//End of helper methods
        //-----------------------------

        //start of click events
        private void btnCancel_Click(object sender, EventArgs e)
        {
            ForecasterMenu fm = new ForecasterMenu(fUser);

            fm.Show();
            this.Hide();
        }
Esempio n. 2
0
        // Change the user's preferred temp unit then close this form
        private void btnApply_Click(object sender, EventArgs e)
        {
            JSONconnection js = new JSONconnection(); //Instance of the JSONconnection class to user JSON methods

            if (radCelsius.Checked == true)           //if the celsius button is checked change the user's preference to celsius
            {
                fUser.IsCelsius = true;
            }
            else //if the fahrenheit button is checked change the user's preferrence to fahrenheit
            {
                fUser.IsCelsius = false;
            }

            if (js.changeUserPreference(fUser)) //Save this changes to the file
            {
                MessageBox.Show("User preference successfully changed");
                ForecasterMenu fm = new ForecasterMenu(fUser);
                this.Hide();
                fm.Show();
            }
            else
            {
                MessageBox.Show("User preference could not be changed, please try again", "Change error");
            }
        }
Esempio n. 3
0
        //Method to handle the user login
        private void btnSignIn_Click_1(object sender, EventArgs e)
        {
            JSONconnection js = new JSONconnection();            //Onstance of the JSONConnection class to use the JSON methods

            UserModel user = new UserModel();                    //User model that will be used to store the found user

            user = js.login(txtUsername.Text, txtPassword.Text); //Capture the username and password from the textboxes and pass them into the JSON login method

            if (user.FName != null)                              //If there there was a user found on the system
            {
                if (user.FName.Equals("no users available"))     //This will determine if there are no users registered on the system
                {
                    DialogResult dr = MessageBox.Show("There are no users registered on the system. would you like to sign up?", "No Users", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (dr == DialogResult.Yes) //Send the user to the sign up page
                    {
                        signup sg = new signup();
                        sg.Show();
                        this.Hide();
                    }
                }
                else if (user.Type.Equals("general user")) //If the user found is a general user open the general user side of the application
                {
                    Dashboard ds = new Dashboard(user);
                    this.Hide();
                    ds.Show();
                }
                else //If the user found is a forecaster open the Forecaster side of the application
                {
                    ForecasterMenu fm = new ForecasterMenu(user);
                    this.Hide();
                    fm.Show();
                }
            }
            else // if the user credentials are incorrect display an error message and clear all fields
            {
                MessageBox.Show("User could not be found... Please check your credentials");
                txtUsername.Clear();
                txtPassword.Clear();
            }
        }
        //end of helper methods
        //--------------------------------

        //start of events
        //-----------------------------

        //this method will overwrite the data stored in the file with new values
        private void btnCapture_Click(object sender, EventArgs e)
        {
            WeatherModel weather = new WeatherModel();
            bool         valid   = true;

            weath = js.readWeatherFile();

            //check for errors
            #region
            if (errorCheck(txtMax) == false) // check if the control is a numeric value and check if it is not empty
            {
                valid = false;
                return;
            }


            if (errorCheck(txtMin) == false)
            {
                valid = false;
                return;
            }


            if (errorCheck(txtHumid) == false)
            {
                valid = false;
                return;
            }

            if (errorCheck(txtMin) == false)
            {
                valid = false;
                return;
            }

            if (errorCheck(txtWind) == false)
            {
                valid = false;
                return;
            }

            if (cboCloud.SelectedIndex == -1)
            {
                captureError.SetError(cboCloud, "Please select the cloud cover");
                valid = false;
            }

            if (cboUvIndex.SelectedIndex == -1)
            {
                captureError.SetError(cboUvIndex, "Please select the UV index");
                valid = false;
            }
            #endregion

            if (valid)
            {
                captureError.Clear();
                foreach (WeatherModel item in weath)
                {
                    if (item.City.Equals(cboCity.Text) && item.Date == dtpDate.Value.Date) //check if there is already a value with the same date
                    {
                        //if a value already exits for the this city and date, ask the user if they would like to overide
                        DialogResult dr = MessageBox.Show("are you sure you would like to overwrite the values?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                        if (dr == DialogResult.Yes)
                        {
                            weather.City          = cboCity.Text;
                            weather.Date          = dtpDate.Value.Date;
                            weather.Max           = Convert.ToDouble(txtMax.Text);
                            weather.Min           = Convert.ToDouble(txtMin.Text);
                            weather.Humidity      = Convert.ToDouble(txtHumid.Text);
                            weather.Precipitation = Convert.ToDouble(txtPrecip.Text);
                            weather.Wind          = Convert.ToDouble(txtWind.Text);
                            weather.CloudCover    = cboCloud.SelectedIndex;
                            weather.UvIndex       = cboUvIndex.Text;


                            if (js.overwriteFile(weather))
                            {
                                MessageBox.Show("Data overwritten successfully");
                                ForecasterMenu fm = new ForecasterMenu(fUser);
                                this.Hide();
                                fm.Show();
                            }
                            else
                            {
                                MessageBox.Show("There was an error with the request", "Overwrite error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                break;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Operation cancelled", "Overwrite cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            cboCity.SelectedIndex = -1;
                            txtMax.Clear();
                            txtMin.Clear();
                            txtHumid.Clear();
                            txtPrecip.Clear();
                            txtWind.Clear();
                            cboCloud.SelectedIndex   = -1;
                            cboUvIndex.SelectedIndex = -1;
                        }
                    }
                }
            }
        }