Exemplo n.º 1
0
        protected virtual void AddAutoBindColumns(PDFDataContext context)
        {
            if (string.IsNullOrEmpty(this.DataSourceID))
            {
                throw new InvalidOperationException("Can only auto bind the schema when the DataGrid has an explicit DataSourceID and the referencing source supports Schema derriving");
            }

            IPDFDataSource found = base.FindDocumentComponentById(this.DataSourceID) as IPDFDataSource;

            if (null == found || found.SupportsDataSchema == false)
            {
                throw new InvalidOperationException("Can only auto bind the schema when the DataGrid has an explicit DataSourceID and the referencing source supports Schema derriving");
            }

            PDFDataSchema schema = found.GetDataSchema(this.SelectPath, context);

            if (null == schema || schema.Items == null || schema.Items.Count == 0)
            {
                context.TraceLog.Add(TraceLevel.Warning, "PDFDataGrid", string.Format("Cannot autobind the columns as no schema items were returned for the path '{0}'", this.SelectPath));
            }
            else
            {
                foreach (PDFDataItem item in schema.Items)
                {
                    if (ShouldIncludeAutoBoundItem(item))
                    {
                        DataGridColumn col = GetDataColumnForType(item.DataType);
                        if (null != col)
                        {
                            col.HeaderText = string.IsNullOrEmpty(item.Title) ? item.Name : item.Title;
                            col.SetDataSourceBindingItem(item, context);
                            if (context.TraceLog.ShouldLog(TraceLevel.Debug))
                            {
                                context.TraceLog.Add(TraceLevel.Debug, "PDFDataGrid", string.Format("The data column was automatically created for the schdema item '{0}' in data grid '{1}'", item, this));
                            }
                            this.Columns.Add(col);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Returns the PDFDataScema associated with this source.
 /// </summary>
 /// <param name="path"></param>
 /// <param name="context"></param>
 /// <returns>The data schema associated with the source</returns>
 /// <exception cref="System.NotSupportedException" >Thrown if this data source does not support schema extraction</exception>
 public override PDFDataSchema GetDataSchema(string path, PDFDataContext context)
 {
     System.Data.DataSet ds;
     if (this.HasData(out ds))
     {
         PDFDataSchema schema = DataSetSchemaGenerator.CreateSchemaFromSet(ds, context);
         if (!string.IsNullOrEmpty(path))
         {
             if (path == schema.RootPath)
             {
                 return(schema);
             }
             else if (!path.StartsWith(schema.RootPath))
             {
                 return(null);
             }
             else
             {
                 foreach (var one in schema.Items)
                 {
                     if (one.FullPath == path)
                     {
                         PDFDataSchema child = new PDFDataSchema(one.FullPath, one.Children);
                         return(child);
                     }
                 }
                 return(null);
             }
         }
         else
         {
             return(schema);
         }
     }
     else
     {
         return(base.GetDataSchema(path, context));
     }
 }
        private static PDFDataSchema DoPopulateDataSchema(DataSet dataset, PDFDataContext context)
        {
            string dsName    = dataset.DataSetName;
            string dsXmlName = System.Xml.XmlConvert.EncodeLocalName(dsName);

            System.Data.DataTable[] tables   = GetTopLevelTables(dataset);
            List <PDFDataItem>      topItems = new List <PDFDataItem>();

            foreach (System.Data.DataTable table in tables)
            {
                string tableName               = table.TableName;
                string tableXmlName            = System.Xml.XmlConvert.EncodeLocalName(tableName);
                string path                    = PDFDataSchema.CombineElementNames(dsXmlName, tableXmlName);
                PDFDataItemCollection columns  = new PDFDataItemCollection(GetTableColumnSchema(path, table));
                PDFDataItem           topTable = new PDFDataItem(path, tableName, tableName, columns);
                topItems.Add(topTable);

                //TODO: Load child schemas
            }
            PDFDataSchema schema = new PDFDataSchema(dsName, new PDFDataItemCollection(topItems));

            return(schema);
        }
        /// <summary>
        /// Extracts a single schema data item for the provided data column
        /// </summary>
        /// <param name="path"></param>
        /// <param name="col"></param>
        /// <returns></returns>
        private static PDFDataItem GetColumnDataItem(string path, System.Data.DataColumn col)
        {
            string name         = col.ColumnName;
            string relativePath = System.Xml.XmlConvert.EncodeLocalName(name);
            string title        = string.IsNullOrEmpty(col.Caption) ? name : col.Caption;

            System.Xml.XmlNodeType nodetype;
            if (col.ColumnMapping == System.Data.MappingType.Hidden)
            {
                return(null);
            }
            else if (col.ColumnMapping == System.Data.MappingType.Attribute)
            {
                relativePath = "@" + relativePath;
                nodetype     = System.Xml.XmlNodeType.Attribute;
            }
            else if (col.ColumnMapping == System.Data.MappingType.SimpleContent)
            {
                relativePath = "text()";
                nodetype     = System.Xml.XmlNodeType.Text;
            }
            else if (col.ColumnMapping == System.Data.MappingType.Element)
            {
                nodetype      = System.Xml.XmlNodeType.Element;
                relativePath += "/text()";
            }
            else
            {
                throw new ArgumentOutOfRangeException("col.ColumnMapping");
            }

            string fullpath = PDFDataSchema.CombineElementNames(path, relativePath);

            PDFDataItem item = new PDFDataItem(fullpath, relativePath, name, title, nodetype, GetDataTypeFromSystemType(col));

            return(item);
        }
Exemplo n.º 5
0
        protected virtual void AddAutoBindFields(object data, IPDFDataSource source, PDFDataContext context)
        {
            if (string.IsNullOrEmpty(this.DataSourceID))
            {
                throw new InvalidOperationException("Can only auto bind the schema when the With has an explicit DataSourceID and the referencing source supports Schema derriving");
            }

            IPDFDataSource found = base.FindDocumentComponentById(this.DataSourceID) as IPDFDataSource;

            if (null == found || found.SupportsDataSchema == false)
            {
                throw new InvalidOperationException("Can only auto bind the schema when the With has an explicit DataSourceID and the referencing source supports Schema derriving");
            }

            PDFDataSchema schema = found.GetDataSchema(this.SelectPath, context);

            if (null == schema || schema.Items == null || schema.Items.Count == 0)
            {
                context.TraceLog.Add(TraceLevel.Warning, "PDFWithFieldSet", string.Format("Cannot autobind the columns as no schema items were returned for the path '{0}'", this.SelectPath));
            }
            else
            {
                if (context.TraceLog.ShouldLog(TraceLevel.Debug))
                {
                    context.TraceLog.Add(TraceLevel.Debug, "DataGrid", "Initializing and loading root component before binding");
                }

                PDFTraceLog    log  = context.TraceLog;
                PDFInitContext init = new PDFInitContext(context.Items, log, context.PerformanceMonitor, this.Document);
                PDFLoadContext load = new PDFLoadContext(context.Items, log, context.PerformanceMonitor, this.Document);


                foreach (PDFDataItem item in schema.Items)
                {
                    if (ShouldIncludeAutoBoundItem(item))
                    {
                        WithBoundField field = GetFieldForType(item.DataType);
                        if (null != field)
                        {
                            field.StyleClass = this.FieldClass;

                            field.FieldLabel   = string.IsNullOrEmpty(item.Title) ? item.Name : item.Title;
                            field.LabelClass   = this.LabelClass;
                            field.ValueClass   = this.ValueClass;
                            field.LabelPostFix = this.LabelPostFix;
                            field.LayoutType   = this.AutoLayoutType;
                            field.DataType     = item.DataType;
                            field.HideIfEmpty  = this.HideEmptyFields;


                            field.SetDataSourceBindingItem(item, context);
                            if (context.TraceLog.ShouldLog(TraceLevel.Debug))
                            {
                                context.TraceLog.Add(TraceLevel.Debug, "PDFWithFieldSet", string.Format("The data field was automatically created for the schdema item '{0}' in set '{1}'", item, this));
                            }

                            this.Fields.Add(field);
                            field.Init(init);
                            field.Load(load);

                            this.BindingActions.Add(new BindingAction(data, source, field));
                        }
                    }
                }

                //added all the items
            }
        }