From afc16fb9f982313df6b473653e2d13e791ab0b63 Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 3 Nov 2009 16:31:30 +0000 Subject: [PATCH] --- PROMS/DataLoader/Documents.cs | 38 ++++++++++++++-- PROMS/DataLoader/OutsideTransition.cs | 29 +++++++++---- PROMS/DataLoader/Procedures.cs | 62 ++++++++++++++------------- PROMS/DataLoader/RefObjs.cs | 12 +++++- PROMS/DataLoader/Sections.cs | 5 +-- PROMS/DataLoader/Transitions.cs | 4 ++ 6 files changed, 102 insertions(+), 48 deletions(-) diff --git a/PROMS/DataLoader/Documents.cs b/PROMS/DataLoader/Documents.cs index 28d142cd..220b64c8 100644 --- a/PROMS/DataLoader/Documents.cs +++ b/PROMS/DataLoader/Documents.cs @@ -68,6 +68,32 @@ namespace DataLoader * "Special Landscape, Elite, 6 lines per inch" */ + if (stype != null) + { + // stype[1] == 'p' or 'P' or '6' 'f' or 'L' get spc = 6 + int lpi = 6; + if (stype[1] == '*') lpi = 8; + else if (stype[1] == '4') lpi = 4; + else if (stype[1] == '7') lpi = 7; + // if need landscape set too: bool landscape = (stype[1] == 'L'); + d.SetLineSpacing(lpi); // if need landscape set too: , landscape); ; + } + string temppath = Path.GetTempFileName(); + /* 16-bit's type[1] used the following codes to represent the respective lpi setting + * + * char far typestr[] = "*pP46f7L"; + * + * char * far printtypes[] = { + * "Compressed, 8 lines per inch", + * "Elite, 6 lines per inch", + * "Pica, 6 lines per inch", + * "Default font, 4 Lines Per Inch", + * "Default font, 6 Lines Per Inch", + * "Compressed 6 LPI", + * "Default font, 7 Lines Per Inch", + * "Special Landscape, Elite, 6 lines per inch" + */ + if (stype != null) { // stype[1] == 'p' or 'P' or '6' 'f' or 'L' get spc = 6 @@ -111,15 +137,19 @@ namespace DataLoader string t1 = (title == null || title == "") ? null : title; Document doc = Document.MakeDocument(t1, ByteArray, null, ci == null ? null : ci.ToString(), DateTime.Now, "Migration", ".Doc"); FileInfo tmpFile = new FileInfo(temppath); - FileInfo doctmpFile = tmpFile.CopyTo(temppath.Substring(0,temppath.LastIndexOf(".")) + @".doc"); - doc.UpdateDocAscii(temppath.Substring(0, temppath.LastIndexOf(".")) + @".doc"); + string docfile = temppath.Substring(0, temppath.LastIndexOf(".")) + @".doc"; + if (File.Exists(docfile)) File.Delete(docfile); + FileInfo doctmpFile = tmpFile.CopyTo(docfile); + doc.UpdateDocAscii(docfile); doc.Save(); + File.Delete(docfile); DocumentInfo di = DocumentInfo.Get(doc.DocID); return doc.DocID; } // for an io exception, keep trying - catch (IOException) + catch (IOException exio) { + Console.WriteLine("IO: {0} - {1}", exio.GetType().Name, exio.Message); Wait(2); return 0; } @@ -143,4 +173,4 @@ namespace DataLoader return done; } } -} \ No newline at end of file +} diff --git a/PROMS/DataLoader/OutsideTransition.cs b/PROMS/DataLoader/OutsideTransition.cs index fc853648..df069c28 100644 --- a/PROMS/DataLoader/OutsideTransition.cs +++ b/PROMS/DataLoader/OutsideTransition.cs @@ -53,14 +53,19 @@ namespace DataLoader private string GetProc(string setid, string procid) { + string retval = null; string xtproccmd = "SELECT * FROM [xtprocid] WHERE [SETID]='" + setid + "' AND [PROCID]='" + procid + "'"; - OleDbDataAdapter da = new OleDbDataAdapter(xtproccmd, _DbConnect); - DataSet ds = new DataSet(); - da.Fill(ds); - DataTable dt = ds.Tables[0]; - dt.CaseSensitive = true; - DataRow dr = dt.Rows[0]; // there should be only one entry! - return dr["Procnum"].ToString(); // this should be the procedure number! + using (OleDbDataAdapter da = new OleDbDataAdapter(xtproccmd, _DbConnect)) + { + DataSet ds = new DataSet(); + da.Fill(ds); + DataTable dt = ds.Tables[0]; + dt.CaseSensitive = true; + DataRow dr = dt.Rows[0]; // there should be only one entry! + retval = dr["Procnum"].ToString(); // this should be the procedure number! + ds.Dispose(); + } + return retval; } private string GetPath(string setid) @@ -72,7 +77,10 @@ namespace DataLoader DataTable dt = ds.Tables[0]; dt.CaseSensitive = true; DataRow dr = dt.Rows[0]; // there should be only one entry! - return dr["Path"].ToString(); // this should be the path to the proc set! + string retval = dr["Path"].ToString(); + da.Dispose(); + ds.Dispose(); + return retval; // dr["Path"].ToString(); // this should be the path to the proc set! } private string GetTitle(string setid, string procid) @@ -84,7 +92,10 @@ namespace DataLoader DataTable dt = ds.Tables[0]; dt.CaseSensitive = true; DataRow dr = dt.Rows[0]; // there should be only one entry! - return dr["Proctitle"].ToString(); // this should be the procedure number! + string retval = dr["Proctitle"].ToString(); + da.Dispose(); + ds.Dispose(); + return retval; // dr["Proctitle"].ToString(); // this should be the procedure number! } public string GetDescription(string key) diff --git a/PROMS/DataLoader/Procedures.cs b/PROMS/DataLoader/Procedures.cs index 7f69152b..e802bdfb 100644 --- a/PROMS/DataLoader/Procedures.cs +++ b/PROMS/DataLoader/Procedures.cs @@ -71,7 +71,7 @@ namespace DataLoader // if the dbt is bad, fix it. DbtOk(dr["entry"].ToString(),pth); // 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); + OleDbDataAdapter dapsi = new OleDbDataAdapter("select * from [" + dr["entry"] + "] where [STEP] is null", cn); try { dapsi.Fill(ds); @@ -81,35 +81,35 @@ namespace DataLoader Console.WriteLine(ex.Message); Application.Exit(); } - dt = ds.Tables[0]; + 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); + 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(); + 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(); } else // log an error { @@ -146,7 +146,7 @@ namespace DataLoader } } } - if (convertProcedures /* && number == "0POP05-EO-EC00"*/) + if (convertProcedures /*&& number == "0POP05\\u8209?EO\\u8209?ES32"*/) //0POP05\u8209?EO\u8209?ES32 { OleDbDataAdapter da = new OleDbDataAdapter("select * from [" + dr["entry"] + "] where sequence like ' %'", cn); try @@ -174,6 +174,7 @@ namespace DataLoader log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); log.Error(ex.StackTrace); } + da.Dispose(); // dicSecCount is dictionary to track number of subsections for the parent at a level // dicSecID is the parent at that level @@ -192,7 +193,6 @@ namespace DataLoader foreach (DataRowView drw in dv) { SectItm = MigrateSection(parentitem, ProcNumber, cn, drw, ds.Tables["Steps"], SectItm, dicSecCount.Count > 0 ? true : false, pth, docver); - // if no children, add first child (cont) if (addpart) { @@ -234,6 +234,7 @@ namespace DataLoader itm.Save(); } } + ds.Dispose(); return itm; } private Item MigrateProcedures(OleDbConnection cn, string pth, DocVersion docver, bool convertProcedures) @@ -248,6 +249,7 @@ namespace DataLoader Item FrItm = null; frmMain.pbProcMaximum = ds.Tables[0].Rows.Count; frmMain.UpdateLabels(0, 0, 0); + foreach (DataRow dr in ds.Tables[0].Rows) { FrItm = MigrateProcedure(cn, dr, FrItm, pth, docver, convertProcedures); diff --git a/PROMS/DataLoader/RefObjs.cs b/PROMS/DataLoader/RefObjs.cs index 57a59dee..9b9ed527 100644 --- a/PROMS/DataLoader/RefObjs.cs +++ b/PROMS/DataLoader/RefObjs.cs @@ -48,7 +48,13 @@ namespace DataLoader { log.Error("Error getting RO Usages"); log.ErrorFormat("proc number = {0}, oldstepsequence = {1}",ProcNumber, seqcvt); - log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); + do + { + log.ErrorFormat("{0} - {1}", ex.GetType().Name, ex.Message); + ex = ex.InnerException; + } while (ex != null); + ds.Dispose(); + da.Dispose(); return textm; } int tok = textm.IndexOf('\x15'); @@ -105,7 +111,9 @@ namespace DataLoader } if (beg <= textm.Length - 1) rotxt.Append(textm.Substring(beg, textm.Length - beg)); - + + ds.Dispose(); + da.Dispose(); return rotxt.ToString(); } } diff --git a/PROMS/DataLoader/Sections.cs b/PROMS/DataLoader/Sections.cs index 618e42cc..3ac65e4e 100644 --- a/PROMS/DataLoader/Sections.cs +++ b/PROMS/DataLoader/Sections.cs @@ -116,7 +116,6 @@ namespace DataLoader } else itm = Item.MakeItem(FromItem, cont, Dts, Userid); - dicTrans_ItemDone[ProcNumber+"|"+trstpseq] = itm; dicOldStepSequence[itm] = stpseq; return itm; @@ -200,7 +199,7 @@ namespace DataLoader { if ((ds.OldToNew & docstyle)>0) return (int)ds.Index; } - return -1; + return 0; } private FormatInfo GetFormat(Item procitem, DocVersion docver) { @@ -258,6 +257,7 @@ namespace DataLoader { log.ErrorFormat("Error getting long section title {0}", ex.Message); } + da.Dispose(); } // For step sections, the long section title is stored on the section record // (see above comment for accessory pages to see the difference) @@ -442,7 +442,6 @@ namespace DataLoader libDocid = dicLibDocRef[thekey]; } } - Item secitem = AddSection(procitem, num, title, stype, dts, init, ci, step + sequence, fmt, libDocid, pth, FromItem, docver); thesectid = secitem.ItemID; diff --git a/PROMS/DataLoader/Transitions.cs b/PROMS/DataLoader/Transitions.cs index d0093799..d6ff9712 100644 --- a/PROMS/DataLoader/Transitions.cs +++ b/PROMS/DataLoader/Transitions.cs @@ -207,6 +207,8 @@ namespace DataLoader 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); + ds.Dispose(); + da.Dispose(); return textm; } } @@ -260,6 +262,8 @@ namespace DataLoader log.ErrorFormat("Error - extra transition records for step, check data "); log.ErrorFormat("from number = {0} oldstepsequence = {1}", ProcNumber, seqcvt); } + ds.Dispose(); + da.Dispose(); return trtxt.ToString(); } private void ShowMissingTransitions()