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;
if (!Directory.Exists(PEIPath))
Directory.CreateDirectory(PEIPath);
if (_MyMode == "Import")
{
if (MyFolder.ChildFolderCount == 0)
{
Directory.Delete(PEIPath, true);
Directory.CreateDirectory(PEIPath);
}
}
pnlExport.Dock = DockStyle.Fill;
pnlImport.Dock = DockStyle.Fill;
if (_MyMode.ToLower() == "export")
@ -586,6 +589,19 @@ namespace DataLoader
//if (!Old2NewContent.ContainsKey(oldid))
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.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\transitions.xml";
@ -721,6 +737,7 @@ namespace DataLoader
{
Old2NewItem = new Dictionary<int, int>();
Old2NewContent = new Dictionary<int, int>();
Old2NewLibDoc = new Dictionary<int, int>();
PendingTransitions = new XmlDocument();
FileInfo fi = new FileInfo(ofd.FileName);
string dn = fi.Directory.Name;
@ -763,6 +780,15 @@ namespace DataLoader
MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save();
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> Old2NewContent;
private Dictionary<int, int> Old2NewLibDoc;
private XmlDocument PendingTransitions;
private RODb MyRODb = null;
private Folder AddFolder(Folder folder, XmlReader xr)
{
Old2NewItem = new Dictionary<int, int>();
Old2NewContent = new Dictionary<int, int>();
Old2NewLibDoc = new Dictionary<int, int>();
string title = xr.GetAttribute("title");
string name = xr.GetAttribute("name");
string shortname = xr.GetAttribute("shortname");
@ -2634,6 +2662,15 @@ namespace DataLoader
}
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;
byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText);
string docascii = xn.Attributes.GetNamedItem("docascii").InnerText;
@ -2641,8 +2678,10 @@ namespace DataLoader
string userid = xn.Attributes.GetNamedItem("userid").InnerText;
DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").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();
Old2NewLibDoc.Add(docid, d.DocID);
}
return d;
}
#endregion

View File

@ -53,10 +53,13 @@ namespace VEPROMS
PEIPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\VEPROMS\PEI_" + Database.VEPROMS_SqlConnection.Database;
if (!Directory.Exists(PEIPath))
Directory.CreateDirectory(PEIPath);
if (MyFolder.ChildFolderCount == 0)
if (_MyMode == "Import")
{
Directory.Delete(PEIPath,true);
Directory.CreateDirectory(PEIPath);
if (MyFolder.ChildFolderCount == 0)
{
Directory.Delete(PEIPath, true);
Directory.CreateDirectory(PEIPath);
}
}
pnlExport.Dock = DockStyle.Fill;
pnlImport.Dock = DockStyle.Fill;
@ -586,6 +589,19 @@ namespace VEPROMS
//if (!Old2NewContent.ContainsKey(oldid))
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.Extract(PEIPath, ExtractExistingFileAction.OverwriteSilently);
fn = PEIPath + @"\transitions.xml";
@ -721,6 +737,7 @@ namespace VEPROMS
{
Old2NewItem = new Dictionary<int, int>();
Old2NewContent = new Dictionary<int, int>();
Old2NewLibDoc = new Dictionary<int, int>();
PendingTransitions = new XmlDocument();
FileInfo fi = new FileInfo(ofd.FileName);
string dn = fi.Directory.Name;
@ -763,6 +780,15 @@ namespace VEPROMS
MyImpxZipFile.AddFile(fn, "");
MyImpxZipFile.Save();
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> Old2NewContent;
private Dictionary<int, int> Old2NewLibDoc;
private XmlDocument PendingTransitions;
private RODb MyRODb = null;
private Folder AddFolder(Folder folder, XmlReader xr)
{
Old2NewItem = new Dictionary<int, int>();
Old2NewContent = new Dictionary<int, int>();
Old2NewLibDoc = new Dictionary<int, int>();
string title = xr.GetAttribute("title");
string name = xr.GetAttribute("name");
string shortname = xr.GetAttribute("shortname");
@ -2634,15 +2662,26 @@ namespace VEPROMS
}
private Document AddDocument(XmlNode xn)
{
string libtitle = xn.Attributes.GetNamedItem("libtitle").InnerText;
byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText);
string docascii = xn.Attributes.GetNamedItem("docascii").InnerText;
string config = xn.Attributes.GetNamedItem("config").InnerText;
string userid = xn.Attributes.GetNamedItem("userid").InnerText;
DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").InnerText);
string fileextension = xn.Attributes.GetNamedItem("fileextension").InnerText;
Document d = Document.MakeDocument(libtitle, doccontent, docascii, config, dts, userid, fileextension);
d.Save();
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;
byte[] doccontent = Convert.FromBase64String(xn.Attributes.GetNamedItem("doccontent").InnerText);
string docascii = xn.Attributes.GetNamedItem("docascii").InnerText;
string config = xn.Attributes.GetNamedItem("config").InnerText;
string userid = xn.Attributes.GetNamedItem("userid").InnerText;
DateTime dts = DateTime.Parse(xn.Attributes.GetNamedItem("dts").InnerText);
string fileextension = xn.Attributes.GetNamedItem("fileextension").InnerText;
d = Document.MakeDocument(libtitle, doccontent, docascii, config, dts, userid, fileextension);
d.Save();
Old2NewLibDoc.Add(docid, d.DocID);
}
return d;
}
#endregion