Example #1
0
        /// <summary>
        /// Converts a date value that is stored in a object to a DateTime value that is
        /// guaranteed to be valid.
        ///
        /// In case the date value in the object is empty, either the lowest or the
        /// highest possible date is returned.
        ///
        /// @comment Very useful for untyped data in DataSets that is known to be of
        /// DateTime type.
        ///
        /// </summary>
        /// <param name="ADateObject">TObject containing a date value</param>
        /// <param name="ANullHandling">Switch to return either the lowest (nhReturnLowestDate)
        /// or the highest (nhReturnHighestDate) possible date in case the date value
        /// in the TObject is empty</param>
        /// <returns>A valid DateTime
        /// </returns>
        public static DateTime ObjectToDate(object ADateObject, TNullHandlingEnum ANullHandling)
        {
            DateTime ReturnValue;

            if (ADateObject != null)
            {
                if (ADateObject is DateTime)
                {
                    ReturnValue = (DateTime)ADateObject;
                }
                else if (!(ADateObject.ToString() == ""))
                {
                    ReturnValue = Convert.ToDateTime(ADateObject);
                }
                else
                {
                    if (ANullHandling == TNullHandlingEnum.nhReturnLowestDate)
                    {
                        ReturnValue = DateTime.MinValue;
                    }
                    else
                    {
                        ReturnValue = DateTime.MaxValue;
                    }
                }
            }
            else
            {
                if (ANullHandling == TNullHandlingEnum.nhReturnLowestDate)
                {
                    ReturnValue = DateTime.MinValue;
                }
                else
                {
                    ReturnValue = DateTime.MaxValue;
                }
            }

            return(ReturnValue);
        }
Example #2
0
        /// <summary>
        /// Converts a DataColumn that holds a DateTime into a DateTime that is
        /// guaranteed to be valid.
        ///
        /// In case the date value in the DataColumn is DBNull, the lowest possible date
        /// is returned.
        ///
        /// @comment Very useful for DataColumns in Typed DataTables that are of DateTime
        /// type. Using this function, no Exception is thrown when trying to get the
        /// value of a DataColumn of Type DateTime that is DBNull.
        ///
        /// </summary>
        /// <param name="ADataColumn">DataColumn of Type DateTime</param>
        /// <param name="ADataRow">DataRow in which the value is found</param>
        /// <param name="ANullHandling">Switch to return either the lowest (nhReturnLowestDate)
        /// or the highest (nhReturnHighestDate) possible date in case the date value
        /// in the TObject is empty</param>
        /// <returns>A valid DateTime
        /// </returns>
        public static DateTime DateColumnToDate(DataColumn ADataColumn, DataRow ADataRow, TNullHandlingEnum ANullHandling)
        {
            DateTime ReturnValue;

            if (ADataRow.IsNull(ADataColumn))
            {
                if (ANullHandling == TNullHandlingEnum.nhReturnLowestDate)
                {
                    ReturnValue = DateTime.MinValue;
                }
                else
                {
                    ReturnValue = DateTime.MaxValue;
                }

                // MessageBox.Show('Column is DBNull!');
            }
            else
            {
                // MessageBox.Show('Column is not DBNull!');
                ReturnValue = (DateTime)ADataRow[ADataColumn];
            }

            return ReturnValue;
        }
Example #3
0
        /// <summary>
        /// Converts a date value that is stored in a object to a DateTime value that is
        /// guaranteed to be valid.
        ///
        /// In case the date value in the object is empty, either the lowest or the
        /// highest possible date is returned.
        ///
        /// @comment Very useful for untyped data in DataSets that is known to be of
        /// DateTime type.
        ///
        /// </summary>
        /// <param name="ADateObject">TObject containing a date value</param>
        /// <param name="ANullHandling">Switch to return either the lowest (nhReturnLowestDate)
        /// or the highest (nhReturnHighestDate) possible date in case the date value
        /// in the TObject is empty</param>
        /// <returns>A valid DateTime
        /// </returns>
        public static DateTime ObjectToDate(object ADateObject, TNullHandlingEnum ANullHandling)
        {
            DateTime ReturnValue;

            if (ADateObject != null)
            {
                if (ADateObject is DateTime)
                {
                    ReturnValue = (DateTime)ADateObject;
                }
                else if (!(ADateObject.ToString() == ""))
                {
                    ReturnValue = Convert.ToDateTime(ADateObject);
                }
                else
                {
                    if (ANullHandling == TNullHandlingEnum.nhReturnLowestDate)
                    {
                        ReturnValue = DateTime.MinValue;
                    }
                    else
                    {
                        ReturnValue = DateTime.MaxValue;
                    }
                }
            }
            else
            {
                if (ANullHandling == TNullHandlingEnum.nhReturnLowestDate)
                {
                    ReturnValue = DateTime.MinValue;
                }
                else
                {
                    ReturnValue = DateTime.MaxValue;
                }
            }

            return ReturnValue;
        }
Example #4
0
        /// <summary>
        /// Converts a DataColumn that holds a DateTime into a DateTime that is
        /// guaranteed to be valid.
        ///
        /// In case the date value in the DataColumn is DBNull, the lowest possible date
        /// is returned.
        ///
        /// @comment Very useful for DataColumns in Typed DataTables that are of DateTime
        /// type. Using this function, no Exception is thrown when trying to get the
        /// value of a DataColumn of Type DateTime that is DBNull.
        ///
        /// </summary>
        /// <param name="ADataColumn">DataColumn of Type DateTime</param>
        /// <param name="ADataRow">DataRow in which the value is found</param>
        /// <param name="ANullHandling">Switch to return either the lowest (nhReturnLowestDate)
        /// or the highest (nhReturnHighestDate) possible date in case the date value
        /// in the TObject is empty</param>
        /// <returns>A valid DateTime
        /// </returns>
        public static DateTime DateColumnToDate(DataColumn ADataColumn, DataRow ADataRow, TNullHandlingEnum ANullHandling)
        {
            DateTime ReturnValue;

            if (ADataRow.IsNull(ADataColumn))
            {
                if (ANullHandling == TNullHandlingEnum.nhReturnLowestDate)
                {
                    ReturnValue = DateTime.MinValue;
                }
                else
                {
                    ReturnValue = DateTime.MaxValue;
                }

                // MessageBox.Show('Column is DBNull!');
            }
            else
            {
                // MessageBox.Show('Column is not DBNull!');
                ReturnValue = (DateTime)ADataRow[ADataColumn];
            }

            return(ReturnValue);
        }