Пример #1
0
        public static CondFormat Deserialize(
            XmlTextReader tr)
        {
            string txt;

            CondFormat cf = new CondFormat();

            txt = tr.GetAttribute("ColumnType");
            if (txt != null)
            {
                EnumUtil.TryParse(txt, out cf.ColumnType);
            }

            XmlUtil.GetStringAttribute(tr, "Name", ref cf.Name);
            XmlUtil.GetBoolAttribute(tr, "Option1", ref cf.Option1);
            XmlUtil.GetBoolAttribute(tr, "Option2", ref cf.Option2);
            //XmlUtil.GetBoolAttribute(tr, "ShowInHeaders", ref cf.ShowInHeaders);

            tr.Read();             // get CondFormatRules element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "CondFormatRules"))
            {
                throw new Exception("CondFormat.Deserialize - \"CondFormat\" end element not found");
            }

            if (!tr.IsEmptyElement)
            {
                cf.Rules = CondFormatRules.Deserialize(tr);
                cf.Rules.InitializeInternalMatchValues(cf.ColumnType);
            }

            else
            {
                cf.Rules = new CondFormatRules(); // no rules
            }
            tr.Read();                            // get CondFormat end element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "CondFormat") || tr.NodeType != XmlNodeType.EndElement)
            {
                throw new Exception("CondFormat.Deserialize - Expected CondFormat end element");
            }

            if (cf.ColumnType == MetaColumnType.Date && cf.Rules != null)
            {             // store normalized dates
                foreach (CondFormatRule rule in cf.Rules)
                {
                    if (!String.IsNullOrEmpty(rule.Value))
                    {
                        rule.ValueNormalized = DateTimeMx.Normalize(rule.Value);
                    }

                    if (!String.IsNullOrEmpty(rule.Value2))
                    {
                        rule.Value2Normalized = DateTimeMx.Normalize(rule.Value2);
                    }
                }
            }

            return(cf);
        }
Пример #2
0
        /// <summary>
        /// Match a DateTime value
        /// </summary>
        /// <param name="rules"></param>
        /// <param name="dtValue"></param>
        /// <returns></returns>

        public static CondFormatRule Match(
            CondFormat condFormat,
            DateTime dtValue)
        {
            CondFormatRules rules = condFormat.Rules;

            if (dtValue == DateTime.MinValue)
            {
                return(MatchNull(condFormat));
            }
            string         dateString   = DateTimeMx.Normalize(dtValue);
            CondFormatRule matchingRule = Match(condFormat, dateString);

            return(matchingRule);
        }
Пример #3
0
        /// <summary>
        /// Initialize internal match values for a single rule
        /// </summary>
        /// <param name="columnType"></param>

        public void InitializeInternalMatchValues(MetaColumnType columnType)
        {
            OpCode = ConvertOpNameToCode(Op);

            bool calculateEpsilonFromCfValue = false;             // if true use cf value (note: may not be same number of decimals as output format)

            Epsilon = 0;

            if (MetaColumn.IsNumericMetaColumnType(columnType) && !String.IsNullOrEmpty(Value))
            {
                double.TryParse(Value, out ValueNumber);

                if (calculateEpsilonFromCfValue)
                {
                    Epsilon = MobiusDataType.GetEpsilon(Value);
                }

                else
                {
                    int decimals = 10;                     // use default epsilon value
                    Epsilon = MobiusDataType.GetEpsilon(decimals);
                }
            }

            else if (columnType == MetaColumnType.Date && !String.IsNullOrEmpty(Value))
            {
                ValueNormalized = DateTimeMx.Normalize(Value);
            }

            if (MetaColumn.IsNumericMetaColumnType(columnType) && !String.IsNullOrEmpty(Value2))
            {
                double.TryParse(Value2, out Value2Number);
                double e2 = MobiusDataType.GetEpsilon(Value2);
                if (e2 < Epsilon)
                {
                    Epsilon = e2;
                }
            }
            else if (columnType == MetaColumnType.Date && !String.IsNullOrEmpty(Value2))
            {
                Value2Normalized = DateTimeMx.Normalize(Value2);
            }
        }
Пример #4
0
        /// <summary>
        /// Try parse of a US format date string string to a DateTime
        /// </summary>
        /// <param name="dtString"></param>
        /// <param name="dateTime"></param>
        /// <returns></returns>

        public static bool TryParseDate(string dtString, out DateTime dateTime)
        {
            dateTime = DateTime.MinValue;

            try
            {
                string normalized = DateTimeMx.Normalize(dtString);
                if (String.IsNullOrEmpty(normalized))
                {
                    return(false);
                }
                dateTime = DateTimeMx.NormalizedToDateTime(normalized);
                if (dateTime == DateTime.MinValue)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            catch (Exception ex) { return(false); }
        }