public object EvaluateVariable(Variable var)
        {
            var expressionValue = EvaluateVariableExpression(var.GetHashCode());
            var actualValue = var.Value;

            if (var.Formula == Variable.CALCULATION_NONE)
            {
                var.Value = expressionValue;
                return expressionValue;
            }

            if (actualValue == null) actualValue = 0.0;

            var val = (double) actualValue;
            if (var.Formula == Variable.CALCULATION_COUNT)
            {
                val ++;
                var.Value = val;
            }
            else if (var.Formula == Variable.CALCULATION_SUM)
            {
                val = var.sum + (double) expressionValue;
                var.sum = val;
                var.Value = val;
            }
            else if (var.Formula == Variable.CALCULATION_AVERAGE)
            {
            }
            else if (var.Formula == Variable.CALCULATION_HIGHEST)
            {
            }
            else if (var.Formula == Variable.CALCULATION_LOWEST)
            {
            }
            return val;
        }
Beispiel #2
0
        public Report Parse()
        {
            var report = new Report();

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:

                        switch (reader.Name)
                        {
                            case "MelonReport":
                                report.Title = reader.GetAttribute("title");
                                report.Height = XmlConvert.ToInt16(reader.GetAttribute("height"));
                                report.Width = XmlConvert.ToInt16(reader.GetAttribute("width"));
                                report.LeftMargin = XmlConvert.ToInt16(reader.GetAttribute("left-margin"));
                                report.RightMargin = XmlConvert.ToInt16(reader.GetAttribute("right-margin"));
                                report.TopMargin = XmlConvert.ToInt16(reader.GetAttribute("top-margin"));
                                report.BottonMargin = XmlConvert.ToInt16(reader.GetAttribute("botton-margin"));
                                break;
                            case "Connection":
                                report.ConnectionString = reader.GetAttribute("String");
                                break;
                            case "QueryString":
                                report.QueryString = reader.ReadString();
                                break;
                            case "Field":
                                var field = new Field(reader.GetAttribute("name")) {Type = reader.GetAttribute("type")};
                                report.Fields.Add(field);
                                break;
                            case "Variable":
                                var variable = new Variable(reader.GetAttribute("name"))
                                             	{
                                             		Type = reader.GetAttribute("type"),
                                             		Level = reader.GetAttribute("level")
                                             	};
                                if (variable.Level.Equals(Variable.RESET_TYPE_GROUP))
                                    variable.ResetingGroup = reader.GetAttribute("group");
                                variable.Formula = reader.GetAttribute("formula");
                                variable.Expression = reader.ReadString();
                                report.Variables.Add(variable.Name,variable);
                                break;
                            case "ReportFont":
                                var f = new Font(reader.GetAttribute("name"), reader.GetAttribute("fontName"));
                                if (reader.MoveToAttribute("default"))
                                    f.IsDefault = XmlConvert.ToBoolean(reader.GetAttribute("default"));
                                report.Fonts.Add(f);
                                break;
                            case "Title":
                                report.PageTitle = ParseBands(reader, "Title", report);
                                break;
                            case "ReportHeader":
                                report.ReportHeader = ParseBands(reader, "ReportHeader", report);
                                break;
                            case "PageHeader":
                                report.PageHeader = ParseBands(reader, "PageHeader", report);
                                break;
                            case "Detail":
                                report.Detail = ParseBands(reader, "Detail", report);
                                break;
                            case "PageFooter":
                                report.PageFooter = ParseBands(reader, "PageFooter", report);
                                break;
                            case "Summary":
                                report.Summary = ParseBands(reader, "Summary", report);
                                break;
                            case "Group":
                                var g = new Group(reader.GetAttribute("name"))
                                            {
                                                Invariant = reader.GetAttribute("invariant"),
                                                GroupHeader = ParseBands(reader, "groupHeader", report),
                                                GroupFooter = ParseBands(reader, "groupFooter", report)
                                            };

                                if (report.Variables[g.Invariant] == null)
                                {
                                    throw new Exception("Unknown variable : " + g.Invariant);
                                }

                                foreach (var var in report.Variables.Values)
                                {
                                    if (var.Level.Equals(Variable.RESET_TYPE_GROUP) && var.ResetingGroup.Equals(g.Name))
                                    {
                                        g.GroupChange += var.UpdateMe;
                                    }
                                }

                                report.Groups.Add(g);
                                break;
                        }
                        break;
                }
            }
            return report;
        }
 private static CodeMemberProperty createProperty(Variable variable)
 {
     var p = new CodeMemberProperty();
     p.GetStatements.Add(new CodeSnippetStatement("return (" + variable.Type + ")EvaluateVariable(variables[\"" + variable.Name + "\"]);"));
     //p.SetStatements.Add(new CodeSnippetStatement("_" + ((Variable)it.Value).Name+ " = value ;"));
     p.Type = new CodeTypeReference(variable.Type);
     p.Name = variable.Name;
     p.Attributes = MemberAttributes.Public;
     return p;
 }
 private static string Case(Variable variable)
 {
     return "		case " + variable.GetHashCode() + ":\n" +
            "		o = " + variable.Expression.Trim() + ";\n" +
            "		break;\n";
 }