Added code to prevent multiple instances of library documents

This commit is contained in:
Rich 2014-06-20 02:28:38 +00:00
parent fbe6dba810
commit ec4d47c4a3
2 changed files with 91 additions and 13 deletions

View File

@ -53,11 +53,14 @@ namespace DataLoader
PEIPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\VEPROMS\PEI_" + Database.VEPROMS_SqlConnection.Database; PEIPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\VEPROMS\PEI_" + Database.VEPROMS_SqlConnection.Database;
if (!Directory.Exists(PEIPath)) if (!Directory.Exists(PEIPath))
Directory.CreateDirectory(PEIPath); Directory.CreateDirectory(PEIPath);
if (_MyMode == "Import")
{
if (MyFolder.ChildFolderCount == 0) if (MyFolder.ChildFolderCount == 0)
{ {
Directory.Delete(PEIPath, true); Directory.Delete(PEIPath, true);
Directory.CreateDirectory(PEIPath); Directory.CreateDirectory(PEIPath);
} }
}
pnlExport.Dock = DockStyle.Fill; pnlExport.Dock = DockStyle.Fill;
pnlImport.Dock = DockStyle.Fill; pnlImport.Dock = DockStyle.Fill;
if (_MyMode.ToLower() == "export") if (_MyMode.ToLower() == "export")
@ -586,6 +589,19 @@ namespace DataLoader
//if (!Old2NewContent.ContainsKey(oldid)) //if (!Old2NewContent.ContainsKey(oldid))
Old2NewContent.Add(oldid, newid); Old2NewContent.Add(oldid, newid);
} }
ze = MyImpxZipFile["libdocs.xml"];
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\libdocs.xml";
xd = new XmlDocument();
xd.Load(fn);
nl = xd.SelectNodes("//libdoc");
foreach (XmlNode nd in nl)
{
int oldid = int.Parse(nd.Attributes.GetNamedItem("old").InnerText);
int newid = int.Parse(nd.Attributes.GetNamedItem("new").InnerText);
//if (!Old2NewContent.ContainsKey(oldid))
Old2NewLibDoc.Add(oldid, newid);
}
ze = MyImpxZipFile["transitions.xml"]; ze = MyImpxZipFile["transitions.xml"];
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently); ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\transitions.xml"; fn = PEIPath + @"\transitions.xml";
@ -721,6 +737,7 @@ namespace DataLoader
{ {
Old2NewItem = new Dictionary<int, int>(); Old2NewItem = new Dictionary<int, int>();
Old2NewContent = new Dictionary<int, int>(); Old2NewContent = new Dictionary<int, int>();
Old2NewLibDoc = new Dictionary<int, int>();
PendingTransitions = new XmlDocument(); PendingTransitions = new XmlDocument();
FileInfo fi = new FileInfo(ofd.FileName); FileInfo fi = new FileInfo(ofd.FileName);
string dn = fi.Directory.Name; string dn = fi.Directory.Name;
@ -763,6 +780,15 @@ namespace DataLoader
MyImpxZipFile.AddFile(fn, ""); MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save(); MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
//libdocids
xd = new XmlDocument();
xe = xd.CreateElement("libdocs");
xd.AppendChild(xe);
fn = PEIPath + @"\libdocs.xml";
xd.Save(fn);
MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save();
File.Delete(fn);
} }
} }
} }
@ -1769,12 +1795,14 @@ namespace DataLoader
} }
private Dictionary<int, int> Old2NewItem; private Dictionary<int, int> Old2NewItem;
private Dictionary<int, int> Old2NewContent; private Dictionary<int, int> Old2NewContent;
private Dictionary<int, int> Old2NewLibDoc;
private XmlDocument PendingTransitions; private XmlDocument PendingTransitions;
private RODb MyRODb = null; private RODb MyRODb = null;
private Folder AddFolder(Folder folder, XmlReader xr) private Folder AddFolder(Folder folder, XmlReader xr)
{ {
Old2NewItem = new Dictionary<int, int>(); Old2NewItem = new Dictionary<int, int>();
Old2NewContent = new Dictionary<int, int>(); Old2NewContent = new Dictionary<int, int>();
Old2NewLibDoc = new Dictionary<int, int>();
string title = xr.GetAttribute("title"); string title = xr.GetAttribute("title");
string name = xr.GetAttribute("name"); string name = xr.GetAttribute("name");
string shortname = xr.GetAttribute("shortname"); string shortname = xr.GetAttribute("shortname");
@ -2633,6 +2661,15 @@ namespace DataLoader
Entry ee = Entry.MakeEntry(content, dd, dts, userid); Entry ee = Entry.MakeEntry(content, dd, dts, userid);
} }
private Document AddDocument(XmlNode xn) private Document AddDocument(XmlNode xn)
{
Document d;
int docid = int.Parse(xn.Attributes.GetNamedItem("docid").InnerText);
if (Old2NewLibDoc.ContainsKey(docid))
{
docid = Old2NewLibDoc[docid];
d = Document.Get(docid);
}
else
{ {
string libtitle = xn.Attributes.GetNamedItem("libtitle").InnerText; string libtitle = xn.Attributes.GetNamedItem("libtitle").InnerText;
byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText); byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText);
@ -2641,8 +2678,10 @@ namespace DataLoader
string userid = xn.Attributes.GetNamedItem("userid").InnerText; string userid = xn.Attributes.GetNamedItem("userid").InnerText;
DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").InnerText); DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").InnerText);
string fileextension = xn.Attributes.GetNamedItem("fileextension").InnerText; string fileextension = xn.Attributes.GetNamedItem("fileextension").InnerText;
Document d = Document.MakeDocument(libtitle, doccontent, docascii, config, dts, userid, fileextension); d = Document.MakeDocument(libtitle, doccontent, docascii, config, dts, userid, fileextension);
d.Save(); d.Save();
Old2NewLibDoc.Add(docid, d.DocID);
}
return d; return d;
} }
#endregion #endregion

