DataLoader changes during development
This commit is contained in:
@@ -19,13 +19,13 @@ using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Volian.CSLA.Library;
|
||||
using VEPROMS.CSLA.Library;
|
||||
|
||||
namespace DataLoader
|
||||
{
|
||||
public partial class frmLoader : Form
|
||||
public partial class Loader
|
||||
{
|
||||
private Int32 MigrateProcedure(OleDbConnection cn, DataRow dr, Byte FromType, Int32 FromID, string pth)
|
||||
private Item MigrateProcedure(OleDbConnection cn, DataRow dr, Item FromItem, string pth, DocVersion docver)
|
||||
{
|
||||
dicOldStepSequence = new Dictionary<object, string>();
|
||||
Stack<int> SubSectLevels = new Stack<int>(); // levels of subsections
|
||||
@@ -33,6 +33,7 @@ namespace DataLoader
|
||||
ProcNumber = dr["Number"].ToString();
|
||||
DateTime dts = GetDTS(dr["Date"].ToString(), dr["Time"].ToString());
|
||||
string userid = dr["initials"].ToString().Trim();
|
||||
if (userid == null || userid == "") userid = "Migration";
|
||||
|
||||
ConfigInfo ci = null;
|
||||
string tstr = dr["Proccode"].ToString();
|
||||
@@ -41,63 +42,92 @@ namespace DataLoader
|
||||
ci = new ConfigInfo(null);
|
||||
ci.AddItem("Procedure", "ProcCode", tstr);
|
||||
}
|
||||
tstr = dr["Series"].ToString();
|
||||
if (tstr != null && tstr != "")
|
||||
|
||||
// check that there is a "Series" column, i.e. the 10th column, some datasets
|
||||
// may not have it, for example vetuec\master.sl1
|
||||
if (dr.ItemArray.Length > 10)
|
||||
{
|
||||
if (ci == null) ci = new ConfigInfo(null);
|
||||
ci.AddItem("Procedure", "Series", tstr);
|
||||
tstr = dr["Series"].ToString();
|
||||
if (tstr != null && tstr != "")
|
||||
{
|
||||
if (ci == null) ci = new ConfigInfo(null);
|
||||
ci.AddItem("Procedure", "Series", tstr);
|
||||
}
|
||||
}
|
||||
|
||||
DataSet ds = new DataSet();
|
||||
DataTable dt = null;
|
||||
|
||||
// See if there is PSI and if so, add it to the xml.
|
||||
OleDbDataAdapter dapsi = new OleDbDataAdapter("select * from [" + dr["entry"] + "] where [STEP] is null", cn);
|
||||
dapsi.Fill(ds);
|
||||
dt = ds.Tables[0];
|
||||
|
||||
if (dt.Rows.Count > 0)
|
||||
// check that file exists, i.e. if proc file doesn't exist but has entry in set
|
||||
// file, flag error, but continue.
|
||||
string fname = frmMain.tbSourceText +"\\"+ dr["entry"] + ".dbf";
|
||||
if (File.Exists(fname))
|
||||
{
|
||||
DataRow drpsi = dt.Rows[0];
|
||||
string psistr = drpsi["TEXTM"].ToString();
|
||||
if (psistr != null && psistr != "")
|
||||
{
|
||||
StringReader strrd = new StringReader(psistr);
|
||||
// if the dbt is bad, fix it.
|
||||
DbtOk(dr["entry"].ToString());
|
||||
// See if there is PSI and if so, add it to the xml.
|
||||
OleDbDataAdapter dapsi = new OleDbDataAdapter("select * from [" + dr["entry"] + "] where [STEP] is null", cn);
|
||||
try
|
||||
{
|
||||
dapsi.Fill(ds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
Application.Exit();
|
||||
}
|
||||
dt = ds.Tables[0];
|
||||
|
||||
string sLine;
|
||||
if (ci == null) ci = new ConfigInfo(null);
|
||||
while ((sLine = strrd.ReadLine()) != null)
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
DataRow drpsi = dt.Rows[0];
|
||||
string psistr = drpsi["TEXTM"].ToString();
|
||||
if (psistr != null && psistr != "")
|
||||
{
|
||||
int indx = sLine.IndexOf(' ');
|
||||
string nm = null;
|
||||
string vl = null;
|
||||
if (indx < 0)
|
||||
nm = sLine;
|
||||
else
|
||||
StringReader strrd = new StringReader(psistr);
|
||||
|
||||
string sLine;
|
||||
if (ci == null) ci = new ConfigInfo(null);
|
||||
while ((sLine = strrd.ReadLine()) != null)
|
||||
{
|
||||
nm = sLine.Substring(0, indx);
|
||||
vl = sLine.Substring(indx+1, sLine.Length-indx-1);
|
||||
int indx = sLine.IndexOf(' ');
|
||||
string nm = null;
|
||||
string vl = null;
|
||||
if (indx < 0)
|
||||
nm = sLine;
|
||||
else
|
||||
{
|
||||
nm = sLine.Substring(0, indx);
|
||||
vl = sLine.Substring(indx + 1, sLine.Length - indx - 1);
|
||||
}
|
||||
ci.AddItem("PSI", nm, vl == null ? null : vl);
|
||||
}
|
||||
ci.AddItem("PSI", nm, vl==null?null:vl);
|
||||
}
|
||||
}
|
||||
dapsi.Dispose();
|
||||
}
|
||||
else // log an error
|
||||
{
|
||||
log.ErrorFormat("Missing DBF: {0}", fname);
|
||||
}
|
||||
dapsi.Dispose();
|
||||
|
||||
// Note, for now the data from the format field will be saved. Later, xpath, ??
|
||||
EditSectId = 0;
|
||||
|
||||
Byte FrType = 2;
|
||||
Int32 FrID = 0;// str.Structureid;
|
||||
Procedure prc = Procedure.MakeProcedure(TextConvert.ConvertText(dr["Number"].ToString()), TextConvert.ConvertText(dr["Title"].ToString()), ci==null?null:ci.ToString(), null, 0, 0, dts, userid);
|
||||
Structure str = Structure.MakeStructure(FromType, FromID, 1, prc.ProcID, dts, userid);
|
||||
UpdateLabels(1, 0, 0);
|
||||
//OleDbDataAdapter da = new OleDbDataAdapter("select * from (select asc(mid(sequence,2,1)) as locb,* from [" + dr["entry"] + "] where sequence like ' %') order by locb asc", cn);
|
||||
|
||||
// See if no caret convert...
|
||||
Format docverFormat = docver.ActiveFormat;
|
||||
bool do_cvt = !(docverFormat.PlantFormat.FormatData.XtraOptions("DontConvertCarrotToDelta"));
|
||||
// pass in a 0 on MakeContent for type of procedure, i.e. procedure = 0 (on type field)
|
||||
Content cont = Content.New(TextConvert.ConvertText(dr["Number"].ToString()), TextConvert.ConvertText(dr["Title"].ToString(),do_cvt), 0, null, ci == null ? null : ci.ToString(), dts, userid);
|
||||
Item itm = Item.MakeItem(FromItem, cont, dts, userid);
|
||||
frmMain.UpdateLabels(1, 0, 0);
|
||||
Database.LogInfoFormat("Processing Procedure [{0}] - [{1}] - {2} - {3}", frmMain.pbProcValue, dr["entry"], cont.Number, cont.Text);
|
||||
|
||||
OleDbDataAdapter da = new OleDbDataAdapter("select * from [" + dr["entry"] + "] where sequence like ' %'", cn);
|
||||
try
|
||||
{
|
||||
LoadSection(ds, da, dr["entry"].ToString());
|
||||
da.SelectCommand.CommandText = "select * from [" + dr["entry"] + "] where step not like ' '";
|
||||
da.SelectCommand.CommandText = "select * from [" + dr["entry"] + "] where step not like ' ' and step not like '%~'";
|
||||
da.Fill(ds, "Steps");
|
||||
dt = ds.Tables["Steps"];
|
||||
dt.CaseSensitive = true;
|
||||
@@ -119,71 +149,108 @@ namespace DataLoader
|
||||
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
|
||||
log.Error(ex.StackTrace);
|
||||
}
|
||||
|
||||
|
||||
// dicSecCount is dictionary to track number of subsections for the parent at a level
|
||||
// dicSecID is the parent at that level
|
||||
Dictionary<int, int> dicSecCount = new Dictionary<int, int>();
|
||||
Dictionary<int, int> dicSecID = new Dictionary<int, int>();
|
||||
pbSect.Maximum = ds.Tables["Sections"].Rows.Count;
|
||||
pbSect.Value = 0;
|
||||
Dictionary<int, Item> dicSecParentItem = new Dictionary<int, Item>();
|
||||
frmMain.pbSectMaximum = ds.Tables["Sections"].Rows.Count;
|
||||
frmMain.pbSectValue = 0;
|
||||
|
||||
DataTable dtsect = ds.Tables["Sections"];
|
||||
dtsect.CaseSensitive = true;
|
||||
DataView dv = new DataView(dtsect, "", "locb", DataViewRowState.CurrentRows);
|
||||
Item SectItm = null;
|
||||
int level = 0;
|
||||
bool addpart = true;
|
||||
Item parentitem = itm;
|
||||
foreach (DataRowView drw in dv)
|
||||
{
|
||||
FrID = MigrateSection(prc, cn, drw, ds.Tables["Steps"], FrType, FrID, dicSecCount.Count > 0 ? true : false, pth);
|
||||
if (prc.StructureID == 0)
|
||||
SectItm = MigrateSection(parentitem, cont.Number, cn, drw, ds.Tables["Steps"], SectItm, dicSecCount.Count > 0 ? true : false, pth, docver);
|
||||
|
||||
// if no children, add first child (cont)
|
||||
if (addpart)
|
||||
{
|
||||
prc.StructureID = FrID;
|
||||
prc.Save(true); //force update
|
||||
// ContentsParts.Add can use 'fromtype', item - fromtype here = 2, section
|
||||
cont.ContentParts.Add(2,SectItm);
|
||||
if (cont.MyZContent.OldStepSequence == null || cont.MyZContent.OldStepSequence == "") cont.MyZContent.OldStepSequence = ProcNumber;
|
||||
if (!cont.IsSavable) ErrorRpt.ErrorReport(cont);
|
||||
cont.Save();
|
||||
addpart = false;
|
||||
}
|
||||
FrType = 0;
|
||||
dicSecID[dicSecCount.Count] = FrID;
|
||||
if (dicSecCount.Count > 0)
|
||||
//FrType = 0;
|
||||
dicSecParentItem[level] = SectItm;
|
||||
if (level > 0)
|
||||
{
|
||||
if ((dicSecCount[dicSecCount.Count]) == 1)
|
||||
{
|
||||
dicSecCount.Remove(dicSecCount.Count);
|
||||
FrID = dicSecID[dicSecCount.Count];
|
||||
}
|
||||
if ((dicSecCount[level]) == 1)
|
||||
// shift up a level, i.e. give me the parent for the previous level
|
||||
SectItm = dicSecParentItem[--level];
|
||||
else
|
||||
{
|
||||
dicSecCount[dicSecCount.Count] = dicSecCount[dicSecCount.Count] - 1;
|
||||
}
|
||||
dicSecCount[level]--; // decrements number of sections to process
|
||||
}
|
||||
// get number of subsections for this section
|
||||
int subSecs = drw["Sequence"].ToString().PadRight(12, ' ')[5] - 48;
|
||||
if (subSecs > 0)
|
||||
{
|
||||
dicSecCount[dicSecCount.Count + 1] = subSecs;
|
||||
FrType = 2;
|
||||
dicSecCount[++level] = subSecs;
|
||||
cont = SectItm.MyContent;
|
||||
parentitem = SectItm;
|
||||
addpart = true;
|
||||
SectItm = null; // no previous sibling for the first child node.
|
||||
}
|
||||
}
|
||||
// need section start
|
||||
if (EditSectId != 0)
|
||||
{
|
||||
prc.StructureStart = EditSectId;
|
||||
EditSectId = 0;
|
||||
prc.Save(true); // force update
|
||||
if (ci == null) ci = new ConfigInfo(null);
|
||||
ci.AddItem("Procedure", "SectionStart", string.Format("{0}", EditSectId));
|
||||
itm.MyContent.Config = (ci == null) ? null : ci.ToString();
|
||||
if (!itm.IsSavable) ErrorRpt.ErrorReport(itm);
|
||||
itm.Save();
|
||||
}
|
||||
return str.StructureID;
|
||||
return itm;
|
||||
}
|
||||
private Int32 MigrateProcedures(OleDbConnection cn, string pth)
|
||||
private Item MigrateProcedures(OleDbConnection cn, string pth, DocVersion docver)
|
||||
{
|
||||
// Loop through Set File for each Procedure
|
||||
OleDbDataAdapter da = new OleDbDataAdapter("Select * from [set] where entry is not null", cn);
|
||||
DataSet ds = new DataSet();
|
||||
da.Fill(ds);
|
||||
Byte FrType = 1;
|
||||
Int32 FrID = 0;
|
||||
Int32 FirstID = 0;
|
||||
pbProc.Maximum = ds.Tables[0].Rows.Count;
|
||||
UpdateLabels(0, 0, 0);
|
||||
Item FrItm = null;
|
||||
Item FirstItm = null;
|
||||
frmMain.pbProcMaximum = ds.Tables[0].Rows.Count;
|
||||
frmMain.UpdateLabels(0, 0, 0);
|
||||
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
FrID = MigrateProcedure(cn, dr, FrType, FrID, pth);
|
||||
if (FirstID == 0) FirstID = FrID;
|
||||
FrType = 0;
|
||||
FrItm = MigrateProcedure(cn, dr, FrItm, pth, docver);
|
||||
if (FirstItm == null) FirstItm = FrItm;
|
||||
}
|
||||
da.Dispose();
|
||||
return FirstID;
|
||||
return FirstItm;
|
||||
}
|
||||
private void DbtOk(string fname)
|
||||
{
|
||||
string dbtname = frmMain.tbSourceText + "\\" + fname + ".dbt";
|
||||
if (File.Exists(dbtname))
|
||||
{
|
||||
// check if dbt is at least 512, if not append 508 bytes. This is to fix
|
||||
// a problem where dbts were created with only 4 bytes in the 16-bit code.
|
||||
// if only 4 bytes, ado.net gives an "External table not in expected format"
|
||||
// error
|
||||
FileInfo fi = new FileInfo(dbtname);
|
||||
if (fi.Length < 512)
|
||||
{
|
||||
FileStream fs = new FileStream(dbtname, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);
|
||||
BinaryWriter bw = new BinaryWriter(fs);
|
||||
bw.Seek(0, SeekOrigin.End);
|
||||
byte[] wrBytes = new byte[512 - fi.Length];
|
||||
for (int i = 0; i < 512 - fi.Length; i++) wrBytes[i] = 0;
|
||||
wrBytes[4] = 0x02;
|
||||
bw.Write(wrBytes);
|
||||
bw.Close();
|
||||
}
|
||||
fi = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user