示例#1
0
        public bool CreateDate(IDateOrder dateorder)
        {
            try
            {
                //get date column name from settings
                string dateColName = Settings.Default.TimeStampName;

                //create object to build date list
                IProcessDateTime process    = new ProcessDate(_data);
                List <DateTime>  newdateCol = process.BuildDateTimeList(dateorder);
                //add
                if (Utils.AddColtoDataTable <DateTime>(dateColName, newdateCol, _data))
                {
                    DataColumn dc = _data.Columns[dateColName];
                    _dateIndex = dc.Ordinal;
                    _columns.Add(new SessionColumn(dc.Ordinal, dc.ColumnName));
                    this[dateColName].ColumnType = SessionColumnType.DateTime;
                    _dateStatus = DataSetDateStatus.Found;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#2
0
        public List <DateTime> BuildDateTimeList(IDateOrder dateorder)
        {
            //depends on IDateOrder object parameters provided elsewhere
            //the datepart  column indexes will need to be provided by the user at run time
            try
            {
                Type            type       = dateorder.GetType();
                PropertyInfo [] properties = type.GetProperties();

                List <DateOrderIndexValue> dateidx = new List <DateOrderIndexValue>();
                foreach (PropertyInfo property in properties)
                {
                    //Console.WriteLine(property.GetValue(dateorder,null).GetType ());
                    dateidx.Add(((DateOrderIndexValue )property.GetValue(dateorder, null)));
                }

                Type datetype = typeof(DateOrderIndexValue);

                Dictionary <string, string> values     = new Dictionary <string, string>();
                Dictionary <string, int>    colindexes = new Dictionary <string, int>();

                List <DateTime> dateList = new List <DateTime>();
                foreach (DataRow row in _data.Rows)
                {
                    //populate dictionary of values and indexes
                    foreach (DateOrderIndexValue property in dateidx)
                    {
                        //Console.WriteLine(property.index);
                        property.value = row[property.index].ToString();
                    }

                    DateTime resultdate = dateorder.AssembleDate();
                    dateList.Add(resultdate);
                }
                return(dateList);
            }
            catch (Exception e)
            {
                throw e;
            }
        }