View File

@ -53,11 +53,14 @@ namespace VEPROMS
PEIPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\VEPROMS\PEI_" + Database.VEPROMS_SqlConnection.Database; PEIPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\VEPROMS\PEI_" + Database.VEPROMS_SqlConnection.Database;
if (!Directory.Exists(PEIPath)) if (!Directory.Exists(PEIPath))
Directory.CreateDirectory(PEIPath); Directory.CreateDirectory(PEIPath);
if (_MyMode == "Import")
{
if (MyFolder.ChildFolderCount == 0) if (MyFolder.ChildFolderCount == 0)
{ {
Directory.Delete(PEIPath,true); Directory.Delete(PEIPath, true);
Directory.CreateDirectory(PEIPath); Directory.CreateDirectory(PEIPath);
} }
}
pnlExport.Dock = DockStyle.Fill; pnlExport.Dock = DockStyle.Fill;
pnlImport.Dock = DockStyle.Fill; pnlImport.Dock = DockStyle.Fill;
if (_MyMode.ToLower() == "export") if (_MyMode.ToLower() == "export")
@ -586,6 +589,19 @@ namespace VEPROMS
//if (!Old2NewContent.ContainsKey(oldid)) //if (!Old2NewContent.ContainsKey(oldid))
Old2NewContent.Add(oldid, newid); Old2NewContent.Add(oldid, newid);
} }
ze = MyImpxZipFile["libdocs.xml"];
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\libdocs.xml";
xd = new XmlDocument();
xd.Load(fn);
nl = xd.SelectNodes("//libdoc");
foreach (XmlNode nd in nl)
{
int oldid = int.Parse(nd.Attributes.GetNamedItem("old").InnerText);
int newid = int.Parse(nd.Attributes.GetNamedItem("new").InnerText);
//if (!Old2NewContent.ContainsKey(oldid))
Old2NewLibDoc.Add(oldid, newid);
}
ze = MyImpxZipFile["transitions.xml"]; ze = MyImpxZipFile["transitions.xml"];
ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently); ze.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\transitions.xml"; fn = PEIPath + @"\transitions.xml";
@ -721,6 +737,7 @@ namespace VEPROMS
{ {
Old2NewItem = new Dictionary<int, int>(); Old2NewItem = new Dictionary<int, int>();
Old2NewContent = new Dictionary<int, int>(); Old2NewContent = new Dictionary<int, int>();
Old2NewLibDoc = new Dictionary<int, int>();
PendingTransitions = new XmlDocument(); PendingTransitions = new XmlDocument();
FileInfo fi = new FileInfo(ofd.FileName); FileInfo fi = new FileInfo(ofd.FileName);
string dn = fi.Directory.Name; string dn = fi.Directory.Name;
@ -763,6 +780,15 @@ namespace VEPROMS
MyImpxZipFile.AddFile(fn, ""); MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save(); MyImpxZipFile.Save();
File.Delete(fn); File.Delete(fn);
//libdocids
xd = new XmlDocument();
xe = xd.CreateElement("libdocs");
xd.AppendChild(xe);
fn = PEIPath + @"\libdocs.xml";
xd.Save(fn);
MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save();
File.Delete(fn);
} }
} }
} }
@ -1769,12 +1795,14 @@ namespace VEPROMS
} }
private Dictionary<int, int> Old2NewItem; private Dictionary<int, int> Old2NewItem;
private Dictionary<int, int> Old2NewContent; private Dictionary<int, int> Old2NewContent;
private Dictionary<int, int> Old2NewLibDoc;
private XmlDocument PendingTransitions; private XmlDocument PendingTransitions;
private RODb MyRODb = null; private RODb MyRODb = null;
private Folder AddFolder(Folder folder, XmlReader xr) private Folder AddFolder(Folder folder, XmlReader xr)
{ {
Old2NewItem = new Dictionary<int, int>(); Old2NewItem = new Dictionary<int, int>();
Old2NewContent = new Dictionary<int, int>(); Old2NewContent = new Dictionary<int, int>();
Old2NewLibDoc = new Dictionary<int, int>();
string title = xr.GetAttribute("title"); string title = xr.GetAttribute("title");
string name = xr.GetAttribute("name"); string name = xr.GetAttribute("name");
string shortname = xr.GetAttribute("shortname"); string shortname = xr.GetAttribute("shortname");
@ -2634,6 +2662,15 @@ namespace VEPROMS
} }
private Document AddDocument(XmlNode xn) private Document AddDocument(XmlNode xn)
{ {
Document d;
int docid = int.Parse(xn.Attributes.GetNamedItem("docid").InnerText);
if (Old2NewLibDoc.ContainsKey(docid))
{
docid = Old2NewLibDoc[docid];
d = Document.Get(docid);
}
else
{
string libtitle = xn.Attributes.GetNamedItem("libtitle").InnerText; string libtitle = xn.Attributes.GetNamedItem("libtitle").InnerText;
byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText); byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText);
string docascii = xn.Attributes.GetNamedItem("docascii").InnerText; string docascii = xn.Attributes.GetNamedItem("docascii").InnerText;
@ -2641,8 +2678,10 @@ namespace VEPROMS
string userid = xn.Attributes.GetNamedItem("userid").InnerText; string userid = xn.Attributes.GetNamedItem("userid").InnerText;
DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").InnerText); DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").InnerText);
string fileextension = xn.Attributes.GetNamedItem("fileextension").InnerText; string fileextension = xn.Attributes.GetNamedItem("fileextension").InnerText;
Document d = Document.MakeDocument(libtitle, doccontent, docascii, config, dts, userid, fileextension); d = Document.MakeDocument(libtitle, doccontent, docascii, config, dts, userid, fileextension);
d.Save(); d.Save();
Old2NewLibDoc.Add(docid, d.DocID);
}
return d; return d;
} }
#endregion #endregion