C2020-032: Allow Import procedure set when name exists

This commit is contained in:
Kathy Ruffing 2021-05-12 14:46:50 +00:00
parent 5e7796182b
commit 2ba654b622

View File

@ -856,10 +856,39 @@ namespace VEPROMS
this.btnDoImport.Enabled = true; // allow user to change mind and perform the import 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 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) 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"); // 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; return false;
} }
_MyNewFolder = FolderInfo.Get(ff.FolderID); _MyNewFolder = FolderInfo.Get(ff.FolderID);
@ -3388,12 +3417,12 @@ namespace VEPROMS
// return folder; // return folder;
//} //}
private Folder AddFolder(Folder p, XmlDocument xd) private Folder AddFolder(Folder p, XmlDocument xd, string name)
{ {
lblImportStatus.Text = "Creating Folder..."; lblImportStatus.Text = "Creating Folder...";
Application.DoEvents(); Application.DoEvents();
string title = xd.DocumentElement.Attributes.GetNamedItem("title").InnerText; 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 shortname = xd.DocumentElement.Attributes.GetNamedItem("shortname").InnerText;
string usrid = xd.DocumentElement.Attributes.GetNamedItem("usrid").InnerText; string usrid = xd.DocumentElement.Attributes.GetNamedItem("usrid").InnerText;
DateTime dts = DateTime.Parse(xd.DocumentElement.Attributes.GetNamedItem("dts").InnerText); DateTime dts = DateTime.Parse(xd.DocumentElement.Attributes.GetNamedItem("dts").InnerText);