Change date format dynamically and set UpperCase
Change date format dynamically and set UpperCase
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);
}
}
}
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
Hello,
You can use the following code in text expression:
{Variable1.ToString("ddMMMyyyy").ToUpper()}
Please sample report in attachment.
Thank you.
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
Change date format dynamically and set UpperCase
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
{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
Hello,
If you use DesignerFx then you can use the folowing expression
Thank you.
If you use DesignerFx then you can use the folowing expression
Code: Select all
{AvxCompanyActivity.ValidFrom.ToString("ddMMMyyyy").ToUpper()}
Change date format dynamically and set UpperCase
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
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
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.
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
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);
}
}
}
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
Hello,
As a workaround, instead of code
please try to use the following code, for example:
Thank you.
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);
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()}";
}