diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index 8eee4893..6c0dad02 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -856,11 +856,40 @@ namespace VEPROMS this.btnDoImport.Enabled = true; // allow user to change mind and perform the import return false; // Return False to Indicate that the Import did not succeed } - Folder ff = AddFolder(Folder.Get(MyFolder.FolderID), xd); + string name = xd.DocumentElement.Attributes.GetNamedItem("name").InnerText; + Folder ff = AddFolder(Folder.Get(MyFolder.FolderID), xd, name); if (ff == null) { - MessageBox.Show("You can not import the same procedure set more than once. You should rename the existing folder then try again.", "Duplicate Import Error"); - return false; + // C2020-032: Import Procedure set when existing name exists, allow user to import with 'Copy (#) of'. + // This is similar functionality to the import of a procedure without the overwrite part. + string msg = string.Format("The procedure set you are importing, {0}, already exists.\n\nDo you want to import {0} as a COPY of the existing set?\n\nThis will prefix the name with \"Copy (#) of\"", name); + DialogResult dr = MessageBox.Show(this, msg, "Create Copy Of Existing Procedure Set", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop); + if (dr == DialogResult.Yes) + { + string number = ""; + int max = -1; + // get maximum number of existing copies. + foreach (FolderInfo fi in MyFolder.ChildFolders) + { + int indx = fi.Name.IndexOf("Copy ("); + if (indx > -1) + { + int indxend = fi.Name.IndexOf(")", indx); + if (indxend > indx) + { + string tmp = fi.Name.Substring(indx + 6, indxend - (indx + 6)); + int ii = Convert.ToInt32(tmp); + if (ii > max) max = ii; + } + } + } + number = max > -1 ? (max + 1).ToString() : "1"; + name = string.Format("Copy ({0}) of {1}", number, name); + + ff = AddFolder(Folder.Get(MyFolder.FolderID), xd, name); + } + else + return false; } _MyNewFolder = FolderInfo.Get(ff.FolderID); AddAnnotationTypes(xd); @@ -3388,12 +3417,12 @@ namespace VEPROMS // return folder; //} - private Folder AddFolder(Folder p, XmlDocument xd) + private Folder AddFolder(Folder p, XmlDocument xd, string name) { lblImportStatus.Text = "Creating Folder..."; Application.DoEvents(); string title = xd.DocumentElement.Attributes.GetNamedItem("title").InnerText; - string name = xd.DocumentElement.Attributes.GetNamedItem("name").InnerText; + //string name = xd.DocumentElement.Attributes.GetNamedItem("name").InnerText; string shortname = xd.DocumentElement.Attributes.GetNamedItem("shortname").InnerText; string usrid = xd.DocumentElement.Attributes.GetNamedItem("usrid").InnerText; DateTime dts = DateTime.Parse(xd.DocumentElement.Attributes.GetNamedItem("dts").InnerText);