public static string DateFormatsEnumtoCSharpDate(DateFormatsEnum dateEnum) { string cSharpDateFormat = ""; if (dateEnum == DateFormatsEnum.NotApplicable) { //DataPanel.getDateFormat cSharpDateFormat = "MM/dd/yyyy HH:mm:ss"; } if (dateEnum == DateFormatsEnum.mSLdSLy) { cSharpDateFormat = "MM/dd/y"; } if (dateEnum == DateFormatsEnum.dSLmSLy) { cSharpDateFormat = "dd/MM/yy"; } if (dateEnum == DateFormatsEnum.ySLmSLd) { cSharpDateFormat = "y/MM/dd"; } if (dateEnum == DateFormatsEnum.ySLdSLm) { cSharpDateFormat = "y/dd/MM"; } if (dateEnum == DateFormatsEnum.mDAdDAy) { cSharpDateFormat = "MM-dd-y"; } if (dateEnum == DateFormatsEnum.dDAmDAy) { cSharpDateFormat = "dd-MM-y"; } if (dateEnum == DateFormatsEnum.yDAmDAd) { cSharpDateFormat = "y-MM-dd"; } if (dateEnum == DateFormatsEnum.yDAdDAm) { cSharpDateFormat = "y-dd-MM"; } //Handling 4 year format if (dateEnum == DateFormatsEnum.mSLdSLY) { cSharpDateFormat = "MM/dd/yyyy"; } if (dateEnum == DateFormatsEnum.dSLmSLY) { cSharpDateFormat = "dd/MM/yyyy"; } if (dateEnum == DateFormatsEnum.YSLmSLd) { cSharpDateFormat = "yyyy/MM/dd"; } if (dateEnum == DateFormatsEnum.YSLdSLm) { cSharpDateFormat = "yyyy/dd/MM"; } if (dateEnum == DateFormatsEnum.mDAdDAY) { cSharpDateFormat = "MM-dd-yyyy"; } if (dateEnum == DateFormatsEnum.dDAmDAY) { cSharpDateFormat = "dd-MM-yyyy"; } if (dateEnum == DateFormatsEnum.YDAmDAd) { cSharpDateFormat = "yyyy-MM-dd"; } if (dateEnum == DateFormatsEnum.YDAdDAm) { cSharpDateFormat = "yyyy-dd-MM"; } //Added by Aaron 07/25/2020 //Handling hour, minute and secs if (dateEnum == DateFormatsEnum.mSLdSLySPHCOMCOS) { cSharpDateFormat = "MM/dd/y HH:mm:ss"; } if (dateEnum == DateFormatsEnum.dSLmSLySPHCOMCOS) { cSharpDateFormat = "dd/MM/yy HH:mm:ss"; } if (dateEnum == DateFormatsEnum.ySLmSLdSPHCOMCOS) { cSharpDateFormat = "y/MM/dd HH:mm:ss"; } if (dateEnum == DateFormatsEnum.ySLdSLmSPHCOMCOS) { cSharpDateFormat = "y/dd/MM HH:mm:ss"; } if (dateEnum == DateFormatsEnum.mDAdDAySPHCOMCOS) { cSharpDateFormat = "MM-dd-y HH:mm:ss"; } if (dateEnum == DateFormatsEnum.dDAmDAySPHCOMCOS) { cSharpDateFormat = "dd-MM-y HH:mm:ss"; } if (dateEnum == DateFormatsEnum.yDAmDAdSPHCOMCOS) { cSharpDateFormat = "y-MM-dd HH:mm:ss"; } if (dateEnum == DateFormatsEnum.yDAdDAmSPHCOMCOS) { cSharpDateFormat = "y-dd-MM HH:mm:ss"; } //Handling 4 year format if (dateEnum == DateFormatsEnum.mSLdSLYSPHCOMCOS) { cSharpDateFormat = "MM/dd/yyyy HH:mm:ss"; } if (dateEnum == DateFormatsEnum.dSLmSLYSPHCOMCOS) { cSharpDateFormat = "dd/MM/yyyy HH:mm:ss"; } if (dateEnum == DateFormatsEnum.YSLmSLdSPHCOMCOS) { cSharpDateFormat = "yyyy/MM/dd HH:mm:ss"; } if (dateEnum == DateFormatsEnum.YSLdSLmSPHCOMCOS) { cSharpDateFormat = "yyyy/dd/MM HH:mm:ss"; } if (dateEnum == DateFormatsEnum.mDAdDAYSPHCOMCOS) { cSharpDateFormat = "MM-dd-yyyy HH:mm:ss"; } if (dateEnum == DateFormatsEnum.dDAmDAYSPHCOMCOS) { cSharpDateFormat = "dd-MM-yyyy HH:mm:ss"; } if (dateEnum == DateFormatsEnum.YDAmDAdSPHCOMCOS) { cSharpDateFormat = "yyyy-MM-dd HH:mm:ss"; } if (dateEnum == DateFormatsEnum.YDAdDAmSPHCOMCOS) { cSharpDateFormat = "yyyy-dd-MM HH:mm:ss"; } return(cSharpDateFormat); }
object IList.this[int fIndex] { get { if (dictIndex.ContainsKey(fIndex)) { return(dictIndex[fIndex]); } // Now we have our type. Let's create an instance from it: object generetedObject = Activator.CreateInstance(type); // Loop over all the generated properties, and assign the values from our XML: PropertyInfo[] properties = type.GetProperties(); int propertiesCounter = 0; bool rowatonce = true; string[] rowdata = null; if (rowatonce) { rowdata = GetRowData(fIndex); //fetched row } if (rowdata == null) { return(null); } long celldata = 0; bool isparsed = false; bool ToLocalDateTime = false; //25Aug2017: TRUE: Date will be converted to local date/time string dateformat = ""; //25Aug2017 yy-MMM-dd hh:mm:ss zzz DateTime dt = new DateTime(1970, 1, 1); for (int i = 0; i < _dataSource.FewVariables.Count; ++i) { if ((_dataSource.FewVariables[i].DataClass.Equals("POSIXct") || _dataSource.Variables[i].DataClass.Equals("Date") )) { DateFormatsEnum datefmt = _dataSource.FewVariables[i].DateFormat; // dateformat = DateformatConvertor.DateEnumToString(datefmt); // mSLdSLy, dSLmSLy, ySLmSLd, ySLdSLm, mDAdDAy, dDAmDAy, yDAmDAd, yDAdDAm //NOTE: dateformat holds the format supported by c# dateformat = DateformatConvertor.DateFormatsEnumtoCSharpDate(datefmt); if (rowdata[i] == "<NA>" || rowdata[i] == "NA") { //dt = ToLocalDateTime? new DateTime(0001, 01, 01).ToLocalTime() : new DateTime(0001, 01, 01) ; properties[propertiesCounter].SetValue(generetedObject, "NA", null); } else if (rowdata[i].Contains("AM") || rowdata[i].Contains("PM"))//Date string { dt = ToLocalDateTime ? DateTime.Parse(rowdata[i]).ToLocalTime() : DateTime.Parse(rowdata[i]); properties[propertiesCounter].SetValue(generetedObject, dt.ToString(dateformat), null); } else { if (!Int64.TryParse(rowdata[i], out celldata)) { celldata = 0; } try { //used before 16Feb2020 //dt = ToLocalDateTime ? new DateTime(1970, 1, 1).AddSeconds(celldata).ToLocalTime() : new DateTime(1970, 1, 1).AddSeconds(celldata + _dataSource.FewVariables[i].UTCOffset*3600);//UTC in secs +19800 //Excel dates are in UTC=0 if we do ToLocalTime() it will cause it to shift // So we do not do ToLocalTime() on UTC=0 if (_dataSource.FewVariables[i].UTCOffset == 0) { dt = new DateTime(1970, 1, 1).AddSeconds(celldata + _dataSource.FewVariables[i].UTCOffset * 3600); } else { dt = new DateTime(1970, 1, 1).AddSeconds(celldata).ToLocalTime(); } properties[propertiesCounter].SetValue(generetedObject, dt.ToString(dateformat), null); } catch (Exception ex) { if (ex != null) { } } } } else if ((_dataSource.FewVariables[i].DataClass.Equals("Date"))) //For Date type show only Date part { dateformat = "yyyy-MM-dd"; if (rowdata[i] == "<NA>" || rowdata[i] == "NA") { //dt = ToLocalDateTime ? new DateTime(0001, 01, 01).ToLocalTime() : new DateTime(0001, 01, 01); properties[propertiesCounter].SetValue(generetedObject, "NA", null); } else if (rowdata[i].Contains("AM") || rowdata[i].Contains("PM"))//R Date type when read by R.NET(uses DateTime) { dt = ToLocalDateTime ? DateTime.Parse(rowdata[i]).ToLocalTime() : DateTime.Parse(rowdata[i]); properties[propertiesCounter].SetValue(generetedObject, dt.Date.ToString(dateformat), null); } else // Total number of signed seconds { celldata = Convert.ToInt64(rowdata[i]);//, celldata); try { dt = ToLocalDateTime ? new DateTime(1970, 1, 1).AddSeconds(celldata).ToLocalTime() : new DateTime(1970, 1, 1).AddSeconds(celldata); properties[propertiesCounter].SetValue(generetedObject, dt.Date.ToString(dateformat), null); } catch (Exception ex) { if (ex != null) { } } } } else { //01Jul2016 //This is codition is added because properties is having 15 elements and rowdat is having 16. if (i < properties.Length && i < rowdata.Length) { if (rowatonce) { properties[propertiesCounter].SetValue(generetedObject, rowdata[i], null); } else { properties[propertiesCounter].SetValue(generetedObject, GetCellValue(fIndex, i), null); } } } propertiesCounter++; } dictIndex.Add(fIndex, generetedObject); //A. row(object) is added to dictionary. Key is index dict.Add(generetedObject, fIndex); //A. row is added to dictionary. Key is row(object) return(generetedObject); } set { } }
public static string DateEnumToString(DateFormatsEnum enumDateFormat) { //mSLdSLy, dSLmSLy, ySLmSLd, ySLdSLm, mDAdDAy, dDAmDAy, yDAmDAd, yDAdDAm if (enumDateFormat.ToString() == "NotApplicable") { return("Not Applicable"); } else if (enumDateFormat.ToString() == "mSLdSLy") { return("%m/%d/%y"); } else if (enumDateFormat.ToString() == "dSLmSLy") { return("%d/%m/%y"); } else if (enumDateFormat.ToString() == "ySLmSLd") { return("%y/%m/%d"); } else if (enumDateFormat.ToString() == "ySLdSLm") { return("%y/%d/%m"); } else if (enumDateFormat.ToString() == "mDAdDAy") { return("%m-%d-%y"); } else if (enumDateFormat.ToString() == "dDAmDAy") { return("%d-%m-%y"); } else if (enumDateFormat.ToString() == "yDAmDAd") { return("%y-%m-%d"); } else if (enumDateFormat.ToString() == "yDAdDAm") { return("%y-%d-%m"); } if (enumDateFormat.ToString() == "mSLdSLY") { return("%m/%d/%Y"); } else if (enumDateFormat.ToString() == "dSLmSLY") { return("%d/%m/%Y"); } else if (enumDateFormat.ToString() == "YSLmSLd") { return("%Y/%m/%d"); } else if (enumDateFormat.ToString() == "YSLdSLm") { return("%Y/%d/%m"); } else if (enumDateFormat.ToString() == "mDAdDAY") { return("%m-%d-%Y"); } else if (enumDateFormat.ToString() == "dDAmDAY") { return("%d-%m-%Y"); } else if (enumDateFormat.ToString() == "YDAmDAd") { return("%Y-%m-%d"); } else if (enumDateFormat.ToString() == "YDAdDAm") { return("%Y-%d-%m"); } else if (enumDateFormat.ToString() == "mSLdSLySPHCOMCOS") { return("%m/%d/%y %H:%M:%S"); } else if (enumDateFormat.ToString() == "dSLmSLySPHCOMCOS") { return("%d/%m/%y %H:%M:%S"); } else if (enumDateFormat.ToString() == "ySLmSLdSPHCOMCOS") { return("%y/%m/%d %H:%M:%S"); } else if (enumDateFormat.ToString() == "ySLdSLmSPHCOMCOS") { return("%y/%d/%m %H:%M:%S"); } else if (enumDateFormat.ToString() == "mDAdDAySPHCOMCOS") { return("%m-%d-%y %H:%M:%S"); } else if (enumDateFormat.ToString() == "dDAmDAySPHCOMCOS") { return("%d-%m-%y %H:%M:%S"); } else if (enumDateFormat.ToString() == "yDAmDAdSPHCOMCOS") { return("%y-%m-%d %H:%M:%S"); } else if (enumDateFormat.ToString() == "yDAdDAmSPHCOMCOS") { return("%y-%d-%m %H:%M:%S"); } if (enumDateFormat.ToString() == "mSLdSLYSPHCOMCOS") { return("%m/%d/%Y %H:%M:%S"); } else if (enumDateFormat.ToString() == "dSLmSLYSPHCOMCOS") { return("%d/%m/%Y %H:%M:%S"); } else if (enumDateFormat.ToString() == "YSLmSLdSPHCOMCOS") { return("%Y/%m/%d %H:%M:%S"); } else if (enumDateFormat.ToString() == "YSLdSLmSPHCOMCOS") { return("%Y/%d/%m %H:%M:%S"); } else if (enumDateFormat.ToString() == "mDAdDAYSPHCOMCOS") { return("%m-%d-%Y %H:%M:%S"); } else if (enumDateFormat.ToString() == "dDAmDAYSPHCOMCOS") { return("%d-%m-%Y %H:%M:%S"); } else if (enumDateFormat.ToString() == "YDAmDAdSPHCOMCOS") { return("%Y-%m-%d %H:%M:%S"); } else if (enumDateFormat.ToString() == "YDAdDAmSPHCOMCOS") { return("%Y-%d-%m %H:%M:%S"); } else { return("%m/%d/%y %H:%M:%S"); } }