Need help parsing a string and adding months to the date

Stimulsoft Reports.NET discussion
JayHill77
Posts: 6
Joined: Sat Oct 12, 2019 11:52 pm

Need help parsing a string and adding months to the date

Post by JayHill77 »

Hello,

I hope this is the correct forum. Our developers use Stimulsoft for our reporting solution within the app. When I customize a template (using the Report Designer), I'm trying solve an issue and keep running into various issues. We have a string of text in one of the fields (Status) in the DataSource. It will be like one of the following strings:

10/01/2019
● 04/17/2020

The first string indicates something was completed this day. The second string indicates something has not yet been completed and is due on that date. What I want to end up with is the date only to which I can compare and see if that due date is within the next 3 months. So, I want to parse the date out, add 3 months to it and compare that to the current date and then highlight the data element with font and other formatting if it is within 3 months to the due date.

If the string starts with a bullet character, I need to strip it off and leave just the date. This I've been able to accomplish with an IIF and Substring functions if I put it in the Expression on the field in the Data band. That expression is: {IIF(Left(DataSource.Status,1) != "●", DataSource.Status,Substring(DataSource.Status,2,10))}

However, I cannot convert this to a date value to which I can then add 3 months to the date and then do a Condition format on it.

I tried putting that IIF expression in a user-defined variable that I've added in the report but it does not seem to work (nothing prints/displays in the field).

Do you have any suggestions? I have scoured the forums, a number of websites (including Stack Overflow) and cannot seem to get this figured out. I'd like to be able to do this without having our development staff have to modify the DataSource.

Thanks in advance!
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Need help parsing a string and adding months to the date

Post by Lech Kulikowski »

Hello,

Please try to use the following expression:
{DateTime.Parse(YourStringValue).AddMonths(3)}

Thank you.
JayHill77
Posts: 6
Joined: Sat Oct 12, 2019 11:52 pm

Re: Need help parsing a string and adding months to the date

Post by JayHill77 »

Thanks. I had tried a variation of that without success. When I use the following (replacing the "YourStringValue")

{DateTime.Parse(IIF(Left(MasterDataEAndCList.Status,1) != "●", MasterDataEAndCList.Status,Substring(MasterDataEAndCList.Status,2,10))).AddMonths(3)}

If I use only the Expression inside the Parse() parens, it presents the information correctly, just the date. But once I add it to the Parse() function, I get the following error when previewing the report, which never renders: An error occurred while parsing the response from the server.

If I use the "Check" button in the Expression screen, it shows "OK" but then errors when running the report.
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Need help parsing a string and adding months to the date

Post by Lech Kulikowski »

Hello,

Please send us a sample report with test data that reproduces the issue for analysis.

Thank you.
JayHill77
Posts: 6
Joined: Sat Oct 12, 2019 11:52 pm

Re: Need help parsing a string and adding months to the date

Post by JayHill77 »

How do I do this when we have multiple data sources that comprise our report? See attached image.

Thank you
Attachments
EandC_Data_Sources.jpg
EandC_Data_Sources.jpg (118.81 KiB) Viewed 3030 times
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Need help parsing a string and adding months to the date

Post by Lech Kulikowski »

Hello,

Please try to save data to resources.

Thank you.
Attachments
Annotation 2019-10-19 120321.png
Annotation 2019-10-19 120321.png (22.58 KiB) Viewed 3019 times
JayHill77
Posts: 6
Joined: Sat Oct 12, 2019 11:52 pm

Re: Need help parsing a string and adding months to the date

Post by JayHill77 »

That option is not available to me. I only have 2 options on the Actions menu.
Attachments
EandC_Data_Options.jpg
EandC_Data_Options.jpg (99.54 KiB) Viewed 3016 times
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Need help parsing a string and adding months to the date

Post by Lech Kulikowski »

Hello,

Please try to use the following code in the BeforePrint event of a page:
[YourDataSourceName].DataTable.DataSet.WriteXml(@"e:\data.xml");
[YourDataSourceName].DataTable.DataSet.WriteXmlSchema(@"e:\data.xsd")

Thank you.
JayHill77
Posts: 6
Joined: Sat Oct 12, 2019 11:52 pm

Re: Need help parsing a string and adding months to the date

Post by JayHill77 »

I tried a couple of different strings without success:

First, replacing "[YourDataSourceName]" with "MasterDataEAndCList" in each line like the following:

MasterDataEAndCList.DataTable.DataSet.WriteXml(@"c:\data.xml")
MasterDataEAndCList.DataTable.DataSet.WriteXmlSchema(@"c:\data.xsd")

I don't get any errors but the xml and xsd files are not created.

Then I tried replacing both "[YourDataSourceName]" and "DataTable" with "MasterDataEAndCList" in each line so that they read like below and in the screenshot (which also shows the data dictionary). I get an error when previewing the page with those strings and no xml and xsd files.

MasterDataEAndCList.MasterDataEAndCList.DataSet.WriteXml(@"c:\data.xml")
MasterDataEAndCList.MasterDataEAndCList.DataSet.WriteXmlSchema(@"c:\data.xsd")

Thank you!
Attachments
EandC_SaveData_Expression.jpg
EandC_SaveData_Expression.jpg (741.84 KiB) Viewed 2979 times
Lech Kulikowski
Posts: 6198
Joined: Tue Mar 20, 2018 5:34 am

Re: Need help parsing a string and adding months to the date

Post by Lech Kulikowski »

Hello,

Please clarify which product are you use? That code will work only in NET designer.

Thank you.
Post Reply