Page 1 of 1

Change date format dynamically and set UpperCase

Posted: Thu May 05, 2011 4:23 pm
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);


}
}
}

Change date format dynamically and set UpperCase

Posted: Fri May 06, 2011 7:52 am
by Alex K.
Hello,

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

Thank you.

Change date format dynamically and set UpperCase

Posted: Thu May 12, 2011 2:01 am
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

Change date format dynamically and set UpperCase

Posted: Fri May 13, 2011 7:41 am
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.

Change date format dynamically and set UpperCase

Posted: Sun May 15, 2011 5:13 pm
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

Change date format dynamically and set UpperCase

Posted: Mon May 16, 2011 3:10 am
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.

Change date format dynamically and set UpperCase

Posted: Fri May 20, 2011 12:37 am
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);


}
}
}

Change date format dynamically and set UpperCase

Posted: Tue Jun 07, 2011 3:14 am
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.