Change date format dynamically and set UpperCase

Stimulsoft Reports.WEB discussion
Post Reply
Tapir
Posts: 13
Joined: Fri Jan 14, 2011 1:21 am
Location: Sweden

Change date format dynamically and set UpperCase

Post by Tapir »

Hi
Is there a easy way to both set date format and make a data field upper case dynamically.
I change the date format depending on what the user decides, and normally this is the format ddMMMyy e.g. 01MAY11, but it always becomes 01may11
Can i some way also do uppercase, I have tried to do upper case in the data field directly in the desinger, but it doesnt work
Im looping thorugh my fields like this so set the date format, but I cant get it to uppercase

public static void CheckComponents(Stimulsoft.Report.Components.StiComponentsCollection comps, string longdateformat, string shortdateformat,string timeformat, Stimulsoft.Report.StiReport rpt)
{

foreach (Stimulsoft.Report.Components.StiComponent c in comps)
{

if (c is Stimulsoft.Report.Components.StiContainer)
{
Stimulsoft.Report.Components.StiContainer cont = (Stimulsoft.Report.Components.StiContainer)c;
CheckComponents(cont.Components, longdateformat, shortdateformat,timeformat,rpt);
}
if (c is Stimulsoft.Report.Components.StiText)
{
Stimulsoft.Report.Components.StiText t = (Stimulsoft.Report.Components.StiText)c;
if (t.Name.Length > 8)
{

if (t.Name.Substring(0, 8) == "DateText")
t.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService(shortdateformat, String.Empty);
else if (t.Name.Substring(0, 8) == "DaTmText")
t.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService(longdateformat, String.Empty);
else if (t.Name.Substring(0, 8) == "TimeText")
t.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService(timeformat, String.Empty);


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

Change date format dynamically and set UpperCase

Post by Alex K. »

Hello,

You can use the following code in text expression:
{Variable1.ToString("ddMMMyyyy").ToUpper()}
Please sample report in attachment.

Thank you.
Attachments
990.SampleReport.mrt
(4.2 KiB) Downloaded 667 times
Tapir
Posts: 13
Joined: Fri Jan 14, 2011 1:21 am
Location: Sweden

Change date format dynamically and set UpperCase

Post by Tapir »

This dosent work....

{ToUpp(AvxCompanyActivity.ValidFrom)}

AvxCompanyActivity.ValidFrom is a Business Class Property

Changing this in the designer or dynamically do the change makes the report crash the report saying the ToUpp does not exist
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Change date format dynamically and set UpperCase

Post by Alex K. »

Hello,

If you use DesignerFx then you can use the folowing expression

Code: Select all

{AvxCompanyActivity.ValidFrom.ToString("ddMMMyyyy").ToUpper()}
Thank you.
Tapir
Posts: 13
Joined: Fri Jan 14, 2011 1:21 am
Location: Sweden

Change date format dynamically and set UpperCase

Post by Tapir »

Hi
Hmm, but I want to set the date format dynamically and also make it upper case...
Thats why I loop through the components...
I dont (or cant because of customer requirements) set it in design time.
And this format ddMMMyy is used but some customers, and I want to have that upper case ..

Thanx
Andrew
Posts: 4108
Joined: Fri Jun 09, 2006 3:58 am

Change date format dynamically and set UpperCase

Post by Andrew »

Hello,

Sorry maybe we did not exactly what do you mean under "dynamically" in your case?
Could you please explain why the code we showed is not good for you?

Also, as a way, you can add a calculated column in which you use the expression ToString("ddMMMyyyy").ToUpper() and if needed use either original or this calculated column.

Thank you.
Tapir
Posts: 13
Joined: Fri Jan 14, 2011 1:21 am
Location: Sweden

Change date format dynamically and set UpperCase

Post by Tapir »

With dynamically I mean the user not me will set the date format,
So I have a datetime field in the MRT file. That field needs to be converted to correct data format when the report is generated.
This works fine to change this as I loop through the components and if I find a field which should be datetime (I find that with help of the name)
I set the format then according to what the user wants:

t.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService(shortdateformat, String.Empty);

The problem now is if the user sets format ddMMMyy .e.g 01MAY11, 01may11 is returned, which is not what they expect, they want upper case on this field, so I need to user ToUpper or ToUpp
but I dont know where to set this, If I do it in the property of the field (in the designer like {AvxCompanyActivity.ValidFrom.ToUpper()}
, I get an error. Remember I cant set the date format in design, I need to set that in run time

The code to change date formtat (which works, but I get lower case)


if (c is Stimulsoft.Report.Components.StiContainer)
{
Stimulsoft.Report.Components.StiContainer cont = (Stimulsoft.Report.Components.StiContainer)c;
CheckComponents(cont.Components, longdateformat, shortdateformat,timeformat,rpt);
}
if (c is Stimulsoft.Report.Components.StiText)
{
Stimulsoft.Report.Components.StiText t = (Stimulsoft.Report.Components.StiText)c;
if (t.Name.Length > 8)
{

if (t.Name.Substring(0, 8) == "DateText")
t.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService(shortdateformat, String.Empty);
else if (t.Name.Substring(0, 8) == "DaTmText")
t.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService(longdateformat, String.Empty);
else if (t.Name.Substring(0, 8) == "TimeText")
t.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService(timeformat, String.Empty);


}
}
}
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Change date format dynamically and set UpperCase

Post by Ivan »

Hello,

As a workaround, instead of code

Code: Select all

if (t.Name.Substring(0, 8) == "DateText")
t.TextFormat = new Stimulsoft.Report.Components.TextFormats.StiDateFormatService(shortdateformat, String.Empty);
please try to use the following code, for example:

Code: Select all

                if (t.Name.Substring(0, 8) == "DateText")
                {
                    string st = t.Text.Value;
                    t.Text.Value = "{" + st.Substring(1, st.Length - 2).Trim() + ".ToString(\"ddMMMyyyy\").ToUpper()}";
                }
Thank you.
Post Reply