From f5378a0f27ee624bbd01310627f9fbab531d28b2 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 31 May 2012 16:18:44 +0000 Subject: [PATCH] =?UTF-8?q?Fixes=20a=20bug=20in=20importing=20the=2016-bit?= =?UTF-8?q?=20Approved=20PDF=20files.=20=20We=20were=20not=20handling=20in?= =?UTF-8?q?valid=20(and=20null)=20dates=20when=20reading=20through=20the?= =?UTF-8?q?=20list=20of=20approved=20procedures=20(from=20the=20SET.dbf=20?= =?UTF-8?q?file).=20If=20an=20invalid=20date=20is=20found,=20the=20current?= =?UTF-8?q?=20date=20is=20used=20instead=20=E2=80=93=20copied=20existing?= =?UTF-8?q?=20logic=20we=20have=20in=20other=20places=20of=20the=20DataLoa?= =?UTF-8?q?der.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PROMS/DataLoader/Approve.cs | 63 ++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/PROMS/DataLoader/Approve.cs b/PROMS/DataLoader/Approve.cs index 9bafc138..d1011112 100644 --- a/PROMS/DataLoader/Approve.cs +++ b/PROMS/DataLoader/Approve.cs @@ -327,6 +327,7 @@ namespace DataLoader } public partial class ProcInfo { + private log4net.ILog log; private string _Number; public string Number { @@ -375,10 +376,14 @@ namespace DataLoader Entry = dr["ENTRY"].ToString(); UserID = dr["INITIALS"].ToString(); if (UserID == string.Empty) UserID = "UNKNOWN"; - string date = System.DateTime.Parse(dr["DATE"].ToString()).ToString("MM/dd/yyyy"); - string time = dr["TIME"].ToString(); - date += " " + time.Substring(0, 2) + ":" + time.Substring(2, 2); - StartDateTime = System.DateTime.Parse(date); + //string date = GetDTS(dr["DATE"].ToString(), dr["TIME"].ToString()).ToString("MM/dd/yyyy HH:MM");//System.DateTime.Parse(dr["DATE"].ToString()).ToString("MM/dd/yyyy"); + //string time = dr["TIME"].ToString(); + //if (time.EndsWith(":")) + // date += " " + time.Substring(0, 2) + ":" + time.Substring(2, 2); + //else + // date += " " + time.Substring(0, 2) + ":" + time.Substring(3, 2); + //StartDateTime = System.DateTime.Parse(date); + StartDateTime = GetDTS(dr["DATE"].ToString(), dr["TIME"].ToString()); FixItems fis = new FixItems(new FileInfo(string.Format(@"{0}\{1}.fix", afpath, Entry))); if (fis.Count > 0) { @@ -387,6 +392,56 @@ namespace DataLoader ReviewDate = fis[0].ReviewDate; } } + public System.DateTime GetDTS(string date, string time) + { + // Set the date/time stamp. If there is no 'date', set the date + // to 1/1/2000 (this can be changed!). If there is not 'time', + // set the time to 0:0:0 (midnight). + + System.DateTime dts = System.DateTime.Now; + string month = "01"; + string day = "01"; + string year = "2000"; + string hour = ""; + string minute = ""; + try + { + if (date != null && date != "") + { + int indx1 = date.IndexOf("/"); + month = date.Substring(0, indx1); + int indx2 = date.IndexOf("/", indx1 + 1); + day = date.Substring(indx1 + 1, indx2 - indx1 - 1); + year = date.Substring(indx2 + 1, 4); + } + if (time == null || time == "") + { + hour = "0"; + minute = "0"; + } + else + { + + hour = time.Substring(0, 2); + int indxc = time.IndexOfAny(":A-".ToCharArray()); + if (indxc == time.Length - 1) + minute = time.Substring(2, 2); + else + minute = time.Substring(indxc + 1, time.Length - indxc - 1); + } + dts = new System.DateTime(System.Convert.ToInt32(year), System.Convert.ToInt32(month), System.Convert.ToInt32(day), + System.Convert.ToInt32(hour), System.Convert.ToInt32(minute), 0); + } + catch (System.Exception ex) + { + 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; + } + return dts; + } private string GetDBFRevDate(string afpath) {