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");
|
||||
MyWriter.Close();
|
||||
}
|
||||
private void btnDoImport_Click(object sender, EventArgs e)
|
||||
{
|
||||
btnImport.Enabled = false;
|
||||
this.Cursor = Cursors.WaitCursor;
|
||||
MyStart = DateTime.Now;
|
||||
btnDoImport.Enabled = false;
|
||||
lblImportStatus.Text = "Performing Import";
|
||||
//LoadImportDataReader();
|
||||
if (MyFolder != null)
|
||||
{
|
||||
TurnChangeManagerOff.Execute();
|
||||
LoadImportDataDocument();
|
||||
private void btnDoImport_Click(object sender, EventArgs e)
|
||||
{
|
||||
btnImport.Enabled = false;
|
||||
this.Cursor = Cursors.WaitCursor;
|
||||
MyStart = DateTime.Now;
|
||||
btnDoImport.Enabled = false;
|
||||
lblImportStatus.Text = "Performing Import";
|
||||
//LoadImportDataReader();
|
||||
if (MyFolder != null)
|
||||
{
|
||||
TurnChangeManagerOff.Execute();
|
||||
LoadImportDataDocument();
|
||||
MyDocVersion = null;
|
||||
TurnChangeManagerOn.Execute();
|
||||
}
|
||||
if (MyDocVersion != null)
|
||||
{
|
||||
TurnChangeManagerOff.Execute();
|
||||
XmlDocument xd = new XmlDocument();
|
||||
xd.Load(txtImport.Text);
|
||||
bool isImported = false;
|
||||
pbImportProcedure.Maximum = 1;
|
||||
string rofolderpath = xd.DocumentElement.Attributes.GetNamedItem("rofolderpath").InnerText;
|
||||
TurnChangeManagerOn.Execute();
|
||||
}
|
||||
if (MyDocVersion != null)
|
||||
{
|
||||
TurnChangeManagerOff.Execute();
|
||||
XmlDocument xd = new XmlDocument();
|
||||
xd.Load(txtImport.Text);
|
||||
bool isImported = false;
|
||||
pbImportProcedure.Maximum = 1;
|
||||
string rofolderpath = xd.DocumentElement.Attributes.GetNamedItem("rofolderpath").InnerText;
|
||||
int rodbid = int.Parse(xd.DocumentElement.Attributes.GetNamedItem("rodbid").InnerText);
|
||||
int rofstid = int.Parse(xd.DocumentElement.Attributes.GetNamedItem("rofstid").InnerText);
|
||||
List<string> localROPaths = new List<string>();
|
||||
RODbInfoList rolist = RODbInfoList.Get();
|
||||
foreach (RODbInfo dbi in rolist)
|
||||
{
|
||||
if (dbi.FolderPath == rofolderpath && dbi.RODbID == rodbid)
|
||||
{
|
||||
List<string> localROPaths = new List<string>();
|
||||
RODbInfoList rolist = RODbInfoList.Get();
|
||||
foreach (RODbInfo dbi in rolist)
|
||||
{
|
||||
if (dbi.FolderPath == rofolderpath && dbi.RODbID == rodbid)
|
||||
{
|
||||
MyRODb = RODb.GetJustRoDb(rodbid);
|
||||
oldRODbID = newRODbID = rodbid;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo di = new DirectoryInfo(dbi.FolderPath);
|
||||
if (di.Exists)
|
||||
localROPaths.Add(dbi.FolderPath);
|
||||
}
|
||||
}
|
||||
if (MyRODb == null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo di = new DirectoryInfo(dbi.FolderPath);
|
||||
if (di.Exists)
|
||||
localROPaths.Add(dbi.FolderPath);
|
||||
}
|
||||
}
|
||||
if (MyRODb == null)
|
||||
{
|
||||
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.");
|
||||
@ -246,15 +246,16 @@ namespace VEPROMS
|
||||
foreach (ROFstInfo tmp in myRODBInfo.RODbROFsts)
|
||||
if (fstInfo == null || tmp.ROFstID > fstInfo.ROFstID)
|
||||
fstInfo = tmp;
|
||||
using(DocVersion dv = MyDocVersion.Get())
|
||||
using (DocVersion dv = MyDocVersion.Get())
|
||||
{
|
||||
using (ROFst fst = fstInfo.Get())
|
||||
{
|
||||
{
|
||||
dv.DocVersionAssociations.Add(fst);
|
||||
dv.Save();
|
||||
}
|
||||
dv.Reset_DocVersionAssociations();
|
||||
MyDocVersion.RefreshDocVersionAssociations(); }
|
||||
MyDocVersion.RefreshDocVersionAssociations();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -263,41 +264,53 @@ namespace VEPROMS
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (ProcedureInfo pi in MyDocVersion.Procedures)
|
||||
{
|
||||
if (pi.ItemID == int.Parse(xd.SelectSingleNode("procedure/@itemid").InnerText) || pi.MyContent.Number == xd.SelectSingleNode("procedure/content/@number").InnerText)
|
||||
{
|
||||
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)
|
||||
{
|
||||
ImportProcedureOverwrite(xd, pi);
|
||||
isImported = true;
|
||||
break;
|
||||
}
|
||||
if (dr == DialogResult.No)
|
||||
{
|
||||
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)
|
||||
{
|
||||
ImportProcedureCopy(xd);
|
||||
isImported = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isImported)
|
||||
{
|
||||
ImportProcedureNew(xd);
|
||||
}
|
||||
TurnChangeManagerOn.Execute();
|
||||
}
|
||||
TimeSpan elapsed = DateTime.Now.Subtract(MyStart);
|
||||
lblImportStatus.Text = "Import Completed in " + elapsed.ToString();
|
||||
this.Cursor = Cursors.Default;
|
||||
btnCloseImport.Enabled = true;
|
||||
}
|
||||
}
|
||||
// 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
|
||||
bool resolvedProcNum = true;
|
||||
foreach (ProcedureInfo pi in MyDocVersion.Procedures)
|
||||
{
|
||||
// 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
|
||||
// 2 should be considered the same procedure (fix for B2016-084)
|
||||
string hyphenNum = pi.MyContent.Number == null ? pi.MyContent.Number : pi.MyContent.Number.Replace(@"\u8209?", "-");
|
||||
string hyphenImpNum = xd.SelectSingleNode("procedure/content/@number").InnerText;
|
||||
hyphenImpNum = hyphenImpNum == null ? hyphenImpNum : hyphenImpNum.Replace("\u8030?", "-");
|
||||
|
||||
if (pi.ItemID == int.Parse(xd.SelectSingleNode("procedure/@itemid").InnerText) || hyphenNum == hyphenImpNum)
|
||||
{
|
||||
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)
|
||||
{
|
||||
ImportProcedureOverwrite(xd, pi);
|
||||
isImported = true;
|
||||
break;
|
||||
}
|
||||
if (dr == DialogResult.No)
|
||||
{
|
||||
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)
|
||||
{
|
||||
ImportProcedureCopy(xd);
|
||||
isImported = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
resolvedProcNum = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
//add imported procedure
|
||||
@ -350,6 +363,8 @@ namespace VEPROMS
|
||||
ProcedureInfo lastProcedure = null;
|
||||
//determine count of existing procedures with same number
|
||||
string number = xd.SelectSingleNode("procedure/content/@number").InnerText;
|
||||
|
||||
// kbr - could replace '-' with unicode in number, here.
|
||||
int count = 0;
|
||||
foreach (ProcedureInfo pi in MyDocVersion.Procedures)
|
||||
{
|
||||
@ -2806,7 +2821,7 @@ namespace VEPROMS
|
||||
string config = nd.Attributes.GetNamedItem("config").InnerText;
|
||||
string userid = nd.Attributes.GetNamedItem("userid").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);
|
||||
ann.Save();
|
||||
}
|
||||
|
@ -602,6 +602,36 @@ namespace VEPROMS.CSLA.Library
|
||||
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)
|
||||
{
|
||||
if (dr.Read()) return new AnnotationType(dr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user