Custom Component : How send a message of error to client in preview mode?

Stimulsoft Reports.NET discussion
proexito
Posts: 6
Joined: Sun Oct 02, 2011 10:42 am
Location: MExico

Custom Component : How send a message of error to client in preview mode?

Post by proexito »

Hi,

I have a custom component that implements StiComponentGdiPainter.
On Paint method, I want to send a message of error to client in some cases only in preview mode.
I was trying to use Report.WriteToReportRenderingMessages(), without success,

What do I need to do ?

namespace Sample
{
public class ComponenteGdiPainter : StiComponentGdiPainter
{
public override void Paint(StiComponent component, StiPaintEventArgs e)
{
Componente customComponent = component as Componente;
if (!component.IsDesigning){
//Here I want to send some error to client
if (customComponent.Left==100){
string aa = string.Format("Code can't be processed '{0}' !", 100);
StiLogService.Write(this.GetType(), aa);
customComponent.
Report.WriteToReportRenderingMessages(aa);
return;
}
else
......


}else
.......
}
}
}







proexito
Posts: 6
Joined: Sun Oct 02, 2011 10:42 am
Location: MExico

Custom Component : How send a message of error to client in preview mode?

Post by proexito »

Update:

When I use the function Report.WriteToReportRenderingMessages Inside of customComponent (StiComponent)
namespace sample
{
public class CodigoComponente : StiComponent
{
public override double Height
{
Report.WriteToReportRenderingMessages("TEST");//Here work without trouble
}
}
}

work flawlessly but inside of ComponenteGdiPainter (StiComponentGdiPainter) don't.

Why instance of Report in StiComponent its diferent of instance in StiComponentGdiPainter
if you check here [StiComponentGdiPainter]
public override void Paint(StiComponent component, StiPaintEventArgs e)

I supposed the StiComponent component was the current instance of CodigoComponente : StiComponent, but something happens

When I Call component.Report.WriteToReportRenderingMessages("TEST");//Here Doesn't work

Its these a BUG?






proexito
Posts: 6
Joined: Sun Oct 02, 2011 10:42 am
Location: MExico

Custom Component : How send a message of error to client in preview mode?

Post by proexito »

How reproduce these throuble on project CustomComponent located in Samples\C#\CustomComponent

Open file MyCustomComponentWithExpression.cs
add after the last #endregion
private double height;
public override double Height
{
get
{
StiReport report = (StiReport)this.GetReport();
if (report != null)
{
if (this != null)
{
height = base.Height;
if (!this.IsDesigning)
{
Report.WriteToReportRenderingMessages("TEST inside Height");
}

}

}

return height;
}

}


Then open file MyCustomComponentWithExpressionGdiPainter.cs
and type inside the Paint method :
component.Report.WriteToReportRenderingMessages("TEST inside Paint");

The run app select the component 3 and add to design
press PREVIEW TAB
Now only you see "TEST inside Height" on Report Rendering Messages
Never see "TEST inside Paint"
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Custom Component : How send a message of error to client in preview mode?

Post by Andrew »

Hello,

The WriteToReportRenderingMessages method works correctly.
But the pop-up window displays only the messages that appeared during the report rendering and you try to add this message while the rendered report is displayed.

Workaround:
1) The most simple and clear one is to display the required message instead of the ComponenteGdiPainter component.
2) Create your own ComponenteV2Builder and display in it a message, when rendering a report.

Thank you.
proexito
Posts: 6
Joined: Sun Oct 02, 2011 10:42 am
Location: MExico

Custom Component : How send a message of error to client in preview mode?

Post by proexito »

Thanks Andrew.

But my trouble its about a value get from field evaluated in run time through an expression {VALUE}

I implement
public class CodigoComponenteBuilderV2 :
StiComponentV2Builder
{
public override StiComponent InternalRender(StiComponent masterComp) {
CodigoComponente renderedComponent = base.InternalRender(masterComp) as CodigoComponente;
renderedComponent.Report.WriteToReportRenderingMessages("->>"+renderedComponent.CodigoProcesadoValue);
return renderedComponent;
}
}

and inside of StiComponent
I have
private string codigoProcesado = null;
[
Browsable(false)
][
StiSerializable(StiSerializeTypes.SerializeToDocument)
] public string CodigoProcesadoValue
{
get
{
return codigoProcesado;
}
set
{
codigoProcesado = value;
}
}

and get his value from StiUnifiedExpression
when I debug, I saw how codigoProcesado get the value first then call StiComponentV2Builder

But here again
if when I try to use some logic based on renderedComponent.CodigoProcesadoValue these always is null

It's no possible use Report.WriteToReportRenderingMessages here.
renderedComponent.Report.WriteToReportRenderingMessages("->>"+renderedComponent.CodigoProcesadoValue);


How can inform to the user of an error on preview maybe instead of "report rendering" to error tab?



Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Custom Component : How send a message of error to client in preview mode?

Post by Alex K. »

Hello,

First, it is not correct to display a message in the painter.
Second, Report.WriteToReportRenderingMessages() is not correct way to do. Messages are collected there during the report compilation, and immediately are output before rendering.

Thank you.
proexito
Posts: 6
Joined: Sun Oct 02, 2011 10:42 am
Location: MExico

Custom Component : How send a message of error to client in preview mode?

Post by proexito »

I m agree with you only in Report.WriteToReportRenderingMessages() cant send messages on painter

But my necessities are send messages there because only you get data from datasource in that point from {tag}. 
 Suppose you have some special calculus using database values and with these values you get null pointer how you can inform to your user preview about that. 
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Custom Component : How send a message of error to client in preview mode?

Post by HighAley »

Hello.
proexito wrote:I m agree with you only in Report.WriteToReportRenderingMessages() cant send messages on painter

But my necessities are send messages there because only you get data from datasource in that point from {tag}. 
 Suppose you have some special calculus using database values and with these values you get null pointer how you can inform to your user preview about that. 
You can write a message like in the attached report template.

Thank you.
Attachments
1432.Report.mrt
(3.38 KiB) Downloaded 142 times
proexito
Posts: 6
Joined: Sun Oct 02, 2011 10:42 am
Location: MExico

Custom Component : How send a message of error to client in preview mode?

Post by proexito »

THANK YOU Aleksey Andreyanov

This simple solution I can sow it before you write this post.

Thanks to Andrew too.

SOLUTION ACCEPTED.

PD.
I don't know how close this post.
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Custom Component : How send a message of error to client in preview mode?

Post by Andrew »

Hello,

Great! Have a nice day!

Thank you.
Post Reply