Пример #1
0
        private static IEnumerable <Field> TemplateFields(FieldCollection templateFields, TemplateModel model)
        {
            foreach (FieldElement fieldElement in templateFields)
            {
                String key   = fieldElement.Key;
                Field  field = null;

                switch (fieldElement.Type)
                {
                case FieldType.Standard:
                    StandardField standardField = new StandardField();
                    standardField.Value = model.GetField(key, FieldAttribute.Value, fieldElement.Value.Value);

                    field = standardField;
                    break;

                case FieldType.Date:
                    DateField dateField = new DateField();

                    if (fieldElement.DateStyle != FieldDateTimeStyle.Unspecified)
                    {
                        dateField.DateStyle = fieldElement.DateStyle;
                    }

                    if (fieldElement.TimeStyle != FieldDateTimeStyle.Unspecified)
                    {
                        dateField.TimeStyle = fieldElement.TimeStyle;
                    }

                    if (fieldElement.IgnoresTimeZone.HasValue)
                    {
                        dateField.IgnoresTimeZone = fieldElement.IgnoresTimeZone.Value;
                    }

                    if (fieldElement.IsRelative.HasValue)
                    {
                        dateField.IsRelative = fieldElement.IsRelative.Value;
                    }

                    DateTime dateValue;

                    if (!DateTime.TryParse(fieldElement.Value.Value, out dateValue))
                    {
                        dateValue = DateTime.MinValue;
                    }

                    dateField.Value = model.GetField <DateTime>(key, FieldAttribute.Value, dateValue);

                    field = dateField;
                    break;

                case FieldType.Number:
                    NumberField numberField = new NumberField();

                    if (fieldElement.NumberStyle != FieldNumberStyle.Unspecified)
                    {
                        numberField.NumberStyle = fieldElement.NumberStyle;
                    }

                    numberField.CurrencyCode = model.GetField(key, FieldAttribute.CurrencyCode, fieldElement.CurrencyCode.Value);

                    Decimal decimalValue;

                    if (!Decimal.TryParse(fieldElement.Value.Value, out decimalValue))
                    {
                        decimalValue = 0;
                    }

                    numberField.Value = model.GetField <Decimal>(key, FieldAttribute.Value, decimalValue);

                    field = numberField;
                    break;
                }

                field.Key = fieldElement.Key;

                field.DataDetectorTypes = fieldElement.DataDetectorTypes;

                if (field.TextAlignment != FieldTextAlignment.Unspecified)
                {
                    field.TextAlignment = fieldElement.TextAlignment;
                }

                field.Label           = model.GetField(key, FieldAttribute.Label, fieldElement.Label.Value);
                field.AttributedValue = model.GetField(key, FieldAttribute.AttributedValue, fieldElement.AttributedValue.Value);
                field.ChangeMessage   = model.GetField(key, FieldAttribute.ChangeMessage, fieldElement.ChangeMessage.Value);

                yield return(field);
            }
        }
		private static IEnumerable<Field> TemplateFields(FieldCollection templateFields, TemplateModel model)
		{
			foreach (FieldElement fieldElement in templateFields)
			{
				String key = fieldElement.Key;
				Field field = null;

				switch (fieldElement.Type)
				{
				case FieldType.Standard:
					StandardField standardField = new StandardField ();
					standardField.Value = model.GetField(key, FieldAttribute.Value, fieldElement.Value.Value);

					field = standardField;
					break;
				case FieldType.Date:
					DateField dateField = new DateField ();

					if (fieldElement.DateStyle != FieldDateTimeStyle.Unspecified)
						dateField.DateStyle = fieldElement.DateStyle;

					if (fieldElement.TimeStyle != FieldDateTimeStyle.Unspecified)
						dateField.TimeStyle = fieldElement.TimeStyle;

					if (fieldElement.IgnoresTimeZone.HasValue)
						dateField.IgnoresTimeZone = fieldElement.IgnoresTimeZone.Value;

					if (fieldElement.IsRelative.HasValue)
						dateField.IsRelative = fieldElement.IsRelative.Value;

					DateTime dateValue;

					if (!DateTime.TryParse(fieldElement.Value.Value, out dateValue))
						dateValue = DateTime.MinValue;

					dateField.Value = model.GetField<DateTime>(key, FieldAttribute.Value, dateValue);

					field = dateField;
					break;
				case FieldType.Number:
					NumberField numberField = new NumberField ();

					if (fieldElement.NumberStyle != FieldNumberStyle.Unspecified)
						numberField.NumberStyle = fieldElement.NumberStyle;

					numberField.CurrencyCode = model.GetField(key, FieldAttribute.CurrencyCode, fieldElement.CurrencyCode.Value); 

					Decimal decimalValue;

					if (!Decimal.TryParse(fieldElement.Value.Value, out decimalValue))
						decimalValue = 0;

					numberField.Value = model.GetField<Decimal>(key, FieldAttribute.Value, decimalValue);

					field = numberField;
					break;
				}

				field.Key = fieldElement.Key;

				field.DataDetectorTypes = fieldElement.DataDetectorTypes;

				if (field.TextAlignment != FieldTextAlignment.Unspecified)
					field.TextAlignment = fieldElement.TextAlignment;

				field.Label = model.GetField(key, FieldAttribute.Label, fieldElement.Label.Value); 
				field.AttributedValue = model.GetField(key, FieldAttribute.AttributedValue, fieldElement.AttributedValue.Value);
				field.ChangeMessage = model.GetField(key, FieldAttribute.ChangeMessage, fieldElement.ChangeMessage.Value);

				yield return field;
			}
		}