DataLoader changes during development

This commit is contained in:
2007-11-14 14:49:18 +00:00
parent da9b899424
commit ef81207dbe
28 changed files with 2118 additions and 962 deletions

View File

@@ -10,19 +10,21 @@ 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 Step AddStep(OleDbConnection cn, string StepType, string Textm, string Recid, string stpseq, string structtype, int structid, DateTime dts, string userid)
private Item AddStep(OleDbConnection cn, string StepType, string Textm, string Recid, string stpseq, string structtype, Item FromItem, DateTime dts, string userid, bool conv_caret)
{
Step stp = null;
UpdateLabels(0, 0, 1);
bool hasxml = false;
ConfigInfo ci = new ConfigInfo(null);
Content content = null;
Item item = null;
frmMain.UpdateLabels(0, 0, 1);
ConfigInfo ci = null;
string stptext = null;
if (userid == null || userid == "") userid = "Migration";
int tok = -1;
char[] chrarr = { '\x1', '\x2', '\x3', '\x5' };
try
@@ -31,9 +33,9 @@ namespace DataLoader
// with it with a 'token' as a separator (see below).
tok = Textm.IndexOfAny(chrarr);
if (tok < 0)
stptext = TextConvert.ConvertText(Textm);
stptext = TextConvert.ConvertText(Textm, conv_caret);
else
stptext = TextConvert.ConvertText(Textm.Substring(0, tok));
stptext = TextConvert.ConvertText(Textm.Substring(0, tok), conv_caret);
string seqcvt = TextConvert.ConvertSeq(stpseq);
@@ -44,9 +46,30 @@ namespace DataLoader
log.Error("Found a old style figure!");
log.ErrorFormat("oldstepsequence = {0}", stpseq);
}
string newstptyp = null;
bool ManualPagebreak = false;
char cbittst = StepType.PadRight(2)[0];
if (cbittst != ' ' && (cbittst & 0x80) > 1)
{
ManualPagebreak = true;
if (ci==null) ci = new ConfigInfo(null);
ci.AddItem("Step", "ManualPagebreak", "True");
newstptyp = StepType.Substring(1, 1);
}
// Need the content record for the RO & transitions.
//content = Content.MakeContent(null, stptext, 20000 + int.Parse(newstptyp!=null?newstptyp:StepType),null, ManualPagebreak?ci.ToString():null, dts, userid);
content = Content.New(null, stptext, 20000 + int.Parse(newstptyp != null ? newstptyp : StepType), null, ManualPagebreak ? ci.ToString() : null, dts, userid);
content.MyZContent.OldStepSequence = ProcNumber + "|" + stpseq;
// Before we save it, handle RO & Transitions tokens.
int tokrt = Textm.IndexOf('\x15');
if (tokrt > -1) stptext = MigrateRos(cn, stptext, seqcvt, structid);
bool txtdirty = false;
if (tokrt > -1)
{
txtdirty = true;
stptext = MigrateRos(cn, stptext, seqcvt, content);
}
// 16-bit code has the following two defines.
// #define TransitionMarker 0xC2
@@ -55,10 +78,34 @@ namespace DataLoader
// use the unicode chars.
char[] chrrotrn = { '\x252C', '\x2566' };
tokrt = Textm.IndexOfAny(chrrotrn);
if (tokrt > -1) stptext = MigrateTrans(cn, stptext, seqcvt, structid);
TextM tm = TextM.MakeTextM(stptext);
stp = Step.MakeStep(StepType, tm.TextMID, null, dts, userid);
dicOldStepSequence[stp] = seqcvt;
if (tokrt > -1)
{
txtdirty = true;
stptext = MigrateTrans(cn, stptext, seqcvt, content);
}
if (txtdirty)
{
content.Text = stptext;
//content.Save();
}
if (!content.IsSavable) ErrorRpt.ErrorReport(content);
content.Save();
// check if already created thru new during transition migration...
if (dicTrans_ItemIds.ContainsKey(ProcNumber + "|" + seqcvt))
{
item = dicTrans_ItemIds[ProcNumber + "|" + seqcvt];
item.MyPrevious = FromItem;
item.MyContent = content;
item.DTS = dts;
item.UserID = userid;
if (!item.IsSavable) ErrorRpt.ErrorReport(item);
item.Save();
dicTrans_ItemIds.Remove(ProcNumber + "|" + seqcvt);
}
else
item = Item.MakeItem(FromItem, content, content.DTS, content.UserID);
dicTrans_ItemDone[ProcNumber + "|" + seqcvt] = item;
dicOldStepSequence[content] = seqcvt;
}
catch (Exception ex)
{
@@ -66,7 +113,7 @@ namespace DataLoader
log.ErrorFormat("oldstepsequence = {0}", stpseq);
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
log.ErrorFormat(ex.StackTrace);
stp = null;
item = null;
}
// now add on any support pieces of text associated with the step.
@@ -77,53 +124,61 @@ namespace DataLoader
// '\3\3'override tab
// '\5' continuous action summary flag
bool recdirty = false;
try
{
while (tok >= 0 && tok != Textm.Length)
{
int nxttok = Textm.IndexOfAny(chrarr, tok + 1);
char chr = Textm[tok];
int typ = 0;
if (chr == '\x1')
typ = STP_COMMENT;
else if (chr == '\x2')
typ = STP_MULT_CHGID;
else if (chr == '\x3')
{
typ = STP_LNK_SEQ;
// check for a double \3 - override tab.
if (tok + 1 < Textm.Length)
{
char nxttokchr = Textm[tok + 1];
if (nxttokchr == '\x3')
{
typ = STP_OVR_TAB;
tok++; // this was a double \3, get past 1st one.
nxttok = Textm.IndexOfAny(chrarr, tok + 1);
}
}
}
else if (chr == '\x5')
{
ci.AddItem("Step", "ContActSum", "True");
//hasxml = SetXml(xmldoc, topElement, "Step", "ContActSum", "True");
if (nxttok < 0) nxttok = Textm.Length;
}
if (chr == '\x1')
{
// add the comment to annotation table. Set type to comment.
if (nxttok < 0) nxttok = Textm.Length;
Annotation annot = Annotation.MakeAnnotation(item, CommentType, null, Textm.Substring(tok + 1, nxttok - tok - 1), null, dts, userid);
}
else if (chr == '\x2')
typ = STP_MULT_CHGID;
else if (chr == '\x3')
{
typ = STP_LNK_SEQ;
// check for a double \3 - override tab.
if (tok + 1 < Textm.Length)
{
char nxttokchr = Textm[tok + 1];
if (nxttokchr == '\x3')
{
typ = STP_OVR_TAB;
tok++; // this was a double \3, get past 1st one.
nxttok = Textm.IndexOfAny(chrarr, tok + 1);
}
}
}
else if (chr == '\x5')
{
recdirty = true;
if (ci == null) ci = new ConfigInfo(null);
ci.AddItem("Step", "ContActSum", "True");
if (nxttok < 0) nxttok = Textm.Length;
}
// if not xml, i.e. chr=='\x5', make a textm element
if (chr != '\x5')
// if not comment or ContActSum (xml) make a steptext element
if (typ == STP_MULT_CHGID || typ == STP_LNK_SEQ || typ == STP_OVR_TAB)
{
if (nxttok < 0) nxttok = Textm.Length;
// if this is a sequence number - may need to convert hi-end chars
string str = null;
string strn = null;
if (typ == STP_LNK_SEQ)
str = TextConvert.ConvertSeq(Textm.Substring(tok + 1, nxttok - tok - 1));
strn = TextConvert.ConvertSeq(Textm.Substring(tok + 1, nxttok - tok - 1));
else
str = Textm.Substring(tok + 1, nxttok - tok - 1);
//StepText stptxt = StepText.MakeStepText(typ, str, true);
//stptxt.ItemType = typ;
//stptxt.Textm = str;
//stp.StepStepTexts.Add(
strn = Textm.Substring(tok + 1, nxttok - tok - 1);
if (strn != null && strn != "")
{
recdirty = true;
content.ContentDetails.Add(typ, strn);
}
}
tok = nxttok;
}
@@ -131,9 +186,10 @@ namespace DataLoader
// also see if a check-off needs added.
if (Recid[0] != '0')
{
recdirty = true;
string chkindx = Recid[0].ToString();
if (ci == null) ci = new ConfigInfo(null);
ci.AddItem("Step", "CheckOffIndex", chkindx);
//hasxml = SetXml(xmldoc, topElement, "Step", "CheckOffIndex", chkindx);
}
// here's where it knows if it's a linked step (or in processstep)
@@ -143,15 +199,12 @@ namespace DataLoader
}
// if checkoffs or the continuous action summary flag, save the xml.
if (hasxml)
if (recdirty)
{
stp.Config = ci.ToString();
stp.Save(true);
if (ci != null) content.Config = ci.ToString();
if (!content.IsSavable) ErrorRpt.ErrorReport(content);
content.Save();
}
// if this has associated steptext, such as tab override or comment,
// save it.
//else if (stp.StepStepTexts.Count > 0)
// stp.Save(true);
}
catch (Exception ex)
{
@@ -160,29 +213,8 @@ namespace DataLoader
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
log.ErrorFormat(ex.StackTrace);
}
return stp;
return item;
}
// private void ProcessSubStep(DataTable dt,DataRowView drv,StepTbl stpP)
// {
// // TODO: Need logic for TextM Support
// StepTbl stp = AddStep(stpP,drv["Type"].ToString(),drv["Text"].ToString(),drv["Step"].ToString()+drv["sequence"].ToString());
// // TODO: Logic to add Sub-steps
// string sPre = drv["Sequence"].ToString();
// ProcessSubSteps(dt,drv["Step"].ToString(),sPre+"[*!]?",stp);// Cautions and Notes
// ProcessSubSteps(dt,drv["Step"].ToString(),sPre+"$",stp);// RNOs
// ProcessSubSteps(dt,drv["Step"].ToString(),sPre+"?",stp);// Substeps
// //ProcessSubSteps(dt,drv["Step"],"S_",stp);// Tables
// }
// private void ProcessSubSteps(DataTable dt,string step,string lookfor,StepTbl stp)
// {
// DataView dv = new DataView(dt,"Step='" + step + "' and Sequence like'" + lookfor + "'",
// "sequence",DataViewRowState.OriginalRows);
// foreach(DataRowView drv in dv)
// {
// ProcessSubStep(dt,drv,stp);
// }
// }
private string GetParent(string s)
{
string retval = "S";
@@ -219,30 +251,30 @@ namespace DataLoader
}
return retval;
}
private Int32 MigrateStep(OleDbConnection cn, DataTable dt, DataRowView drv, Byte FromType, Int32 FromID)
private Item MigrateStep(OleDbConnection cn, DataTable dt, DataRowView drv, Item FromItem, bool conv_caret)
{
try
{
int tmpid = 1;
// Do the structure record first because usages from the step require a structure
// id.
string sType = GetStructType(drv["CSequence"].ToString());
// Structures str = AddStructure(FromType, FromID, (byte)(3 + ("CNRST".IndexOf(sType))), tmpid, drv["CStep"].ToString() + drv["CSequence"].ToString(),
Structure str = AddStructure(FromType, FromID, 3, tmpid, drv["CStep"].ToString() + drv["CSequence"].ToString(),
GetDTS(drv["Date"].ToString(), drv["Time"].ToString()), drv["Initials"].ToString());
Step stp = AddStep(cn, drv["Type"].ToString()
, (drv["textm"] == DBNull.Value ? drv["Text"].ToString() : drv["Textm"].ToString())
, drv["Recid"].ToString(), drv["CStep"].ToString() + drv["CSequence"].ToString(), "S", str.StructureID
, GetDTS(drv["Date"].ToString(), drv["Time"].ToString()), drv["Initials"].ToString());
str.ContentID = stp.StepID;
str.Save(true);
Dictionary<string, Step> dicStep = new Dictionary<string, Step>();
dicStep[drv["CSequence"].ToString()] = stp;
Dictionary<string, Dictionary<string, int>> dicStruct = new Dictionary<string, Dictionary<string, int>>();
Dictionary<string, int> dicBase = new Dictionary<string, int>();
Item item = AddStep(cn, drv["Type"].ToString()
, (drv["textm"] == DBNull.Value ? drv["Text"].ToString() : drv["Textm"].ToString())
, drv["Recid"].ToString(), drv["CStep"].ToString() + drv["CSequence"].ToString(), "S", FromItem // was str
, GetDTS(drv["Date"].ToString(), drv["Time"].ToString()), drv["Initials"].ToString(), conv_caret);
//Content cont = Content.MakeContent(null,(drv["textm"] == DBNull.Value ? drv["Text"].ToString() : drv["Textm"].ToString()),drv["Type"]+20000,null,null,
// GetDTS(drv["Date"].ToString(), drv["Time"].ToString()), drv["Initials"].ToString());
//Item item = Item.MakeItem(FromItem, cont, cont.DTS, cont.UserID);
//Structure str = AddStructure(FromType, FromID, 3, tmpid, drv["CStep"].ToString() + drv["CSequence"].ToString(),
// GetDTS(drv["Date"].ToString(), drv["Time"].ToString()), drv["Initials"].ToString());
//Step stp = AddStep(cn, drv["Type"].ToString()
// , (drv["textm"] == DBNull.Value ? drv["Text"].ToString() : drv["Textm"].ToString())
// , drv["Recid"].ToString(), drv["CStep"].ToString() + drv["CSequence"].ToString(), "S", str
// , GetDTS(drv["Date"].ToString(), drv["Time"].ToString()), drv["Initials"].ToString());
Dictionary<string, Item> dicStep = new Dictionary<string, Item>();
dicStep[drv["CSequence"].ToString()] = item;
Dictionary<string, Dictionary<string, Item>> dicStruct = new Dictionary<string, Dictionary<string, Item>>();
Dictionary<string, Item> dicBase = new Dictionary<string, Item>();
dicStruct[drv["CSequence"].ToString()] = dicBase;
dicBase[""] = str.StructureID;
dicBase[""] = item;
// Logic to add Sub-steps
string sQry = "CStep = '" + drv["CStep"].ToString() + "' and CSequence <> 'S'";
// sort order - for sections use currentrows.
@@ -250,8 +282,8 @@ namespace DataLoader
//dataGrid1.DataSource=dv;
//Loop through DataView and add Steps one at a time
//Console.WriteLine("={0}",drv["Step"]);
Byte FrType = 0;
Int32 FrID = str.StructureID;
int FrType = 0; // type of relationship (not type of step)
Item FrItem = item;
foreach (DataRowView drvs in dv)
{
//Console.WriteLine(">{0}",drvs["CStep"]);
@@ -259,49 +291,53 @@ namespace DataLoader
string sParent = GetParent(drvs["CSequence"].ToString());
if (dicStep.ContainsKey(sParent))
{
Step stpp = dicStep[sParent];
Item itemp = dicStep[sParent];
sType = GetStructType(drvs["CSequence"].ToString());
Dictionary<string,int> dicStr = dicStruct[sParent];
if (dicStr.ContainsKey(sType))
Dictionary<string,Item> dicStr = dicStruct[sParent];
// check if a step type of 'sType' exists to see if child/sibling
//Content contc = Content.MakeContent(null,(drvs["textm"] == DBNull.Value ? drvs["Text"].ToString() : drvs["Textm"].ToString()),drvs["Type"]+20000,null,null,
// GetDTS(drvs["Date"].ToString(), drvs["Time"].ToString()), drvs["Initials"].ToString()));
Item itemc = null;
if (dicStr.ContainsKey(sType)) // next sibling
{
FrID = (Int32)dicStr[sType];
FrItem = dicStr[sType];
FrType = 0;
}
else
else // child of a node
{
FrID = (Int32)dicStr[""];
FrType = (byte)(3 + ("CNRST".IndexOf(sType)));
FrItem = null;
FrType = (3 + ("CNRST".IndexOf(sType)));
}
Structure str1 = AddStructure(FrType, FrID, 3, tmpid++, drvs["CStep"].ToString() + drvs["CSequence"].ToString(),
GetDTS(drvs["Date"].ToString(), drvs["Time"].ToString()), drvs["Initials"].ToString());
Step stpc = AddStep(cn, drvs["Type"].ToString()
, (drvs["textm"] == DBNull.Value ? drvs["Text"].ToString() : drvs["Textm"].ToString())
, drv["Recid"].ToString(), drvs["CStep"].ToString() + drvs["CSequence"].ToString(), GetStructType(drvs["sequence"].ToString()), str1.StructureID
, GetDTS(drvs["Date"].ToString(), drvs["Time"].ToString()), drvs["Initials"].ToString());
str1.ContentID = stpc.StepID;
str1.Save(true);
dicStep[drvs["CSequence"].ToString()] = stpc;
dicBase = new Dictionary<string, int>();
dicStruct[drvs["CSequence"].ToString()] = dicBase;
dicBase[""] = str1.StructureID;
dicStr[sType] = str1.StructureID;
itemc = AddStep(cn, drvs["Type"].ToString()
, (drvs["textm"] == DBNull.Value ? drvs["Text"].ToString() : drvs["Textm"].ToString())
, drv["Recid"].ToString(), drvs["CStep"].ToString() + drvs["CSequence"].ToString()
, GetStructType(drvs["sequence"].ToString()), FrItem
, GetDTS(drvs["Date"].ToString(), drvs["Time"].ToString()), drvs["Initials"].ToString(), conv_caret);
if (FrType > 0 )
{
itemp.MyContent.ContentParts.Add(FrType, itemc);
if (!itemp.MyContent.IsSavable) ErrorRpt.ErrorReport(itemp.MyContent);
itemp.MyContent.Save();
}
dicStr[sType] = itemc;
dicStruct[drvs["CSequence"].ToString()] = new Dictionary<string, Item>();
dicStep[drvs["CSequence"].ToString()] = itemc;
}
else
{
log.ErrorFormat("Parent {0} Could not be found for {1}", sParent, drvs["sequence"].ToString());
}
}
return str.StructureID;
return item;
}
catch (Exception ex)
{
log.Error("PROCESS STEP");
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
log.ErrorFormat(ex.StackTrace);
return 0;
return null;
}
//return 0;
}
}
}