Development #342

Merged
djankowski merged 6 commits from Development into master 2024-06-20 11:36:59 -04:00
2 changed files with 120 additions and 22 deletions
Showing only changes of commit 2ffab17caf - Show all commits

View File

@ -241,6 +241,21 @@ namespace JR.Utils.GUI.Forms
return FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, defaultButton);
}
/// <summary>
/// Shows the specified message box.
/// </summary>
/// <param name="owner">The owner.</param>
/// <param name="text">The text.</param>
/// <param name="caption">The caption.</param>
/// <param name="buttons">The buttons.</param>
/// <param name="icon">The icon.</param>
/// <param name="defaultButton">The default button.</param>
/// <returns>The dialog result.</returns>
public static DialogResult ShowCustom(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
return FlexibleMessageBoxForm.ShowCustom(null, text, caption, buttons, icon);
}
#endregion
#region Internal form class
@ -420,15 +435,15 @@ namespace JR.Utils.GUI.Forms
private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_SPACES = " ";
//These are the possible buttons (in a standard MessageBox)
private enum ButtonID { OK = 0, CANCEL, YES, NO, ABORT, RETRY, IGNORE };
private enum ButtonID { OK = 0, CANCEL, YES, NO, ABORT, RETRY, IGNORE, OVERWRITE, RENAME };
//These are the buttons texts for different languages.
//If you want to add a new language, add it here and in the GetButtonText-Function
private enum TwoLetterISOLanguageID { en, de, es, it };
private static readonly String[] BUTTON_TEXTS_ENGLISH_EN = { "OK", "Cancel", "&Yes", "&No", "&Abort", "&Retry", "&Ignore" }; //Note: This is also the fallback language
private static readonly String[] BUTTON_TEXTS_GERMAN_DE = { "OK", "Abbrechen", "&Ja", "&Nein", "&Abbrechen", "&Wiederholen", "&Ignorieren" };
private static readonly String[] BUTTON_TEXTS_SPANISH_ES = { "Aceptar", "Cancelar", "&Sí", "&No", "&Abortar", "&Reintentar", "&Ignorar" };
private static readonly String[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora" };
private static readonly String[] BUTTON_TEXTS_ENGLISH_EN = { "OK", "Cancel", "&Yes", "&No", "&Abort", "&Retry", "&Ignore", "&Overwrite", "&Rename" }; //Note: This is also the fallback language
private static readonly String[] BUTTON_TEXTS_GERMAN_DE = { "OK", "Abbrechen", "&Ja", "&Nein", "&Abbrechen", "&Wiederholen", "&Ignorieren", "&Overwrite", "&Rename" };
private static readonly String[] BUTTON_TEXTS_SPANISH_ES = { "Aceptar", "Cancelar", "&Sí", "&No", "&Abortar", "&Reintentar", "&Ignorar", "&Overwrite", "&Rename" };
private static readonly String[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora", "&Overwrite", "&Rename" };
#endregion
@ -693,6 +708,7 @@ namespace JR.Utils.GUI.Forms
flexibleMessageBoxForm.CancelButton = flexibleMessageBoxForm.button3;
break;
case MessageBoxButtons.OK:
default:
@ -709,16 +725,38 @@ namespace JR.Utils.GUI.Forms
flexibleMessageBoxForm.defaultButton = defaultButton;
}
#endregion
private static void SetDialogButtonsCustom(FlexibleMessageBoxForm flexibleMessageBoxForm)
{
flexibleMessageBoxForm.visibleButtonsCount = 3;
#region Private event handlers
flexibleMessageBoxForm.button1.Visible = true;
flexibleMessageBoxForm.button1.Text = flexibleMessageBoxForm.GetButtonText(ButtonID.CANCEL);
flexibleMessageBoxForm.button1.DialogResult = DialogResult.Abort;
/// <summary>
/// Handles the Shown event of the FlexibleMessageBoxForm control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void FlexibleMessageBoxForm_Shown(object sender, EventArgs e)
flexibleMessageBoxForm.button2.Visible = true;
flexibleMessageBoxForm.button2.Text = flexibleMessageBoxForm.GetButtonText(ButtonID.OVERWRITE);
flexibleMessageBoxForm.button2.DialogResult = DialogResult.Retry;
flexibleMessageBoxForm.button3.Visible = true;
flexibleMessageBoxForm.button3.Text = flexibleMessageBoxForm.GetButtonText(ButtonID.RENAME);
flexibleMessageBoxForm.button3.DialogResult = DialogResult.Ignore;
flexibleMessageBoxForm.ControlBox = false;
}
#endregion
#region Private event handlers
/// <summary>
/// Handles the Shown event of the FlexibleMessageBoxForm control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void FlexibleMessageBoxForm_Shown(object sender, EventArgs e)
{
int buttonIndexToFocus = 1;
Button buttonToFocus;
@ -866,6 +904,46 @@ namespace JR.Utils.GUI.Forms
return flexibleMessageBoxForm.ShowDialog(owner);
}
/// <summary>
/// Shows the specified message box.
/// </summary>
/// <param name="owner">The owner.</param>
/// <param name="text">The text.</param>
/// <param name="caption">The caption.</param>
/// <param name="buttons">The buttons.</param>
/// <param name="icon">The icon.</param>
/// <param name="defaultButton">The default button.</param>
/// <returns>The dialog result.</returns>
public static DialogResult ShowCustom(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
//Create a new instance of the FlexibleMessageBox form
var flexibleMessageBoxForm = new FlexibleMessageBoxForm();
flexibleMessageBoxForm.ShowInTaskbar = false;
//Bind the caption and the message text
flexibleMessageBoxForm.CaptionText = caption;
flexibleMessageBoxForm.MessageText = text;
flexibleMessageBoxForm.FlexibleMessageBoxFormBindingSource.DataSource = flexibleMessageBoxForm;
//Set the buttons visibilities and texts. Also set a default button.
SetDialogButtonsCustom(flexibleMessageBoxForm);
//Set the dialogs icon. When no icon is used: Correct placement and width of rich text box.
SetDialogIcon(flexibleMessageBoxForm, icon);
//Set the font for all controls
flexibleMessageBoxForm.Font = FONT;
flexibleMessageBoxForm.richTextBoxMessage.Font = FONT;
//Calculate the dialogs start size (Try to auto-size width to show longest text row). Also set the maximum dialog size.
SetDialogSizes(flexibleMessageBoxForm, text, caption);
//Set the dialogs start position when given. Otherwise center the dialog on the current screen.
SetDialogStartPosition(flexibleMessageBoxForm, owner);
//Show the dialog
return flexibleMessageBoxForm.ShowDialog(owner);
}
#endregion
} //class FlexibleMessageBoxForm

