AyaNova service management & work order software
AyaNova Support Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



How to format date field if using Summary... Expand / Collapse
Author
Message
Posted 11/16/2006 11:30:33 AM
AyaNova Sales & Support

AyaNova Sales & SupportAyaNova Sales & SupportAyaNova Sales & SupportAyaNova Sales & SupportAyaNova Sales & SupportAyaNova Sales & SupportAyaNova Sales & SupportAyaNova Sales & Support

Group: Administrators
Last Login: Yesterday @ 5:11:14 PM
Posts: 1,778, Visits: 4,123
Right now if using a summary report template, date fields can not be formatted to display other than they do within the AyaNova program

This sample is to show how to use a script and the date formatter to format a date field in a summary report template.


The sample report template Service Workorders Invoiced available from the Service Workorders grid in the Service navigation pane by default displays the Service Date in the format it does within your AyaNova program as per the screen shot below.


 


Let's say we want it to instead display in the format dddd, dd MMMM yyyy HH:mm:ss  such as Thursday 16 November 2006 11:00:14

If a detailed report template, all we would do is set the FormatString property for the datafield via the Properties tab as in the screenshot below, but because this is a summary report template we also need to include a script that converts the date field from a string to a recognizable date so it can be formatted.
 

As this is a summary report template, we include the script in the OnBeforePrint script and set the date fields FormatString property

1. Either open the existing sample Service Workorders Invoice summary report template and perform the same steps, or download this completed sample report template so that you may see what has been done to it

Sample Service Workorders Invoiced with Date Format

2. Click on the Service Date field in the designer panel, and select the Properties tab

3. Expand the Scripts property and select to open the script editor for the OnBeforePrint


 


4. Delete everything presently in this OnBeforePrint script editor, than copy all text below  - don’t forget the last  } symbol, and paste into the OnBeforeScript editor and select OK to save


private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {

//This code takes a summary report date field which is not a DateTime object
//converts it to a DateTime object, then sets the label control's text to
//the format selected in the databinding.FormatString property of the control


//Get a reference to the label on the report
XRLabel lbl = sender as XRLabel;

//If it's empty then no need to format it
if(lbl.Text=="") return;

//It's not empty, so parse it's text into a DateTime object

//Create a datetime object to hold the date
DateTime dt = new DateTime();

//First try to parse it using the current thread's locale setting:
//if that fails to parse then try the invariant culture format
if (!DateTime.TryParse(lbl.Text, out dt))
    if (!DateTime.TryParse(lbl.Text, System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat, System.Globalization.DateTimeStyles.None, out dt))
        {
        //if the code makes it to here then the date/time was not recognized
        //and the code can not proceed.  An alternative to this is to simply return
        //without changing the lbl.Text by commenting out the following line
        //this will ensure that *something* is printed even if not formatted   
        lbl.Text="Unrecognized date";
        return;
    }

//At this point we have a valid dateTime object containing
//the datetime from the data source,
//so set the label's text to a formatted representation of the
//date and time using the format string set in the report designer
//for the databinding property of the control
lbl.Text=string.Format(lbl.DataBindings[0].FormatString,dt);

}


5. Now expand the DataBindings property for this field, expand the Text property of the Databindings property and select to open the FormatString property designer


 

6. Select DateTime category, and select the date format you want.

 
7. Now preview the report template to ensure your formatting has been applied.



AyaNova Sales & Technical Support
http://www.ayanova.com
Post #2271
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: AyaNova Sales & Support

Permissions Expand / Collapse

All times are GMT -8:00, Time now is 8:17pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.078. 10 queries. Compression Disabled.