DataLoader changes during development
This commit is contained in:
145
PROMS/DataLoader/Formats.cs
Normal file
145
PROMS/DataLoader/Formats.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
// ========================================================================
|
||||
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
|
||||
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
||||
// ------------------------------------------------------------------------
|
||||
// $Workfile: $ $Revision: $
|
||||
// $Author: $ $Date: $
|
||||
//
|
||||
// $History: $
|
||||
// ========================================================================
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.Xml.XPath;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using VEPROMS.CSLA.Library;
|
||||
|
||||
namespace DataLoader
|
||||
{
|
||||
public partial class Loader
|
||||
{
|
||||
|
||||
private Format AddFormatToDB(Format parent, string format, bool issub, DateTime Dts, string Userid)
|
||||
{
|
||||
string fmtdata = null;
|
||||
string genmacdata = null;
|
||||
XmlDocument xd = null;
|
||||
|
||||
string path = "e:\\fmtall\\" + format + "all.xml";
|
||||
if (File.Exists(path))
|
||||
{
|
||||
xd = new XmlDocument();
|
||||
xd.Load(path);
|
||||
fmtdata = xd.OuterXml;
|
||||
}
|
||||
|
||||
// Do we need genmac - only if non-subformat
|
||||
if (!issub)
|
||||
{
|
||||
path = "e:\\genmacall\\" + format + ".svg";
|
||||
if (File.Exists(path))
|
||||
{
|
||||
XmlDocument xdg = new XmlDocument();
|
||||
xdg.Load(path);
|
||||
genmacdata = xdg.OuterXml;
|
||||
}
|
||||
}
|
||||
// Get the name & then create the record.
|
||||
if (Userid == null || Userid == "") Userid = "Migration";
|
||||
|
||||
string nmattr = "Default";
|
||||
|
||||
// use xpath to get name.
|
||||
if (parent != null)
|
||||
{
|
||||
XmlNode nmnode = xd.SelectSingleNode("//FormatData");
|
||||
if (nmnode is XmlElement)
|
||||
{
|
||||
XmlElement xm = (XmlElement)nmnode;
|
||||
nmattr = xm.GetAttribute("Name");
|
||||
}
|
||||
}
|
||||
// use the format name if base or non sub. If it's a sub, remove the "_".
|
||||
string fname = issub ? format.Replace("_", "") : format;
|
||||
Format rec = Format.MakeFormat(parent, fname, nmattr, fmtdata, genmacdata, Dts, Userid);
|
||||
return rec;
|
||||
}
|
||||
public void LoadAllFormats()
|
||||
{
|
||||
Format basefmt = null;
|
||||
Format parent = null;
|
||||
|
||||
// Load base format.
|
||||
basefmt = AddFormatToDB(null, "base", false, DateTime.Now, "Migration");
|
||||
|
||||
// now loop through all files... If there is an _ in the name, it's a subformat
|
||||
// (for example, AEP_00.xml) skip it in main loop, it's handled for each format.
|
||||
DirectoryInfo di = new DirectoryInfo("e:\\fmtall");
|
||||
FileInfo[] fis = di.GetFiles("*.xml");
|
||||
|
||||
foreach (FileInfo fi in fis)
|
||||
{
|
||||
bool issub = (fi.Name.IndexOf("_") > 0) ? true : false;
|
||||
if (!issub && fi.Name.ToLower()!="baseall.xml")
|
||||
{
|
||||
string fmtname = fi.Name.Substring(0, fi.Name.Length - 7);
|
||||
// remove the all.xml part of the filename.
|
||||
parent = AddFormatToDB(basefmt, fmtname, issub, DateTime.Now, "Migration");
|
||||
|
||||
// now see if there are any subformats associated with this, if so
|
||||
// add them here...
|
||||
DirectoryInfo sdi = new DirectoryInfo("e:\\fmtall");
|
||||
FileInfo[] sfis = di.GetFiles(fmtname+"_*.xml");
|
||||
foreach (FileInfo sfi in sfis)
|
||||
{
|
||||
string nm = sfi.Name.Substring(0, sfi.Name.Length-7);
|
||||
Format subfmt = AddFormatToDB(parent, nm, true, DateTime.Now, "Migration");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public Format GetFormat(string format)
|
||||
{
|
||||
Format parent = null;
|
||||
Format rec = null;
|
||||
|
||||
// get base
|
||||
Format baseparent = Format.Get(1);
|
||||
|
||||
// if there is no format - what should be done? maybe nothing.
|
||||
if (format == null || format == "") return null;
|
||||
|
||||
try
|
||||
{
|
||||
if (format.IndexOf(' ') > -1) // will have spaces if it's a user format
|
||||
{
|
||||
string part1 = format.Substring(0, format.IndexOf(' '));
|
||||
string part2 = format.Substring(format.LastIndexOf(' ') + 1, 2);
|
||||
format = part1 + part2;
|
||||
|
||||
// get the parent format's id (for example, AEP for AEP00).
|
||||
parent = Format.GetExistingByParentID_Name(baseparent.FormatID, part1);
|
||||
}
|
||||
else
|
||||
parent = baseparent;
|
||||
|
||||
// see if the format has been added, if not go get it.
|
||||
rec = Format.GetExistingByParentID_Name(parent.FormatID, format);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.ErrorFormat("Error getting xml version of format {0}", ex.Message);
|
||||
}
|
||||
return rec;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user