From 5d8d79e32c719a6f72e2e42d868f0fffd6b0b97a Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 22 Mar 2016 14:57:47 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20B2016-045,=20B2016-083=20&=20084:=20Proce?= =?UTF-8?q?dure=20number=20hyphen=20representation,=20create=20non-existin?= =?UTF-8?q?g=20annotation=20type=20&=20don=E2=80=99t=20import=20if=20user?= =?UTF-8?q?=20does=20not=20overwrite/copy=20existing=20procedure.=20Fix=20?= =?UTF-8?q?B2016-083:=20Added=20a=20method=20=E2=80=98GetByNameOrCreate?= =?UTF-8?q?=E2=80=99=20that=20will=20create=20the=20Annotation=20type=20if?= =?UTF-8?q?=20it=20doesn=E2=80=99t=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VEPROMS User Interface/dlgExportImport.cs | 169 ++++++++++-------- .../Generated/AnnotationType.cs | 30 ++++ 2 files changed, 122 insertions(+), 77 deletions(-) diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index 99c9799f..f98a3e8a 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -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 localROPaths = new List(); - RODbInfoList rolist = RODbInfoList.Get(); - foreach (RODbInfo dbi in rolist) - { - if (dbi.FolderPath == rofolderpath && dbi.RODbID == rodbid) - { + List localROPaths = new List(); + 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(); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs index 84a0b50b..1b388c58 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/AnnotationType.cs @@ -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(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);