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) {