在ColdFusion 8中使用日期范围 [英] Playing around with date range in ColdFusion 8

查看:318
本文介绍了在ColdFusion 8中使用日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下代码:

在此代码中,系统会要求用户从两个选项中选择一个日期范围,然后点击应用按钮,以便结果可以显示在所选日期范围的Web浏览器上。
我想知道我应该如何进行。

In this code, a user will be asked to select a date range from the two options and click on apply button so that the result can be displayed on the web browser for the selected date range. I'm wondering how should I proceed. Please throw some light on this.

2)如何确保我可以使用下载CSV选项启用下载数据的选项?

2) How can I make sure that I can enable the option of downloading the data using "Download CSV" option?

请让我知道需要做哪些更改。任何帮助将不胜感激。

Please let me know what changes are required. Any help would be appreciated.

<body>

<cfparam name="Form.startdate" default="#dateformat(now()-5, 'mm/dd/yyyy')#">
<cfparam name="Form.enddate" default="#dateformat(now()-1, 'mm/dd/yyyy')#">
<cfparam name="Form.selectdate" default="#dateformat(now(), 'mm/dd/yyyy')#">


<!--- <cfquery datasource = "xx.xx.x.x" name="qCheck">

SELECT * 
FROM   mydatabase
ORDER BY DTSId_bi LIMIT 10;

</cfquery>
 --->

<cfquery datasource = "xx.xx.x.x" name="qDatabase">

SELECT    (SELECT count(*) FROM mydatabase) AS TOTAL_CONNECTIONS,
          (SELECT count(*)FROM mydatabase WHERE event_vc = "open") AS OPEN_CONNECTIONS,
          (SELECT count(*)FROM mydatabase WHERE event_vc = "BOUNCE") AS BOUNCE_CONNECTIONS,
          (SELECT count(*) from mydatabase where event_vc = "DEFERRED") AS DEFERRED_CONNECTIONS,
          (SELECT count(*) from mydatabase where event_vc = "DELIVERED") AS DELIVERED_CONNECTIONS,
          (SELECT count(*) from mydatabase where event_vc = "DROPPED") AS DROPPED_CONNECTIONS,
          (SELECT count(*) from mydatabase where event_vc = "PROCESSED") AS PROCESSED_CONNECTIONS,
          (ROUND((SELECT OPEN_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "OPEN",
          (ROUND((SELECT BOUNCE_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "BOUNCE" ,
          (ROUND((SELECT DEFERRED_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "DEFERRED",
          (ROUND((SELECT DELIVERED_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "DELIVERED",
          (ROUND((SELECT DROPPED_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "DROPPED",
          (ROUND((SELECT PROCESSED_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "PROCESSED";
</cfquery>



<cfform format="flash" preloader ="false">

<!--- Arranging the two buttons adjacent to each other using cfformgroup tag --->
<cfformgroup type="horizontal">


<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>
  <cfinput type="dateField" name="startdate" label="Start Date" width="100" value="#Form.startdate#">
  <cfinput type="dateField" name="enddate" label="End Date" width="100" value="#Form.enddate#">
  <cfinput name="submit" type="submit" value = "Apply">
  <cfinput name="cancel" type="submit" value="Download CSV">
</p>
</cfformgroup>

<!--- For Horizontal Line --->
<cfformitem type = "hrule" style=""></cfformitem>


</cfform>

<cfchart
         format="png"
         chartwidth="500"
         chartheight="500"
         scalefrom="0"
         scaleto="1200000"
         title="Email Reporting "
         pieslicestyle="solid">

         <cfchartseries type="line"
                         >

        <cfchartdata item="% OPEN" value="#qDatabase.OPEN#">
        <cfchartdata item="% BOUNCE" value="#qDatabase.BOUNCE#">
        <cfchartdata item="% DEFERRED" value="#qDatabase.DEFERRED#">
        <cfchartdata item="% DELIVERED" value="#qDatabase.DELIVERED#">
        <cfchartdata item="% DROPPED" value="#qDatabase.DROPPED#">
        <cfchartdata item="% PROCESSED" value="#qDatabase.PROCESSED#"> 


    </cfchartseries>
</cfchart>





</body>


推荐答案

如果我是你, qDatabase查询它是非常低效的!至于下载csv的最好的方法是写一个文件到一个临时区域经常被清理,所以它不会填满你的高清。我将帮助编写文件,但不是清理哈哈。您可以这样做:

If I were you I would really consider re-working the qDatabase query it is VERY inefficient! As far as downloading a csv the best way is to write a file to a temp area that frequestly gets cleaned out so it doesn't fill up you HD. I will help with writing the file but not the clean up lol. You can do something like this:

<cfscript>
    var tl ='';
    var nl = (Chr( 13 ) & Chr( 10 ));
    var fileContent = createObject("java","java.lang.StringBuffer").init();
    var counter =1;
    fileContent.append( 'OPEN,BOUNCE,DEFERRED,DELIVERED, etc');
     fileContent.append(nl);
            for(i=1;i<=qDatabase.recordCount;i=i+1){
                tl = qDatabase.OPEN&','qDatabase.BOUNCE&','qDatabase.DEFERRED&','qDatabase.DELIVERED&',' etc;
                fileContent.append(tl);
                fileContent.append(nl);
            }

</cfscript>
<cffile action="write" file="#absoluteFilePathAndName#" mode="775" output="#fileContent.toString()#"/>
<a href="#realtiveFilePathAndName#>Download</a>

每次有人点击页面时,都会将csv文件写入绝对路径,因此您将需要一些条件逻辑来防止这种情况发生。

This will write a csv file to the absolute path every time someone hits the page so you will want some conditional logic around it to prevent that happening.

在你提供的代码,并重新思考你在做什么,但一旦你做这个代码将让你开始这不是你的最终解决方案。

Over all you need to relook at the code you have provided and rethink what you are doing but once you do this code will get you started IT IS NOT your final solution.

这篇关于在ColdFusion 8中使用日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