View File

@ -228,22 +228,42 @@ namespace VEPROMS
else if (MyProcedure != null)
{
var fileLocation = txtExport.Text;
if (File.Exists(fileLocation))
{ // C2022-029 if an existing export of the same name is found, provide option to overwrite it
DialogResult ovewriteEx = FlexibleMessageBox.Show("There is already another export file with the same name, would you like to overwrite it?\r\n\r\nSelecting 'Cancel' will cancel the export.", "Overwrite the export change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);// == DialogResult.Yes;
DialogResult ovewriteEx = FlexibleMessageBox.ShowCustom(null, "There is already another export file with the same name, you can either overwrite the existing file, or have the existing file renamed with it's created date appended?\r\n\r\nSelecting 'Cancel' will cancel the export.", "What would you like to do?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);// == DialogResult.Yes;
if (ovewriteEx == DialogResult.Cancel) btnCloseExport.Enabled = true;
else
if (ovewriteEx == DialogResult.Abort) btnCloseExport.Enabled = true;
else if (ovewriteEx == DialogResult.Retry)
{
// Ovewrite
// Extract directory, filename, and extension
string directory = Path.GetDirectoryName(fileLocation);
string filename = Path.GetFileNameWithoutExtension(fileLocation);
string extension = Path.GetExtension(fileLocation);
fileLocation = $"{directory}\\{filename}{extension}";
msg = "The export file has been overwritten. ";
}
else if (ovewriteEx == DialogResult.Ignore)
{
// Extract directory, filename, and extension
string directory = Path.GetDirectoryName(fileLocation);
string filename = Path.GetFileNameWithoutExtension(fileLocation);
string extension = Path.GetExtension(fileLocation);
// Generate the new filename with a datestamp
string datestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
fileLocation = $"{directory}\\{filename}_{datestamp}{extension}";
// Generate the new filename with a datestamp
fileLocation = $"{directory}\\{filename}{extension}";
// Get the creation date of the existing file
DateTime creationDate = File.GetCreationTime(fileLocation);
// Format the creation date to use it as a datestamp
string datestamp = creationDate.ToString("yyyyMMddHHmmss");
string newFileLocation = $"{directory}\\{filename}_{datestamp}{extension}";
File.Move(fileLocation, newFileLocation);
msg = "The previous export has been renamed, the export file has been created. ";
}
}
@ -734,7 +754,7 @@ namespace VEPROMS
}
catch (Exception ex)
{
FlexibleMessageBox.Show("The import failed, check the error log for more information.", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
FlexibleMessageBox.Show(null, "The import failed, check the error log for more information.", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
_MyLog.Warn("Failure During Import", ex);
}
return false;