void BuildEditForm()
        {
            var            fieldSettingsTable = FieldSettingsController.GetFieldSettingsTable(ModuleId);
            var            editForm           = new List <FormColumnInfo>();
            FormColumnInfo currentField;
            var            security = new ModuleSecurity(ModuleContext);

            _editControls = new EditControls(ModuleContext);

            foreach (DataRow dr in Data.Tables[DataSetTableName.Fields].Rows)
            {
                var fieldTitle   = dr[FieldsTableColumn.Title].AsString();
                var dataTypeName = dr[FieldsTableColumn.Type].AsString();
                var dataType     = DataType.ByName(dataTypeName);

                var isColumnEditable =
                    Convert.ToBoolean((!dataType.SupportsHideOnEdit ||
                                       Convert.ToBoolean(dr[FieldsTableColumn.ShowOnEdit])) &&
                                      (!Convert.ToBoolean(dr[FieldsTableColumn.IsPrivate]) ||
                                       security.IsAllowedToEditAllColumns()));

                //If Column is hidden, the Fieldtype falls back to "String" as the related EditControl works perfect even if it is not visibile
                //EditControls of other user defined datatypes may use core controls (e.g. UrlControl or RTE) which are not rock solid regarding viewstate.
                if (!isColumnEditable && dataType.IsUserDefinedField)
                {
                    dataTypeName = "String";
                }

                currentField = new FormColumnInfo {
                    IsUserDefinedField = dataType.IsUserDefinedField
                };

                if (dataType.IsSeparator)
                {
                    var fieldId = (int)dr[FieldsTableColumn.Id];
                    currentField.IsCollapsible = Data.Tables[DataSetTableName.FieldSettings].GetFieldSetting("IsCollapsible", fieldId).AsBoolean();
                    currentField.IsSeparator   = true;
                    if (dr[FieldsTableColumn.Visible].AsBoolean())
                    {
                        currentField.Title = fieldTitle;
                    }
                    currentField.Visible = isColumnEditable;
                }
                else
                {
                    currentField.Help     = dr[FieldsTableColumn.HelpText].AsString();
                    currentField.Title    = dr[FieldsTableColumn.Title].AsString();
                    currentField.Required =
                        Convert.ToBoolean(dr[FieldsTableColumn.Required].AsBoolean() &&
                                          dataType.IsUserDefinedField);

                    //advanced Settings: Dynamic control
                    currentField.EditControl = _editControls.Add(dr[FieldsTableColumn.Title].AsString(),
                                                                 dataTypeName, Convert.ToInt32(dr[FieldsTableColumn.Id]),
                                                                 dr[FieldsTableColumn.HelpText].AsString(),
                                                                 dr[FieldsTableColumn.Default].AsString(),
                                                                 dr[FieldsTableColumn.Required].AsBoolean(),
                                                                 dr[FieldsTableColumn.ValidationRule].AsString(),
                                                                 dr[FieldsTableColumn.ValidationMessage].AsString(),
                                                                 dr[FieldsTableColumn.EditStyle].AsString(),
                                                                 dr[FieldsTableColumn.InputSettings].AsString(),
                                                                 dr[FieldsTableColumn.OutputSettings].AsString(),
                                                                 dr[FieldsTableColumn.NormalizeFlag].AsBoolean(),
                                                                 dr[FieldsTableColumn.MultipleValues].AsBoolean(),
                                                                 fieldSettingsTable,
                                                                 this);
                    currentField.Visible = isColumnEditable;
                }
                editForm.Add(currentField);
            }

            if (CaptchaNeeded())
            {
                if (!Settings.PreferReCaptcha)
                {
                    // use DnnCaptcha
                    _ctlCaptcha = new CaptchaControl
                    {
                        ID            = "Captcha",
                        CaptchaWidth  = Unit.Pixel(130),
                        CaptchaHeight = Unit.Pixel(40),
                        ToolTip       = Localization.GetString("CaptchaToolTip", LocalResourceFile),
                        ErrorMessage  = Localization.GetString("CaptchaError", LocalResourceFile)
                    };
                    currentField = new FormColumnInfo
                    {
                        Title              = Localization.GetString("Captcha", LocalResourceFile),
                        EditControl        = _ctlCaptcha,
                        Visible            = true,
                        IsUserDefinedField = false
                    };
                    editForm.Add(currentField);
                }
            }

            var enableFormTemplate = Settings.EnableFormTemplate;
            var formTemplate       = Settings.FormTemplate;

            if (enableFormTemplate && !string.IsNullOrEmpty(formTemplate))
            {
                BuildTemplateForm(editForm, formTemplate);
            }
            else
            {
                BuildCssForm(editForm);
            }
            //Change captions of buttons in Form mode
            if (IsNewRow && Settings.ListOrForm.Contains("Form"))
            {
                cmdUpdate.Attributes["resourcekey"] = "cmdSend.Text";
            }
        }
