SourceCode/PROMS/DataLoader/Transitions.cs
2006-11-14 15:58:03 +00:00

139 lines
5.1 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 int AddTrans(int fromId, DataRow dr)
{
//TODO: ZTransitions tr.Oldto = dr["OLDTO"].ToString();
string thekey = dr["TONUMBER"].ToString() + "|" + dr["TOSEQUENCE"].ToString();
string dti = dr["DTI"].ToString().PadRight(18, ' ');
string userid = dti.Substring(13, 5).Trim();
DateTime dts = GetDTS(MakeDate(dti.Substring(0, 8).Trim()), dti.Substring(8, 5).Trim());
// if it's in the dictionary of structure elements already migrated, just use this
// structure id, or if it's in the dictionary of structure elements that have
// not been migrated but a record was created from this code, use it. Otherwise
// create a new structure record and use its id, its data will be updated later.
// a structure record.
int toid;
if (dicTrans_StrDone.ContainsKey(thekey))
toid = dicTrans_StrDone[thekey];
else
{
if (dicTrans_StrIds.ContainsKey(thekey))
toid = dicTrans_StrIds[thekey];
else
{
Structure str = Structure.MakeStructure(0, 0, 0, 0);
toid = str.StructureID;
dicTrans_StrIds.Add(thekey, toid);
}
}
Transition tr = Transition.MakeTransition(fromId, toid, System.Convert.ToInt32(dr["TYPE"].ToString()),0,0,0,0,dts,userid);
return tr.TransitionId;
}
private string MigrateTrans(OleDbConnection cn, string textm, string seqcvt, int structId)
{
StringBuilder trtxt = new StringBuilder();
int instance = 0;
int beg = 0;
DataTable dt = null;
DataSet ds = null;
OleDbDataAdapter da = null;
char[] chrtrn = { '\x252C', '\x2566' };
int tok = textm.IndexOfAny(chrtrn);
if (tok > -1)
{
string cmd = "SELECT * FROM [tran] WHERE [FROMNUMBER]='" + ProcNumber.Replace("'", "''") + "' AND [FROMSEQUEN] ='" + seqcvt + "' ORDER BY [FROMINSTAN]";
da = new OleDbDataAdapter(cmd, cn);
// get transition records for this step.
ds = new DataSet();
try
{
da.Fill(ds);
dt = ds.Tables[0];
dt.CaseSensitive = true;
}
catch (Exception ex)
{
log.Error("Error getting transitions");
log.ErrorFormat("from number = {0} oldstepsequence = {1}", ProcNumber, seqcvt);
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
return textm;
}
}
while (tok > -1)
{
// found a transition token, add the token and transition id into the string and
// add an transition record for it. Later there may be text added.
trtxt.Append(textm.Substring(beg, tok - beg));
// we have too many tokens and not enough usage records - report an error...
if (instance >= dt.Rows.Count)
{
log.ErrorFormat("Error - ran out of usage records for step, check data ");
log.ErrorFormat("from number = {0} oldstepsequence = {1}", ProcNumber, seqcvt);
}
else
{
DataRow dr = dt.Rows[instance];
int trid = AddTrans(structId, dr);
trtxt.Append(textm[tok]);
trtxt.Append("{{");
trtxt.Append(trid.ToString());
trtxt.Append("}}");
}
instance++;
beg = tok + 1;
if (beg > textm.Length)
{
tok = -1;
da.Dispose();
}
else
tok = textm.IndexOfAny(chrtrn, beg);
}
if (beg < textm.Length - 1)
trtxt.Append(textm.Substring(beg, textm.Length - beg));
if (dt.Rows.Count > instance + 1)
{
log.ErrorFormat("Error - extra usage records for step, check data ");
log.ErrorFormat("from number = {0} oldstepsequence = {1}", ProcNumber, seqcvt);
}
return trtxt.ToString();
}
private void ShowMissingTransitions()
{
log.Info("Missing Transitions");
foreach (string s in dicTrans_StrIds.Keys)
{
log.InfoFormat("{0} - {1}", s, dicTrans_StrIds[s]);
}
log.Info("End of Missing Transitions");
}
}
}