コード例 #1
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
            {
            }
        }
コード例 #2
0
        //Add button to add user with information in textbox
        private void AddButton_Click(object sender, EventArgs e)
        {
            int tempType = 2;

            if (usernameBox.Text != "" && passwordBox.Text != "")
            {
                if (!usernameList.Contains(usernameBox.Text))
                {
                    DialogResult result = MessageBox.Show("This will add a user with the current information in the fields, ensure it is correct.\nWould you like to add this user?", "Add User?", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        PasswordCheck newPasswordCheck = new PasswordCheck();
                        newPasswordCheck.ShowDialog();
                        if (PasswordCheck.allowUser == true)
                        {
                            if (Convert.ToString(userTypeBox.SelectedItem) == "Forecaster")
                            {
                                tempType = 1;
                            }
                            if (Convert.ToString(userTypeBox.SelectedItem) == "Regular")
                            {
                                tempType = 2;
                            }
                            usernameList.Add(usernameBox.Text);
                            passwordList.Add(passwordBox.Text);
                            userType.Add(tempType);
                            String command = String.Format("INSERT INTO TBL_LOGINDETAILS VALUES ('{0}','{1}',{2});", usernameBox.Text, passwordBox.Text, tempType);
                            SetConnectionString();
                            con.Open();
                            using (con)
                            {
                                SqlCommand sqlAdd = new SqlCommand(command, con);
                                try
                                {
                                    sqlAdd.ExecuteNonQuery();
                                    MessageBox.Show("User " + usernameBox.Text + " successfully added.");
                                }
                                catch
                                {
                                    MessageBox.Show("There was an error performing this action.\nDatabase likely not connected.");
                                }
                            }
                            UpdateUsersBox();
                            userBox.SelectedIndex = usernameList.Count - 1;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("A user with this username already exists.\nPlease try a different username.", "Username already exists.");
                }
            }
            else
            {
                MessageBox.Show("One or more fields are blank, please ensure the correct information is entered before updating or adding a user.", "Information Error");
            }
        }
コード例 #3
0
        //Update button to update database with new details
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            int tempType = 2;

            if (usernameBox.Text != "" && passwordBox.Text != "")
            {
                DialogResult result = MessageBox.Show("This will update this user's information with the new information you have entered.\nAre you sure?", "Update User?", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    PasswordCheck newPasswordCheck = new PasswordCheck();
                    newPasswordCheck.ShowDialog();
                    if (PasswordCheck.allowUser == true)
                    {
                        string oldName = Convert.ToString(usernameList[userBox.SelectedIndex]);
                        if (Convert.ToString(userTypeBox.SelectedItem) == "Forecaster")
                        {
                            tempType = 1;
                        }
                        if (Convert.ToString(userTypeBox.SelectedItem) == "Regular")
                        {
                            tempType = 2;
                        }
                        usernameList[userBox.SelectedIndex] = usernameBox.Text;
                        passwordList[userBox.SelectedIndex] = passwordBox.Text;
                        userType[userBox.SelectedIndex]     = tempType;
                        String command = String.Format("UPDATE TBL_LOGINDETAILS SET USERNAME = '******', PASSWORD = '******', USERTYPE = '{2}' WHERE USERNAME = '******';", usernameBox.Text, passwordBox.Text, tempType, oldName);
                        SetConnectionString();
                        con.Open();
                        using (con)
                        {
                            SqlCommand sqlUpdate = new SqlCommand(command, con);
                            try
                            {
                                sqlUpdate.ExecuteNonQuery();
                                MessageBox.Show("User " + oldName + " successfully updated.");
                            }
                            catch
                            {
                                MessageBox.Show("There was an error performing this action.\nDatabase likely not connected.");
                            }
                        }
                        int tempIndex = userBox.SelectedIndex;
                        UpdateUsersBox();
                        userBox.SelectedIndex = tempIndex;
                    }
                }
            }
            else
            {
                MessageBox.Show("One or more fields are blank, please ensure the correct information is entered before updating or adding a user.", "Information Error");
            }
        }
コード例 #4
0
 //Show/Hide Password Button
 private void ShowHidePasswordButton_Click(object sender, EventArgs e)
 {
     //Password button status = True if the password is hidden
     if (passwordButtonStatus == true)
     {
         PasswordCheck newPasswordCheck = new PasswordCheck();
         newPasswordCheck.ShowDialog();
         if (PasswordCheck.allowUser == true)
         {
             passwordButtonStatus = false;
             passwordBox.UseSystemPasswordChar      = false;
             showHidePasswordButton.BackgroundImage = POE_19003041_PROG6211.Properties.Resources.HidePassword;
         }
     }
     else
     {
         passwordButtonStatus = true;
         passwordBox.UseSystemPasswordChar      = true;
         showHidePasswordButton.BackgroundImage = POE_19003041_PROG6211.Properties.Resources.ShowPassword;
     }
 }
コード例 #5
0
        //Delete button to remove selected username from database
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("This will delete the currently selected user.\n\nAre you sure?", "Delete User?", MessageBoxButtons.YesNo);
            DialogResult resultSame;
            Boolean      logout = false;

            if (result == DialogResult.Yes)
            {
                if (Convert.ToString(usernameList[userBox.SelectedIndex]) == Login.loggedInUser)
                {
                    resultSame = MessageBox.Show("Are you sure you want to delete the account you are currently logged in to?", "Delete Current Account?", MessageBoxButtons.YesNo);
                    logout     = true;
                }
                else
                {
                    resultSame = DialogResult.Yes;
                }

                if (resultSame == DialogResult.Yes)
                {
                    PasswordCheck newPasswordCheck = new PasswordCheck();
                    newPasswordCheck.ShowDialog();
                    if (PasswordCheck.allowUser == true)
                    {
                        string oldName = Convert.ToString(usernameList[userBox.SelectedIndex]);

                        usernameList.RemoveAt(userBox.SelectedIndex);
                        passwordList.RemoveAt(userBox.SelectedIndex);
                        userType.RemoveAt(userBox.SelectedIndex);

                        String command = String.Format("DELETE FROM TBL_USERCITIES WHERE USERNAME = '******';", oldName);
                        SetConnectionString();
                        con.Open();
                        using (con)
                        {
                            SqlCommand sqlDelete1 = new SqlCommand(command, con);
                            try
                            {
                                sqlDelete1.ExecuteNonQuery();
                            }
                            catch
                            {
                                MessageBox.Show("There was an error performing this action.\nDatabase likely not connected.");
                            }
                        }

                        String command2 = String.Format("DELETE FROM TBL_LOGINDETAILS WHERE USERNAME = '******';", oldName);
                        SetConnectionString();
                        con.Open();
                        using (con)
                        {
                            SqlCommand sqlDelete2 = new SqlCommand(command2, con);
                            try
                            {
                                sqlDelete2.ExecuteNonQuery();
                                MessageBox.Show("User " + oldName + " successfully deleted.");
                            }
                            catch
                            {
                                MessageBox.Show("There was an error performing this action.\nDatabase likely not connected.");
                            }
                        }
                        int tempIndex = userBox.SelectedIndex;
                        UpdateUsersBox();
                        if (tempIndex == 0)
                        {
                            userBox.SelectedIndex = tempIndex;
                        }
                        else
                        {
                            userBox.SelectedIndex = tempIndex - 1;
                        }
                        if (logout == true)
                        {
                            LogoutToolStripMenuItem_Click(sender, e);
                        }
                    }
                }
            }
        }