コード例 #1
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception("Globals collection argument is null");
                }
                switch (o.ToLower())
                {
                case "pagenumber":
                    return(new FunctionPageNumber());

                case "totalpages":
                    return(new FunctionTotalPages());

                case "executiontime":
                    return(new FunctionExecutionTime());

                case "reportfolder":
                    return(new FunctionReportFolder());

                case "reportname":
                    return(new FunctionReportName());

                default:
                    throw new Exception(string.Format("Globals collection argument '{0}' is unknown.", o));
                }
            }

            return(this);
        }
コード例 #2
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception(Strings.FunctionUserCollection_Error_UserCollectionNull);
                }
                string lo = o.ToLower();
                if (lo == "userid")
                {
                    return(new FunctionUserID());
                }
                if (lo == "language")
                {
                    return(new FunctionUserLanguage());
                }
                throw new Exception(string.Format(Strings.FunctionUserCollection_Error_UserCollectionInvalid, o));
            }

            return(this);
        }
コード例 #3
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception("User collection argument is null");
                }
                string lo = o.ToLower();
                if (lo == "userid")
                {
                    return(new FunctionUserID());
                }
                if (lo == "language")
                {
                    return(new FunctionUserLanguage());
                }
                throw new Exception(string.Format("User collection argument {0} is invalid.", o));
            }

            return(this);
        }
コード例 #4
0
 public IExpr ConstantOptimization()
 {
     if (_Expr != null)
     {
         _Expr = _Expr.ConstantOptimization();
     }
     return((IExpr)this);
 }
コード例 #5
0
        public IExpr ConstantOptimization()
        {
            _rhs = _rhs.ConstantOptimization();
            if (_rhs.IsConstant())
            {
                bool b = EvaluateBoolean(null, null);
                return(new ConstantBoolean(b));
            }

            return(this);
        }
コード例 #6
0
        public IExpr ConstantOptimization()
        {
            _rhs = _rhs.ConstantOptimization();
            if (_rhs.IsConstant())
            {
                double d = EvaluateDouble(null, null);
                return(new ConstantInteger((int)d));
            }

            return(this);
        }
コード例 #7
0
        public IExpr ConstantOptimization()
        {
            _rhs = _rhs.ConstantOptimization();
            if (_rhs.IsConstant())
            {
                decimal d = EvaluateDecimal(null, null);
                return(new ConstantDecimal(d));
            }

            return(this);
        }
コード例 #8
0
 public IExpr ConstantOptimization()
 {
     _rhs.ConstantOptimization();
     if (_rhs.IsConstant())
     {
         return(new ConstantDouble(EvaluateDouble(null, null)));
     }
     else
     {
         return(this);
     }
 }
コード例 #9
0
        public IExpr ConstantOptimization()
        {
            _Formatee = _Formatee.ConstantOptimization();
            _Format   = _Format.ConstantOptimization();
            if (_Formatee.IsConstant() && _Format.IsConstant())
            {
                string s = EvaluateString(null, null);
                return(new Constant <string>(s));
            }

            return(this);
        }
コード例 #10
0
        public IExpr ConstantOptimization()
        {
            // Do constant optimization on all the arguments
            for (int i = 0; i < _Args.GetLength(0); i++)
            {
                IExpr e = (IExpr)_Args[i];
                _Args[i] = e.ConstantOptimization();
            }

            // Can't assume that the function doesn't vary
            //   based on something other than the args e.g. Now()
            return(this);
        }
コード例 #11
0
ファイル: FunctionIif.cs プロジェクト: eksotama/odd-reports
        public IExpr ConstantOptimization()
        {
            _If      = _If.ConstantOptimization();
            _IfTrue  = _IfTrue.ConstantOptimization();
            _IfFalse = _IfFalse.ConstantOptimization();

            if (_If.IsConstant())
            {
                bool result = _If.EvaluateBoolean(null, null);
                return(result? _IfTrue: _IfFalse);
            }

            return(this);
        }
コード例 #12
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception(Strings.FunctionParameterCollection_Error_ParameterCollectionNull);
                }
                ReportParameter rp = _Parameters[o] as ReportParameter;
                if (rp == null)
                {
                    throw new Exception(string.Format(Strings.FunctionParameterCollection_Error_ParameterCollectionInvalid, o));
                }
                return(new FunctionReportParameter(rp));
            }

            return(this);
        }
コード例 #13
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception("Parameter collection argument is null");
                }
                ReportParameter rp = _Parameters[o] as ReportParameter;
                if (rp == null)
                {
                    throw new Exception(string.Format("Parameter collection argument {0} is invalid", o));
                }
                return(new FunctionReportParameter(rp));
            }

            return(this);
        }
コード例 #14
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception(Strings.FunctionReportItemCollection_Error_ReportItemCollectionNull);
                }
                Textbox ri = _ReportItems[o] as Textbox;
                if (ri == null)
                {
                    throw new Exception(string.Format(Strings.FunctionReportItemCollection_Error_ReportItemCollectionInvalid, o));
                }
                return(new FunctionTextbox(ri, null));                  // no access to unique name
            }

            return(this);
        }
コード例 #15
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception("ReportItem collection argument is null");
                }
                Textbox ri = _ReportItems[o] as Textbox;
                if (ri == null)
                {
                    throw new Exception(string.Format("ReportItem collection argument {0} is invalid", o));
                }
                return(new FunctionTextbox(ri, null));                  // no access to unique name
            }

            return(this);
        }
コード例 #16
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception("Field collection argument is null");
                }
                Field f = _Fields[o] as Field;
                if (f == null)
                {
                    throw new Exception(string.Format("Field collection argument {0} is invalid", o));
                }
                return(new FunctionField(f));
            }

            return(this);
        }
コード例 #17
0
        public virtual IExpr ConstantOptimization()
        {
            _ArgExpr = _ArgExpr.ConstantOptimization();

            if (_ArgExpr.IsConstant())
            {
                string o = _ArgExpr.EvaluateString(null, null);
                if (o == null)
                {
                    throw new Exception(Strings.FunctionFieldCollection_Error_FieldCollectionNull);
                }
                Field f = _Fields[o] as Field;
                if (f == null)
                {
                    throw new Exception(string.Format(Strings.FunctionFieldCollection_Error_FieldCollectionInvalid, o));
                }
                return(new FunctionField(f));
            }

            return(this);
        }
コード例 #18
0
		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();
		}
コード例 #19
0
        internal override 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;
        }
コード例 #20
0
        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());
        }
コード例 #21
0
        override internal 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;
        }