override public void FinalPass() { _ds = OwnerReport.DataSetsDefn[this._DataSetName]; if (_ds == null) OwnerReport.rl.LogError(8, "DataSetReference refers to unknown data set '" + _DataSetName + "'"); else { _vField = _ds.Fields[_ValueField]; if (_vField == null) OwnerReport.rl.LogError(8, "ValueField refers to unknown field '" + _ValueField + "'"); else { if (_LabelField == null) _lField = _vField; else { _lField = _ds.Fields[_LabelField]; if (_lField == null) OwnerReport.rl.LogError(8, "LabelField refers to unknown field '" + _LabelField + "'"); } } } return; }
DataRegion _ParentDataRegion; // when DataRegions are nested; the nested regions have the parent set public DataRegion(ReportDefn r, ReportLink p, XmlNode xNode):base(r,p,xNode) { _KeepTogether=false; _NoRows=null; _DataSetName=null; _DataSetDefn=null; _PageBreakAtStart=false; _PageBreakAtEnd=false; _Filters=null; }
IDictionary _Items; // list of report items public DataSetsDefn(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) { if (xNode.ChildNodes.Count < 10) _Items = new ListDictionary(); // Hashtable is overkill for small lists else _Items = new Hashtable(xNode.ChildNodes.Count); // Loop thru all the child nodes foreach(XmlNode xNodeLoop in xNode.ChildNodes) { if (xNodeLoop.NodeType != XmlNodeType.Element) continue; if (xNodeLoop.Name == "DataSet") { DataSetDefn ds = new DataSetDefn(r, this, xNodeLoop); if (ds != null && ds.Name != null) _Items.Add(ds.Name.Nm, ds); } } }
public TypeCode DoParse(Report rpt) { // optimization: avoid expression overhead if this isn't really an expression if (_Source == null) { _Expr = new Constant(""); return(_Expr.GetTypeCode()); } else if (_Source == string.Empty || // empty expression _Source[0] != '=') // if 1st char not '=' { _Expr = new Constant(_Source); // this is a constant value return(_Expr.GetTypeCode()); } Parser p = new Parser(new System.Collections.Generic.List <ICacheData>()); // find the fields that are part of the DataRegion (if there is one) IDictionary fields = null; ReportLink dr = _rl.Parent; Grouping grp = null; // remember if in a table group or detail group or list group Matrix m = null; while (dr != null) { if (dr is Grouping) { p.NoAggregateFunctions = true; } else if (dr is TableGroup) { grp = ((TableGroup)dr).Grouping; } else if (dr is Matrix) { m = (Matrix)dr; // if matrix we need to pass special break; } else if (dr is Details) { grp = ((Details)dr).Grouping; } else if (dr is List) { grp = ((List)dr).Grouping; break; } else if (dr is DataRegion || dr is DataSetDefn) { break; } dr = dr.Parent; } if (dr != null) { if (dr is DataSetDefn) { DataSetDefn d = (DataSetDefn)dr; if (d.Fields != null) { fields = d.Fields.Items; } } else // must be a DataRegion { DataRegion d = (DataRegion)dr; if (d.DataSetDefn != null && d.DataSetDefn.Fields != null) { fields = d.DataSetDefn.Fields.Items; } } } NameLookup lu = new NameLookup(fields, rpt.ReportDefinition.LUReportParameters, rpt.ReportDefinition.LUReportItems, rpt.ReportDefinition.LUGlobals, rpt.ReportDefinition.LUUser, rpt.ReportDefinition.LUAggrScope, grp, m, rpt.ReportDefinition.CodeModules, rpt.ReportDefinition.Classes, rpt.ReportDefinition.DataSetsDefn, rpt.ReportDefinition.CodeType); try { _Expr = p.Parse(lu, _Source); } catch (Exception e) { _Expr = new ConstantError(e.Message); // Invalid expression rpt.rl.LogError(8, ErrorText(e.Message)); } // Optimize removing any expression that always result in a constant try { _Expr = _Expr.ConstantOptimization(); } catch (Exception ex) { rpt.rl.LogError(4, "Expression:" + _Source + "\r\nConstant Optimization exception:\r\n" + ex.Message + "\r\nStack trace:\r\n" + ex.StackTrace); } return(_Expr.GetTypeCode()); }
// Handle parsing of function in final pass override public void FinalPass() { base.FinalPass(); if (this is Table) { // Grids don't have any data responsibilities Table t = this as Table; if (t.IsGrid) { return; } } // DataRegions aren't allowed in PageHeader or PageFooter; if (this.InPageHeaderOrFooter()) { OwnerReport.rl.LogError(8, String.Format("The DataRegion '{0}' is not allowed in a PageHeader or PageFooter", this.Name == null? "unknown": Name.Nm)); } ResolveNestedDataRegions(); if (_ParentDataRegion != null) // when nested we use the dataset of the parent { _DataSetDefn = _ParentDataRegion.DataSetDefn; } else if (_DataSetName != null) { if (OwnerReport.DataSetsDefn != null) { _DataSetDefn = (DataSetDefn)OwnerReport.DataSetsDefn.Items[_DataSetName]; } if (_DataSetDefn == null) { OwnerReport.rl.LogError(8, String.Format("DataSetName '{0}' not specified in DataSets list.", _DataSetName)); } } else { // No name but maybe we can default to a single Dataset if (_DataSetDefn == null && OwnerReport.DataSetsDefn != null && OwnerReport.DataSetsDefn.Items.Count == 1) { foreach (DataSetDefn d in OwnerReport.DataSetsDefn.Items.Values) { _DataSetDefn = d; break; // since there is only 1 this will obtain it } } if (_DataSetDefn == null) { OwnerReport.rl.LogError(8, string.Format("{0} must specify a DataSetName.", this.Name == null? "DataRegions": this.Name.Nm)); } } if (_NoRows != null) { _NoRows.FinalPass(); } if (_Filters != null) { _Filters.FinalPass(); } return; }
DataSetDefn _dsd; // the true definition of the DataSet public DataSet(Report rpt, DataSetDefn dsd) { _rpt = rpt; _dsd = dsd; }
// return an IEnumerable that represents the scope of the data protected RowEnumerable GetDataScope(Report rpt, Row row, out bool bSave) { bSave = true; RowEnumerable re = null; if (this._Scope != null) { Type t = this._Scope.GetType(); //150208AJM GJL Trying - And Succeeding!!! to get data from chart if (t == typeof(Chart)) { Chart c = (Chart)this._Scope; this._Scope = c.ChartMatrix; t = this._Scope.GetType(); } if (t == typeof(Grouping)) { bSave = false; Grouping g = (Grouping)(this._Scope); if (g.InMatrix) { Rows rows = g.GetRows(rpt); if (rows == null) { return(null); } re = new RowEnumerable(0, rows.Data.Count - 1, rows.Data, _LevelCheck); } else { if (row == null || row.R.CurrentGroups == null) // currentGroups can be null when reference Textbox in header/footer that has a scoped aggr function reference (TODO: this is a problem!) { return(null); } GroupEntry ge = row.R.CurrentGroups[g.GetIndex(rpt)]; re = new RowEnumerable(ge.StartRow, ge.EndRow, row.R.Data, _LevelCheck); } } else if (t == typeof(Matrix)) { bSave = false; Matrix m = (Matrix)(this._Scope); Rows mData = m.GetMyData(rpt); re = new RowEnumerable(0, mData.Data.Count - 1, mData.Data, false); } else if (t == typeof(string)) { // happens on page header/footer scope if (row != null) { re = new RowEnumerable(0, row.R.Data.Count - 1, row.R.Data, false); } bSave = false; } else if (row != null) { re = new RowEnumerable(0, row.R.Data.Count - 1, row.R.Data, false); } else { DataSetDefn ds = this._Scope as DataSetDefn; if (ds != null && ds.Query != null) { Rows rows = ds.Query.GetMyData(rpt); if (rows != null) { re = new RowEnumerable(0, rows.Data.Count - 1, rows.Data, false); } } } } else if (row != null) { re = new RowEnumerable(0, row.R.Data.Count - 1, row.R.Data, false); } return(re); }
// Handle parsing of function in final pass override public void FinalPass() { base.FinalPass(); if (this is Table) { // Grids don't have any data responsibilities Table t = this as Table; if (t.IsGrid) return; } // DataRegions aren't allowed in PageHeader or PageFooter; if (this.InPageHeaderOrFooter()) OwnerReport.rl.LogError(8, String.Format("The DataRegion '{0}' is not allowed in a PageHeader or PageFooter", this.Name == null? "unknown": Name.Nm) ); ResolveNestedDataRegions(); if (_ParentDataRegion != null) // when nested we use the dataset of the parent { _DataSetDefn = _ParentDataRegion.DataSetDefn; } else if (_DataSetName != null) { if (OwnerReport.DataSetsDefn != null) _DataSetDefn = (DataSetDefn) OwnerReport.DataSetsDefn.Items[_DataSetName]; if (_DataSetDefn == null) { OwnerReport.rl.LogError(8, String.Format("DataSetName '{0}' not specified in DataSets list.", _DataSetName)); } } else { // No name but maybe we can default to a single Dataset if (_DataSetDefn == null && OwnerReport.DataSetsDefn != null && OwnerReport.DataSetsDefn.Items.Count == 1) { foreach (DataSetDefn d in OwnerReport.DataSetsDefn.Items.Values) { _DataSetDefn = d; break; // since there is only 1 this will obtain it } } if (_DataSetDefn == null) OwnerReport.rl.LogError(8, string.Format("{0} must specify a DataSetName.",this.Name == null? "DataRegions": this.Name.Nm)); } if (_NoRows != null) _NoRows.FinalPass(); if (_Filters != null) _Filters.FinalPass(); return; }
override public void FinalPass() { // optimization: avoid expression overhead if this isn't really an expression if (_Source == null) { _Expr = new Constant(""); return; } else if (_Source == "" || // empty expression _Source[0] != '=') // if 1st char not '=' { _Expr = new Constant(_Source); // this is a constant value return; } Parser p = new Parser(OwnerReport.DataCache); // find the fields that are part of the DataRegion (if there is one) IDictionary fields = null; ReportLink dr = Parent; Grouping grp = null; // remember if in a table group or detail group or list group Matrix m = null; ReportLink phpf = null; while (dr != null) { if (dr is Grouping) { p.NoAggregateFunctions = true; } else if (dr is TableGroup) { grp = ((TableGroup)dr).Grouping; } else if (dr is Matrix) { m = (Matrix)dr; // if matrix we need to pass special break; } else if (dr is Details) { grp = ((Details)dr).Grouping; } else if (dr is List) { grp = ((List)dr).Grouping; break; } else if (dr is PageHeader || dr is PageFooter) { phpf = dr; } else if (dr is DataRegion || dr is DataSetDefn) { break; } dr = dr.Parent; } if (dr != null) { if (dr is DataSetDefn) { DataSetDefn d = (DataSetDefn)dr; if (d.Fields != null) { fields = d.Fields.Items; } } else // must be a DataRegion { DataRegion d = (DataRegion)dr; if (d.DataSetDefn != null && d.DataSetDefn.Fields != null) { fields = d.DataSetDefn.Fields.Items; } } } NameLookup lu = new NameLookup(fields, OwnerReport.LUReportParameters, OwnerReport.LUReportItems, OwnerReport.LUGlobals, OwnerReport.LUUser, OwnerReport.LUAggrScope, grp, m, OwnerReport.CodeModules, OwnerReport.Classes, OwnerReport.DataSetsDefn, OwnerReport.CodeType); if (phpf != null) { // Non-null when expression is in PageHeader or PageFooter; // Expression name needed for dynamic lookup of ReportItems on a page. lu.PageFooterHeader = phpf; lu.ExpressionName = _UniqueName = "xn_" + Interlocked.Increment(ref Parser.Counter).ToString(); } try { _Expr = p.Parse(lu, _Source); } catch (Exception e) { _Expr = new ConstantError(e.Message); // Invalid expression OwnerReport.rl.LogError(8, ErrorText(e.Message)); } // Optimize removing any expression that always result in a constant try { _Expr = _Expr.ConstantOptimization(); } catch (Exception ex) { OwnerReport.rl.LogError(4, "Expression:" + _Source + "\r\nConstant Optimization exception:\r\n" + ex.Message + "\r\nStack trace:\r\n" + ex.StackTrace); } _Type = _Expr.GetTypeCode(); return; }