Exemple #1
0
        public void Apply(Section section)
        {
            // section color
            section.BackColor = BackColor;

            // field font/color
            double          left   = double.MaxValue;
            double          right  = double.MinValue;
            FieldCollection fields = section.Fields;

            foreach (Field f in fields)
            {
                f.Font      = this.Font;
                f.ForeColor = this.ForeColor;
                left        = Math.Min(left, f.Left);
                right       = Math.Max(right, f.Left + f.Width);
            }
            if (fields.Count == 0)
            {
                left  = 0;
                right = section.ParentReport.Layout.Width;
            }

            // delete old lines
            for (int i = 0; i < fields.Count; i++)
            {
                if (fields[i].Name.StartsWith(STYLE_LINE_FIELD_NAME))
                {
                    fields.RemoveAt(i);
                    i--;
                }
            }

            // add lines
            if (section.Height > LINE_WIDTH && LineColor != Color.Transparent && (LineAbove || LineBelow))
            {
                if (LineAbove)
                {
                    string name = GetUniqueFieldName(fields, STYLE_LINE_FIELD_NAME);
                    Field  f    = fields.Add(name, string.Empty, left, 0, right - left, LINE_WIDTH);

                    f.BorderColor = LineColor;
                    f.BorderStyle = BorderStyleEnum.Solid;
                    f.LineSlant   = LineSlantEnum.NoSlant;
                    //f.BackColor = LineColor; // not as good as lines
                }
                if (LineBelow)
                {
                    string name = GetUniqueFieldName(fields, STYLE_LINE_FIELD_NAME);
                    Field  f    = fields.Add(name, string.Empty, left, section.Height - LINE_WIDTH, right - left, LINE_WIDTH);

                    f.BorderColor = LineColor;
                    f.BorderStyle = BorderStyleEnum.Solid;
                    f.LineSlant   = LineSlantEnum.NoSlant;
                    //f.BackColor = LineColor; // not as good as lines

                    f.Anchor = AnchorEnum.Bottom;
                }
            }

            // create script to apply alternate back color
            C1Report rpt = section.ParentReport;

            if (section == rpt.Sections.Detail)
            {
                rpt.OnOpen      = RemoveStyleScript(rpt.OnOpen);
                section.OnPrint = RemoveStyleScript(section.OnPrint);
                if (!AlternateColor.Equals(Color.Transparent) && !AlternateColor.Equals(BackColor))
                {
                    rpt.OnOpen      = rpt.OnOpen + SCRIPT_ONOPEN;
                    section.OnPrint = section.OnPrint + string.Format(SCRIPT_ONPRINT,
                                                                      BackColor.R, BackColor.G, BackColor.B,
                                                                      AlternateColor.R, AlternateColor.G, AlternateColor.B);
                }
            }
        }
Exemple #2
0
        public void Apply(Section section)
        {
            // section color
            section.BackColor = BackColor;

            // field font/color
            double          left   = double.MaxValue;
            double          right  = double.MinValue;
            FieldCollection fields = section.Fields;

            foreach (FieldBase f in fields)
            {
                var t      = f.GetType();
                var pdFont = t.GetProperty("Font");
                if (pdFont != null)
                {
                    var fontHolder = pdFont.GetValue(f, null) as FontHolder;
                    if (fontHolder != null)
                    {
                        fontHolder.Font = this.Font;
                    }
                }
                var pdForeColor = t.GetProperty("ForeColor");
                if (pdForeColor != null)
                {
                    pdForeColor.SetValue(f, this.ForeColor, null);
                }
                left  = Math.Min(left, f.Left);
                right = Math.Max(right, f.Left + f.Width);
            }
            if (fields.Count == 0)
            {
                left  = 0;
                right = section.ParentReport.Layout.Width;
            }

            // delete old lines
            for (int i = 0; i < fields.Count; i++)
            {
                if (fields[i].Name.StartsWith(STYLE_LINE_FIELD_NAME))
                {
                    fields.RemoveAt(i);
                    i--;
                }
            }

            // disable warnings about using Border instead of BorderColor etc:
#pragma warning disable CS0618
            // add lines
            if (section.Height > LINE_WIDTH && LineColor != Color.Transparent && (LineAbove || LineBelow))
            {
                if (LineAbove)
                {
                    string name = GetUniqueFieldName(fields, STYLE_LINE_FIELD_NAME);
                    Field  f    = fields.Add(name, string.Empty, left, 0, right - left, LINE_WIDTH);

                    f.BorderColor = LineColor;
                    f.BorderStyle = BorderStyleEnum.Solid;
                    f.Shape       = new Doc.LineShape(Doc.LineSlantEnum.NoSlant);
                    //f.BackColor = LineColor; // not as good as lines
                }
                if (LineBelow)
                {
                    string name = GetUniqueFieldName(fields, STYLE_LINE_FIELD_NAME);
                    Field  f    = fields.Add(name, string.Empty, left, section.Height - LINE_WIDTH, right - left, LINE_WIDTH);

                    f.BorderColor = LineColor;
                    f.BorderStyle = BorderStyleEnum.Solid;
                    f.Shape       = new Doc.LineShape(Doc.LineSlantEnum.NoSlant);
                    //f.BackColor = LineColor; // not as good as lines
                    f.Anchor = AnchorEnum.Bottom;
                }
            }
#pragma warning restore CS0618

            // create script to apply alternate back color
            C1FlexReport rpt = section.ParentReport;
            if (section == rpt.Sections.Detail)
            {
                rpt.OnOpen      = RemoveStyleScript(rpt.OnOpen);
                section.OnPrint = RemoveStyleScript(section.OnPrint);
                if (!AlternateColor.Equals(Color.Transparent) && !AlternateColor.Equals(BackColor))
                {
                    rpt.OnOpen      = rpt.OnOpen + SCRIPT_ONOPEN;
                    section.OnPrint = section.OnPrint + string.Format(SCRIPT_ONPRINT,
                                                                      BackColor.R, BackColor.G, BackColor.B,
                                                                      AlternateColor.R, AlternateColor.G, AlternateColor.B);
                }
            }
        }