From db4f114cafd8a3affee607fdc2d7367fd81dbad8 Mon Sep 17 00:00:00 2001 From: Kevin Laskey Date: Tue, 4 Jun 2024 08:51:57 -0400 Subject: [PATCH 1/5] C2022-029 - Export Import changes, Set path automatically for single proc export, provide overwrite message on single prompt export. --- .../VEPROMS User Interface/dlgExportImport.cs | 30 ++++++++++++++++++- .../dlgExportImport.designer.cs | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index 66cd2489..55058930 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,27 @@ 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; + + if (ovewriteEx == DialogResult.Cancel) btnCloseExport.Enabled = true; + else + { + // 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}"; + } + + } + this.Cursor = Cursors.WaitCursor; MyStart = DateTime.Now; btnDoExport.Enabled = false; @@ -230,7 +258,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; 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 -- 2.47.2 From 2ffab17caf3b31463e3b44f6a08c9b4fa9898b83 Mon Sep 17 00:00:00 2001 From: Kevin Laskey Date: Fri, 7 Jun 2024 14:17:43 -0400 Subject: [PATCH 2/5] Updates for adding custom buttons --- .../FlexableMessageBox/FlexibleMessageBox.cs | 106 +++++++++++++++--- .../VEPROMS User Interface/dlgExportImport.cs | 36 ++++-- 2 files changed, 120 insertions(+), 22 deletions(-) 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 55058930..d3631612 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -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; -- 2.47.2 From a2e830d0c34be352afc4dd3523caf7a526e3abb7 Mon Sep 17 00:00:00 2001 From: Kevin Laskey Date: Fri, 7 Jun 2024 14:42:26 -0400 Subject: [PATCH 3/5] Update for "cancel" button action --- PROMS/VEPROMS User Interface/dlgExportImport.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index d3631612..0d804ecb 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -230,9 +230,14 @@ namespace VEPROMS 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 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; + 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.Abort) btnCloseExport.Enabled = true; + 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) { // Ovewrite -- 2.47.2 From 11cb2e0efd66789969eced53dff5973b296b2904 Mon Sep 17 00:00:00 2001 From: Kevin Laskey Date: Fri, 7 Jun 2024 15:14:33 -0400 Subject: [PATCH 4/5] Updated message --- PROMS/VEPROMS User Interface/dlgExportImport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index 0d804ecb..60e40a0f 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -230,7 +230,7 @@ namespace VEPROMS 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 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; + 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; if (ovewriteEx == DialogResult.Abort) { -- 2.47.2 From 4f7a762bf1a9cc3390bff0243571f734308c6d6f Mon Sep 17 00:00:00 2001 From: Kevin Laskey Date: Thu, 13 Jun 2024 08:35:13 -0400 Subject: [PATCH 5/5] Updated to use modified date, shortened code a bit. --- .../VEPROMS User Interface/dlgExportImport.cs | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index 60e40a0f..955b5c78 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -232,6 +232,12 @@ namespace VEPROMS { // 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 @@ -240,33 +246,17 @@ namespace VEPROMS } 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}"; + //Overwrite will occur, set msg. 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 - 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"); - + // 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. "; } -- 2.47.2