189 lines
7.3 KiB
C#
189 lines
7.3 KiB
C#
// ========================================================================
|
|
// 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.IO;
|
|
using System.Text;
|
|
using Volian.CSLA.Library;
|
|
|
|
namespace DataLoader
|
|
{
|
|
public partial class frmLoader : Form
|
|
{
|
|
private Int32 MigrateProcedure(OleDbConnection cn, DataRow dr, Byte FromType, Int32 FromID, string pth)
|
|
{
|
|
dicOldStepSequence = new Dictionary<object, string>();
|
|
Stack<int> SubSectLevels = new Stack<int>(); // levels of subsections
|
|
ProcFileName = dr["Entry"].ToString();
|
|
ProcNumber = dr["Number"].ToString();
|
|
DateTime dts = GetDTS(dr["Date"].ToString(), dr["Time"].ToString());
|
|
string userid = dr["initials"].ToString().Trim();
|
|
|
|
ConfigInfo ci = null;
|
|
string tstr = dr["Proccode"].ToString();
|
|
if (tstr != null && tstr != "")
|
|
{
|
|
ci = new ConfigInfo(null);
|
|
ci.AddItem("Procedure", "ProcCode", 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)
|
|
{
|
|
DataRow drpsi = dt.Rows[0];
|
|
string psistr = drpsi["TEXTM"].ToString();
|
|
if (psistr != null && psistr != "")
|
|
{
|
|
StringReader strrd = new StringReader(psistr);
|
|
|
|
string sLine;
|
|
if (ci == null) ci = new ConfigInfo(null);
|
|
while ((sLine = strrd.ReadLine()) != null)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
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);
|
|
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.Fill(ds, "Steps");
|
|
dt = ds.Tables["Steps"];
|
|
dt.CaseSensitive = true;
|
|
ds.Tables["Steps"].CaseSensitive = true;
|
|
dt.Columns.Add("CStep", System.Type.GetType("System.String"));
|
|
dt.Columns.Add("CSequence", System.Type.GetType("System.String"));
|
|
// set the cstep & csequence - couldn't do it in the add because it needed a sql function
|
|
foreach (DataRow drw in ds.Tables["Steps"].Rows)
|
|
{
|
|
drw["CStep"] = TextConvert.ConvertSeq(drw["Step"].ToString());
|
|
drw["CSequence"] = TextConvert.ConvertSeq(drw["Sequence"].ToString());
|
|
}
|
|
dt.Columns.Add("StepNo", System.Type.GetType("System.Int32"), "Convert(Convert(Substring(CStep,2,1),'System.Char'),'System.Int32')-48");
|
|
dt.Columns.Add("Level", System.Type.GetType("System.Int32"), "Len(CSequence)");
|
|
dt.Columns.Add("SubStepNo", System.Type.GetType("System.Int32"), "Convert(Convert(Substring(CSequence,Len(CSequence),1),'System.Char'),'System.Int32')-48");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
|
|
log.Error(ex.StackTrace);
|
|
}
|
|
|
|
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;
|
|
|
|
DataTable dtsect = ds.Tables["Sections"];
|
|
dtsect.CaseSensitive = true;
|
|
DataView dv = new DataView(dtsect, "", "locb", DataViewRowState.CurrentRows);
|
|
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)
|
|
{
|
|
prc.StructureID = FrID;
|
|
prc.Save(true); //force update
|
|
}
|
|
FrType = 0;
|
|
dicSecID[dicSecCount.Count] = FrID;
|
|
if (dicSecCount.Count > 0)
|
|
{
|
|
if ((dicSecCount[dicSecCount.Count]) == 1)
|
|
{
|
|
dicSecCount.Remove(dicSecCount.Count);
|
|
FrID = dicSecID[dicSecCount.Count];
|
|
}
|
|
else
|
|
{
|
|
dicSecCount[dicSecCount.Count] = dicSecCount[dicSecCount.Count] - 1;
|
|
}
|
|
}
|
|
int subSecs = drw["Sequence"].ToString().PadRight(12, ' ')[5] - 48;
|
|
if (subSecs > 0)
|
|
{
|
|
dicSecCount[dicSecCount.Count + 1] = subSecs;
|
|
FrType = 2;
|
|
}
|
|
}
|
|
if (EditSectId != 0)
|
|
{
|
|
prc.StructureStart = EditSectId;
|
|
EditSectId = 0;
|
|
prc.Save(true); // force update
|
|
}
|
|
return str.StructureID;
|
|
}
|
|
private Int32 MigrateProcedures(OleDbConnection cn, string pth)
|
|
{
|
|
// 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);
|
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
|
{
|
|
FrID = MigrateProcedure(cn, dr, FrType, FrID, pth);
|
|
if (FirstID == 0) FirstID = FrID;
|
|
FrType = 0;
|
|
}
|
|
da.Dispose();
|
|
return FirstID;
|
|
}
|
|
}
|
|
} |