Ejemplo n.º 2
0
        private void BuildUDFieldForm()
        {
            List<UDFieldInfo> list = (from p in Cache_UdtList where p.TypeId == TypeId select p).ToList();
            if (list.Count < 1)
            {
                if (tblUserDefinedField.Visible == true)
                {
                    tblUserDefinedField.Rows.Clear();
                    tblUserDefinedField.Visible = false;
                }
                return;
            }
            List<FormColumnInfo> listEditFrom = new List<FormColumnInfo>();
            FormColumnInfo objColumn;
            ListEditControls = new EditControls(ModuleContext);

            foreach (UDFieldInfo objUDField in list)
            {
                objColumn = new FormColumnInfo();
                objColumn.Name = objUDField.FieldName;
                objColumn.IsUserDefinedField = true;
                objColumn.Help = objUDField.HelpText;
                objColumn.Title = (objUDField.FieldTitle == null || objUDField.FieldTitle.Trim() == "") ? objUDField.FieldName : objUDField.FieldTitle;
                objColumn.Required = objUDField.Required;
                objColumn.Visible = true;
                objColumn.EditControl = ListEditControls.Add(objColumn.Name, objColumn.Title, objUDField.FieldType, objUDField.Id, objColumn.Help, objUDField.DefaultValue, objColumn.Required,
                    objUDField.ValidationRule, objUDField.ValidationMessage, objUDField.EditStyle, objUDField.InputSettings, objUDField.OutputSettings, objUDField.NormalizeFlag);
                listEditFrom.Add(objColumn);
            }
            BuildFormAsTable(listEditFrom);
        }
