Beispiel #1
0
            public RowComparer(Report report, DataSourceBase dataSource, string[] expressions, bool[] descending)
            {
                this.report      = report;
                this.dataSource  = dataSource;
                this.expressions = expressions;
                this.descending  = descending;

                // optimize performance if expression is a single data column
                columns = new Column[expressions.Length];
                for (int i = 0; i < expressions.Length; i++)
                {
                    string expr = expressions[i];
                    if (expr.StartsWith("[") && expr.EndsWith("]"))
                    {
                        expr = expr.Substring(1, expr.Length - 2);
                    }
                    Column         column     = DataHelper.GetColumn(this.report.Dictionary, expr);
                    DataSourceBase datasource = DataHelper.GetDataSource(this.report.Dictionary, expr);
                    if (column != null && column.Parent == datasource)
                    {
                        columns[i] = column;
                    }
                    else
                    {
                        columns[i] = null;
                    }
                }
            }
Beispiel #2
0
        public static DataSourceBase GetDataSource(Dictionary dictionary, string complexName)
        {
            if (String.IsNullOrEmpty(complexName))
            {
                return(null);
            }

            string[]       names = complexName.Split(new char[] { '.' });
            DataSourceBase data  = dictionary.FindByAlias(names[0]) as DataSourceBase;

            if (data == null)
            {
                return(null);
            }

            Column column = data;

            // take into account nested tables. Table may even be nested into Column.
            for (int i = 1; i < names.Length; i++)
            {
                Column childColumn = column.Columns.FindByAlias(names[i]);
                if (childColumn == null)
                {
                    break;
                }

                if (childColumn is DataSourceBase)
                {
                    data = childColumn as DataSourceBase;
                }
                column = childColumn;
            }

            return(data);
        }
Beispiel #3
0
        public bool AddData(string materDataName, DataTable dataTable, string dataSourceName)
        {
            AddData(dataTable, dataSourceName);
            DataBand db = this.Report.FindObject(materDataName) as DataBand;

            if (db == null)
            {
                MessageBox.Show("未找到控件 [" + materDataName + "]", "提示");
                return(false);
            }
            else
            {
                FastReport.Data.DataSourceBase source = this.Report.GetDataSource(dataSourceName);
                if (source == null)
                {
                    MessageBox.Show("没有找到名为[" + dataSourceName + "] 的数据源", "提示");
                    return(false);
                }
                else
                {
                    db.DataSource = source;
                    return(true);
                }
            }
        }
Beispiel #4
0
 public static Relation FindRelation(Dictionary dictionary, DataSourceBase parent, DataSourceBase child)
 {
     foreach (Relation relation in dictionary.Relations)
     {
         if (relation.ParentDataSource == parent && relation.ChildDataSource == child)
         {
             return(relation);
         }
     }
     return(null);
 }
Beispiel #5
0
        public static Column GetColumn(Dictionary dictionary, string complexName)
        {
            if (String.IsNullOrEmpty(complexName))
            {
                return(null);
            }

            string[] names = complexName.Split(new char[] { '.' });
            // the first part of complex name is always datasource name.
            DataSourceBase data = dictionary.FindByAlias(names[0]) as DataSourceBase;

            return(GetColumn(dictionary, data, names, false));
        }
        /// <inheritdoc/>
        public override void LoadData(ArrayList rows)
        {
            rows.Clear();
            // custom load data via Load event
            OnLoad();

            DataSourceBase parent         = ParentDataSource;
            bool           isMasterDetail = parent != null && parent.RowCount > 0;

            if (isMasterDetail)
            {
                LoadData(this.Value as IEnumerable, rows);
            }
            else
            {
                // ensure that parent is loaded
                if (parent != null && parent.InternalRows.Count == 0)
                {
                    parent.Init();
                }

                if (parent == null)
                {
                    // this is a root business object, its Reference property contains IEnumerable.
                    LoadData(Reference as IEnumerable, rows);
                }
                else
                {
                    // enumerate parent rows to fill this data source completely
                    parent.First();
                    while (parent.HasMoreRows)
                    {
                        LoadData(this.Value as IEnumerable, rows);
                        parent.Next();
                    }
                    // bug fix - two-pass report shows empty data
                    parent.ClearData();
                }
            }
        }
