// ======================================================================== // 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 VEPROMS.CSLA.Library; namespace DataLoader { public partial class Loader { private List InvalidROs = new List(); private string MigrateRos(OleDbConnection cn, string textm, string seqcvt, Content content, DocVersion docver, bool conv_caret,ref int rotype) { StringBuilder rotxt = new StringBuilder(); int instance = 0; int beg = 0; DataTable dt = null; DataSet ds = null; OleDbDataAdapter da = null; string cmd = "SELECT * FROM USAGERO WHERE [NUMBER]='" + ProcNumber.Replace("'", "''") + "' AND [SEQUENCE] ='" + seqcvt + "' ORDER BY [INSTANCE]"; da = new OleDbDataAdapter(cmd, cn); // get usage records for the ROID. ds = new DataSet(); try { da.Fill(ds); dt = ds.Tables[0]; dt.CaseSensitive = true; } catch (Exception ex) { frmMain.AddError(ex, "migrateRos"); log.Error("Error getting RO Usages"); log.ErrorFormat("proc number = {0}, oldstepsequence = {1}",ProcNumber, seqcvt); do { log.ErrorFormat("{0} - {1}", ex.GetType().Name, ex.Message); ex = ex.InnerException; } while (ex != null); ds.Dispose(); da.Dispose(); return textm; } char[] chrrotrn = { '\x15', '\x3a6' }; int tok = textm.IndexOfAny(chrrotrn); while (tok > -1) { // found a token, add the roid & value into the string and // add an ro usage for it. rotxt.Append(textm.Substring(beg, tok - beg)); if (instance < dt.Rows.Count) { DataRow dr = dt.Rows[instance]; string ROID = dr["ROID"].ToString(); RoUsage ro = RoUsage.MakeRoUsage(content, ROID, null, DateTime.Now, "Migration", rodb); try { ROFSTLookup mylookup = rofstinfo.GetROFSTLookup(DocVersionInfo.Get(docver.VersionID)); ROFSTLookup.rochild myro = mylookup.GetRoChild12(ROID.ToUpper()); rotype = Math.Max(rotype, myro.type); string roval = mylookup.GetTranslatedRoValue(ROID.ToUpper(), conv_caret); if (textm[tok] == '\x3a6' && roval.IndexOf('\n')>-1) // figure - just get image name { roval = roval.Substring(0, roval.IndexOf('\n')); } roval = roval.Replace("{", @"\{"); roval = roval.Replace("}", @"\}"); // add an annotation stating "Invalid Unit RO 'ROID'. Need an Item for this, so just add // it to a list of 'invalid ros' so that calling method can add annotations to the Item. if (roval == "?") { if (ROID.StartsWith("FFFF")) InvalidROs.Add(string.Format("Invalid Unit RO '{0}'", ROID.Substring(0, 12))); else InvalidROs.Add(string.Format("Invalid RO '{0}'", ROID.Substring(0, 12))); } //if (roval.Contains("\r") || roval.Contains("\n")) // Console.WriteLine("RO has new Lines"); //string results = string.Format(@"\v \v0 ", // rofstinfo.ROFSTLookup.GetRoValue(ROID.Substring(0, 12).ToUpper()), ro.ROUsageID, ROID, rodb.RODbID); // RHM 20100308 - string results = string.Format(@"\v \v0 ", // RHM 20100308 - roval.Replace("\r\n","\\par\r\n"), ro.ROUsageID, ROID, rodb.RODbID); string results = string.Format(@"\v \v0 ", roval, ro.ROUsageID, ROID, rodb.RODbID); rotxt.Append(results); } catch (Exception ex) { frmMain.AddError(ex, "MigrateRos '{0}' '{1}' {2}", ProcNumber, seqcvt, instance); log.Error("Error setting RO data in text field"); log.ErrorFormat("Error Message = {0}", ex.Message); log.ErrorFormat("proc number = {0}, oldstepsequence = {1}, instance = {2}", ProcNumber, seqcvt, instance); } instance++; } else { rotxt.Append("?"); InvalidROs.Add("The ? in the step text represents an RO that was not connected to the ro database."); log.Error("Error setting RO data in text field"); log.ErrorFormat("proc number = {0}, oldstepsequence = {1}, instance = {2}", ProcNumber, seqcvt, instance); } beg = tok + 1; if (beg > textm.Length) { tok = -1; da.Dispose(); } else tok = textm.IndexOf('\x15', beg); // there would only be one figure - only check for ro after 1st time } if (beg <= textm.Length - 1) rotxt.Append(textm.Substring(beg, textm.Length - beg)); ds.Dispose(); da.Dispose(); return rotxt.ToString(); } } }