//Update button private void updateButton_Click(object sender, EventArgs e) { 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 = user[userBox.SelectedIndex * 3]; user[userBox.SelectedIndex * 3] = usernameBox.Text; user[userBox.SelectedIndex * 3 + 1] = passwordBox.Text; if (Convert.ToString(userTypeBox.SelectedItem) == "Forecaster") { user[userBox.SelectedIndex * 3 + 2] = "1"; } else if (Convert.ToString(userTypeBox.SelectedItem) == "Regular") { user[userBox.SelectedIndex * 3 + 2] = "2"; } System.IO.File.WriteAllLines("../../LoginDetails.txt", user); MessageBox.Show("User " + oldName + " successfully updated."); 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"); } }
//Add (Plus) Button private void addButton_Click(object sender, EventArgs e) { if (usernameBox.Text != "" && passwordBox.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) { newUser.Add(usernameBox.Text); newUser.Add(passwordBox.Text); if (Convert.ToString(userTypeBox.SelectedItem) == "Forecaster") { newUser.Add("1"); } else if (Convert.ToString(userTypeBox.SelectedItem) == "Regular") { newUser.Add("2"); } user = (string[])newUser.ToArray(typeof(string)); System.IO.File.WriteAllLines("../../LoginDetails.txt", user); updateUsersBox(); MessageBox.Show("User " + usernameBox.Text + " successfully added."); userBox.SelectedIndex = (newUser.Count / 3) - 1; } } } else { MessageBox.Show("One or more fields are blank, please ensure the correct information is entered before updating or adding a user.", "Information Error"); } }
//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 = Task2_19003041_PROG6211.Properties.Resources.HidePassword; } } else { passwordButtonStatus = true; passwordBox.UseSystemPasswordChar = true; showHidePasswordButton.BackgroundImage = Task2_19003041_PROG6211.Properties.Resources.ShowPassword; } }
//Delete button 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(newUser[userBox.SelectedIndex * 3]) == 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) { newUser.RemoveAt(userBox.SelectedIndex * 3 + 2); newUser.RemoveAt(userBox.SelectedIndex * 3 + 1); newUser.RemoveAt(userBox.SelectedIndex * 3); user = (string[])newUser.ToArray(typeof(string)); File.WriteAllLines("../../LoginDetails.txt", user); int tempIndex = userBox.SelectedIndex; updateUsersBox(); userBox.SelectedIndex = tempIndex - 1; if (logout == true) { logoutToolStripMenuItem_Click(sender, e); } } } } }
//Update currently selected result with new details 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) { string[] lines = System.IO.File.ReadAllLines("../../WeatherData.txt"); lines[editBox.SelectedIndex * 7] = cityBox.Text; lines[editBox.SelectedIndex * 7 + 1] = Convert.ToString(dateInputBox.Value); lines[editBox.SelectedIndex * 7 + 2] = Convert.ToString(minTempBox.Text); lines[editBox.SelectedIndex * 7 + 3] = Convert.ToString(maxTempBox.Text); lines[editBox.SelectedIndex * 7 + 4] = Convert.ToString(precipBox.Text); lines[editBox.SelectedIndex * 7 + 5] = Convert.ToString(humidBox.Text); lines[editBox.SelectedIndex * 7 + 6] = Convert.ToString(windBox.Text); System.IO.File.WriteAllLines("../../WeatherData.txt", lines); MessageBox.Show("You have successfully updated this weather entry."); Weather.populateArrayLists(); int oldIndex = editBox.SelectedIndex; updateUpdateBox(); editBox.SelectedIndex = oldIndex; } } 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 { } }