Beispiel #7
0
        internal void Init(Relation relation, string filter, SortCollection sort, bool useAllParentRows)
        {
            if (FShowAccessDataMessage)
            {
                Config.ReportSettings.OnProgress(Report, Res.Get("Messages,AccessingData"));
            }

            // InitSchema may fail sometimes (for example, when using OracleConnection with nested select).
            try
            {
                InitSchema();
            }
            catch
            {
            }
            LoadData();

            // fill rows, emulate relation
            rows.Clear();
            if (relation != null && relation.Enabled)
            {
                if (useAllParentRows)
                {
                    DataSourceBase parentData = relation.ParentDataSource;
                    // parentData must be initialized prior to calling this method!
                    parentData.First();
                    while (parentData.HasMoreRows)
                    {
                        GetChildRows(relation);
                        parentData.Next();
                    }
                }
                else
                {
                    GetChildRows(relation);
                }
            }
            else
            {
                foreach (object row in InternalRows)
                {
                    rows.Add(row);
                }
            }

            // filter data rows
            if (FShowAccessDataMessage && rows.Count > 10000)
            {
                Config.ReportSettings.OnProgress(Report, Res.Get("Messages,PreparingData"));
            }

            if (filter != null && filter.Trim() != "")
            {
                for (int i = 0; i < rows.Count; i++)
                {
                    CurrentRowNo = i;
                    object match = Report.Calc(filter);
                    if (match is bool && !(bool)match)
                    {
                        rows.RemoveAt(i);
                        i--;
                    }
                }
            }

            // additional filter
            if (AdditionalFilter.Count > 0)
            {
                ApplyAdditionalFilter();
            }

            // sort data rows
            if (sort != null && sort.Count > 0)
            {
                string[] expressions = new string[sort.Count];
                bool[]   descending  = new bool[sort.Count];
                for (int i = 0; i < sort.Count; i++)
                {
                    expressions[i] = sort[i].Expression;
                    descending[i]  = sort[i].Descending;
                }
                rows.Sort(new RowComparer(Report, this, expressions, descending));
            }

            FShowAccessDataMessage = false;
            First();
        }
Beispiel #8
0
        internal void Init(DataSourceBase parentData, string filter, SortCollection sort, bool useAllParentRows)
        {
            Relation relation = parentData != null?DataHelper.FindRelation(Report.Dictionary, parentData, this) : null;

            Init(relation, filter, sort, useAllParentRows);
        }
Beispiel #9
0
 /// <summary>
 /// Initializes this datasource and filters data rows according to the master-detail relation between
 /// this datasource and <b>parentData</b>. Also applies the specified filter and sorts the rows.
 /// </summary>
 /// <param name="parentData">Parent datasource.</param>
 /// <param name="filter">The filter expression.</param>
 /// <param name="sort">The collection of sort descriptors.</param>
 /// <remarks>
 /// To use master-detail relation, you must define the <see cref="Relation"/> object that describes
 /// the relation, and add it to the <b>Report.Dictionary.Relations</b> collection.
 /// </remarks>
 public void Init(DataSourceBase parentData, string filter, SortCollection sort)
 {
     Init(parentData, filter, sort, false);
 }
Beispiel #10
0
 /// <summary>
 /// Initializes this datasource and filters data rows according to the master-detail relation between
 /// this datasource and <b>parentData</b>.
 /// </summary>
 /// <param name="parentData">Parent datasource.</param>
 /// <remarks>
 /// To use master-detail relation, you must define the <see cref="Relation"/> object that describes
 /// the relation, and add it to the <b>Report.Dictionary.Relations</b> collection.
 /// </remarks>
 public void Init(DataSourceBase parentData)
 {
     Init(parentData, "", null);
 }
Beispiel #11
0
        /// <summary>
        /// Initializes this datasource, applies the specified filter and sorts the rows.
        /// </summary>
        /// <param name="filter">The filter expression.</param>
        /// <param name="sort">The collection of sort descriptors.</param>
        public void Init(string filter, SortCollection sort)
        {
            DataSourceBase parentData = null;

            Init(parentData, filter, sort);
        }
Beispiel #12
0
        public static Column GetColumn(Dictionary dictionary, DataSourceBase data, string[] names, bool initRelation)
        {
            // Process the following cases:
            // - Table.Column
            // - Table.NestedTable.Column (specific to BO)
            // - Table.RelatedTable.Column
            // - Table.Column where Column has '.' inside (specific to MSSQL)
            // - Table.ComplexColumn.Column (specific to BO)

            if (data == null || names.Length < 2)
            {
                return(null);
            }

            // search for relation
            int i = 1;

            for (; i < names.Length; i++)
            {
                bool found = false;
                foreach (Relation r in dictionary.Relations)
                {
                    if (r.ChildDataSource == data &&
                        (r.ParentDataSource != null && r.ParentDataSource.Alias == names[i] || r.Alias == names[i]))
                    {
                        data = r.ParentDataSource;
                        if (initRelation)
                        {
                            data.FindParentRow(r);
                        }
                        found = true;
                        break;
                    }
                }

                // nothing found, break and try column name.
                if (!found)
                {
                    break;
                }
            }

            // the rest is column name.
            ColumnCollection columns = data.Columns;

            // try full name first
            string columnName = "";

            for (int j = i; j < names.Length; j++)
            {
                columnName += (columnName == "" ? "" : ".") + names[j];
            }

            Column column = columns.FindByAlias(columnName);

            if (column != null)
            {
                return(column);
            }

            // try nested columns
            for (int j = i; j < names.Length; j++)
            {
                column = columns.FindByAlias(names[j]);
                if (column == null)
                {
                    return(null);
                }
                columns = column.Columns;
            }

            return(column);
        }