Ejemplo n.º 3
0
        void BuildEditForm()
        {
            var fieldSettingsTable = FieldSettingsController.GetFieldSettingsTable(ModuleId);
            var editForm = new List<FormColumnInfo>();
            FormColumnInfo currentField;
            var security = new ModuleSecurity(ModuleContext);

            _editControls = new EditControls(ModuleContext);

            foreach (DataRow dr in Data.Tables[DataSetTableName.Fields].Rows)
            {
                var fieldTitle = dr[FieldsTableColumn.Title].AsString();
                var dataTypeName = dr[FieldsTableColumn.Type].AsString();
                var dataType = DataType.ByName(dataTypeName);

                var isColumnEditable =
                    Convert.ToBoolean((! dataType.SupportsHideOnEdit ||
                                       Convert.ToBoolean(dr[FieldsTableColumn.ShowOnEdit])) &&
                                      (! Convert.ToBoolean(dr[FieldsTableColumn.IsPrivate]) ||
                                       security.IsAllowedToEditAllColumns()));

                //If Column is hidden, the Fieldtype falls back to "String" as the related EditControl works perfect even if it is not visibile
                //EditControls of other user defined datatypes may use core controls (e.g. UrlControl or RTE) which are not rock solid regarding viewstate.
                if (! isColumnEditable && dataType.IsUserDefinedField)
                {
                    dataTypeName = "String";
                }

                currentField = new FormColumnInfo {IsUserDefinedField = dataType.IsUserDefinedField};

                if (dataType.IsSeparator)
                {
                    var fieldId = (int)dr[FieldsTableColumn.Id];
                    currentField.IsCollapsible = Data.Tables[DataSetTableName.FieldSettings].GetFieldSetting("IsCollapsible", fieldId).AsBoolean();
                    currentField.IsSeparator = true;
                    if (dr[FieldsTableColumn.Visible].AsBoolean())
                    {
                        currentField.Title = fieldTitle;
                    }
                    currentField.Visible = isColumnEditable;
                }
                else
                {
                    currentField.Help = dr[FieldsTableColumn.HelpText].AsString();
                    currentField.Title = dr[FieldsTableColumn.Title].AsString();
                    currentField.Required =
                        Convert.ToBoolean(dr[FieldsTableColumn.Required].AsBoolean() &&
                                          dataType.IsUserDefinedField);

                    //advanced Settings: Dynamic control
                    currentField.EditControl = _editControls.Add(dr[FieldsTableColumn.Title].AsString(),
                                                                dataTypeName, Convert.ToInt32(dr[FieldsTableColumn.Id]),
                                                                dr[FieldsTableColumn.HelpText].AsString(),
                                                                dr[FieldsTableColumn.Default].AsString(),
                                                                dr[FieldsTableColumn.Required].AsBoolean(),
                                                                dr[FieldsTableColumn.ValidationRule].AsString(),
                                                                dr[FieldsTableColumn.ValidationMessage].AsString(),
                                                                dr[FieldsTableColumn.EditStyle].AsString(),
                                                                dr[FieldsTableColumn.InputSettings].AsString(),
                                                                dr[FieldsTableColumn.OutputSettings].AsString(),
                                                                dr[FieldsTableColumn.NormalizeFlag].AsBoolean(),
                                                                dr[FieldsTableColumn.MultipleValues].AsBoolean(),
                                                                fieldSettingsTable,
                                                                this );
                    currentField.Visible = isColumnEditable;
                }
                editForm.Add(currentField);
            }

            if (CaptchaNeeded())
            {
                _ctlCaptcha = new CaptchaControl
                                  {
                                      ID = "Captcha",
                                      CaptchaWidth = Unit.Pixel(130),
                                      CaptchaHeight = Unit.Pixel(40),
                                      ToolTip = Localization.GetString("CaptchaToolTip", LocalResourceFile),
                                      ErrorMessage = Localization.GetString("CaptchaError", LocalResourceFile)
                                  };
                currentField = new FormColumnInfo
                                   {
                                       Title = Localization.GetString("Captcha", LocalResourceFile),
                                       EditControl = _ctlCaptcha,
                                       Visible = true,
                                       IsUserDefinedField = false
                                   };
                editForm.Add(currentField);
            }
            BuildCssForm(editForm);
            //Change captions of buttons in Form mode
            if (IsNewRow && Settings.ListOrForm.Contains("Form"))
            {
                cmdUpdate.Attributes["resourcekey"] = "cmdSend.Text";
     }
        }
        /// <summary>
        /// Returns one settings row that contains a cell for help, a cell for setting item
        /// name and a cell for setting item and validators.
        /// </summary>
        /// <param name="currentSetting">The current setting.</param>
        /// <param name="currentItem">The current item.</param>
        /// <returns></returns>
        private TableRow createOneSettingRow(string currentSetting, SettingItem currentItem)
        {
            // the table row is going to have three cells
            TableRow row = new TableRow();

            // cell for help icon and description
            TableCell helpCell = new TableCell();
            Image     img      = new Image();

            if (currentItem.Description.Length > 0)
            {
                Image _myImg = ((Page)Page).CurrentTheme.GetImage("Buttons_Help", "Help.gif");
                img          = new Image();
                img.ImageUrl = _myImg.ImageUrl;
                img.Height   = _myImg.Height;
                img.Width    = _myImg.Width;
                // Jminond: added netscape tooltip support
                img.AlternateText = currentItem.Description;
                img.Attributes.Add("title", General.GetString(currentSetting + "_DESCRIPTION"));
                img.ToolTip = General.GetString(currentSetting + "_DESCRIPTION"); //Fixed key for simplicity
            }
            else
            {
                // Jes1111 - 17/12/2004
                img          = new Image();
                img.Width    = Unit.Pixel(25);
                img.ImageUrl = ((Page)Page).CurrentTheme.GetImage("Spacer", "Spacer.gif").ImageUrl;
            }

            helpCell.Controls.Add(img);

            // add help cell to the row
            row.Cells.Add(helpCell);

            // Setting Name cell
            TableCell nameCell = new TableCell();

            nameCell.Attributes.Add("width", "20%");
            nameCell.CssClass = "SubHead";

            if (currentItem.EnglishName.Length == 0)
            {
                nameCell.Text = General.GetString(currentSetting, currentSetting + "<br />Key Not In Resources");
            }
            else
            {
                nameCell.Text = General.GetString(currentItem.EnglishName, currentItem.EnglishName);
            }

            // add name cell to the row
            row.Cells.Add(nameCell);

            // Setting Control cell
            TableCell settingCell = new TableCell();

            settingCell.Attributes.Add("width", "80%");
            settingCell.CssClass = "st-control";

            Control editControl;

            try
            {
                editControl    = currentItem.EditControl;
                editControl.ID = currentSetting; // Jes1111
                editControl.EnableViewState = true;
            }
            catch (Exception ex)
            {
                editControl = new LiteralControl("There was an error loading this control");
                //LogHelper.Logger.Log(Rainbow.Framework.LogLevel.Warn, "There was an error loading '" + currentItem.EnglishName + "'", ex);
            }
            settingCell.Controls.Add(editControl);

            // TODO: WHAT IS THIS?
            // nameText.LabelForControl = editControl.ClientID;

            //Add control to edit controls collection
            EditControls.Add(currentSetting, editControl);

            //Validators
            settingCell.Controls.Add(new LiteralControl("<br />"));

            //Required
            // TODO : Whhn we bring back ELB easy list box, we need to put this back

            /*
             * if (currentItem.Required && !(editControl is ELB.EasyListBox))
             * {
             *  RequiredFieldValidator req = new RequiredFieldValidator();
             *  req.ErrorMessage =General.GetString("SETTING_REQUIRED", "%1% is required!", req).Replace("%1%", currentSetting);
             *  req.ControlToValidate = currentSetting;
             *  req.CssClass = "Error";
             *  req.Display = ValidatorDisplay.Dynamic;
             *  req.EnableClientScript = true;
             *  settingCell.Controls.Add(req);
             * }
             */

            //Range Validator
            if (currentItem.MinValue != 0 || currentItem.MaxValue != 0)
            {
                RangeValidator rang = new RangeValidator();

                switch (currentItem.DataType)
                {
                case PropertiesDataType.String:
                    rang.Type = ValidationDataType.String;
                    break;

                case PropertiesDataType.Integer:
                    rang.Type = ValidationDataType.Integer;
                    break;

                case PropertiesDataType.Currency:
                    rang.Type = ValidationDataType.Currency;
                    break;

                case PropertiesDataType.Date:
                    rang.Type = ValidationDataType.Date;
                    break;

                case PropertiesDataType.Double:
                    rang.Type = ValidationDataType.Double;
                    break;
                }

                if (currentItem.MinValue >= 0 && currentItem.MaxValue >= currentItem.MinValue)
                {
                    rang.MinimumValue = currentItem.MinValue.ToString();

                    if (currentItem.MaxValue == 0)
                    {
                        rang.ErrorMessage =
                            General.GetString("SETTING_EQUAL_OR_GREATER", "%1% must be equal or greater than %2%!", rang)
                            .Replace("%1%", currentSetting).Replace("%2%", currentItem.MinValue.ToString());
                    }
                    else
                    {
                        rang.MaximumValue = currentItem.MaxValue.ToString();
                        rang.ErrorMessage =
                            General.GetString("SETTING_BETWEEN", "%1% must be between %2% and %3%!", rang).Replace(
                                "%1%", currentSetting).Replace("%2%", currentItem.MinValue.ToString()).Replace("%3%",
                                                                                                               currentItem
                                                                                                               .
                                                                                                               MaxValue
                                                                                                               .
                                                                                                               ToString
                                                                                                                   ());
                    }
                }
                rang.ControlToValidate  = currentSetting;
                rang.CssClass           = "Error";
                rang.Display            = ValidatorDisplay.Dynamic;
                rang.EnableClientScript = true;
                settingCell.Controls.Add(rang);
            }
            // add setting cell into the row
            row.Cells.Add(settingCell);

            // all done send it back
            return(row);
        }