/// <summary>
		/// Creates a field for a DataMember
		/// </summary>
		public FormField AddField(MemberInfo member)
		{
			//if there's no values defined, exit
			if (member == null) throw new ArgumentNullException(nameof(member));

			//field
			FormField field;
			Type returnType = MemberExpression.GetReturnType(member);

			//String
			if (returnType.Equals(typeof(string)))
			{
				field = new StringField();

				//set max lenght, if defined
				int maxLenght = (int) StringLengthValidator.GetMaxLength(member);

				if (maxLenght == 0)
				{
					field.TableWide = true;
				}
				else
				{
					((StringField) field).MaxLenght = maxLenght;
				}

				//set regular expression validation, if defined
				var regex = member.CustomAttributes.Where(att => att.AttributeType.Equals(typeof(RegexValidator))).SingleOrDefault();

				if (regex != null)
				{
					((StringField) field).RegularExpression = (string) regex.ConstructorArguments[0].Value;
				}
			}

			//DataType
			else if (returnType.Equals(typeof(DataType)))
			{
				field = new DataTypeField();
			}

			//otherwise delegate to the static method to create the field from the return type
			else
			{
				field = CreateField(returnType);
			}

			field.Name = member.Name;
			field.Container = this;
			field.Required = RequiredValidator.IsRequired(member);
			field.CaptionControl.Text = Translator.Translate(member);
			//if (member.Column.IsPrimaryKey) field.SortOrder = 0;

			//add to fields collection
			Fields.Add(field);

			return field;
		}
Beispiel #2
0
        /// <summary>
        /// Creates a field that will contain a value of a specific type
        /// </summary>
        public static FormField CreateField(Type type)
        {
            //validate arguments
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            //field
            FormField field;

            //The type is a persistent type
            if (DataType.IsMapped(type))
            {
                field = new ObjectListPickerField(DataType.GetMap(type));

                //if it's a short list, create a DropDown

                /*if (DataBase.Current.Count(type) <= 100)
                 * {
                 *      field = new DataObjectListPickerField();
                 * }
                 * //otherwise create an autocomplete
                 * else
                 * {
                 *      field = new DataObjectAutoCompleteField();
                 * }*/
            }

            //DataType
            else if (type.Equals(typeof(DataType)))
            {
                field = new DataTypeField();
            }

            //just create a simple field for common values
            else
            {
                field = FormField.CreateFieldFrom(type);
            }

            //return
            return(field);
        }
		/// <summary>
		/// Creates a field that will contain a value of a specific type
		/// </summary>
		public static FormField CreateField(Type type)
		{
			//validate arguments
			if (type == null) throw new ArgumentNullException("type");

			//field
			FormField field;

			//The type is a persistent type
			if (DataType.IsMapped(type))
			{
				field = new ObjectListPickerField(DataType.GetMap(type));

				//if it's a short list, create a DropDown
				/*if (DataBase.Current.Count(type) <= 100)
				{
					field = new DataObjectListPickerField();
				}
				//otherwise create an autocomplete
				else
				{
					field = new DataObjectAutoCompleteField();
				}*/
			}

			//DataType
			else if (type.Equals(typeof(DataType)))
			{
				field = new DataTypeField();
			}

			//just create a simple field for common values
			else
			{
				field = FormField.CreateFieldFrom(type);
			}

			//return
			return field;
		}
Beispiel #4
0
		/// <summary>
		/// Creates a field that will contain a value of a specific type
		/// <para xml:lang="es">
		/// Crea un campo que contendra un valor de un tipo especifco
		/// </para>
		/// </summary>
		public static FormField CreateFieldFrom(Type type)
		{
			//validate arguments
			if (type == null) throw new ArgumentNullException("type");

			//field
			FormField field;

			//The type is a persistent type
			if (DataType.IsMapped(type))
			{
				var select = new Operations.Select();
				select.DataType = type;

				field = new ObjectListPickerField(select);

				////show total records
				//Operations.SelectAggregate count = new Operations.SelectAggregate();
				//count.DataType = type;
				//count.AggregateMembers.Add(new Operations.SelectAggregateMember(select.DataType.PrimaryKey.First(), Operations.SelectAggregateFunction.Count));

				//int totalRecords = 0;

				//using (var db = DataBase.CreateDataBase())
				//{
				//	totalRecords = Data.Convert.ChangeType<int>(db.SelectScalar(count));
				//}

				////if it's a short list, create a DropDown
				//if (totalRecords <= 100)
				//{
				//	field = new ObjectListPickerField(select);
				//}
				////otherwise create an autocomplete
				//else
				//{
				//	field = new ObjectAutoCompleteField(select);
				//}
			}

			//DataType
			else if (type.Equals(typeof(DataType)))
			{
				field = new DataTypeField();
			}

			//just create a simple field for common values
			else
			{
				field = FormField.CreateFieldFrom(type);
			}

			//return
			return field;
		}
Beispiel #5
0
        /// <summary>
        /// Creates a field for a DataMember
        /// </summary>
        public FormField AddField(MemberInfo member)
        {
            //if there's no values defined, exit
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            //field
            FormField field;
            Type      returnType = MemberExpression.GetReturnType(member);

            //String
            if (returnType.Equals(typeof(string)))
            {
                field = new StringField();

                //set max lenght, if defined
                int maxLenght = (int)StringLengthValidator.GetMaxLength(member);

                if (maxLenght == 0)
                {
                    field.TableWide = true;
                }
                else
                {
                    ((StringField)field).MaxLenght = maxLenght;
                }

                //set regular expression validation, if defined
                var regex = member.CustomAttributes.Where(att => att.AttributeType.Equals(typeof(RegexValidator))).SingleOrDefault();

                if (regex != null)
                {
                    ((StringField)field).RegularExpression = (string)regex.ConstructorArguments[0].Value;
                }
            }

            //DataType
            else if (returnType.Equals(typeof(DataType)))
            {
                field = new DataTypeField();
            }

            //otherwise delegate to the static method to create the field from the return type
            else
            {
                field = CreateField(returnType);
            }

            field.Name                = member.Name;
            field.Container           = this;
            field.Required            = RequiredValidator.IsRequired(member);
            field.CaptionControl.Text = Translator.Translate(member);
            //if (member.Column.IsPrimaryKey) field.SortOrder = 0;

            //add to fields collection
            Fields.Add(field);

            return(field);
        }