<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Serge&#039;s Technology View &#187; datetime entry format</title>
	<atom:link href="http://blog.dragonsoft.us/tag/datetime-entry-format/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dragonsoft.us</link>
	<description>Talk about Technologies, Software Architecture and Management</description>
	<lastBuildDate>Tue, 20 Apr 2010 14:42:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Crystal Reports 2008 : hacking datetime parameter format &#8211; reloaded</title>
		<link>http://blog.dragonsoft.us/2008/12/31/crystal-reports-2008-hacking-datetime-parameter-format-reloaded/</link>
		<comments>http://blog.dragonsoft.us/2008/12/31/crystal-reports-2008-hacking-datetime-parameter-format-reloaded/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 19:59:53 +0000</pubDate>
		<dc:creator>Serguei Dosyukov</dc:creator>
				<category><![CDATA[Crystal Reports]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[change datetime parameter format]]></category>
		<category><![CDATA[crystal reports 2008]]></category>
		<category><![CDATA[crystal reports viewer]]></category>
		<category><![CDATA[datetime as date]]></category>
		<category><![CDATA[datetime entry format]]></category>

		<guid isPermaLink="false">http://blog.dragonsoft.us/?p=713</guid>
		<description><![CDATA[Few weeks ago I have wrote on how to hack Crystal Reports 2008 ASP.Net Viewer control to suppress time part in the parameter calendar control. With release of Service Pack 1 for Crystal Reports 2008, suggested solution no longer works since structure of the files has been changed. So I went digging around again. Forgot to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.dragonsoft.us/wp-content/uploads/2008/12/step1.png"></a>Few weeks ago I have wrote on <a href="http://blog.dragonsoft.us/2008/12/16/crystal-report…rameter-formatcrystal/" target="_self">how to hack Crystal Reports 2008 ASP.Net Viewer control to suppress time part</a> in the parameter calendar control.</p>
<p>With release of Service Pack 1 for Crystal Reports 2008, suggested solution no longer works since structure of the files has been changed.</p>
<p>So I went digging around again. Forgot to mention last time, but in situations like this, scripting debugging supported in Visual Studio really helps (if you are not familiar with JS debugging check following links <a href="http://weblogs.asp.net/scottgu/archive/2007/07/19/vs-2008-javascript-debugging.aspx" target="_blank">[1]</a> <a href="http://www.asp.net/learn/3.5-videos/video-219.aspx" target="_blank">[2]</a> for more info.</p>
<blockquote><p>Note. It is interesting to observe how code is changing over time. And after some analisys, I would say that SAP development team is one click away from adding ability to suppress time parts for datetime parameters: only one thing missing &#8211; new property on parameter level which would allow specify how to treat it (date, time or datetime). Question is if they will decide to do so.</p></blockquote>
<p>I will be using Visual Studio 2008 and run against my WebDev.WebServer.</p>
<p>After creating simple CrystalReports ASP.Net application with report which has datetime parameter, lets see what exactly is happening here.</p>
<p><a href="http://blog.dragonsoft.us/wp-content/uploads/2008/12/step1.png" target="_blank"><img class="size-thumbnail wp-image-715" style="margin-right: 10px;" title="Step 1" src="http://blog.dragonsoft.us/wp-content/uploads/2008/12/step1-150x150.png" alt="Step 1" width="150" height="150" /></a> <a href="http://blog.dragonsoft.us/wp-content/uploads/2008/12/step2.png" target="_blank"><img class="size-thumbnail wp-image-720" style="margin-right: 10px;" title="Step 2" src="http://blog.dragonsoft.us/wp-content/uploads/2008/12/step2-150x150.png" alt="Step 2" width="150" height="150" /></a></p>
<p>Let&#8217;s run an application up to the point when engine would request parameter values being entered (<a href="http://blog.dragonsoft.us/wp-content/uploads/2008/12/step1.png" target="_blank">Img 1</a>).</p>
<p>And then let&#8217;s open Solution Explorer in Visual Studio (<a href="http://blog.dragonsoft.us/wp-content/uploads/2008/12/step2.png" target="_blank">Img 2</a>).<br />
You would notice a few JavaScript files, where one we were looking for - <strong>promptengine_calendar2.js</strong>.</p>
<p>While having page open, dbl-click on the file in Solution Explorer and look around. (In my case actual file location is <em>C:\Windows\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles\crystalreportviewers12\prompting\js\</em>, but may vary.)</p>
<p>Internal Calendar control (which reside in Calendar.js file) relay on setShowTime method to manage visibility and behaviour of the calendar and this is where we will &#8220;hack&#8221; our way in.</p>
<p>As usual code below only highlights changes to the code in <em>promptengine_calendar2.js</em> file.<br />
This time I am making no changes to the data, only how it is displayed and extracted from the calendar control. And it seems to work much better then prior solution.<br />
Make sure you have the copy of original file backed up.</p>
<pre class="brush: jscript;">/** First, lets add one more variable to control data flow **/
    bobj.prompt.Calendar = function
    ...
       this.isDateTimeData = false;
    }
...
    /** While suppressing DateTime format we still need to know original type of the data **/
    setIsDateTime : function(isDateTime) {
       // this.isDateTime = isDateTime;
       this.isDateTimeData = isDateTime;
       this.isDateTime = false;
    },
...
    /** while suppressing time part, it is still need to be returned back in to parameter form **/
    _getStringValue : function(dateValue) {
        var format = this.isDateTime ? this.dateTimeFormat : this.dateFormat;

        if ((!this.isDateTime) &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp; this.isDateTimeData) {
                format = format + ' 00:00:00';
        }

        return  bobj.external.date.formatDate(dateValue, format);     
       
    },</pre>
<p>Changes are very isolated and allows a) hide time entry box and b) properly return data back into parameter form.</p>
<p>This solution is generic and applies to all datetime parameters visible. As a result, calendar control become for date entry only, while resetting time portion. User can still enter time part if necessary, but on the page level.</p>
<p>Again, make sure that file with changes we just made is replaced everywhere. Depend on your development and production environment you may have few other locations for it.</p>
<hr/><span style="font-size: 7pt">Copyright &copy; 2010 <strong><a href="http://blog.dragonsoft.us">Serge&#039;s Technology View</a></strong>. This Feed is for personal non-commercial use only.</span>]]></content:encoded>
			<wfw:commentRss>http://blog.dragonsoft.us/2008/12/31/crystal-reports-2008-hacking-datetime-parameter-format-reloaded/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crystal Reports 2008 : hacking datetime parameter format</title>
		<link>http://blog.dragonsoft.us/2008/12/16/crystal-reports-2008-hacking-datetime-parameter-format/</link>
		<comments>http://blog.dragonsoft.us/2008/12/16/crystal-reports-2008-hacking-datetime-parameter-format/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 16:27:43 +0000</pubDate>
		<dc:creator>Serguei Dosyukov</dc:creator>
				<category><![CDATA[Crystal Reports]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[change datetime parameter format]]></category>
		<category><![CDATA[crystal reports 2008]]></category>
		<category><![CDATA[crystal reports viewer]]></category>
		<category><![CDATA[datetime as date parameter]]></category>
		<category><![CDATA[datetime entry format]]></category>

		<guid isPermaLink="false">http://blog.dragonsoft.us/?p=668</guid>
		<description><![CDATA[One would think that this should be a no-brainer : ability to specify an edit format for date/time parameter in Crystal Reports. Not so fast&#8230; Problem is as following: ASP.Net Web client with Crystal Reports Viewer control is used. When our report is based of some stored procedure which uses datetime parameter, it will inherit [...]]]></description>
			<content:encoded><![CDATA[<p>One would think that this should be a no-brainer : ability to specify an edit format for date/time parameter in Crystal Reports. Not so fast&#8230;</p>
<p>Problem is as following:</p>
<blockquote><p>ASP.Net Web client with Crystal Reports Viewer control is used.</p>
<p>When our report is based of some stored procedure which uses datetime parameter, it will inherit it as is and when report parameter entry form is displayed we would be asked to enter both date and time portion.</p></blockquote>
<p>While, in general, it is OK, some reports are really interested only in date part being entered and time should be always set to 00:00:00. So we are forced to type time every time because if it is not provided calendar control would try to set time part initially to current time.</p>
<p>After some research off the Internet, visiting SAP forums, it is appear to be engine limitation. But we would want to overcome it somehow.</p>
<p><em><strong>DISCLAIMER: solution below could only be used as a last resort and only if your business logic requires using date only params. And while it is only applies to calendar control, it is not per se a generic solution. This is a first &#8220;rough&#8221; attempt of achieving desired result and may lack some features otherwise expected.</strong></em></p>
<p><strong><em>It has been reported that solution above only works for current month. Since we are now using Crystal Reports 2008 with SP1, I would address this issue </em></strong><strong><em>in my new post below</em></strong><strong><em>.</em></strong></p>
<p><strong><em><span style="color: #ff0000;">IMPORTANT! With release of Service Pack 1 for Crystal Reports 2008, method blow is no longer applicable since structure of the files has changed. Please refer <a href="http://blog.dragonsoft.us/2008/12/31/crystal-report…ormat-reloadedcrystal-reports-2008-hacking-datetime-parameter-format-reloaded/" target="_self">to this new post for more information</a>.</span></em></strong></p>
<p>Otherwise, Where there is a will, there is a way&#8230;</p>
<p>Fortunately we have access to internals behind the parameter handlers in Crystal Report Viewer web control.</p>
<p>Navigate to one of following locations:</p>
<ul>
<li>C:\Inetpub\wwwroot\aspnet_client\system_web\2_0_50727\crystalreportviewers12\</li>
<li>C:\windows\Microsoft.NET\Framework\v2.0.50727\ASP.NETClientFiles\crystalreportviewers12\</li>
<li>C:\Program Files\Business Objects\Common\4.0\crystalreportviewers12\</li>
</ul>
<p>and locate the file called <strong>allInOne.js</strong> &#8211; this is our victim. This file contains all JS code behind for CRV control which would be used by your web-site.</p>
<p><em><strong>IMPORTANT: always create a backup copy before making any modifications.</strong></em></p>
<p><span id="more-668"></span></p>
<p>Remember that our objective is to ensure that when calendar control is used time part of date/time value is always set as 00:00:00. Let&#8217;s add a new function to <strong>bobj.crv.Calendar</strong> object</p>
<pre class="brush: jscript;">/**
 * Reset time part of datetime to 00:00:00
 */
bobj.crv.Calendar._resetTime = function(date) {
    var newdate = this._copyDate(date);
    newdate.setHours(0);
    newdate.setMinutes(0);
    newdate.setSeconds(0);
    newdate.setMilliseconds(0);
    return newdate;
}</pre>
<p>In my case I have put it just before bobj.crv.Calendar.justInTimeInit = function()  (line 39792).</p>
<p>As you can see the main purpose of the function is create a copy of date value with time portion being reset to desired time.</p>
<p>Now we would be looking for any instance in the code where the following substring is present</p>
<blockquote><p><strong>_timeField.setValue</strong></p></blockquote>
<p>We would find 3 functions where the following adjustment would be made:</p>
<pre class="brush: jscript;">bobj.crv.Calendar.justInTimeInit = function() {
...
    // mod: reset time
    this.date = this._resetTime(this.date);
    // mod
    this._timeField.setValue(bobj.external.date.formatDate(this.date, this._curTimeFormat));
...
}
...
bobj.crv.Calendar.justInTimeInit = function(){
...
    // mod: reset time
    this.date = this._resetTime(this.date);
    // mod
    this._timeField.setValue(bobj.external.date.formatDate(this.date, this._curTimeFormat));
...
}
...
bobj.crv.Calendar._onTimeChange = function() {
...
    if (date) {
        this._curTimeFormat = format;
        // mod: reset time
        date = this._resetTime(date);
        // mod
        this.date.setHours(date.getHours());
...
    else {
        // mod: reset time
        this.date = this._resetTime(this.date);
        // mod
...
}
...
bobj.crv.Calendar.setDate = function(date) {
    // mod: assign and reset time
    this.date = this._resetTime(date);
...
}</pre>
<p>After all changes above are done, we would get a calendar control which &#8220;keeps time at bay&#8221;. This only affects calendar itself and not an edit control associated with the parameter. As a result we can still adjust time if choose to do so.</p>
<p>Last step would be to ensure that all allInOne.js file instances are in sync and we got desired functionality.</p>
<hr/><span style="font-size: 7pt">Copyright &copy; 2010 <strong><a href="http://blog.dragonsoft.us">Serge&#039;s Technology View</a></strong>. This Feed is for personal non-commercial use only.</span>]]></content:encoded>
			<wfw:commentRss>http://blog.dragonsoft.us/2008/12/16/crystal-reports-2008-hacking-datetime-parameter-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
