예제 #1
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        public override void Save()
        {
            lock (m_Locker)
            {
                var prevalues = new List <object>();

                // Set settings
                if (this._settings == null)
                {
                    this._settings = DtgHelpers.GetSettings(this.m_DataType.DataTypeDefinitionId);
                }

                this._settings.ShowLabel      = this._showLabel != null && this._showLabel.Checked;
                this._settings.ShowGridHeader = this._showHeader != null && this._showHeader.Checked;
                this._settings.ShowGridFooter = this._showFooter != null && this._showFooter.Checked;
                this._settings.ReadOnly       = this._readOnly != null && this._readOnly.Checked;
                this._settings.TableHeight    = this._tableHeight != null?int.Parse(this._tableHeight.Text) : 300;

                prevalues.Add(this._settings);

                // Add existing prevalues;
                foreach (var t in this._preValues)
                {
                    var parsedprevalue = ParsePrevalue(t);

                    if (parsedprevalue != null)
                    {
                        prevalues.Add(parsedprevalue);
                    }
                }

                // Add last (new) prevalue
                var newprevalue = ParsePrevalue(this._newPreValue);

                if (newprevalue != null)
                {
                    prevalues.Add(newprevalue);
                }

                if (prevalues.Count > 0)
                {
                    // Delete former values
                    PreValues.DeleteByDataTypeDefinition(this.m_DataType.DataTypeDefinitionId);

                    // Add new values
                    AddPrevalues(prevalues);

                    // Must not refresh on initial load. [LK]
                    if (prevalues.Count > 1)
                    {
                        // Reload IFrame to show changes
                        this.Page.Response.Redirect(this.Page.Request.Url.ToString());
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the DTG config.
        /// </summary>
        public void GetConfig()
        {
            // Add blank PreValue row in the beginning
            this._newPreValue = new PreValueRow()
            {
                Id = DtgHelpers.GetAvailableId(this.m_DataType.DataTypeDefinitionId)
            };

            // Add the stored values
            foreach (var s in DtgHelpers.GetConfig(this.m_DataType.DataTypeDefinitionId))
            {
                this._preValues.Add(s);
            }
        }
예제 #3
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        public void Save()
        {
            // Get new values
            this.Rows = new StoredValueRowCollection(this.ColumnConfigurations, this.DataString);

            this.data.Value = this.Rows.ToString();

            // Refresh grid
            this.RefreshGrid();

            // Clear input controls
            this.ClearControls();

            DtgHelpers.AddLogEntry(string.Format("DTG: Saved the following data to database: {0}", this.data.Value));
        }
예제 #4
0
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // DEBUG: Reset stored values
            // this.Data.Value = "<items><item id='1'><name nodeName='Name' nodeType='-88' >Anna</name><age nodeName='Age' nodeType='-51' >25</age><picture nodeName='Picture' nodeType='1035' ></picture></item><item id='6'><name nodeName='Name' nodeType='-88' >Ove</name><gender nodeName='Gender' nodeType='-88'>Male</gender><age nodeName='Age' nodeType='-51' >23</age><picture nodeName='Picture' nodeType='1035' ></picture></item></items>";

            // Set default value if none exists
            if (this.data.Value == null)
            {
                DtgHelpers.AddLogEntry(string.Format("DTG: No values exist in database for this property"));

                this.data.Value = string.Empty;
            }
            else
            {
                DtgHelpers.AddLogEntry(
                    string.Format("DTG: Retrieved the following data from database: {0}", this.data.Value));
            }

            // Use data from viewstate if present
            if (!string.IsNullOrEmpty(this.DataString))
            {
                this.data.Value = this.DataString;
            }

            this.ShowGridHeader = new HiddenField()
            {
                ID = "ShowGridHeader", Value = this.settings.ShowGridHeader.ToString()
            };
            this.ShowGridFooter = new HiddenField()
            {
                ID = "ShowGridFooter", Value = this.settings.ShowGridFooter.ToString()
            };
            this.ReadOnly = new HiddenField()
            {
                ID = "ReadOnly", Value = this.settings.ReadOnly.ToString()
            };
            this.DataTablesTranslation = new LiteralControl()
            {
                ID = "DataTablesTranslation", Text = this.GetDataTablesTranslation()
            };
            this.TableHeight = new HiddenField()
            {
                ID = "TableHeight", Value = this.settings.TableHeight.ToString()
            };
            this.Value = new HiddenField()
            {
                ID = "Value", Value = this.data.Value != null?this.data.Value.ToString() : string.Empty
            };
            this.Grid = new Table {
                ID = "tblGrid", CssClass = "display"
            };
            this.Toolbar = new Panel {
                ID = "pnlToolbar", CssClass = "Toolbar"
            };

            // Get column configurations
            this.ColumnConfigurations = this.GetColumnConfigurations(this.dataTypeDefinitionId);

            // Add value container here, because we need the unique id
            this.Controls.Add(this.Value);

            // Use value from viewstate if present
            if (this.Page != null && !string.IsNullOrEmpty(this.Page.Request.Form[this.Value.UniqueID]))
            {
                // Parse to StoredValueRowCollection to get the values sorted
                var l = new StoredValueRowCollection(this.ColumnConfigurations, this.Page.Request.Form[this.Value.UniqueID]);

                this.DataString = l.ToString();
            }

            // Set up rows
            Rows            = new StoredValueRowCollection(this.ColumnConfigurations, this.DataString);
            InsertDataTypes = GetInsertDataTypes();
            EditDataTypes   = GetEditDataTypes();

            InsertControls = new Panel {
                ID = "ctrlInsert", CssClass = "InsertControls"
            };
            EditControls = new Panel {
                ID = "ctrlEdit", CssClass = "EditControls"
            };
            DeleteControls = new Panel {
                ID = "ctrlDelete", CssClass = "DeleteControls"
            };

            // Generate header row
            GenerateHeaderRow();

            // Generate rows with edit, delete and row data
            GenerateValueRows();

            // Generate insert and delete controls if grid is not in readonly mode
            if (!this.settings.ReadOnly)
            {
                // Generate footer row
                GenerateFooterToolbar();

                // Generate insert controls
                GenerateInsertControls();

                // Generate edit controls
                GenerateEditControls();
            }

            // Add controls to container
            this.Controls.Add(this.ShowGridHeader);
            this.Controls.Add(this.ShowGridFooter);
            this.Controls.Add(this.TableHeight);
            this.Controls.Add(this.DataTablesTranslation);
            this.Controls.Add(this.Grid);
            this.Controls.Add(this.Toolbar);
            this.Controls.Add(this.InsertControls);
            this.Controls.Add(this.EditControls);
            this.Controls.Add(this.DeleteControls);
        }
예제 #5
0
 /// <summary>
 /// Handles the ServerValidate event of the regexValidation control.
 /// </summary>
 /// <param name="source">The source of the event.</param>
 /// <param name="e">The <see cref="System.Web.UI.WebControls.ServerValidateEventArgs"/> instance containing the event data.</param>
 private void valNewValidation_ServerValidate(object source, ServerValidateEventArgs e)
 {
     e.IsValid = DtgHelpers.ValidateRegex(e.Value);
 }
예제 #6
0
        /// <summary>
        /// Creates child controls for this control
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // Get configuration
            this._newPreValue = new PreValueRow();
            this._preValues   = new List <PreValueRow>();
            this._settings    = DtgHelpers.GetSettings(this.m_DataType.DataTypeDefinitionId);
            this.GetConfig();

            // Instantiate default controls
            this._accordionContainer = new Panel {
                ID = "dtg_accordion_" + this.m_DataType.DataTypeDefinitionId, CssClass = "dtg_accordion"
            };
            this._showLabel = new CheckBox()
            {
                ID = "showLabel", Checked = this._settings.ShowLabel
            };
            this._showHeader = new CheckBox()
            {
                ID = "showHeader", Checked = this._settings.ShowGridHeader
            };
            this._showFooter = new CheckBox()
            {
                ID = "showFooter", Checked = this._settings.ShowGridFooter
            };
            this._readOnly = new CheckBox()
            {
                ID = "readOnly", Checked = this._settings.ReadOnly
            };
            this._tableHeight = new TextBox()
            {
                ID = "TableHeight", Text = this._settings.TableHeight.ToString()
            };
            this._tableHeightValidator = new RegularExpressionValidator()
            {
                ID                   = "NumberOfRowsValidator",
                CssClass             = "validator",
                ValidationExpression = @"^[1-9]*[0-9]*$",
                ControlToValidate    = this._tableHeight.ClientID,
                Display              = ValidatorDisplay.Dynamic,
                ErrorMessage         = Helper.Dictionary.GetDictionaryItem("MustBeANumber", "Must be a number")
            };

            // Write controls for adding new entry
            var addNewProperty = new Panel()
            {
                ID = "newProperty", CssClass = "addNewProperty"
            };

            var addNewPropertyHeader = new Panel()
            {
                CssClass = "propertyHeader"
            };

            var addNewPropertyTitle = new HtmlGenericControl("h3")
            {
                InnerText = Helper.Dictionary.GetDictionaryItem("AddNewDataType", "Add new datatype")
            };

            addNewPropertyTitle.Attributes["class"] = "propertyTitle";

            var icnNewError = new HtmlGenericControl("span")
            {
                InnerText = Helper.Dictionary.GetDictionaryItem("Error", "Error")
            };

            icnNewError.Attributes["class"] = "ErrorProperty";

            addNewPropertyHeader.Controls.Add(addNewPropertyTitle);
            addNewPropertyHeader.Controls.Add(icnNewError);

            var addNewPropertyControls = new Panel()
            {
                ID = "addNewPropertyControls", CssClass = "propertyControls"
            };

            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "<ul>"
            });

            // NAME
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "<li>"
            });

            // Instantiate controls
            var txtNewName = new TextBox()
            {
                ID = "newName", CssClass = "newName"
            };
            var lblNewName = new Label()
            {
                AssociatedControlID = txtNewName.ClientID,
                Text = Helper.Dictionary.GetDictionaryItem("Name", "Name")
                       + "<br/><small class='description'>"
                       + Helper.Dictionary.GetDictionaryItem(
                    "NameDescription",
                    "The column display name") + "</small>",
                CssClass = "label"
            };
            var valNewName = new RequiredFieldValidator()
            {
                ID                = "newNameValidator",
                CssClass          = "validator",
                Enabled           = false,
                ControlToValidate = txtNewName.ClientID,
                Display           = ValidatorDisplay.Dynamic,
                ErrorMessage      = Helper.Dictionary.GetDictionaryItem("YouMustSpecifyAName", "You must specify a name")
            };

            // Add controls to control
            addNewPropertyControls.Controls.Add(lblNewName);
            addNewPropertyControls.Controls.Add(txtNewName);
            addNewPropertyControls.Controls.Add(valNewName);
            ((PreValueRow)this._newPreValue).Controls.Add(txtNewName);
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "</li>"
            });

            // ALIAS
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "<li>"
            });

            // Instantiate controls
            var txtNewAlias = new TextBox()
            {
                ID = "newAlias", CssClass = "newAlias"
            };
            var lblNewAlias = new Label()
            {
                AssociatedControlID = txtNewAlias.ClientID,
                Text = Helper.Dictionary.GetDictionaryItem("Alias", "Alias")
                       + "<br/><small class='description'>"
                       + Helper.Dictionary.GetDictionaryItem(
                    "AliasDescription",
                    "The column alias") + "</small>",
                CssClass = "label"
            };
            var valNewAlias = new RequiredFieldValidator()
            {
                ID                = "newAliasValidator",
                CssClass          = "validator",
                Enabled           = false,
                ControlToValidate = txtNewAlias.ClientID,
                Display           = ValidatorDisplay.Dynamic,
                ErrorMessage      =
                    Helper.Dictionary.GetDictionaryItem("YouMustSpecifyAnAlias", "You must specify an alias")
            };

            var valNewAliasExists = new CustomValidator()
            {
                ID                       = "newAliasExistsValidator",
                CssClass                 = "validator exists",
                Enabled                  = false,
                ControlToValidate        = txtNewAlias.ClientID,
                Display                  = ValidatorDisplay.Dynamic,
                ClientValidationFunction = "ValidateNewAliasExists",
                ErrorMessage             = Helper.Dictionary.GetDictionaryItem("AliasAlreadyExists", "Alias already exists!")
            };

            valNewAliasExists.ServerValidate += valNewAliasExists_ServerValidate;

            // Add controls to control
            addNewPropertyControls.Controls.Add(lblNewAlias);
            addNewPropertyControls.Controls.Add(txtNewAlias);
            addNewPropertyControls.Controls.Add(valNewAlias);
            addNewPropertyControls.Controls.Add(valNewAliasExists);
            ((PreValueRow)this._newPreValue).Controls.Add(txtNewAlias);
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "</li>"
            });

            // DATATYPE
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "<li>"
            });

            // Instantiate controls
            var ddlNewType = DtgHelpers.GetDataTypeDropDown();

            ddlNewType.ID = "newType";
            var lblNewType = new Label()
            {
                AssociatedControlID = ddlNewType.ClientID,
                Text = Helper.Dictionary.GetDictionaryItem("DataType", "Datatype")
                       + "<br/><small class='description'>"
                       + Helper.Dictionary.GetDictionaryItem(
                    "DatatypeDescription",
                    "The column data editor") + "</small>",
                CssClass = "label"
            };

            // Add controls to control
            addNewPropertyControls.Controls.Add(lblNewType);
            addNewPropertyControls.Controls.Add(ddlNewType);
            ((PreValueRow)this._newPreValue).Controls.Add(ddlNewType);
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "</li>"
            });

            // MANDATORY
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "<li>"
            });

            // Instantiate controls
            var chkNewMandatory = new CheckBox()
            {
                ID = "newMandatory", CssClass = "newMandatory"
            };
            var lblNewMandatory = new Label()
            {
                AssociatedControlID = chkNewMandatory.ClientID,
                Text =
                    Helper.Dictionary.GetDictionaryItem("Mandatory", "Mandatory")
                    + "<br/><small class='description'>"
                    + Helper.Dictionary.GetDictionaryItem(
                        "MandatoryDescription",
                        "Whether this column is mandatory") + "</small>",
                CssClass = "label"
            };

            // Add controls to control
            addNewPropertyControls.Controls.Add(lblNewMandatory);
            addNewPropertyControls.Controls.Add(chkNewMandatory);
            ((PreValueRow)this._newPreValue).Controls.Add(chkNewMandatory);
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "</li>"
            });

            // VISIBLE
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "<li>"
            });

            // Instantiate controls
            var chkNewVisible = new CheckBox()
            {
                ID = "newVisible", CssClass = "newVisible", Checked = true
            };
            var lblNewVisible = new Label()
            {
                AssociatedControlID = chkNewVisible.ClientID,
                Text = Helper.Dictionary.GetDictionaryItem("Visible", "Visible")
                       + "<br/><small class='description'>"
                       + Helper.Dictionary.GetDictionaryItem(
                    "VisibleDescription",
                    "Whether this column is visible in the grid. <br/>(it can still be edited)") + "</small>",
                CssClass = "label"
            };

            // Add controls to control
            addNewPropertyControls.Controls.Add(lblNewVisible);
            addNewPropertyControls.Controls.Add(chkNewVisible);
            ((PreValueRow)this._newPreValue).Controls.Add(chkNewVisible);
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "</li>"
            });

            // VALIDATION
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "<li>"
            });

            // Instantiate controls
            var txtNewValidation = new TextBox()
            {
                ID       = "newValidation",
                TextMode = TextBoxMode.MultiLine,
                Rows     = 2,
                Columns  = 20,
                CssClass = "newValidation"
            };
            var lblNewValidation = new Label()
            {
                AssociatedControlID = txtNewValidation.ClientID,
                Text = Helper.Dictionary.GetDictionaryItem("Validation", "Validation")
                       + "<br/><small class='description'>"
                       + Helper.Dictionary.GetDictionaryItem(
                    "ValidationDescription",
                    "The regular expression used for validation. Leave empty to disable") + "</small>",
                CssClass = "label"
            };
            var lnkNewValidation = new HyperLink
            {
                ID          = "newValidationLink",
                CssClass    = "validationLink",
                NavigateUrl = "#",
                Text        =
                    Helper.Dictionary.GetDictionaryItem(
                        "SearchForARegularExpression", "Search for a regular expression")
            };
            var valNewValidation = new CustomValidator()
            {
                ID                       = "newValidationValidator",
                CssClass                 = "validator",
                ControlToValidate        = txtNewValidation.ClientID,
                Display                  = ValidatorDisplay.Dynamic,
                ClientValidationFunction = "ValidateRegex",
                ErrorMessage             =
                    Helper.Dictionary.GetDictionaryItem(
                        "ValidationStringIsNotValid", "Validation string is not valid")
            };

            valNewValidation.ServerValidate += this.valNewValidation_ServerValidate;

            // Add controls to control
            addNewPropertyControls.Controls.Add(lblNewValidation);
            addNewPropertyControls.Controls.Add(txtNewValidation);
            addNewPropertyControls.Controls.Add(valNewValidation);
            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "<br/>"
            });
            addNewPropertyControls.Controls.Add(lnkNewValidation);
            ((PreValueRow)this._newPreValue).Controls.Add(txtNewValidation);

            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "</li>"
            });


            // PREVALUE SORT ORDER

            // Instantiate controls
            var hdnNewSortOrder = new HiddenField()
            {
                Value = (this._preValues.Count + 1).ToString()
            };

            addNewPropertyControls.Controls.Add(hdnNewSortOrder);
            ((PreValueRow)this._newPreValue).Controls.Add(hdnNewSortOrder);

            addNewPropertyControls.Controls.Add(new LiteralControl()
            {
                Text = "</ul>"
            });

            addNewProperty.Controls.Add(addNewPropertyHeader);
            addNewProperty.Controls.Add(addNewPropertyControls);

            this._accordionContainer.Controls.Add(addNewProperty);

            // Write stored entries
            foreach (var s in this._preValues)
            {
                var editProperty = new Panel()
                {
                    ID = "editProperty_" + s.Id.ToString(), CssClass = "editProperty"
                };

                var editDataType = ddlNewType.Items.FindByValue(s.DataTypeId.ToString());

                var editPropertyHeader = new Panel()
                {
                    CssClass = "propertyHeader"
                };
                var editPropertyTitle = new HtmlGenericControl("h3")
                {
                    InnerText =
                        string.Format(
                            "{0} ({1}), {2}: {3}",
                            s.Name.StartsWith("#")
                                                            ? uQuery.GetDictionaryItem(
                                s.Name.Substring(
                                    1, s.Name.Length - 1),
                                s.Name.Substring(
                                    1, s.Name.Length - 1))
                                                            : s.Name,
                            s.Alias,
                            uQuery.GetDictionaryItem("Type", "Type"),
                            editDataType != null
                                                            ? editDataType.Text
                                                            : "ERROR: This datatype is not supported")
                };

                editPropertyTitle.Attributes["class"] = "propertyTitle";

                var lnkDelete = new LinkButton
                {
                    CssClass = "DeleteProperty ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only",
                    Text     =
                        "<span class='ui-button-icon-primary ui-icon ui-icon-close'>&nbsp;</span><span class='ui-button-text'>Delete</span>",
                    OnClientClick =
                        "return confirm('"
                        +
                        uQuery.GetDictionaryItem(
                            "AreYouSureYouWantToDeleteThisColumn", "Are you sure you want to delete this column")
                        + "?');",
                    CommandArgument = s.Id.ToString(),
                    CommandName     = "Delete"
                };
                lnkDelete.Command += new CommandEventHandler(this.lnkDelete_Command);

                var icnEditError = new HtmlGenericControl("span")
                {
                    InnerText = Helper.Dictionary.GetDictionaryItem("Error", "Error")
                };
                icnEditError.Attributes["class"] = "ErrorProperty";

                editPropertyHeader.Controls.Add(editPropertyTitle);
                editPropertyHeader.Controls.Add(lnkDelete);
                editPropertyHeader.Controls.Add(icnEditError);

                var editPropertyControls = new Panel()
                {
                    CssClass = "propertyControls"
                };

                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "<ul>"
                });

                // NAME
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "<li>"
                });

                // Instantiate controls
                var txtEditName = new TextBox()
                {
                    ID = "editName_" + this._preValues.IndexOf(s), CssClass = "editName", Text = s.Name
                };
                var lblEditName = new Label()
                {
                    AssociatedControlID = txtEditName.ClientID,
                    Text = Helper.Dictionary.GetDictionaryItem("Name", "Name")
                           + "<br/><small class='description'>"
                           + Helper.Dictionary.GetDictionaryItem(
                        "NameDescription",
                        "The column display name") + "</small>",
                    CssClass = "label"
                };
                var valEditName = new RequiredFieldValidator()
                {
                    ID                = "editNameValidator_" + this._preValues.IndexOf(s),
                    CssClass          = "validator",
                    ControlToValidate = txtEditName.ClientID,
                    Display           = ValidatorDisplay.Dynamic,
                    ErrorMessage      = "You must specify a name"
                };

                // Add controls to control
                editPropertyControls.Controls.Add(lblEditName);
                editPropertyControls.Controls.Add(txtEditName);
                editPropertyControls.Controls.Add(valEditName);
                s.Controls.Add(txtEditName);
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "</li>"
                });


                // ALIAS
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "<li>"
                });

                // Instantiate controls
                var txtEditAlias = new TextBox()
                {
                    ID = "editAlias_" + this._preValues.IndexOf(s), CssClass = "editAlias", Text = s.Alias
                };
                var lblEditAlias = new Label()
                {
                    AssociatedControlID = txtEditAlias.ClientID,
                    Text = Helper.Dictionary.GetDictionaryItem("Alias", "Alias")
                           + "<br/><small class='description'>"
                           + Helper.Dictionary.GetDictionaryItem(
                        "AliasDescription",
                        "The column alias") + "</small>",
                    CssClass = "label"
                };
                var valEditAlias = new RequiredFieldValidator()
                {
                    ID                = "editAliasValidator_" + this._preValues.IndexOf(s),
                    CssClass          = "validator",
                    ControlToValidate = txtEditAlias.ClientID,
                    Display           = ValidatorDisplay.Dynamic,
                    ErrorMessage      = "You must specify an alias"
                };
                var valEditAliasExists = new CustomValidator()
                {
                    ID                       = "editAliasExistsValidator_" + this._preValues.IndexOf(s),
                    CssClass                 = "validator exists",
                    ControlToValidate        = txtEditAlias.ClientID,
                    Display                  = ValidatorDisplay.Dynamic,
                    ClientValidationFunction = "ValidateAliasExists",
                    ErrorMessage             = "Alias already exists!"
                };
                valEditAliasExists.ServerValidate += valEditAliasExists_ServerValidate;

                // Add controls to control
                editPropertyControls.Controls.Add(lblEditAlias);
                editPropertyControls.Controls.Add(txtEditAlias);
                editPropertyControls.Controls.Add(valEditAlias);
                editPropertyControls.Controls.Add(valEditAliasExists);
                s.Controls.Add(txtEditAlias);
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "</li>"
                });


                // DATATYPE
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "<li>"
                });

                // Instantiate controls
                var ddlEditType = DtgHelpers.GetDataTypeDropDown();
                ddlEditType.ID = "editDataType_" + this._preValues.IndexOf(s);
                var lblEditType = new Label()
                {
                    AssociatedControlID = ddlEditType.ClientID,
                    Text = Helper.Dictionary.GetDictionaryItem("DataType", "Datatype")
                           + "<br/><small class='description'>"
                           + Helper.Dictionary.GetDictionaryItem(
                        "DatatypeDescription",
                        "The column data editor") + "</small>",
                    CssClass = "label"
                };

                // Add controls to control
                editPropertyControls.Controls.Add(lblEditType);
                ddlEditType.SelectedValue = s.DataTypeId.ToString();
                editPropertyControls.Controls.Add(ddlEditType);
                s.Controls.Add(ddlEditType);
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "</li>"
                });


                // MANDATORY
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "<li>"
                });

                // Instantiate controls
                var chkEditMandatory = new CheckBox()
                {
                    ID = "editMandatory_" + this._preValues.IndexOf(s), CssClass = "editMandatory", Checked = s.Mandatory
                };
                var lblEditMandatory = new Label()
                {
                    AssociatedControlID = chkEditMandatory.ClientID,
                    Text = Helper.Dictionary.GetDictionaryItem("Mandatory", "Mandatory")
                           + "<br/><small class='description'>"
                           + Helper.Dictionary.GetDictionaryItem(
                        "MandatoryDescription",
                        "Whether this column is mandatory") + "</small>",
                    CssClass = "label"
                };

                // Add controls to control
                editPropertyControls.Controls.Add(lblEditMandatory);
                editPropertyControls.Controls.Add(chkEditMandatory);
                s.Controls.Add(chkEditMandatory);
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "</li>"
                });


                // VISIBLE
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "<li>"
                });

                // Instantiate controls
                var chkEditVisible = new CheckBox()
                {
                    ID = "editVisible_" + this._preValues.IndexOf(s), CssClass = "editVisible", Checked = s.Visible
                };
                var lblEditVisible = new Label()
                {
                    AssociatedControlID = chkEditVisible.ClientID,
                    Text = Helper.Dictionary.GetDictionaryItem("Visible", "Visible")
                           + "<br/><small class='description'>"
                           + Helper.Dictionary.GetDictionaryItem(
                        "VisibleDescription",
                        "Whether this column is visible in the grid. <br/>(it can still be edited)") + "</small>",
                    CssClass = "label"
                };

                // Add controls to control
                editPropertyControls.Controls.Add(lblEditVisible);
                editPropertyControls.Controls.Add(chkEditVisible);
                s.Controls.Add(chkEditVisible);
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "</li>"
                });


                // VALIDATION
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "<li>"
                });

                // Instantiate control
                var txtEditValidation = new TextBox()
                {
                    ID       = "editValidation_" + this._preValues.IndexOf(s),
                    TextMode = TextBoxMode.MultiLine,
                    Rows     = 2,
                    Columns  = 20,
                    CssClass = "editValidation",
                    Text     = s.ValidationExpression
                };
                var lblEditValidation = new Label()
                {
                    AssociatedControlID = txtEditValidation.ClientID,
                    Text = Helper.Dictionary.GetDictionaryItem("Validation", "Validation")
                           + "<br/><small class='description'>"
                           + Helper.Dictionary.GetDictionaryItem(
                        "ValidationDescription",
                        "The regular expression used for validation. Leave empty to disable") + "</small>",
                    CssClass = "label"
                };
                var lnkEditValidation = new HyperLink
                {
                    CssClass    = "validationLink",
                    NavigateUrl = "#",
                    Text        =
                        Helper.Dictionary.GetDictionaryItem(
                            "SearchForARegularExpression", "Search for a regular expression")
                };
                var valEditValidation = new CustomValidator()
                {
                    ID                       = "editValidationValidator_" + this._preValues.IndexOf(s),
                    CssClass                 = "validator",
                    ControlToValidate        = txtEditValidation.ClientID,
                    Display                  = ValidatorDisplay.Dynamic,
                    ClientValidationFunction = "ValidateRegex",
                    ErrorMessage             =
                        Helper.Dictionary.GetDictionaryItem(
                            "ValidationStringIsNotValid", "Validation string is not valid")
                };
                valEditValidation.ServerValidate += valEditValidation_ServerValidate;

                // Add controls to control
                editPropertyControls.Controls.Add(lblEditValidation);
                editPropertyControls.Controls.Add(txtEditValidation);
                editPropertyControls.Controls.Add(valEditValidation);
                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "<br/>"
                });
                editPropertyControls.Controls.Add(lnkEditValidation);
                s.Controls.Add(txtEditValidation);

                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "</li>"
                });


                // SORT ORDER

                // Instantiate controls
                var hdnEditSortOrderWrapper = new Panel()
                {
                    CssClass = "sortOrder"
                };
                var hdnEditSortOrder = new HiddenField()
                {
                    Value = s.SortOrder.ToString()
                };
                hdnEditSortOrderWrapper.Controls.Add(hdnEditSortOrder);
                editPropertyControls.Controls.Add(hdnEditSortOrderWrapper);
                s.Controls.Add(hdnEditSortOrder);


                editPropertyControls.Controls.Add(new LiteralControl()
                {
                    Text = "</ul>"
                });

                editProperty.Controls.Add(editPropertyHeader);
                editProperty.Controls.Add(editPropertyControls);

                this._accordionContainer.Controls.Add(editProperty);
            }

            this.Controls.Add(this._showLabel);
            this.Controls.Add(this._showHeader);
            this.Controls.Add(this._showFooter);
            this.Controls.Add(this._readOnly);
            this.Controls.Add(this._tableHeight);
            this.Controls.Add(this._tableHeightValidator);
            this.Controls.Add(this._accordionContainer);
        }
