Пример #1
0
        /// <summary>
        /// 解析日期时间型表达式
        /// </summary>
        /// <param name="p_srcValue">数据值</param>
        /// <param name="p_mask">掩码格式</param>
        /// <returns>解析后的表达式</returns>
        public static string ParseDateTimeMask(object p_srcValue, string p_mask)
        {
            DateTimeFormatInfo     formatInfo = DateTimeMaskManager.GetGoodCalendarDateTimeFormatInfo(CultureInfo.CurrentCulture);
            DateTimeMaskFormatInfo maskInfo   = new DateTimeMaskFormatInfo(p_mask, formatInfo);
            DateTime?dt = null;

            if ((p_srcValue is DateTime) || (p_srcValue == null))
            {
                dt = (DateTime?)p_srcValue;
            }
            else if (p_srcValue is TimeSpan)
            {
                TimeSpan span = (TimeSpan)p_srcValue;
                dt = (DateTime?)new DateTime(span.Ticks);
            }
            else
            {
                try
                {
                    dt = new DateTime?(DateTime.Parse(p_srcValue.ToString(), CultureInfo.InvariantCulture));
                }
                catch
                { }
            }

            if (dt.HasValue)
            {
                return(maskInfo.Format(dt.Value));
            }
            return(string.Empty);
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mask"></param>
 /// <param name="isOperatorMask"></param>
 /// <param name="culture"></param>
 /// <param name="allowNull"></param>
 public DateTimeMaskManager(string mask, bool isOperatorMask, CultureInfo culture, bool allowNull)
 {
     _AllowNull                  = true;
     _cachedValue                = new DateTime(0L);
     _cachedIndex                = -1;
     _cachedDCP                  = -1;
     _cachedDSA                  = -1;
     _AllowNull                  = allowNull;
     _IsOperatorMask             = isOperatorMask;
     _fInitialMask               = mask;
     _fInitialDateTimeFormatInfo = GetGoodCalendarDateTimeFormatInfo(culture);
     _fFormatInfo                = new DateTimeMaskFormatInfo(mask, _fInitialDateTimeFormatInfo);
     CursorHome(false);
 }