示例#1
0
        private static void UpdateColumnConstraints(TableDefinitionCollection tableList, IDataReader reader)
        {
            while (reader.Read())
            {
                TableColumnDefinition columnInfo = tableList.FindColumn(reader.GetString(0), reader.GetString(1), reader.GetString(2));
                if (columnInfo == null)
                {
                    continue;
                }

                switch (reader.GetString(3))
                {
                case SchemaValue.ForeignKey:
                    columnInfo.IsForeignKey = true;
                    break;

                case SchemaValue.PrimaryKey:
                    columnInfo.IsPrimaryKey           = true;
                    columnInfo.ParentTable.PrimaryKey = columnInfo;
                    break;

                case SchemaValue.Unique:
                    columnInfo.IsUnique = true;
                    break;
                }
            }
        }
示例#2
0
 public OsuMarkdownTableCell(TableCell cell, TableColumnDefinition definition, bool isHeading)
     : base(cell, definition)
 {
     this.isHeading  = isHeading;
     Masking         = false;
     BorderThickness = 0;
 }
        public IActionResult Add(TableColumnAndModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { state = "error", data = "提交信息验证失败" }));
            }

            try
            {
                var p = new TableColumnDefinition()
                {
                    Field         = model.Field,
                    Format        = string.IsNullOrEmpty(model.Format) ? "" : model.Format,
                    FunctionId    = model.FunctionId,
                    Align         = model.Align,
                    Index         = model.Index,
                    Name          = model.Name,
                    TableColumnId = Guid.NewGuid().ToString("N"),
                    Visible       = model.Visible,
                    Width         = model.Width,
                };
                TableColumnDal.Add(p);
                return(Json(new { state = "ok", data = 1 }));
            }
            catch (Exception ex)
            {
                return(Json(new { state = "error", data = ex.Message }));
            }
        }
示例#4
0
        public MarkdownTableCell(TableCell cell, TableColumnDefinition definition, bool isHeading)
        {
            this.cell       = cell;
            this.definition = definition;

            RelativeSizeAxes = Axes.Both;

            BorderThickness = 1.8f;
            BorderColour    = Color4.White;
            Masking         = true;
        }
示例#5
0
 private static void UpdateForeignKeyColumns(TableDefinitionCollection tableList, IDataReader reader)
 {
     while (reader.Read())
     {
         TableColumnDefinition columnInfo = tableList.FindColumn(reader.GetString(0), reader.GetString(1), reader.GetString(2));
         if (columnInfo != null && columnInfo.IsForeignKey)
         {
             columnInfo.ForeignKeyColumn = tableList.FindColumn(reader.GetString(3), reader.GetString(4), reader.GetString(5));
         }
     }
 }
