/// <summary> /// Calls the save function when the user clicks the save file button. /// </summary> private void SaveButton_Click(object sender, EventArgs e) { if (FileOP.GetFile() != "") { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); UnlockFile(); FileOP.WriteToFile(dataTable); LockFile(); } }
/// <summary> /// Function for when the form closes. Asks the consumer if they would like to save the file they currently have open /// </summary> private void MasterForm_FormClosing(Object sender, FormClosingEventArgs e) { if (FileOP.GetFile() != "") { if (MessageBox.Show("Would you like to save the current working file?", "Close Program", MessageBoxButtons.YesNo) == DialogResult.Yes) { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); UnlockFile(); FileOP.WriteToFile(dataTable); LockFile(); } ClearMem(); } }
/// <summary> /// Lock and encrypt the currently open file. /// </summary> private void LockButton_Click(object sender, EventArgs e) { if (FileOP.GetFile() != "") { DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo); if (savePrompt == DialogResult.Yes) { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); UnlockFile(); FileOP.WriteToFile(dataTable); LockFile(); } ClearMem(); } }
/// <summary> /// Calls the select file method and shows the next form when the open button is clicked from the file dropdown menu. /// </summary> private void OpenFileDropDown_Click(object sender, EventArgs e) { // if there is currently a file open if (FileOP.GetFile() != "") { //open a dialog asking if the consumer would like to save DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo); // save the file contents if (savePrompt == DialogResult.Yes) { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); UnlockFile(); FileOP.WriteToFile(dataTable); LockFile(); } // clear any references to file paths in the memory ClearMem(); } // if the dialog from fileOP returns true if (FileOP.SelectFile()) { // inflate the next form EnterPasswordForFile frm = new EnterPasswordForFile { TheParent = this }; // Adding all the enterPasswordForFile components to the list of components in the master from. // This is done to apply the same theme and text size to all of the forms textBoxes.AddRange(frm.enterPasswordForFileTextBoxes); labels.AddRange(frm.enterPasswordForFileLabels); this.buttons.AddRange(frm.enterPasswordForFileButtons); forms.Add(frm); // Changing theme of enterPasswordForFile if (darkThemeEnabled) { ChangeTheme(System.Drawing.Color.White, System.Drawing.Color.DarkGray, System.Drawing.Color.DarkSlateGray); frm.enterPasswordForFileDarkThemeEnabled = true; } else { ChangeTheme(System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Window, System.Drawing.SystemColors.Control); frm.enterPasswordForFileDarkThemeEnabled = false; } // Changing text size of enterPasswordForFile if (defaultTextSizeEnabled) { ChangeFontSize(8.0f); frm.enterPasswordForFileDefaultTextSizeEnabled = true; frm.enterPasswordForFileSmallTextSizeEnabled = false; frm.enterPasswordForFileLargeTextSizeEnabled = false; } else if (smallTextSizeEnabled) { ChangeFontSize(6.0f); frm.enterPasswordForFileDefaultTextSizeEnabled = false; frm.enterPasswordForFileSmallTextSizeEnabled = true; frm.enterPasswordForFileLargeTextSizeEnabled = false; } else if (largeTextSizeEnabled) { ChangeFontSize(10.0f); frm.enterPasswordForFileDefaultTextSizeEnabled = false; frm.enterPasswordForFileSmallTextSizeEnabled = false; frm.enterPasswordForFileLargeTextSizeEnabled = true; } frm.ShowDialog(); } }
/// <summary> /// Displays a warning to the user that they are about to create a new file. /// </summary> private void DisplayNewFileWarning() { string message = "Are you sure you wish to create a new password File?"; string title = "Pass Keeper"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; //creates a dialog box with the message, title and button options DialogResult confirm = MessageBox.Show(message, title, buttons); //if they want to make a new file if (confirm == DialogResult.Yes) { if (FileOP.GetFile() != "") { DialogResult savePrompt = MessageBox.Show("Would you like to save the current working file?", "Lock Current File", MessageBoxButtons.YesNo); if (savePrompt == DialogResult.Yes) { DataTable dataTable = FileOP.DataGridViewToDataTable(dataGridView1); FileOP.WriteToFile(dataTable); } ClearMem(); } //call the create file method and inflate the next form if (FileOP.CreateFile()) { PasswordOptions passwordOptionsForm; // Creates a passwordOptions form with the correct theme if (darkThemeEnabled) { passwordOptionsForm = new PasswordOptions(Color.White, Color.DarkGray, Color.DarkSlateGray, darkThemeEnabled) { TheParent = this }; } else { passwordOptionsForm = new PasswordOptions(SystemColors.ControlText, SystemColors.Window, SystemColors.Control, darkThemeEnabled) { TheParent = this }; } // Adding all the password options components to the list of components in the master from. // This is done to apply the same theme and text size to all of the forms textBoxes.AddRange(passwordOptionsForm.passwordOptionsTextBoxes); labels.AddRange(passwordOptionsForm.passwordOptionsLabels); this.buttons.AddRange(passwordOptionsForm.passwordOptionsButtons); forms.Add(passwordOptionsForm); // Changing text size of passwordOptions if (defaultTextSizeEnabled) { ChangeFontSize(8.0f); passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = true; passwordOptionsForm.passwordOptionsSmallTextSizeEnabled = false; passwordOptionsForm.passwordOptionsLargeTextSizeEnabled = false; } else if (smallTextSizeEnabled) { ChangeFontSize(6.0f); passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = false; passwordOptionsForm.passwordOptionsSmallTextSizeEnabled = true; passwordOptionsForm.passwordOptionsLargeTextSizeEnabled = false; } else if (largeTextSizeEnabled) { ChangeFontSize(10.0f); passwordOptionsForm.passwordOptionsDefaultTextSizeEnabled = false; passwordOptionsForm.passwordOptionsSmallTextSizeEnabled = false; passwordOptionsForm.passwordOptionsLargeTextSizeEnabled = true; } passwordOptionsForm.ShowDialog(); passwordOptionsForm.Activate(); } ; } }