Fix B2016-045, B2016-083 & 084: Procedure number hyphen representation, create non-existing annotation type & don’t import if user does not overwrite/copy existing procedure.
Fix B2016-083: Added a method ‘GetByNameOrCreate’ that will create the Annotation type if it doesn’t exist
This commit is contained in:
parent
5ec4b86663
commit
5d8d79e32c
@ -180,50 +180,50 @@ namespace VEPROMS
|
|||||||
ExportFolder(MyFolder, "folder");
|
ExportFolder(MyFolder, "folder");
|
||||||
MyWriter.Close();
|
MyWriter.Close();
|
||||||
}
|
}
|
||||||
private void btnDoImport_Click(object sender, EventArgs e)
|
private void btnDoImport_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
btnImport.Enabled = false;
|
btnImport.Enabled = false;
|
||||||
this.Cursor = Cursors.WaitCursor;
|
this.Cursor = Cursors.WaitCursor;
|
||||||
MyStart = DateTime.Now;
|
MyStart = DateTime.Now;
|
||||||
btnDoImport.Enabled = false;
|
btnDoImport.Enabled = false;
|
||||||
lblImportStatus.Text = "Performing Import";
|
lblImportStatus.Text = "Performing Import";
|
||||||
//LoadImportDataReader();
|
//LoadImportDataReader();
|
||||||
if (MyFolder != null)
|
if (MyFolder != null)
|
||||||
{
|
{
|
||||||
TurnChangeManagerOff.Execute();
|
TurnChangeManagerOff.Execute();
|
||||||
LoadImportDataDocument();
|
LoadImportDataDocument();
|
||||||
MyDocVersion = null;
|
MyDocVersion = null;
|
||||||
TurnChangeManagerOn.Execute();
|
TurnChangeManagerOn.Execute();
|
||||||
}
|
}
|
||||||
if (MyDocVersion != null)
|
if (MyDocVersion != null)
|
||||||
{
|
{
|
||||||
TurnChangeManagerOff.Execute();
|
TurnChangeManagerOff.Execute();
|
||||||
XmlDocument xd = new XmlDocument();
|
XmlDocument xd = new XmlDocument();
|
||||||
xd.Load(txtImport.Text);
|
xd.Load(txtImport.Text);
|
||||||
bool isImported = false;
|
bool isImported = false;
|
||||||
pbImportProcedure.Maximum = 1;
|
pbImportProcedure.Maximum = 1;
|
||||||
string rofolderpath = xd.DocumentElement.Attributes.GetNamedItem("rofolderpath").InnerText;
|
string rofolderpath = xd.DocumentElement.Attributes.GetNamedItem("rofolderpath").InnerText;
|
||||||
int rodbid = int.Parse(xd.DocumentElement.Attributes.GetNamedItem("rodbid").InnerText);
|
int rodbid = int.Parse(xd.DocumentElement.Attributes.GetNamedItem("rodbid").InnerText);
|
||||||
int rofstid = int.Parse(xd.DocumentElement.Attributes.GetNamedItem("rofstid").InnerText);
|
int rofstid = int.Parse(xd.DocumentElement.Attributes.GetNamedItem("rofstid").InnerText);
|
||||||
List<string> localROPaths = new List<string>();
|
List<string> localROPaths = new List<string>();
|
||||||
RODbInfoList rolist = RODbInfoList.Get();
|
RODbInfoList rolist = RODbInfoList.Get();
|
||||||
foreach (RODbInfo dbi in rolist)
|
foreach (RODbInfo dbi in rolist)
|
||||||
{
|
{
|
||||||
if (dbi.FolderPath == rofolderpath && dbi.RODbID == rodbid)
|
if (dbi.FolderPath == rofolderpath && dbi.RODbID == rodbid)
|
||||||
{
|
{
|
||||||
MyRODb = RODb.GetJustRoDb(rodbid);
|
MyRODb = RODb.GetJustRoDb(rodbid);
|
||||||
oldRODbID = newRODbID = rodbid;
|
oldRODbID = newRODbID = rodbid;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DirectoryInfo di = new DirectoryInfo(dbi.FolderPath);
|
DirectoryInfo di = new DirectoryInfo(dbi.FolderPath);
|
||||||
if (di.Exists)
|
if (di.Exists)
|
||||||
localROPaths.Add(dbi.FolderPath);
|
localROPaths.Add(dbi.FolderPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MyRODb == null)
|
if (MyRODb == null)
|
||||||
{
|
{
|
||||||
if (localROPaths.Count == 0)
|
if (localROPaths.Count == 0)
|
||||||
{
|
{
|
||||||
MessageBox.Show("There has been no RO folder defined for this database.\r\n\r\nIn order to import a procedure, you need to assign a RO folder path.\r\n\r\nImport process will terminate.");
|
MessageBox.Show("There has been no RO folder defined for this database.\r\n\r\nIn order to import a procedure, you need to assign a RO folder path.\r\n\r\nImport process will terminate.");
|
||||||
@ -246,7 +246,7 @@ namespace VEPROMS
|
|||||||
foreach (ROFstInfo tmp in myRODBInfo.RODbROFsts)
|
foreach (ROFstInfo tmp in myRODBInfo.RODbROFsts)
|
||||||
if (fstInfo == null || tmp.ROFstID > fstInfo.ROFstID)
|
if (fstInfo == null || tmp.ROFstID > fstInfo.ROFstID)
|
||||||
fstInfo = tmp;
|
fstInfo = tmp;
|
||||||
using(DocVersion dv = MyDocVersion.Get())
|
using (DocVersion dv = MyDocVersion.Get())
|
||||||
{
|
{
|
||||||
using (ROFst fst = fstInfo.Get())
|
using (ROFst fst = fstInfo.Get())
|
||||||
{
|
{
|
||||||
@ -254,7 +254,8 @@ namespace VEPROMS
|
|||||||
dv.Save();
|
dv.Save();
|
||||||
}
|
}
|
||||||
dv.Reset_DocVersionAssociations();
|
dv.Reset_DocVersionAssociations();
|
||||||
MyDocVersion.RefreshDocVersionAssociations(); }
|
MyDocVersion.RefreshDocVersionAssociations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -263,41 +264,53 @@ namespace VEPROMS
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (ProcedureInfo pi in MyDocVersion.Procedures)
|
// use resolvedProcNum to determine if procedure is 'unique', i.e. if the procedure number exists
|
||||||
{
|
// and user does not overwrite or copy, then the procedure should NOT be imported. Fix for B2016-045
|
||||||
if (pi.ItemID == int.Parse(xd.SelectSingleNode("procedure/@itemid").InnerText) || pi.MyContent.Number == xd.SelectSingleNode("procedure/content/@number").InnerText)
|
bool resolvedProcNum = true;
|
||||||
{
|
foreach (ProcedureInfo pi in MyDocVersion.Procedures)
|
||||||
DialogResult dr = MessageBox.Show(this, "The procedure you are importing already exists in this procedure set. Do you want to overwrite the existing procedure?", "Overwrite Existing Procedure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop);
|
{
|
||||||
if (dr == DialogResult.Yes)
|
// procedure numbers that contain a hyphen may have the hyphen represented as the unicode character
|
||||||
{
|
// '\u8209?' or the '-' character. If proc number is same except for hyphen representation, they
|
||||||
ImportProcedureOverwrite(xd, pi);
|
// 2 should be considered the same procedure (fix for B2016-084)
|
||||||
isImported = true;
|
string hyphenNum = pi.MyContent.Number == null ? pi.MyContent.Number : pi.MyContent.Number.Replace(@"\u8209?", "-");
|
||||||
break;
|
string hyphenImpNum = xd.SelectSingleNode("procedure/content/@number").InnerText;
|
||||||
}
|
hyphenImpNum = hyphenImpNum == null ? hyphenImpNum : hyphenImpNum.Replace("\u8030?", "-");
|
||||||
if (dr == DialogResult.No)
|
|
||||||
{
|
if (pi.ItemID == int.Parse(xd.SelectSingleNode("procedure/@itemid").InnerText) || hyphenNum == hyphenImpNum)
|
||||||
dr = MessageBox.Show(this, "The procedure you are importing already exists in this procedure set. Do you want to create a copy of the existing procedure?", "Create Copy Of Existing Procedure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop);
|
{
|
||||||
if (dr == DialogResult.Yes)
|
DialogResult dr = MessageBox.Show(this, "The procedure you are importing already exists in this procedure set. Do you want to overwrite the existing procedure?", "Overwrite Existing Procedure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop);
|
||||||
{
|
if (dr == DialogResult.Yes)
|
||||||
ImportProcedureCopy(xd);
|
{
|
||||||
isImported = true;
|
ImportProcedureOverwrite(xd, pi);
|
||||||
break;
|
isImported = true;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
if (dr == DialogResult.No)
|
||||||
}
|
{
|
||||||
if (!isImported)
|
dr = MessageBox.Show(this, "The procedure you are importing already exists in this procedure set. Do you want to create a copy of the existing procedure?", "Create Copy Of Existing Procedure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop);
|
||||||
{
|
if (dr == DialogResult.Yes)
|
||||||
ImportProcedureNew(xd);
|
{
|
||||||
}
|
ImportProcedureCopy(xd);
|
||||||
TurnChangeManagerOn.Execute();
|
isImported = true;
|
||||||
}
|
break;
|
||||||
TimeSpan elapsed = DateTime.Now.Subtract(MyStart);
|
}
|
||||||
lblImportStatus.Text = "Import Completed in " + elapsed.ToString();
|
else
|
||||||
this.Cursor = Cursors.Default;
|
resolvedProcNum = false;
|
||||||
btnCloseImport.Enabled = true;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (!isImported && resolvedProcNum)
|
||||||
|
{
|
||||||
|
ImportProcedureNew(xd);
|
||||||
|
}
|
||||||
|
TurnChangeManagerOn.Execute();
|
||||||
|
}
|
||||||
|
TimeSpan elapsed = DateTime.Now.Subtract(MyStart);
|
||||||
|
lblImportStatus.Text = "Import Completed in " + elapsed.ToString();
|
||||||
|
this.Cursor = Cursors.Default;
|
||||||
|
btnCloseImport.Enabled = true;
|
||||||
|
}
|
||||||
private void ImportProcedureNew(XmlDocument xd)
|
private void ImportProcedureNew(XmlDocument xd)
|
||||||
{
|
{
|
||||||
//add imported procedure
|
//add imported procedure
|
||||||
@ -350,6 +363,8 @@ namespace VEPROMS
|
|||||||
ProcedureInfo lastProcedure = null;
|
ProcedureInfo lastProcedure = null;
|
||||||
//determine count of existing procedures with same number
|
//determine count of existing procedures with same number
|
||||||
string number = xd.SelectSingleNode("procedure/content/@number").InnerText;
|
string number = xd.SelectSingleNode("procedure/content/@number").InnerText;
|
||||||
|
|
||||||
|
// kbr - could replace '-' with unicode in number, here.
|
||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (ProcedureInfo pi in MyDocVersion.Procedures)
|
foreach (ProcedureInfo pi in MyDocVersion.Procedures)
|
||||||
{
|
{
|
||||||
@ -2806,7 +2821,7 @@ namespace VEPROMS
|
|||||||
string config = nd.Attributes.GetNamedItem("config").InnerText;
|
string config = nd.Attributes.GetNamedItem("config").InnerText;
|
||||||
string userid = nd.Attributes.GetNamedItem("userid").InnerText;
|
string userid = nd.Attributes.GetNamedItem("userid").InnerText;
|
||||||
DateTime dts = DateTime.Parse(nd.Attributes.GetNamedItem("dts").InnerText);
|
DateTime dts = DateTime.Parse(nd.Attributes.GetNamedItem("dts").InnerText);
|
||||||
AnnotationType annType = AnnotationType.GetByName(nd.Attributes.GetNamedItem("typename").InnerText);
|
AnnotationType annType = AnnotationType.GetByNameOrCreate(nd.Attributes.GetNamedItem("typename").InnerText);
|
||||||
Annotation ann = Annotation.MakeAnnotation(itm, annType, rtftext, searchtext, config, dts, userid);
|
Annotation ann = Annotation.MakeAnnotation(itm, annType, rtftext, searchtext, config, dts, userid);
|
||||||
ann.Save();
|
ann.Save();
|
||||||
}
|
}
|
||||||
|
@ -602,6 +602,36 @@ namespace VEPROMS.CSLA.Library
|
|||||||
throw new DbCslaException("Error on AnnotationType.GetByName", ex);
|
throw new DbCslaException("Error on AnnotationType.GetByName", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// GetByNameOrCreate: gets the AnnotationType by its name, if it exists. If it
|
||||||
|
// doesn't exist, create it (fix B2016-083)
|
||||||
|
public static AnnotationType GetByNameOrCreate(string name)
|
||||||
|
{
|
||||||
|
if (!CanGetObject())
|
||||||
|
throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
AnnotationType tmp = GetCachedByName(name);
|
||||||
|
if (tmp == null)
|
||||||
|
{
|
||||||
|
tmp = DataPortal.Fetch<AnnotationType>(new NameCriteria(name));
|
||||||
|
AddToCache(tmp);
|
||||||
|
}
|
||||||
|
// if the type doesn't exist, try to add it
|
||||||
|
if (tmp.ErrorMessage == "No Record Found")
|
||||||
|
{
|
||||||
|
tmp.Dispose(); // Clean-up AnnotationType
|
||||||
|
tmp = null;
|
||||||
|
tmp = AnnotationType.MakeAnnotationType(name, null);
|
||||||
|
AddToCache(tmp);
|
||||||
|
AnnotationTypeInfoList.Refresh();
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new DbCslaException("Error on AnnotationType.GetByNameOrCreate", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static AnnotationType Get(SafeDataReader dr)
|
public static AnnotationType Get(SafeDataReader dr)
|
||||||
{
|
{
|
||||||
if (dr.Read()) return new AnnotationType(dr);
|
if (dr.Read()) return new AnnotationType(dr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user