/// <summary>
 /// Adds the provided entity to the collection.
 /// </summary>
 /// <param name="entity">The entity to add to the collection.</param>
 public void Add(EntityFormItem entity)
 {
     if (entity != null)
     {
         List.Add(entity);
     }
 }
Exemplo n.º 2
0
        protected override void OnInit(EventArgs e)
        {
            using (LogGroup logGroup = LogGroup.Start("Initializing the EntityForm control.", NLog.LogLevel.Debug))
            {
                HeadingRow.CssClass = HeadingCssClass;
                Rows.AddAt(0, HeadingRow);
                HeadingRow.Cells.Add(HeadingCell);

                HeadingCell.Text       = HeadingText;
                HeadingCell.ColumnSpan = 2;

                foreach (TableRow row in Rows)
                {
                    LogWriter.Debug("Row type: " + row.GetType().ToString());

                    if (row is EntityFormButtonsItem)
                    {
                        EntityFormButtonsItem item = (EntityFormButtonsItem)row;

                        LogWriter.Debug("Binding item with field control ID: " + item.FieldControlID);

                        foreach (Control control in item.Cells[1].Controls)
                        {
                            if (control is Button)
                            {
                                HandleEvents((Button)control);
                            }
                        }
                    }
                    else if (row is EntityFormItem || row.GetType().BaseType == typeof(EntityFormItem))
                    {
                        EntityFormItem item = (EntityFormItem)row;

                        LogWriter.Debug("Binding item with field control ID: " + item.FieldControlID);

                        // If a custom CSS class hasn't been set on the object use the default one
                        if (item.TextCssClass != String.Empty)
                        {
                            item.TextCssClass = ItemTextCssClass;
                        }

                        foreach (Control control in item.Cells[1].Controls)
                        {
                            if (control is Button)
                            {
                                // HandleEvents((Button)control);
                            }
                        }
                    }
                    else if (row is TableRow)
                    {
                    }
                }
            }

            base.OnInit(e);
        }
Exemplo n.º 3
0
        public void ReverseBind()
        {
            using (LogGroup logGroup = LogGroup.Start("Transferring data from form fields to entity.", NLog.LogLevel.Debug))
            {
                if (DataSource == null)
                {
                    LogWriter.Debug("DataSource == null - Reverse bind skipped");
                }
                else
                {
                    ActivateStrategy.New((IEntity)DataSource).Activate((IEntity)DataSource);

                    foreach (TableRow row in this.Rows)
                    {
                        if (row is EntityFormItem)
                        {
                            using (LogGroup logGroup2 = LogGroup.StartDebug("Checking row with field control ID '" + ((EntityFormItem)row).FieldControlID + "'."))
                            {
                                LogWriter.Debug("Enabled: " + row.Enabled);
                                LogWriter.Debug("Visible: " + row.Visible);

                                if (row.Enabled && row.Visible)
                                {
                                    LogWriter.Debug("Enabled and visible.");

                                    EntityFormItem item = (EntityFormItem)row;

                                    if (item.AutoBind && item.PropertyName != null && item.PropertyName != String.Empty)
                                    {
                                        LogWriter.Debug("Property name: " + item.PropertyName);

                                        WebControl field = (WebControl)FindControl(item.FieldControlID);
                                        // Skip label fields, they're not editable
                                        if (field.GetType() != typeof(Label) &&
                                            field.Enabled)
                                        {
                                            Type propertyType = Reflector.GetPropertyType(DataSource, item.PropertyName);

                                            LogWriter.Debug("Property type: " + (propertyType == null ? "[null]" : propertyType.ToString()));

                                            object value = EntityFormHelper.GetFieldValue(field, item.ControlValuePropertyName, propertyType);

                                            LogWriter.Debug("Field value type: " + (value == null ? "[null]" : value.GetType().ToString()));
                                            LogWriter.Debug("Field value: " + (value == null ? "[null]" : value.ToString()));

                                            object castValue = EntityFormHelper.Convert(value, propertyType);

                                            Reflector.SetPropertyValue(DataSource, item.PropertyName, castValue);
                                        }
                                    }
                                    else
                                    {
                                        LogWriter.Debug("Not auto binding or no property name specified.");
                                    }
                                }
                                else
                                {
                                    LogWriter.Debug("Skipping.");
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public override void DataBind()
        {
            using (LogGroup logGroup = LogGroup.Start("Binding the DataSource data to the values of the fields in the EntityForm.", NLog.LogLevel.Debug))
            {
                base.DataBind();

                foreach (TableRow row in Rows)
                {
                    if (DataSource != null)
                    {
                        LogWriter.Debug("DataSource != null");

                        if (row is EntityFormItem)
                        {
                            LogWriter.Debug("row is EntityFormItem");

                            EntityFormItem item         = (EntityFormItem)row;
                            string         propertyName = ((EntityFormItem)item).PropertyName;

                            if (item.AutoBind && propertyName != String.Empty)
                            {
                                using (LogGroup logGroup2 = LogGroup.Start("Property: " + propertyName, NLog.LogLevel.Debug))
                                {
                                    LogWriter.Debug("Field control ID: " + item.FieldControlID);

                                    object propertyValue = Reflector.GetPropertyValue(DataSource, propertyName);
                                    Type   propertyType  = Reflector.GetPropertyType(DataSource, propertyName);

                                    LogWriter.Debug("Property type: " + propertyType.ToString());

                                    if (propertyValue == null)
                                    {
                                        LogWriter.Debug("PropertyValue: [null]");
                                    }
                                    else
                                    {
                                        LogWriter.Debug("Property value: " + propertyValue.ToString());

                                        if (propertyValue is Array)
                                        {
                                            LogWriter.Debug("Property array length: " + ((Array)propertyValue).Length.ToString());
                                        }
                                    }

                                    Control field = FindControl(item.FieldControlID);

                                    EntityFormHelper.SetFieldValue(field, propertyValue, item.ControlValuePropertyName, propertyType);
                                }
                            }
                        }
                        else
                        {
                            LogWriter.Debug("!(row is EntityFormItem)");
                        }
                    }
                    else
                    {
                        LogWriter.Debug("DataSource == null");
                    }
                }
            }
        }
 /// <summary>
 /// Checks whether the provided entity instance is found in the collection.
 /// </summary>
 /// <param name="entity">The entity to look for in the application.</param>
 /// <returns>A boolean value indicating whether the entity was found in the collection.</returns>
 public bool Contains(EntityFormItem entity)
 {
     return(List.Contains(entity));
 }
 /// <summary>
 /// Adds the provided entity to the collection.
 /// </summary>
 /// <param name="entity">The entity to add to the collection.</param>
 public EntityFormItemCollection(EntityFormItem entity)
 {
     Add(entity);
 }
 /// <summary>
 /// Checks whether the provided entity instance is found in the collection.
 /// </summary>
 /// <param name="entity">The entity to look for in the application.</param>
 /// <returns>A boolean value indicating whether the entity was found in the collection.</returns>
 public bool Contains(EntityFormItem entity)
 {
     return List.Contains(entity);
 }