示例#6
0
        private static void PopulateTableInfo(IWriteEnumerable <TableDefinition> tableList, IDataReader reader, ActiveMapCodeGenConfigurationSection configuration)
        {
            TableDefinition tableInfo = null;
            string          lastOwner = null;
            string          lastTable = null;

            while (reader.Read())
            {
                string newOwner = reader.GetString(0);
                string newTable = reader.GetString(1);

                if (newTable.StartsWith("sys", StringComparison.OrdinalIgnoreCase) ||
                    newTable.StartsWith("dt", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (tableInfo == null || (newOwner != lastOwner || newTable != lastTable))
                {
                    // TODO: Implement data source name usage
                    // TODO: Separate Views from Tables
                    tableInfo = new TableDefinition(null, newTable, newOwner, configuration)
                    {
                        IsReadOnly = reader.GetString(2) != SchemaValue.BaseTable
                    };

                    tableList.Add(tableInfo);
                }

                TableColumnDefinition columnInfo = new TableColumnDefinition(configuration)
                {
                    Name         = reader.GetString(3),
                    IsNullable   = reader.GetString(4) == SchemaValue.Yes,
                    MaxLength    = reader.IsDBNull(6) ? 0 : reader.GetInt32(6),
                    IsComputed   = reader.GetInt32(7) == 1,
                    IsIdentity   = reader.GetInt32(8) == 1,
                    Ordinal      = Convert.ToInt32(reader[9]),
                    Description  = Convert.ToString(reader[10]),
                    DefaultValue = Convert.ToString(reader[11])
                };

                columnInfo.DbType = GetDbType(reader.GetString(5), columnInfo.MaxLength);
                tableInfo.Columns.Add(columnInfo);

                lastOwner = tableInfo.Owner;
                lastTable = tableInfo.Name;
            }
        }
        private static void AddColumnDefinitions(HtmlNode htmlNode, GridDefinition grid)
        {
            var table = new TableColumnDefinition(htmlNode);
            var tr    = htmlNode.FirstOrDefault("tr");

            if (tr == null)
            {
                return;
            }

            foreach (var node in tr.Nodes("td"))
            {
                var td = new TdColumnDefinition(table, node);
                grid.ColumnDefinitions.Add(td);
            }
        }
示例#8
0
 protected virtual MarkdownTableCell CreateTableCell(TableCell cell, TableColumnDefinition definition, bool isHeading)
 {
     return(new MarkdownTableCell(cell, definition, isHeading));
 }
示例#9
0
        /// <summary>
        /// Auto generates a table based on the schema of a query
        /// </summary>
        /// <param name="query">The query</param>
        /// <param name="tableTitle">The table title</param>
        /// <param name="excludedColumns">The names of excluded columns</param>
        /// <returns>The table definition created</returns>
        protected virtual TableDefinition AutoGenerateTable
        (
            IQuery query,
            string tableTitle,
            params string[] excludedColumns
        )
        {
            Validate.IsNotNull(query);
            Validate.IsNotNull(excludedColumns);

            var tableDefinition = new TableDefinition
                                  (
                query.Name,
                tableTitle,
                query
                                  );

            foreach (var columnInfo in query.Columns)
            {
                var columnName = columnInfo.Column.Name;

                var isExcluded = excludedColumns.Any
                                 (
                    exclusion => exclusion.Equals(columnName, StringComparison.OrdinalIgnoreCase)
                                 );

                if (false == isExcluded)
                {
                    var valueType       = columnInfo.Column.ValueType;
                    var totalAggregator = default(IAggregateFunction);

                    if (valueType.IsNumericType() && false == valueType.IsEnumAssignable())
                    {
                        totalAggregator = new SumFunction
                                          (
                            new DataBinding
                            (
                                columnName
                            )
                                          );
                    }

                    var columnDefinition = new TableColumnDefinition
                                           (
                        columnName.Spacify(),
                        new DataBinding
                        (
                            DataBindingType.QueryPath,
                            columnName
                        ),
                        totalAggregator
                                           );

                    tableDefinition.StaticColumns.Add
                    (
                        columnDefinition
                    );
                }
            }

            return(tableDefinition);
        }
示例#10
0
        /// <summary>
        /// Generates a table based on the schema of a query with the columns specified
        /// </summary>
        /// <param name="query">The query</param>
        /// <param name="tableTitle">The table title</param>
        /// <param name="columnMappings">The names of columns to map</param>
        /// <returns>The table definition created</returns>
        /// <remarks>
        /// The column mappings are represented as an array of key-value pairs.
        ///
        /// Each pair represents a single query column (key) and the table
        /// column (value) that it maps to.
        /// </remarks>
        protected virtual TableDefinition GenerateTableWith
        (
            IQuery query,
            string tableTitle,
            params KeyValuePair <string, string>[] columnMappings
        )
        {
            Validate.IsNotNull(query);
            Validate.IsNotNull(columnMappings);

            if (columnMappings.Length == 0)
            {
                throw new ArgumentException
                      (
                          "At least one column must be specified to create a table."
                      );
            }

            var tableDefinition = new TableDefinition
                                  (
                query.Name,
                tableTitle,
                query
                                  );

            foreach (var mapping in columnMappings)
            {
                var columnFound = query.HasColumn
                                  (
                    mapping.Key
                                  );

                if (false == columnFound)
                {
                    throw new InvalidOperationException
                          (
                              $"The query does not have a column named '{mapping.Key}'."
                          );
                }

                var columnInfo = query.GetColumn
                                 (
                    mapping.Key
                                 );

                var totalAggregator = default(IAggregateFunction);

                if (columnInfo.Column.ValueType.IsNumeric())
                {
                    totalAggregator = new SumFunction
                                      (
                        new DataBinding
                        (
                            mapping.Key
                        )
                                      );
                }

                var columnDefinition = new TableColumnDefinition
                                       (
                    mapping.Value,
                    new DataBinding
                    (
                        DataBindingType.QueryPath,
                        mapping.Key
                    ),
                    totalAggregator
                                       );

                tableDefinition.StaticColumns.Add
                (
                    columnDefinition
                );
            }

            return(tableDefinition);
        }
示例#11
0
        /// <summary>
        /// Parses a table block.
        /// </summary>
        /// <param name="markdown"> The markdown text. </param>
        /// <param name="start"> The location of the first character in the block. </param>
        /// <param name="endOfFirstLine"> The location of the end of the first line. </param>
        /// <param name="maxEnd"> The location to stop parsing. </param>
        /// <param name="quoteDepth"> The current nesting level for block quoting. </param>
        /// <param name="actualEnd"> Set to the end of the block when the return value is non-null. </param>
        /// <returns> A parsed table block, or <c>null</c> if this is not a table block. </returns>
        internal static TableBlock Parse(string markdown, int start, int endOfFirstLine, int maxEnd, int quoteDepth, out int actualEnd)
        {
            // A table is a line of text, with at least one vertical bar (|), followed by a line of
            // of text that consists of alternating dashes (-) and vertical bars (|) and optionally
            // vertical bars at the start and end.  The second line must have at least as many
            // interior vertical bars as there are interior vertical bars on the first line.
            actualEnd = start;

            // First thing to do is to check if there is a vertical bar on the line.
            int barOrNewLineIndex = markdown.IndexOf('|', start, endOfFirstLine - start);

            if (barOrNewLineIndex < 0)
            {
                return(null);
            }

            var rows = new List <TableRow>();

            // Parse the first row.
            var firstRow = new TableRow();

            start = firstRow.Parse(markdown, start, maxEnd, quoteDepth);
            rows.Add(firstRow);

            // Parse the contents of the second row.
            var secondRowContents = new List <string>();

            start = TableRow.ParseContents(
                markdown,
                start,
                maxEnd,
                quoteDepth,
                requireVerticalBar: false,
                contentParser: (start2, end2) => secondRowContents.Add(markdown.Substring(start2, end2 - start2)));

            // There must be at least as many columns in the second row as in the first row.
            if (secondRowContents.Count < firstRow.Cells.Count)
            {
                return(null);
            }

            // Check each column definition.
            // Note: excess columns past firstRowColumnCount are ignored and can contain anything.
            var columnDefinitions = new List <TableColumnDefinition>(firstRow.Cells.Count);

            for (int i = 0; i < firstRow.Cells.Count; i++)
            {
                var cellContent = secondRowContents[i];
                if (cellContent.Length == 0)
                {
                    return(null);
                }

                // The first and last characters can be '-' or ':'.
                if (cellContent[0] != ':' && cellContent[0] != '-')
                {
                    return(null);
                }

                if (cellContent[cellContent.Length - 1] != ':' && cellContent[cellContent.Length - 1] != '-')
                {
                    return(null);
                }

                // Every other character must be '-'.
                for (int j = 1; j < cellContent.Length - 1; j++)
                {
                    if (cellContent[j] != '-')
                    {
                        return(null);
                    }
                }

                // Record the alignment.
                var columnDefinition = new TableColumnDefinition();
                if (cellContent.Length > 1 && cellContent[0] == ':' && cellContent[cellContent.Length - 1] == ':')
                {
                    columnDefinition.Alignment = ColumnAlignment.Center;
                }
                else if (cellContent[0] == ':')
                {
                    columnDefinition.Alignment = ColumnAlignment.Left;
                }
                else if (cellContent[cellContent.Length - 1] == ':')
                {
                    columnDefinition.Alignment = ColumnAlignment.Right;
                }

                columnDefinitions.Add(columnDefinition);
            }

            // Parse additional rows.
            while (start < maxEnd)
            {
                var row = new TableRow();
                start = row.Parse(markdown, start, maxEnd, quoteDepth);
                if (row.Cells.Count == 0)
                {
                    break;
                }

                rows.Add(row);
            }

            actualEnd = start;
            return(new TableBlock {
                ColumnDefinitions = columnDefinitions, Rows = rows
            });
        }
示例#12
0
 protected override MarkdownTableCell CreateTableCell(TableCell cell, TableColumnDefinition definition, bool isHeading) => new OsuMarkdownTableCell(cell, definition, isHeading);
示例#13
0
        private string BrowseColumns(ICollection <TableColumnDefinition> desc, string columnName, string tableAlias, TableColumnResolveCallback getCustomColumnDef, out TableColumnDefinition def)
        {
            def = desc.FirstOrDefault(n => n.ColumnName.Equals(columnName, StringComparison.OrdinalIgnoreCase));
            if (def != null)
            {
                return(SyntaxProvider.FullQualifyColumn(tableAlias, def.ColumnName)); // $"{(tableAlias != null ? $"[{tableAlias}]." : "")}[{col.ColumnName}]";
            }

            return(getCustomColumnDef?.Invoke(columnName, out def));
        }
示例#14
0
 public static TableColumnDefinition ColumnHidden(this TableColumnDefinition col)
 {
     col.Hidden = true;
     return(col);
 }
示例#15
0
 public static TableColumnDefinition ColumnReadOnly(this TableColumnDefinition col)
 {
     col.ReadOnly = true;
     return(col);
 }