Page 1 of 2

StiText Component doesn't work correctly

Posted: Fri Feb 27, 2015 2:49 pm
by wellmonge
Hi there!

I'm trying to create a header and footer throungh runtime with an existing compiled report
but StiText components doesn't show any text after report is printed, my code is rigth below:

private StiReport DesenhaCabecalhoRodape(StiReport report)
{
if (identity == null) return report;

var empresa = _repositoryEmpresa.FindBy<Empresa, Int64>(identity.CompanyId);

var page = report.Pages[0];

/* Creating report page Image*/
var ms = new MemoryStream(empresa.LogoRelatorio);
var image = Image.FromStream(ms);

/* Creating report page Brush*/
var myBrush = new StiSolidBrush(Color.LightGray);
var myBrushTransparent = new StiSolidBrush(Color.Transparent);
var myBrushWhite = new StiSolidBrush(Color.White);
var myBrushBlack = new StiSolidBrush(Color.Black);

/* Creating report border*/
var myBorder = new StiBorder
{
Color = Color.Black,
Side = StiBorderSides.All,
Size = 1
};

/* Creating report page header*/
var pageHeaderTemplate = new StiPageHeaderBand
{
Height = 2,
Name = "PageHeader",
Brush = myBrush,
Border = myBorder
};

/* Creating text header */
var headerText = new StiText(new RectangleD(20, 20, 4.7, 0.4))
{
HorAlignment = StiTextHorAlignment.Center,
Name = "TextTest",
Text = "teste : {ultimoAcesso}",
Brush = myBrushTransparent,
TextBrush = myBrushBlack,
Border = myBorder,
TextFormat = new StiGeneralFormatService(),
Left = 0.3,
Top = 0.6
};

/* Creating company image logo */
var imageLogo = new StiImage
{
Height = 1.6,
Width = 2.2,
Left = 0.2,
Top = 0.2,
Stretch = true,
Brush = myBrushWhite,
Border = myBorder,
Image = image
};

//create footer
var pagefootertemplate = new StiPageFooterBand
{
Height = 0.5,
Name = "PageFooter",
Brush = myBrush,
Border = myBorder
};

//Create page count on footer
var footerText = new StiText(new RectangleD(0, 0, 7, 0.5))
{
Text = "Página {PageNumber} de {TotalPageCount}",
HorAlignment = StiTextHorAlignment.Left,
Name = "footerPageCount",
Enabled = true,
Brush = myBrush,
Font = new Font("Arial", 12F, FontStyle.Bold)
};

page.Components.AddRange(new StiComponent[]
{
pageHeaderTemplate,
pagefootertemplate
});

pageHeaderTemplate.Components.AddRange(new StiComponent[]
{
imageLogo,
headerText
});

pagefootertemplate.Components.Add(footerText);

return report;
}

Re: StiText Component doesn't work correctly

Posted: Sat Feb 28, 2015 5:15 pm
by Jan
Hello,

I have additional question. You write about compiled report. You want add additional components to compiled report? If yes you should take in consideration that in compiled report all expressions have the compiled status and you can't add expression! You should add event handler. For example:

Code: Select all

 var test = new StiText();
test.GetValue += delegate(object sender, StiGetValueEventArgs e)
 {
      e.Value = "This is sample text";
};
I'm waiting your response.

Thank you.

Re: StiText Component doesn't work correctly

Posted: Sun Mar 01, 2015 2:41 pm
by wellmonge
Hello Jan,
thanks for the answer... It work fine! Using a delegate event as you showed I feel dumbest programmer ever.

kind regards

Re: StiText Component doesn't work correctly

Posted: Sun Mar 01, 2015 4:13 pm
by Jan
Hello,

Glad to help you!

Please contact us if you need any help.

Thank you.

Re: StiText Component doesn't work correctly

Posted: Mon Jul 04, 2016 3:11 pm
by wellmonge
Hello, Jan I'm facing a problem using event handler bellow... when I need to make "report.pageNofM" inside of it, doens't work. Can you help?

var test = new StiText();
test.GetValue += delegate(object sender, StiGetValueEventArgs e)
{
e.Value = "This is sample text";
};

Re: StiText Component doesn't work correctly

Posted: Tue Jul 05, 2016 4:37 pm
by Alex K.
Hello,

Page numbers are calculated at the end of the render of the report. This approach will not work for the pageNofM.

Thank you.

Re: StiText Component doesn't work correctly

Posted: Tue Jul 05, 2016 6:55 pm
by Jan
Hello,

PageNofM its a property of the report object. So you can use following code in event handler:

Code: Select all

e.Value = report.CompiledReport.PageNofM;
or

Code: Select all

e.Value = ((StiText)sender).Report.PageNofM;
Thank you.

Re: StiText Component doesn't work correctly

Posted: Tue Jul 05, 2016 9:49 pm
by wellmonge
Hello, Aleksey I try to add PageNofM at the EndRender of my dynamic report invoking GETVALUE of my component, but didn't work either.

Code: Select all


                report.EndRender += delegate (object sender, EventArgs e)
                {
                    var componentFooter = (sender as StiReport).GetComponentByName("stiTextFooter");

                    (componentFooter as StiText).InvokeGetValue(componentFooter,new StiGetValueEventArgs());
                };

There's any possibility to change value of StiText at de Report EndRender event? Or even a workaround to indicate?

Re: StiText Component doesn't work correctly

Posted: Wed Jul 06, 2016 10:17 pm
by Ivan
Hello,

This is a restriction of using named components in the report.
During report rendering exist two instances of each component (minimum two instances).
One instance - component in the report template.
Second instance - component which created for rendered report.
During the creation of the second instance, report engine calculates expressions and write it to the second instance.

The method report.GetComponentByName() return the component from the report template (first instance).
So you assign a value to the instance from the report template, and instances from the rendered report are not changed.

For getting rendered components, you can use the following code, for example:

Code: Select all

foreach (StiPage page in report.RenderedPages)
{
    foreach (StiComponent comp in page.Components)
    {
        if (comp.Name == "your_component_name")
        {
            (comp as StiText).InvokeGetValue(comp, new Stimulsoft.Report.Events.StiGetValueEventArgs());
        }
    }
}
Thank you.

Re: StiText Component doesn't work correctly

Posted: Thu Oct 27, 2016 5:36 pm
by wellmonge
Hi there, I still face the same problem, with the solution indicate I reach to the PageNofM with the full text "1 of 20", but when I invoke getvalue of stitext every page print the same value "1 of 20".

Code: Select all

private void EndRenderCustom(object sender, EventArgs e)
        {
            var rep = sender as StiReport;
            for (int i = 0; i < rep.RenderedPages.Count; i++)
            {
                StiPage page = rep.RenderedPages[i];

                for (int j = 0; j < page.Components.Count; j++)
                {
                    StiComponent comp = page.Components[j];

                    if (comp.Name == "footerPageCount")
                    {
                        (comp as StiText).InvokeGetValue(comp, new Stimulsoft.Report.Events.StiGetValueEventArgs());
                    }
                }
            }
     }
-----------------------------

     //* Adding Event To Set de Text Value */
                footerText.GetValue += delegate (object sender, StiGetValueEventArgs e)
                {
                    var obj = sender as StiText;
                    if (obj != null) obj.Text.Value = "Página " + obj.Report.PageNofM;
                };