diff --git a/PROMS/DataLoader/DocVersions.cs b/PROMS/DataLoader/DocVersions.cs index 35b388b2..20438f0e 100644 --- a/PROMS/DataLoader/DocVersions.cs +++ b/PROMS/DataLoader/DocVersions.cs @@ -63,6 +63,7 @@ namespace DataLoader if (convertProcedures) { ShowMissingTransitions(); + frmMain.Status = string.Format("{0}\r\nConversion completed in {1} seconds.", pth, TimeSpan.FromTicks(lTime).TotalSeconds); log.InfoFormat("Completed Migration of {0}", pth); MessageBox.Show("Completed Migration of " + pth); @@ -70,6 +71,8 @@ namespace DataLoader dicTrans_ItemDone.Clear(); dicTrans_ItemDone = null; } + else + frmMain.Status = string.Format("{0}\r\nDone.", pth); cn.Close(); if (itm != null) { diff --git a/PROMS/DataLoader/Documents.cs b/PROMS/DataLoader/Documents.cs index 220b64c8..6a883179 100644 --- a/PROMS/DataLoader/Documents.cs +++ b/PROMS/DataLoader/Documents.cs @@ -78,7 +78,7 @@ namespace DataLoader // if need landscape set too: bool landscape = (stype[1] == 'L'); d.SetLineSpacing(lpi); // if need landscape set too: , landscape); ; } - string temppath = Path.GetTempFileName(); + //string temppath = Path.GetTempFileName(); /* 16-bit's type[1] used the following codes to represent the respective lpi setting * * char far typestr[] = "*pP46f7L"; @@ -118,7 +118,8 @@ namespace DataLoader } } else - log.ErrorFormat("Missing rtf file: {0}", fname); + //log.ErrorFormat("Missing rtf file: {0}", fname); + frmMain.AddError("Missing rtf file: {0}", fname); return docid; } private int SaveWordDoc(string temppath, string stype) @@ -150,6 +151,7 @@ namespace DataLoader catch (IOException exio) { Console.WriteLine("IO: {0} - {1}", exio.GetType().Name, exio.Message); + frmMain.AddError(exio, "SaveTheDoc('{0}','{1}')", temppath, title); Wait(2); return 0; } @@ -157,6 +159,7 @@ namespace DataLoader { log.Error("Save Word Doc"); log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); + frmMain.AddError(ex, "SaveTheDoc('{0}','{1}')", temppath, title); return -1; } @@ -173,4 +176,4 @@ namespace DataLoader return done; } } -} +} \ No newline at end of file diff --git a/PROMS/DataLoader/Formats.cs b/PROMS/DataLoader/Formats.cs index ddef3570..df4728cc 100644 --- a/PROMS/DataLoader/Formats.cs +++ b/PROMS/DataLoader/Formats.cs @@ -36,9 +36,17 @@ namespace DataLoader string path = "c:\\development\\fmtall\\" + format + "all.xml"; if (File.Exists(path)) { - xd = new XmlDocument(); - xd.Load(path); - fmtdata = xd.OuterXml; + try + { + xd = new XmlDocument(); + xd.Load(path); + fmtdata = xd.OuterXml; + } + catch(Exception ex) + { + frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path); + return null; + } } // Do we need genmac - only if non-subformat @@ -47,9 +55,17 @@ namespace DataLoader path = "c:\\development\\genmacall\\" + format + ".svg"; if (File.Exists(path)) { - XmlDocument xdg = new XmlDocument(); - xdg.Load(path); - genmacdata = xdg.OuterXml; + try + { + XmlDocument xdg = new XmlDocument(); + xdg.Load(path); + genmacdata = xdg.OuterXml; + } + catch (Exception ex) + { + frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path); + return null; + } } } // Get the name & then create the record. @@ -79,7 +95,7 @@ namespace DataLoader // Load base format. basefmt = AddFormatToDB(null, "base", false, DateTime.Now, "Migration"); - + if (basefmt == null) return; // now loop through all files... If there is an _ in the name, it's a subformat // (for example, AEP_00.xml) skip it in main loop, it's handled for each format. DirectoryInfo di = new DirectoryInfo(@"c:\development\fmtall"); @@ -95,28 +111,33 @@ namespace DataLoader try { parent = AddFormatToDB(basefmt, fmtname, issub, DateTime.Now, "Migration"); - - // now see if there are any subformats associated with this, if so - // add them here... - DirectoryInfo sdi = new DirectoryInfo("c:\\development\\fmtall"); - FileInfo[] sfis = di.GetFiles(fmtname + "_*.xml"); - foreach (FileInfo sfi in sfis) + if (parent != null) { - string nm = sfi.Name.Substring(0, sfi.Name.Length - 7); - Console.WriteLine("Processing {0}", sfi.Name); - try + // now see if there are any subformats associated with this, if so + // add them here... + DirectoryInfo sdi = new DirectoryInfo("c:\\development\\fmtall"); + FileInfo[] sfis = di.GetFiles(fmtname + "_*.xml"); + foreach (FileInfo sfi in sfis) { - Format subfmt = AddFormatToDB(parent, nm, true, DateTime.Now, "Migration"); - } - catch (Exception ex) - { - Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message); + string nm = sfi.Name.Substring(0, sfi.Name.Length - 7); + //Console.WriteLine("Processing {0}", sfi.Name); + frmMain.Status = string.Format("Processing Format {0}", sfi.Name); + try + { + AddFormatToDB(parent, nm, true, DateTime.Now, "Migration"); + } + catch (Exception ex) + { + frmMain.AddError(ex, "LoadAllFormats() '{0}'", sfi.Name); + //Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message); + } } } } catch (Exception ex) { - Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message); + frmMain.AddError(ex, "LoadAllFormats() '{0}'", fi.Name); + //Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message); } } } @@ -152,7 +173,8 @@ namespace DataLoader catch (Exception ex) { log.ErrorFormat("Error getting xml version of format {0}", ex.Message); - } + frmMain.AddError(ex, "GetFormat('{0}')", format); + } FormatInfo recInfo = FormatInfo.Get(rec.FormatID); return recInfo; } diff --git a/PROMS/DataLoader/LoadTreeDB.cs b/PROMS/DataLoader/LoadTreeDB.cs index 0aee1e91..726c4209 100644 --- a/PROMS/DataLoader/LoadTreeDB.cs +++ b/PROMS/DataLoader/LoadTreeDB.cs @@ -86,6 +86,7 @@ namespace DataLoader catch (Exception ex) { log.ErrorFormat("error in convert curset.dat, ex = {0}", ex.Message); + frmMain.AddError(ex, "error in convert curset.dat"); } } string titlepath = vb.Path + "\\" + "Title"; diff --git a/PROMS/DataLoader/Loader.cs b/PROMS/DataLoader/Loader.cs index 6740899d..7d231fba 100644 --- a/PROMS/DataLoader/Loader.cs +++ b/PROMS/DataLoader/Loader.cs @@ -120,7 +120,8 @@ namespace DataLoader catch (Exception ex) { log.ErrorFormat("Could not load data, error = {0}", ex.Message); - return false; + //return false; + throw ex; } return true; } @@ -186,6 +187,7 @@ namespace DataLoader { log.ErrorFormat("Bad Date/Time {0} {1}. Set to NOW.", date, time); log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); + frmMain.AddError(ex, "Bad Date/Time {0} {1}", date, time); //log.ErrorFormat(ex.StackTrace); return dts; } diff --git a/PROMS/DataLoader/Procedures.cs b/PROMS/DataLoader/Procedures.cs index e802bdfb..26e86c99 100644 --- a/PROMS/DataLoader/Procedures.cs +++ b/PROMS/DataLoader/Procedures.cs @@ -29,12 +29,18 @@ namespace DataLoader public static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //public static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #endregion + public static int HandleCount + { + get { return System.Diagnostics.Process.GetCurrentProcess().HandleCount; } + } + private bool RunWithDB2K = false; private Item MigrateProcedure(OleDbConnection cn, DataRow dr, Item FromItem, string pth, DocVersion docver, bool convertProcedures) { dicOldStepSequence = new Dictionary(); Stack SubSectLevels = new Stack(); // levels of subsections ProcFileName = dr["Entry"].ToString(); ProcNumber = dr["Number"].ToString(); + frmMain.Status = "Processing Procedure " + ProcNumber + " - " + ProcFileName; DateTime dts = GetDTS(dr["Date"].ToString(), dr["Time"].ToString()); string userid = dr["initials"].ToString().Trim(); if (userid == null || userid == "") userid = "Migration"; @@ -72,6 +78,7 @@ namespace DataLoader 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); + int handleBefore = HandleCount; try { dapsi.Fill(ds); @@ -79,7 +86,26 @@ namespace DataLoader catch (Exception ex) { Console.WriteLine(ex.Message); - Application.Exit(); + //Application.Exit(); + throw ex; // Exit from Data Loader + } + int handleAfter = HandleCount; + if (!RunWithDB2K && handleAfter - handleBefore > 10) + { + string msg = "It appears that handles are being created and not cleared."; + if (dB2KInstalled()) + { + msg += "\r\n\r\nThis is most likely because dB2K is installed." + + "\r\n\r\nUninstall dB2K and run again."; + if (MessageBox.Show(msg + "\r\n\r\nDo you want to continue?", "Run with dB2K", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + RunWithDB2K = true; + } + else + { + msg += "\r\n\r\nCall Volian for support."; + } + if (!RunWithDB2K)throw new Exception(msg); } dt = ds.Tables[0]; @@ -140,7 +166,7 @@ namespace DataLoader foreach(ItemInfo ii in dvi.Procedures){ if (ii.MyContent.Number == number) { - Console.WriteLine(number); + //Console.WriteLine(number); itm = ii.Get(); cont = ii.MyContent.Get(); } @@ -173,6 +199,7 @@ namespace DataLoader { log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); log.Error(ex.StackTrace); + frmMain.AddError(ex, "MigrateProcedure - {0}", ProcFileName); } da.Dispose(); @@ -237,6 +264,13 @@ namespace DataLoader ds.Dispose(); return itm; } + private bool dB2KInstalled() + { + Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"software\dBase\dB2K"); + bool retval = key != null; + key.Close(); + return retval; + } private Item MigrateProcedures(OleDbConnection cn, string pth, DocVersion docver, bool convertProcedures) { Item FirstItm = null; @@ -260,6 +294,7 @@ namespace DataLoader catch (Exception ex) { _MyLog.ErrorFormat("MigrateProcedures - {0} - {1}\r\n\r\n{2}", pth,ex.Message, ex.InnerException); + throw ex; } return FirstItm; } diff --git a/PROMS/DataLoader/RefObjs.cs b/PROMS/DataLoader/RefObjs.cs index 9b9ed527..36300a89 100644 --- a/PROMS/DataLoader/RefObjs.cs +++ b/PROMS/DataLoader/RefObjs.cs @@ -46,6 +46,7 @@ namespace DataLoader } catch (Exception ex) { + frmMain.AddError(ex, "migrateRos"); log.Error("Error getting RO Usages"); log.ErrorFormat("proc number = {0}, oldstepsequence = {1}",ProcNumber, seqcvt); do @@ -89,6 +90,7 @@ namespace DataLoader } 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); diff --git a/PROMS/DataLoader/RoFst.cs b/PROMS/DataLoader/RoFst.cs index 8d3fc275..4a0d67a1 100644 --- a/PROMS/DataLoader/RoFst.cs +++ b/PROMS/DataLoader/RoFst.cs @@ -164,7 +164,7 @@ namespace DataLoader } } else - Console.WriteLine(string.Format("{0}", imgfile), "Cannot Find Image File"); + frmMain.AddError("Cannot Find Image File {0}", imgfile); } } } diff --git a/PROMS/DataLoader/Sections.cs b/PROMS/DataLoader/Sections.cs index 3ac65e4e..af6d4f70 100644 --- a/PROMS/DataLoader/Sections.cs +++ b/PROMS/DataLoader/Sections.cs @@ -43,7 +43,7 @@ namespace DataLoader // Find the docstyle based on the section type (step[1]) & the 'type' from the dbf // record sectype[0]) string dstyleindx = ((stpseq == null || stpseq == "") ? " " : stpseq.Substring(1, 1)) + ((SecType==null||SecType == "") ? " " : SecType.Substring(0, 1)); - int docstyleindx = GetDocStyleIndx(dstyleindx, format, procitem, docver); + int docstyleindx = GetDocStyleIndx(dstyleindx, format, procitem, docver,Number,Title); // tack on the column mode - add to config xml for node. if (stpseq != null && stpseq.Substring(1, 1) == "0" && stpseq.Substring(5, 1) != " ") @@ -122,6 +122,7 @@ namespace DataLoader } catch (Exception ex) { + frmMain.AddError(ex, "Save Section"); log.Error("Save Section"); log.ErrorFormat("oldstepsequence = {0}", stpseq); log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); @@ -182,12 +183,13 @@ namespace DataLoader } catch (Exception ex) { + frmMain.AddError(ex, "OldToNew {0}", lkup); Console.WriteLine(string.Format("Error in oldtonew {0}", lkup)); Console.WriteLine(string.Format("Error = {0}", ex.Message)); } return retval; } - private int GetDocStyleIndx(string dstyleindx, FormatInfo format, Item procitem, DocVersion docver) + private int GetDocStyleIndx(string dstyleindx, FormatInfo format, Item procitem, DocVersion docver, string Number, string Title) { // get the format, if format is set, use it, otherwise walk if (format == null) @@ -199,7 +201,9 @@ namespace DataLoader { if ((ds.OldToNew & docstyle)>0) return (int)ds.Index; } - return 0; + frmMain.AddError("Bad OldToNew Document Style {0}:{1} dStyleIndex = '{2}'\r\n{3} - Missing OldToNew {4}", + procitem.DisplayNumber, (Number ?? "") == "" ? Title : Number, dstyleindx, format, docstyle); + return 0; // Default is Zero } private FormatInfo GetFormat(Item procitem, DocVersion docver) { @@ -255,7 +259,8 @@ namespace DataLoader } catch (Exception ex) { - log.ErrorFormat("Error getting long section title {0}", ex.Message); + frmMain.AddError(ex, "Error getting long section title"); + log.ErrorFormat("Error getting long section title {0}", ex.Message); } da.Dispose(); } @@ -532,6 +537,8 @@ namespace DataLoader LoadSection(ds, da, FileName);// Try Again break; default: // Unrecognized error + frmMain.AddError(ex, "Unrecognized error in LoadSection {0}", FileName); + Console.WriteLine("Unrecognized error: error = {0}", ex.Message); log.ErrorFormat("File - {0}.DBF\r\n\r\n{1}\r\n\r\n{2}", FileName, ex.Message, ex.InnerException); break; } diff --git a/PROMS/DataLoader/Steps.cs b/PROMS/DataLoader/Steps.cs index 111c1157..4dfed10c 100644 --- a/PROMS/DataLoader/Steps.cs +++ b/PROMS/DataLoader/Steps.cs @@ -143,6 +143,8 @@ namespace DataLoader } catch (Exception ex) { + frmMain.AddError(ex, "AddStep {0}",stpseq); + //Console.WriteLine("{0} {1}", ex.GetType().Name, ex.Message); log.Error("Save Step"); log.ErrorFormat("oldstepsequence = {0}", stpseq); log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); @@ -208,7 +210,7 @@ namespace DataLoader if ((nxttok = tkstring.IndexOf("\x1")) > -1) // Comment { // add the comment to annotation table. Set type to comment. - Console.WriteLine("Comment text: {0}", tkstring.Substring(nxttok + 1)); + log.InfoFormat("Comment text: {0}", tkstring.Substring(nxttok + 1)); Annotation annot = Annotation.MakeAnnotation(item, CommentType, null, tkstring.Substring(nxttok + 1), null, dts, userid); } } @@ -239,6 +241,8 @@ namespace DataLoader } catch (Exception ex) { + //Console.WriteLine("Subtexts: {0} {1}", ex.GetType().Name, ex.Message); + frmMain.AddError(ex, "AddStep 2 {0}", stpseq); log.Error("Save Step part 2"); log.ErrorFormat("oldstepsequence = {0}", stpseq); log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); @@ -375,6 +379,8 @@ namespace DataLoader } catch (Exception ex) { + //Console.WriteLine("{0} {1}", ex.GetType().Name, ex.Message); + frmMain.AddError(ex, "MigrateStep"); log.Error("PROCESS STEP"); log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); log.ErrorFormat(ex.StackTrace); diff --git a/PROMS/DataLoader/Transitions.cs b/PROMS/DataLoader/Transitions.cs index d6ff9712..39d98de9 100644 --- a/PROMS/DataLoader/Transitions.cs +++ b/PROMS/DataLoader/Transitions.cs @@ -64,6 +64,7 @@ namespace DataLoader } catch (Exception ex) { + frmMain.AddError(ex,"Error converting transition type '{0}'",dr["TYPE"].ToString()); log.Error("Error converting transition type"); log.ErrorFormat("type from database = {0}", dr["TYPE"].ToString()); log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); @@ -167,6 +168,7 @@ namespace DataLoader } catch (Exception ex) { + frmMain.AddError(ex, "Error addition transition record"); log.Error("Error addition transition record"); log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); } @@ -204,6 +206,7 @@ namespace DataLoader } catch (Exception ex) { + frmMain.AddError(ex, "Error getting transitions '{0}' '{1}'", ProcNumber, seqcvt); 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); @@ -269,10 +272,11 @@ namespace DataLoader private void ShowMissingTransitions() { if (dicTrans_ItemIds.Keys.Count > 0) - log.Warn("Missing Transitions from Dictionary"); + //log.Warn("Missing Transitions from Dictionary"); foreach (string s in dicTrans_ItemIds.Keys) { - log.WarnFormat("{0} - {1}", s, dicTrans_ItemIds[s]); + //log.WarnFormat("{0} - {1}", s, dicTrans_ItemIds[s]); + frmMain.AddError("Missing Transition Destination {0} - {1}", s, dicTrans_ItemIds[s].ItemID); //AddItemAnnotation(dicTrans_ItemIds[s]); } foreach (string s in dicTrans_MigrationErrors.Keys) diff --git a/PROMS/DataLoader/frmLoader.Designer.cs b/PROMS/DataLoader/frmLoader.Designer.cs index 777568c1..794d5155 100644 --- a/PROMS/DataLoader/frmLoader.Designer.cs +++ b/PROMS/DataLoader/frmLoader.Designer.cs @@ -30,6 +30,7 @@ namespace DataLoader private void InitializeComponent() { this.sc = new System.Windows.Forms.SplitContainer(); + this.cbFormatsOnly = new System.Windows.Forms.CheckBox(); this.btnBrowseVeProms = new System.Windows.Forms.Button(); this.tbVePromsPath = new System.Windows.Forms.TextBox(); this.btnCtTok = new System.Windows.Forms.Button(); @@ -59,7 +60,7 @@ namespace DataLoader this.fbd = new System.Windows.Forms.FolderBrowserDialog(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); - this.cbFormatsOnly = new System.Windows.Forms.CheckBox(); + this.tsslError = new System.Windows.Forms.ToolStripStatusLabel(); this.sc.Panel1.SuspendLayout(); this.sc.Panel2.SuspendLayout(); this.sc.SuspendLayout(); @@ -70,7 +71,7 @@ namespace DataLoader // this.sc.Dock = System.Windows.Forms.DockStyle.Fill; this.sc.Location = new System.Drawing.Point(0, 0); - this.sc.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.sc.Margin = new System.Windows.Forms.Padding(2); this.sc.Name = "sc"; this.sc.Orientation = System.Windows.Forms.Orientation.Horizontal; // @@ -111,10 +112,21 @@ namespace DataLoader this.sc.SplitterWidth = 3; this.sc.TabIndex = 46; // + // cbFormatsOnly + // + this.cbFormatsOnly.AutoSize = true; + this.cbFormatsOnly.Location = new System.Drawing.Point(477, 195); + this.cbFormatsOnly.Margin = new System.Windows.Forms.Padding(2); + this.cbFormatsOnly.Name = "cbFormatsOnly"; + this.cbFormatsOnly.Size = new System.Drawing.Size(87, 17); + this.cbFormatsOnly.TabIndex = 73; + this.cbFormatsOnly.Text = "Formats Only"; + this.cbFormatsOnly.UseVisualStyleBackColor = true; + // // btnBrowseVeProms // this.btnBrowseVeProms.Location = new System.Drawing.Point(478, 29); - this.btnBrowseVeProms.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnBrowseVeProms.Margin = new System.Windows.Forms.Padding(2); this.btnBrowseVeProms.Name = "btnBrowseVeProms"; this.btnBrowseVeProms.Size = new System.Drawing.Size(119, 19); this.btnBrowseVeProms.TabIndex = 72; @@ -125,7 +137,7 @@ namespace DataLoader // tbVePromsPath // this.tbVePromsPath.Location = new System.Drawing.Point(2, 29); - this.tbVePromsPath.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tbVePromsPath.Margin = new System.Windows.Forms.Padding(2); this.tbVePromsPath.Name = "tbVePromsPath"; this.tbVePromsPath.Size = new System.Drawing.Size(464, 20); this.tbVePromsPath.TabIndex = 71; @@ -163,7 +175,7 @@ namespace DataLoader // btnBrowseVesam // this.btnBrowseVesam.Location = new System.Drawing.Point(478, 58); - this.btnBrowseVesam.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnBrowseVesam.Margin = new System.Windows.Forms.Padding(2); this.btnBrowseVesam.Name = "btnBrowseVesam"; this.btnBrowseVesam.Size = new System.Drawing.Size(119, 19); this.btnBrowseVesam.TabIndex = 67; @@ -205,7 +217,7 @@ namespace DataLoader this.cbLazy.Checked = true; this.cbLazy.CheckState = System.Windows.Forms.CheckState.Checked; this.cbLazy.Location = new System.Drawing.Point(477, 174); - this.cbLazy.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.cbLazy.Margin = new System.Windows.Forms.Padding(2); this.cbLazy.Name = "cbLazy"; this.cbLazy.Size = new System.Drawing.Size(75, 17); this.cbLazy.TabIndex = 63; @@ -215,7 +227,7 @@ namespace DataLoader // btnConvertSelected // this.btnConvertSelected.Location = new System.Drawing.Point(2, 197); - this.btnConvertSelected.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnConvertSelected.Margin = new System.Windows.Forms.Padding(2); this.btnConvertSelected.Name = "btnConvertSelected"; this.btnConvertSelected.Size = new System.Drawing.Size(160, 19); this.btnConvertSelected.TabIndex = 62; @@ -226,7 +238,7 @@ namespace DataLoader // btnLoadTreeDB // this.btnLoadTreeDB.Location = new System.Drawing.Point(0, 0); - this.btnLoadTreeDB.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnLoadTreeDB.Margin = new System.Windows.Forms.Padding(2); this.btnLoadTreeDB.Name = "btnLoadTreeDB"; this.btnLoadTreeDB.Size = new System.Drawing.Size(118, 19); this.btnLoadTreeDB.TabIndex = 60; @@ -240,7 +252,7 @@ namespace DataLoader this.cbPurgeData.Checked = true; this.cbPurgeData.CheckState = System.Windows.Forms.CheckState.Checked; this.cbPurgeData.Location = new System.Drawing.Point(477, 153); - this.cbPurgeData.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.cbPurgeData.Margin = new System.Windows.Forms.Padding(2); this.cbPurgeData.Name = "cbPurgeData"; this.cbPurgeData.Size = new System.Drawing.Size(119, 17); this.cbPurgeData.TabIndex = 59; @@ -259,7 +271,7 @@ namespace DataLoader // pbStep // this.pbStep.Location = new System.Drawing.Point(159, 150); - this.pbStep.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.pbStep.Margin = new System.Windows.Forms.Padding(2); this.pbStep.Name = "pbStep"; this.pbStep.Size = new System.Drawing.Size(308, 15); this.pbStep.TabIndex = 57; @@ -267,7 +279,7 @@ namespace DataLoader // pbSect // this.pbSect.Location = new System.Drawing.Point(159, 131); - this.pbSect.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.pbSect.Margin = new System.Windows.Forms.Padding(2); this.pbSect.Name = "pbSect"; this.pbSect.Size = new System.Drawing.Size(307, 15); this.pbSect.TabIndex = 56; @@ -275,7 +287,7 @@ namespace DataLoader // pbProc // this.pbProc.Location = new System.Drawing.Point(159, 111); - this.pbProc.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.pbProc.Margin = new System.Windows.Forms.Padding(2); this.pbProc.Name = "pbProc"; this.pbProc.Size = new System.Drawing.Size(308, 15); this.pbProc.TabIndex = 55; @@ -286,7 +298,7 @@ namespace DataLoader this.cbSaveDoc.Checked = true; this.cbSaveDoc.CheckState = System.Windows.Forms.CheckState.Checked; this.cbSaveDoc.Location = new System.Drawing.Point(478, 111); - this.cbSaveDoc.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.cbSaveDoc.Margin = new System.Windows.Forms.Padding(2); this.cbSaveDoc.Name = "cbSaveDoc"; this.cbSaveDoc.Size = new System.Drawing.Size(77, 17); this.cbSaveDoc.TabIndex = 54; @@ -298,7 +310,7 @@ namespace DataLoader // this.cbSaveRTF.AutoSize = true; this.cbSaveRTF.Location = new System.Drawing.Point(478, 132); - this.cbSaveRTF.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.cbSaveRTF.Margin = new System.Windows.Forms.Padding(2); this.cbSaveRTF.Name = "cbSaveRTF"; this.cbSaveRTF.Size = new System.Drawing.Size(75, 17); this.cbSaveRTF.TabIndex = 53; @@ -309,7 +321,7 @@ namespace DataLoader // btnBrowse // this.btnBrowse.Location = new System.Drawing.Point(478, 84); - this.btnBrowse.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnBrowse.Margin = new System.Windows.Forms.Padding(2); this.btnBrowse.Name = "btnBrowse"; this.btnBrowse.Size = new System.Drawing.Size(56, 19); this.btnBrowse.TabIndex = 52; @@ -320,7 +332,7 @@ namespace DataLoader // tbSource // this.tbSource.Location = new System.Drawing.Point(70, 84); - this.tbSource.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tbSource.Margin = new System.Windows.Forms.Padding(2); this.tbSource.Name = "tbSource"; this.tbSource.Size = new System.Drawing.Size(397, 20); this.tbSource.TabIndex = 51; @@ -357,7 +369,7 @@ namespace DataLoader // btnConvert // this.btnConvert.Location = new System.Drawing.Point(2, 85); - this.btnConvert.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnConvert.Margin = new System.Windows.Forms.Padding(2); this.btnConvert.Name = "btnConvert"; this.btnConvert.Size = new System.Drawing.Size(56, 40); this.btnConvert.TabIndex = 46; @@ -369,7 +381,7 @@ namespace DataLoader this.tv.CheckBoxes = true; this.tv.Dock = System.Windows.Forms.DockStyle.Bottom; this.tv.Location = new System.Drawing.Point(0, 7); - this.tv.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.tv.Margin = new System.Windows.Forms.Padding(2); this.tv.Name = "tv"; this.tv.Size = new System.Drawing.Size(622, 210); this.tv.TabIndex = 24; @@ -379,29 +391,30 @@ namespace DataLoader // statusStrip1 // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabel1}); - this.statusStrip1.Location = new System.Drawing.Point(0, 418); + this.toolStripStatusLabel1, + this.tsslError}); + this.statusStrip1.Location = new System.Drawing.Point(0, 400); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(622, 22); + this.statusStrip1.Size = new System.Drawing.Size(622, 40); this.statusStrip1.TabIndex = 47; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusLabel1 // + this.toolStripStatusLabel1.AutoSize = false; + this.toolStripStatusLabel1.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; - this.toolStripStatusLabel1.Size = new System.Drawing.Size(105, 17); + this.toolStripStatusLabel1.Size = new System.Drawing.Size(300, 35); this.toolStripStatusLabel1.Text = "Status Information"; + this.toolStripStatusLabel1.TextAlign = System.Drawing.ContentAlignment.TopLeft; // - // cbFormatsOnly + // tsslError // - this.cbFormatsOnly.AutoSize = true; - this.cbFormatsOnly.Location = new System.Drawing.Point(477, 195); - this.cbFormatsOnly.Margin = new System.Windows.Forms.Padding(2); - this.cbFormatsOnly.Name = "cbFormatsOnly"; - this.cbFormatsOnly.Size = new System.Drawing.Size(87, 17); - this.cbFormatsOnly.TabIndex = 73; - this.cbFormatsOnly.Text = "Formats Only"; - this.cbFormatsOnly.UseVisualStyleBackColor = true; + this.tsslError.AutoSize = false; + this.tsslError.Name = "tsslError"; + this.tsslError.Size = new System.Drawing.Size(300, 35); + this.tsslError.Text = "No Errors"; + this.tsslError.TextAlign = System.Drawing.ContentAlignment.TopLeft; // // frmLoader // @@ -410,9 +423,9 @@ namespace DataLoader this.ClientSize = new System.Drawing.Size(622, 440); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.sc); - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Margin = new System.Windows.Forms.Padding(2); this.Name = "frmLoader"; - this.Text = "frmLoader"; + this.Text = "PROMS-2010 Data Loader"; this.Load += new System.EventHandler(this.frmLoader_Load); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmLoader_FormClosing); this.sc.Panel1.ResumeLayout(false); @@ -459,5 +472,6 @@ namespace DataLoader private System.Windows.Forms.Button btnBrowseVeProms; private System.Windows.Forms.TextBox tbVePromsPath; private System.Windows.Forms.CheckBox cbFormatsOnly; + private System.Windows.Forms.ToolStripStatusLabel tsslError; } } \ No newline at end of file diff --git a/PROMS/DataLoader/frmLoader.cs b/PROMS/DataLoader/frmLoader.cs index 1960fc6b..9fd846e3 100644 --- a/PROMS/DataLoader/frmLoader.cs +++ b/PROMS/DataLoader/frmLoader.cs @@ -60,8 +60,45 @@ namespace DataLoader Application.DoEvents(); } } + private frmErrors _MyFrmErrors = null; - public string tbSourceText { get { return tbSource.Text; } set { tbSource.Text = value; } } + public frmErrors MyFrmErrors + { + get + { + if (_MyFrmErrors == null) + { + _MyFrmErrors = new frmErrors(this); + _MyFrmErrors.FormClosing += new FormClosingEventHandler(_MyFrmErrors_FormClosing); + } + return _MyFrmErrors; + } + } + void _MyFrmErrors_FormClosing(object sender, FormClosingEventArgs e) + { + _MyFrmErrors = null; + } + public string MyError + { + get { return tsslError.Text; } + set { MyFrmErrors.Add(value); tsslError.Text = string.Format("{0} Errors", MyFrmErrors.MyErrors.Count); } + } + public void AddError(string format, params object[] objs) + { + MyError = string.Format(format, objs); + } + public void AddError(Exception ex, string format, params object[] objs) + { + StringBuilder sb = new StringBuilder( string.Format(format, objs)); + int indent = 0; + while (ex != null) + { + sb.Append("\r\n" + "".PadRight((++indent)*2,' ') + string.Format("{0} - {1}",ex.GetType().Name,ex.Message)); + ex=ex.InnerException; + } + MyError = sb.ToString(); + } + public string tbSourceText { get { return tbSource.Text; } set { tbSource.Text = value; } } public frmLoader() { @@ -184,23 +221,51 @@ namespace DataLoader ldr.ClearData(); bool suc = ldr.LoadFolders(tbVePromsPath.Text); } + private System.Diagnostics.Process [] WordProcesses + { + get + { + return System.Diagnostics.Process.GetProcessesByName("WINWORD"); + } + } private void btnConvert_Click(object sender, System.EventArgs e) { - Database.LoggingInfo = false; - bool success = true; - // if purge data, purge it all & reload folders & security. - if (cbPurgeData.Checked) - { - ldr.ClearData(); - success = ldr.LoadFolders(tbVePromsPath.Text); - if (success) success = ldr.LoadSecurity(tbVesamPath.Text, tbVePromsPath.Text); - if (cbFormatsOnly.Checked) - { - MessageBox.Show("Formats Loaded"); - return; - } - } + try + { + System.Diagnostics.Process[] wordProcesses = WordProcesses; + MyFrmErrors.Clear(); + if (wordProcesses.Length > 0) + { + AddError("{0} copies of MS Word are running", wordProcesses.Length); + if (MessageBox.Show("MS Word is Running and must be stopped", "MS Word is Running", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + TerminateProcesses(wordProcesses); + MyFrmErrors.Clear(); + } + else + return; + } + Database.LoggingInfo = false; + bool success = true; + // if purge data, purge it all & reload folders & security. + if (cbPurgeData.Checked) + { + Status = "Purging Data"; + ldr.ClearData(); + Status = "Loading Folders"; + success = ldr.LoadFolders(tbVePromsPath.Text); + if (success) + { + Status = "Loading Security"; + success = ldr.LoadSecurity(tbVesamPath.Text, tbVePromsPath.Text); + } + if (cbFormatsOnly.Checked) + { + MessageBox.Show("Formats Loaded"); + return; + } + } if (success) { TimeSpan ts = new TimeSpan(); @@ -211,7 +276,8 @@ namespace DataLoader if (vi.Title.ToUpper() == tbSource.Text.ToUpper()) // is this the procedure set we want to convert? { v = DocVersion.Get(vi.VersionID); - ts+=ldr.MigrateDocVersion(v, true); + Status = "Load " + v.Title + " - " + v.Name; + ts += ldr.MigrateDocVersion(v, true); } //v = DocVersion.Get(vi.VersionID); //bool convertProcedures = (vi.Title.ToUpper() == tbSource.Text.ToUpper()); @@ -220,7 +286,20 @@ namespace DataLoader } MessageBox.Show(string.Format("{0} seconds", ts.TotalSeconds)); } + } + catch (Exception ex) + { + AddError("===================== Fatal Error ==========================\r\n{0} - {1}", ex.GetType().Name, ex.Message); + MessageBox.Show(ex.Message, "Fatal Error During Loading", MessageBoxButtons.OK, MessageBoxIcon.Error); + _MyLog.Fatal(ex.Message); + } } + + private void TerminateProcesses(System.Diagnostics.Process [] wordProcesses) + { + foreach (System.Diagnostics.Process proc in wordProcesses) + proc.Kill(); + } public void UpdateLabels(int incPrc, int incSec, int incStp) { if (incPrc == 0 && incSec == 0 && incStp == 0)//Reset @@ -241,6 +320,7 @@ namespace DataLoader catch (Exception ex) { _MyLog.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException); + AddError(ex, "UpdateLabels"); } } //Database.LoggingInfo = (pbProc.Value > 153 && pbSect.Value > 11 && pbStep.Value > 61);