/// <summary> /// Updates the user collection information in memory and writes the updated collection to it's respective file. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnUpdate_Click(object sender, EventArgs e) { if (notification != null) { notification.Close(); } if (!string.IsNullOrEmpty(cbWebsites.Text)) { var descriptionName = cbWebsites.Text; UserData.UserInformation updatedInfo = UserSessionData.UserInformationCollection.Where(x => x.Description == cbWebsites.Text).FirstOrDefault(); UserSessionData.UserInformationCollection.Remove(updatedInfo); updatedInfo.Password = tbPasswordDisplay.Text; UserSessionData.UserInformationCollection.Add(updatedInfo); UserSessionData.SaveData(); BindDescriptionMenu(); UserSessionData.UserInformationCollection.OrderBy(x => x.Description); notification = new DialogBox(descriptionName + " has been successfully updated!", MetroFramework.MetroColorStyle.Green, this.DesktopLocation, "Update successful"); notification.Show(); } else { notification = new DialogBox("You must select a website to update!", MetroFramework.MetroColorStyle.Red, this.DesktopLocation, "No Site Selected"); notification.Show(); } }
/// <summary> /// Updates the user information collection in memory and writes to it's respective file /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void btnAddNew_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tbWebDescription.Text) && !string.IsNullOrEmpty(tbNewPassword.Text) && !string.IsNullOrEmpty(tbConfirmNewPassword.Text)) { var descriptionName = tbWebDescription.Text; var siteList = UserSessionData.UserInformationCollection.Select(x => x.Description); if (!siteList.Contains(tbWebDescription.Text)) { if (tbNewPassword.Text.Equals(tbConfirmNewPassword.Text)) { UserData.UserInformation newInfo = new UserData.UserInformation(); newInfo.Description = tbWebDescription.Text; newInfo.Password = tbConfirmNewPassword.Text; UserSessionData.UserInformationCollection.Add(newInfo); UserSessionData.LoadOrCreateEncryptionKey(); UserSessionData.SaveData(); UserSessionData.LoadData(); BindDescriptionMenu(); if (cbRedirect.Checked) { PasswordManagement.SelectTab(InfoManagementTab); } else { ClearApplicationData(); } notification = new DialogBox("Information for: " + descriptionName + " has been successfully added!", MetroFramework.MetroColorStyle.Green, this.DesktopLocation, "Information Saved"); notification.Show(); } else { notification = new DialogBox("Your passwords must patch.", MetroFramework.MetroColorStyle.Red, this.DesktopLocation, "Error"); notification.Show(); } } else { notification = new DialogBox(descriptionName + " already exists.", MetroFramework.MetroColorStyle.Red, this.DesktopLocation, "Error"); notification.Show(); } } else { notification = new DialogBox("A Description, Password and Confirmation Password are needed.", MetroFramework.MetroColorStyle.Red, this.DesktopLocation, "Error"); notification.Show(); } }