예제 #7
0
        public StoredValueRowCollection(IEnumerable <PreValueRow> columnConfigurations, string xml)
            : this(columnConfigurations)
        {
            if (!string.IsNullOrEmpty(xml))
            {
                var l = new List <StoredValueRow>();

                var doc = new XmlDocument();
                doc.LoadXml(xml);

                // Create and add XML declaration.
                var xmldecl = doc.CreateXmlDeclaration("1.0", null, null);
                var root    = doc.DocumentElement;
                doc.InsertBefore(xmldecl, root);

                // Get stored values from database
                if (root.ChildNodes.Count > 0)
                {
                    foreach (XmlNode container in root.ChildNodes)
                    {
                        // <DataTypeGrid>
                        var valueRow = new StoredValueRow();

                        if (container.Attributes["id"] != null)
                        {
                            valueRow.Id = int.Parse(container.Attributes["id"].Value);
                        }

                        if (container.Attributes["sortOrder"] != null)
                        {
                            valueRow.SortOrder = int.Parse(container.Attributes["sortOrder"].Value);
                        }

                        foreach (var config in this.columnConfigurations)
                        {
                            var value = new StoredValue {
                                Name = config.Name, Alias = config.Alias
                            };

                            var datatypeid = config.DataTypeId;

                            if (datatypeid != 0)
                            {
                                var dtd = DataTypeDefinition.GetDataTypeDefinition(datatypeid);
                                var dt  = dtd.DataType;
                                dt.Data.Value = string.Empty;
                                value.Value   = dt;

                                foreach (XmlNode node in container.ChildNodes)
                                {
                                    if (config.Alias.Equals(node.Name))
                                    {
                                        try
                                        {
                                            value.Value.Data.Value = node.InnerText;
                                        }
                                        catch (Exception ex)
                                        {
                                            DtgHelpers.AddLogEntry(string.Format("Stored data ({0}) for '{1}' is incompatible with the datatype '{2}'", node.InnerText, value.Alias, value.Value.DataTypeName));
                                        }
                                    }
                                }

                                valueRow.Cells.Add(value);
                            }
                        }

                        l.Add(valueRow);
                    }

                    // Add values to this instance
                    this.AddRange(l.OrderBy(x => x.SortOrder));
                }
            }
        }