Exemple #1
0
        public string ReplaceValues(string currentValue, PiggybagDataFinder piggybagDataFinder, IData currentDataItem = null, bool useUrlEncode = false)
        {
            string result = currentValue;

            foreach (DataFieldValueHelperEntry entry in _entries)
            {
                IData data = piggybagDataFinder.GetData(entry.InterfaceType, currentDataItem);

                object value;
                if (entry.IsReference == false)
                {
                    value = entry.PropertyInfo.GetValue(data, null);

                    if (value == null)
                    {
                        value = "(NULL)";
                    }
                    else if (entry.PropertyInfo.PropertyType == typeof(DateTime))
                    {
                        value = ((DateTime)value).ToString(entry.Format ?? "yyyy MM dd");
                    }
                    else if (entry.PropertyInfo.PropertyType == typeof(Decimal))
                    {
                        value = ((Decimal)value).ToString(entry.Format ?? "G");
                    }
                    else if (entry.PropertyInfo.PropertyType == typeof(int))
                    {
                        value = ((int)value).ToString(entry.Format ?? "G");
                    }
                }
                else
                {
                    IData referencedData = data.GetReferenced(entry.PropertyInfo.Name);

                    value = referencedData.GetLabel();
                }

                string stringValue = value.ToString();

                if (useUrlEncode)
                {
                    stringValue = HttpUtility.UrlEncode(stringValue);
                }

                result = result.Replace(entry.Match, stringValue);
            }

            return(result);
        }
        public string ReplaceValues(string currentValue, PiggybagDataFinder piggybagDataFinder, IData currentDataItem = null, bool useUrlEncode = false)
        {
            string result = currentValue;

            foreach (DataFieldValueHelperEntry entry in _entries)
            {
                IData data = piggybagDataFinder.GetData(entry.InterfaceType, currentDataItem);

                object value;
                if (entry.IsReference == false)
                {
                    value = entry.PropertyInfo.GetValue(data, null);

                    if (value == null)
                    {
                        value = "(NULL)";
                    }
                    else if (entry.PropertyInfo.PropertyType == typeof(DateTime))
                    {
                        value = ((DateTime)value).ToString("yyyy MM dd");
                    }
                }
                else
                {
                    IData referencedData = data.GetReferenced(entry.PropertyInfo.Name);

                    value = referencedData.GetLabel();
                }

                string stringValue = value.ToString();

                if (useUrlEncode)
                {
                    stringValue = HttpUtility.UrlEncode(stringValue);
                }

                result = result.Replace(entry.Match, stringValue);
            }

            return result;
        }