diff --git a/PROMS/VEPROMS User Interface/dlgExportImport.cs b/PROMS/VEPROMS User Interface/dlgExportImport.cs index fabb1e37..692ea825 100644 --- a/PROMS/VEPROMS User Interface/dlgExportImport.cs +++ b/PROMS/VEPROMS User Interface/dlgExportImport.cs @@ -2710,7 +2710,7 @@ namespace VEPROMS { XmlNode xrofst = xassoc.SelectSingleNode("rofst"); XmlNode xrodb = xrofst.SelectSingleNode("rodb"); - MyRODb = AddRODb(xrodb); + MyRODb = AddRODb(xrodb); ROFst rofst = AddROFst(xrofst); DocVersionAssociation dva = dv.DocVersionAssociations.Add(rofst); dv.Save(); @@ -2752,9 +2752,18 @@ namespace VEPROMS string userid = xrofst.Attributes.GetNamedItem("userid").InnerText; DateTime dts = DateTime.Parse(xrofst.Attributes.GetNamedItem("dts").InnerText); ROFst rv = null; - rv = ROFst.GetByRODbID_DTS(MyRODb.RODbID, dts); //MyRODb.DTS); + rv = ROFst.GetByRODbID_DTS(MyRODb.RODbID, dts); + // if the RO database is not found in the current data (does not have the same RODBid nor date/time stamp + // then spin through the list of RO databases and compare the FST information. + // If the RO FST information is the same, then use that current RO database when importing if (rv == null) { + RODbInfoList rodblst = RODbInfoList.Get(); + foreach (RODbInfo roinfo in rodblst) + { + rv = ROFst.GetByRODbID_DTS(roinfo.RODbID, dts); + if (rv != null && Same(rv.ROLookup,rolookup)) return rv; + } rv = ROFst.MakeROFst(MyRODb, rolookup, config, dts, userid); XmlNode xfigures = xrofst.SelectSingleNode("figures"); if (xfigures != null) @@ -2762,6 +2771,15 @@ namespace VEPROMS } return rv; } + + private bool Same(byte[] p, byte[] rolookup) + { + if (p.Length != rolookup.Length) return false; + for (int i = 0; i < p.Length; i++) + if (p[i] != rolookup[i]) return false; + return true; + } + private void AddFigures(XmlNode xfigures, ROFst rofst) { foreach (XmlNode nd in xfigures.SelectNodes("figure")) @@ -2820,7 +2838,24 @@ namespace VEPROMS RODb rv = null; rv = RODb.GetByFolderPath(folderpath); if (rv == null) - rv = RODb.MakeRODb(roname, folderpath, dbconnectionstring, config, dts, userid); + { + // create a list of the RO databases currently in the database + List roDbNameList = new List(); + RODbInfoList rolist = RODbInfoList.Get(); + foreach (RODbInfo rodbinfo in rolist) + { + if (!roDbNameList.Contains(rodbinfo.ROName)) + roDbNameList.Add(rodbinfo.ROName); + } + rolist.Dispose(); + int cnt = 0; + string roNameNew = roname; + // if the ROname we are importing is the same as one already in the database + // and the ROpaths are different, then rename the one we are importing + while (roDbNameList.Contains(roNameNew)) + roNameNew = string.Format("{0}_{1}",roname,(++cnt).ToString()); + rv = RODb.MakeRODb(roNameNew, folderpath, dbconnectionstring, config, dts, userid); + } newRODbID = rv.RODbID; return rv; }