Field for string values Un campo para valores de cadena.

Inheritance: FormField
コード例 #1
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;
		}
コード例 #2
0
		/// <summary>
		/// Start this instance.
		/// <para xml:lang="es">
		/// Inicia una instancia del objeto Form
		/// </para>
		/// </summary>
		public override void Start()
		{
			base.Start();

			// Inicialize an new instance of the class Form
			Form = new Form();

			// Inicialize an new intsance of the class IntegerField, with Name, Value and text especific and adds it to the Form
			IntegerField intField = new IntegerField();
			intField.Name = "id";
			intField.Value = 5;
			intField.CaptionControl.Text = "id";
			intField.Required = true;
			intField.Container = Form;
			Form.Fields.Add(intField);

			// Inicialize an new intsance of the class StringField, with Name, Value and text especific and adds it to the Form
			StringField stringField = new StringField();
			stringField.Name = "name";
			stringField.Value = "";
			stringField.CaptionControl.Text = "name";
			stringField.Required = true;
			stringField.Container = Form;
			Form.Fields.Add(stringField);

			// Establishes the number of columns of the Form and the position of the captions.
			Form.RepeatColumns = 4;
			Form.LabelPosition = CaptionPosition.Left;
			Form.DataBind();

			// Creates the Button cmdSave with text specific, with the event also click.
			IButton cmdSave = Platform.Current.Create<IButton>();
			cmdSave.Text = "Save";
			cmdSave.Click += CmdSave_Click;

			// Create a new Stack.
			IStack stack = Platform.Current.Create<IStack>();
			// Adds the content of the Form and the button cmdSave it to the stack
			stack.Children.Add(Form.Content);
			stack.Children.Add(cmdSave);

			// Establishes the content and title of the page
			Platform.Current.Page.Title = "Form";
			Platform.Current.Page.Content = stack;
		}
コード例 #3
0
ファイル: FormField.cs プロジェクト: okhosting/OKHOSTING.UI
		/// <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 especifico.
		/// </para>
		/// </summary>
		public static FormField CreateFieldFrom(Type type)
		{
			//validate arguments
			if (type == null) throw new ArgumentNullException("type");

			//field
			FormField field;

			//Enum
			if (type.GetTypeInfo().IsEnum)
			{
				field = new EnumField(type);
			}

			//Type, ignore this since we can't know if type means Person (as in a serializable object) or typeof(Person) as a type which child types you would choose from
			//else if (type.Equals(typeof(Type)))
			//{
			//	field = new TypeField();
			//}

			//Bool
			else if (type.Equals(typeof(bool)))
			{
				field = new BoolField();
			}

			//DateTime
			else if (type.Equals(typeof(DateTime)))
			{
				field = new DateTimeField();
			}

			//Numeric
			else if (type.IsNumeric())
			{
				if (type.IsIntegral())
				{
					field = new IntegerField();
				}
				else
				{
					field = new DecimalField();
				}
			}

			//String serializable
			else if (type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(Data.IStringSerializable)))
			{
				field = new StringSerializableField(type);
			}

			//XML
			else if (type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(System.Xml.Serialization.IXmlSerializable)))
			{
				field = new XmlSerializableField(type);
			}

			//String
			else if (type.Equals(typeof(string)))
			{
				field = new StringField();
			}

			//byte[]
			else if (type.Equals(typeof(byte[])))
			{
				field = new BinaryField();
			}

			//otherwise just create a textbox
			else
			{
				field = new StringField();
			}

			//return
			return field;
		}
コード例 #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 especifico.
        /// </para>
        /// </summary>
        public static FormField CreateFieldFrom(Type type)
        {
            //validate arguments
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            //field
            FormField field;

            //Enum
            if (type.GetTypeInfo().IsEnum)
            {
                field = new EnumField(type);
            }

            //Type, ignore this since we can't know if type means Person (as in a serializable object) or typeof(Person) as a type which child types you would choose from
            //else if (type.Equals(typeof(Type)))
            //{
            //	field = new TypeField();
            //}

            //Bool
            else if (type.Equals(typeof(bool)))
            {
                field = new BoolField();
            }

            //DateTime
            else if (type.Equals(typeof(DateTime)))
            {
                field = new DateTimeField();
            }

            //Numeric
            else if (type.IsNumeric())
            {
                if (type.IsIntegral())
                {
                    field = new IntegerField();
                }
                else
                {
                    field = new DecimalField();
                }
            }

            //String serializable
            else if (type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(Data.IStringSerializable)))
            {
                field = new StringSerializableField(type);
            }

            //XML
            else if (type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(System.Xml.Serialization.IXmlSerializable)))
            {
                field = new XmlSerializableField(type);
            }

            //String
            else if (type.Equals(typeof(string)))
            {
                field = new StringField();
            }

            //byte[]
            else if (type.Equals(typeof(byte[])))
            {
                field = new BinaryField();
            }

            //otherwise just create a textbox
            else
            {
                field = new StringField();
            }

            //return
            return(field);
        }