Example #1
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));
        }
Example #2
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);
        }
Example #3
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));
                }
            }
        }