diff --git a/PROMS/FlexableMessageBox/FlexibleMessageBox.cs b/PROMS/FlexableMessageBox/FlexibleMessageBox.cs
index 7b4c4493..535b983a 100644
--- a/PROMS/FlexableMessageBox/FlexibleMessageBox.cs
+++ b/PROMS/FlexableMessageBox/FlexibleMessageBox.cs
@@ -241,6 +241,21 @@ namespace JR.Utils.GUI.Forms
return FlexibleMessageBoxForm.Show(owner, text, caption, buttons, icon, defaultButton);
}
+ ///
+ /// Shows the specified message box.
+ ///
+ /// The owner.
+ /// The text.
+ /// The caption.
+ /// The buttons.
+ /// The icon.
+ /// The default button.
+ /// The dialog result.
+ 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;
- ///
- /// Handles the Shown event of the FlexibleMessageBoxForm control.
- ///
- /// The source of the event.
- /// The instance containing the event data.
- 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
+
+ ///
+ /// Handles the Shown event of the FlexibleMessageBoxForm control.
+ ///
+ /// The source of the event.
+ /// The instance containing the event data.
+ 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);
}
+ ///
+ /// Shows the specified message box.
+ ///
+ /// The owner.
+ /// The text.
+ /// The caption.
+ /// The buttons.
+ /// The icon.
+ /// The default button.
+ /// The dialog result.
+ 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
diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs
index 66cd2489..955b5c78 100644
--- a/PROMS/VEPROMS User Interface/dlgExportImport.cs
+++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs
@@ -99,6 +99,10 @@ namespace VEPROMS
MyProcedure = procedureInfo;
InitializeComponent();
this.Text = mode + " Dialog for " + procedureInfo.DisplayNumber;
+
+ //Preset path for single procedures.
+ PEIPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\VEPROMS\PEI_" + Database.VEPROMS_SqlConnection.Database;
+ txtExport.Text = string.Format(@"{0}\{1}.pxml", PEIPath, MyProcedure.DisplayNumber.Replace("/", "_").Replace("\\", "_"));
}
private void dlgExportImport_Load(object sender, EventArgs e)
{
@@ -172,6 +176,7 @@ namespace VEPROMS
}
else if (MyProcedure != null)
{
+ txtExport.Enabled = true;
txtExport.Text = string.Format(@"{0}\{1}.pxml", PEIPath, MyProcedure.DisplayNumber.Replace("/", "_").Replace("\\", "_"));
}
}
@@ -190,6 +195,8 @@ namespace VEPROMS
private bool successfullExport = true;
private void btnDoExport_Click(object sender, EventArgs e)
{
+
+
btnExport.Enabled = false;
string msg = "Finished Exporting:\n\n";
if (_MyMode.ToUpper().Contains("FORMAT"))
@@ -220,6 +227,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.ShowCustom(null, "There is already another export file with the same name. You can choose to either overwrite the existing file or have the existing file renamed with the original creation date appended.\r\n\r\nSelecting 'Cancel' will cancel the export.", "What would you like to do?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);// == DialogResult.Yes;
+
+ // Extract directory, filename, and extension
+ string directory = Path.GetDirectoryName(fileLocation);
+ string filename = Path.GetFileNameWithoutExtension(fileLocation);
+ string extension = Path.GetExtension(fileLocation);
+ fileLocation = $"{directory}\\{filename}{extension}";
+
+ if (ovewriteEx == DialogResult.Abort)
+ {
+ MessageBox.Show("Export has been cancelled", "You have chosen to cancel the export.", MessageBoxButtons.OK, MessageBoxIcon.Information); // C2020-042 changed mesage box title
+ btnCloseExport.Enabled = true;
+ return;
+ }
+ else if (ovewriteEx == DialogResult.Retry)
+ {
+ //Overwrite will occur, set msg.
+ msg = "The export file has been overwritten. ";
+ }
+ else if (ovewriteEx == DialogResult.Ignore)
+ {
+ // Get the modified date of the existing file, create a datestamp for use in name, set newlocation to move to
+ DateTime modifiedDate = File.GetLastWriteTime(fileLocation);
+ string datestamp = modifiedDate.ToString("yyyyMMddHHmmss");
+ string newFileLocation = $"{directory}\\{filename}_{datestamp}{extension}";
+
+ //Move and set msg.
+ File.Move(fileLocation, newFileLocation);
+ msg = "The previous export has been renamed, the export file has been created. ";
+ }
+
+ }
+
this.Cursor = Cursors.WaitCursor;
MyStart = DateTime.Now;
btnDoExport.Enabled = false;
@@ -230,7 +273,7 @@ namespace VEPROMS
XmlElement xe = xd.CreateElement("formats");
xd.DocumentElement.AppendChild(xe);
ExportFormats(FormatInfoList.GetFormatInfoListUsed(), xe, "formats", false);
- xd.Save(txtExport.Text);
+ xd.Save(fileLocation);
TimeSpan elapsed = DateTime.Now.Subtract(MyStart);
lblExportStatus.Text = "Export Completed in " + elapsed.ToString();
this.Cursor = Cursors.Default;
@@ -706,7 +749,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;
diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.designer.cs b/PROMS/VEPROMS User Interface/dlgExportImport.designer.cs
index cb3f8404..4e6f1ec4 100644
--- a/PROMS/VEPROMS User Interface/dlgExportImport.designer.cs
+++ b/PROMS/VEPROMS User Interface/dlgExportImport.designer.cs
@@ -400,6 +400,7 @@ namespace VEPROMS
this.pnlImport.PerformLayout();
this.ResumeLayout(false);
+
}
#endregion