Archive

Archive for September, 2009

Set Identity on existing column

September 23, 2009 ppshein Leave a comment

Database of one of our project is stored by Microsoft Access. As you know, MS.Access can’t store much of data amount in it. Lack of such appearance, our website is spontaneously down whenever users surfing through it. That’s why we need to upgrade our DBMS to MsSQL. So, I’m in rush of doing so. First of all, I need to export all data as XML file. Then, import these data to Ms.SQL. But I wanna keep certain ID column of each tables. That’s why I import all data as OFF identity Mode. After importing, I need to turn ON. At that time, I’m in trouble. NO idea to do how to turn ON identity and thinking of various ways. Eventually, I gotcha.

Here we go..

<cftransaction>
<!– Creating Temp Table –>
<cfquery name=Items datasource=”#application.ds#” password=”#application.pw#” username=”#application.un#”>
CREATE TABLE Categories2
(
C_ID int primary key identity(1,1),
C_Name nvarchar(500),
C_SortOrder int,
C_Text nvarchar(4000),
C_Parent int
)
</cfquery>

<!– Set OFF Identity  –>
<cfquery name=Items datasource=”#application.ds#” password=”#application.pw#” username=”#application.un#”>
SET IDENTITY_INSERT Categories2 ON;
</cfquery>

<!– Migrate Data –>
<cfquery name=Items datasource=”#application.ds#” password=”#application.pw#” username=”#application.un#”>
INSERT INTO Categories2(C_ID, C_NAME, C_SortOrder, C_Text, C_Parent)  SELECT C_ID, C_NAME, C_SortOrder, C_Text, C_Parent FROM Categories
</cfquery>

<!– Set On Identity –>
<cfquery name=Items datasource=”#application.ds#” password=”#application.pw#” username=”#application.un#”>
SET IDENTITY_INSERT Categories2 OFF;
</cfquery>

<!– Drop old table –>
<cfquery name=Items datasource=”#application.ds#” password=”#application.pw#” username=”#application.un#”>
DROP TABLE Categories
</cfquery>

<!– Rename Table –>
<cfquery name=Items datasource=”#application.ds#” password=”#application.pw#” username=”#application.un#”>
SP_RENAME Categories2, Categories;
</cfquery>
</cftransaction>

Categories: MSSQL, Projects, coldfusion Tags: ,

Integrate Crystal Reports into CFreport

September 11, 2009 ppshein Leave a comment

Wanna reduce server load cos of reporting so many data? Getting sick of designing HTML coding for report? You don’t need to worry of above 2 questions. CFreport is there for you to fulfill your desire.

First of all, you need to draw your report in crystal report on-click action. Then, save these report. Here you need to embed this report in CFML.

<CFREPORT REPORT=”myreport.rpt”></CFREPORT>

Wanna to pass parameters into this crystal reports? Here you go:

<CFREPORT REPORT=”myreport.rpt”>
{Table_name.field_name} = “ppshein”
</CFREPORT>

Site Encryption with CFML

September 10, 2009 ppshein Leave a comment

You’re so far to use command prompt for encrypting CFML files? Here is tutorial for you to encrypt with CFM file. Here you go..

<cfparam name=”encryptFile” default=”">
<!—
The purpose of this file is to provide a method to recursively encrypt all ColdFusion files with a folder.
The script first goes through all the folders starting from a set point and builds up a query of all the folders and file locations
Finally it will either encrypt the file, or copy it if it is a non-cfm file, to a new location.

CAVEAT:
There does appear to be a bug in CF MX6.1 when using a combination of the version number in cfencode and stating a header in the command line.
Basically if you want a header in the encrypted file you must use v1 encrypting otherwise use v2
—>

<!—set the root folder for the site you want to encrypt—>
<cfset startDir=”D:\sites\pathtosite”>
<!—set a root folder for where you want to save the encrypted/non-encrypted files—>
<cfset newDir=”D:\sites\pathtoencrypted site”>
<!—set the cfm file type (cfm or cfml)—>
<cfset fileExt=”cfm”>
<!—set the path to the cfencode.exe file—>
<cfset pathtoexe=”c:\cfusionmx\bin\cfencode.exe”>
<!—set the cfencode version—>
<cfset encVer=”2″>
<!—if you set the encVer to 1 you can set a header (see caveat above)—>
<cfset encHeader=”This file has been encrypted. Unauthorised decryption attempts strictly forbidden”>

<!—
Mimics the cfdirectory, action=&quot;list&quot; command.
Updated with final CFMX var code.
Fixed a bug where the filter wouldn’t show dirs.

@param directory The directory to list. (Required)
@param filter Optional filter to apply. (Optional)
@param sort Sort to apply. (Optional)
@param recurse Recursive directory list. Defaults to false. (Optional)
@return Returns a query.
@author Raymond Camden (ray@camdenfamily.com)
@version 2, April 8, 2004
@modified by Philip Williams (contact@openmindedsolutions.co.uk)
@version 2.1, May 3rd 2006

Revisions:
Removed extraneous information for the directory query
—>
<cffunction name=”directoryList” output=”false” returnType=”query”>
<cfargument name=”directory” type=”string” required=”true”>
<cfargument name=”filter” type=”string” required=”false” default=”">
<cfargument name=”sort” type=”string” required=”false” default=”">
<cfargument name=”recurse” type=”boolean” required=”false” default=”true”>
<!— temp vars —>
<cfargument name=”dirInfo” type=”query” required=”false”>
<cfargument name=”thisDir” type=”query” required=”false”>
<cfset var path=”">
<cfset var temp=”">

<cfif not recurse>
<cfdirectory name=”temp” directory=”#directory#” filter=”#filter#” sort=”#sort#”>
<cfreturn temp>
<cfelse>
<!— We loop through until done recursing drive —>
<cfif not isDefined(“dirInfo”)>
<cfset dirInfo = queryNew(“name,type,directory”)>
</cfif>

<cfset thisDir = directoryList(directory,filter,sort,false)>
<cfif server.os.name contains “Windows”>
<cfset path = “\”>
<cfelse>
<cfset path = “/”>
</cfif>
<cfloop query=”thisDir”>
<cfset queryAddRow(dirInfo)>
<cfset querySetCell(dirInfo,”name”,name)>
<cfset querySetCell(dirInfo,”type”,type)>
<cfset querySetCell(dirInfo,”directory”,directory)>
<cfif type is “dir”>
<!— go deep! —>
<cfset directoryList(directory & path & name,filter,sort,true,dirInfo)>
</cfif>
</cfloop>
<cfreturn dirInfo>
</cfif>
</cffunction>
<!—ceate the dirList query—>
<cfscript>
dirList = directoryList(“#startDir#”,”",”name desc”);
</cfscript>
<cfoutput query=”dirList”>
<cfset currFold=directory>
<cfset newFold=ReplaceNocase(directory, startDir, newDir)>
currfold:#currfold#<br />
newfold:#newfold#<br />
<!—if the new directory does not exist, we create it—>
<cftry>
<cfdirectory action=”create” directory=”#newFold#”>
newfold created<br />
<cfcatch>newfold exists<br /><!—do nothing as the folder exists—></cfcatch>
</cftry>
<!—if the file is a cfm file then we encode it here—>
<cfif type EQ “file” AND ListLast(name, ‘.’) EQ “#fileExt#”>
<cfset inputFile=”#currFold#\#name#”>
<cfset outputFile=”#newFold#\#name#”>
#inputfile#<br />
#outputfile#<br />
<!—dependent on the encryption version, we set the command line arguments—>
<cfswitch expression=”#encVer#”>
<cfcase value=”1″>
<cfscript>
ArgumentLine=inputFile;
ArgumentLine=ArgumentLine&” “;
ArgumentLine=ArgumentLine&outputFile;
ArgumentLine=ArgumentLine&” “;
ArgumentLine=ArgumentLine&” /q /h “;
ArgumentLine=ArgumentLine&chr(34);
ArgumentLine=ArgumentLine&encHeader;
ArgumentLine=ArgumentLine&chr(34);
ArgumentLine=ArgumentLine&” “;
ArgumentLine=ArgumentLine&” /v 1″;
</cfscript>
</cfcase>
<cfcase value=”2″>
<cfscript>
ArgumentLine=inputFile;
ArgumentLine=ArgumentLine&” “;
ArgumentLine=ArgumentLine&outputFile;
ArgumentLine=ArgumentLine&” “;
ArgumentLine=ArgumentLine&” /q /v 2″;
</cfscript>
</cfcase>
</cfswitch>
argumentline:#argumentline#<br />
<cfexecute
name=”#PathToExe#”
arguments=”#argumentLine#”
timeout=”10″>
</cfexecute>
encrypt complete<br />
<!—the file is not a cfm file so we just copy it to the new location—>
<cfelseif type EQ “file” AND ListLast(name, ‘.’) NEQ “#fileExt#”>
<cftry>
<cffile action=”copy” source=”#currFold#\#name#” destination=”#newFold#\#name#”>
copy:#currFold#\#name#
<cfcatch>nocopy:#currFold#\#name#<!—do nothing, file already exists—></cfcatch>
</cftry>
<cfelse>
</cfif>
<br /><br />
</cfoutput>

Site encryption complete!

JQuery Plugin on Facebook

September 8, 2009 ppshein Leave a comment

I was speechless once I saw this plugin group at facebook. It’s really cool and useful for developers who wanna enhance their websites.

http://www.facebook.com/jqueryplugins

WebChart integrate with CFML – 2

September 3, 2009 ppshein Leave a comment

I think you would be complicated reading above post, “webchart integrate with CFML”. Ok, I’ll explain you simply. It’s quite simple like using <cfchart>. If you wanna use pie chart with WebChart 3D Donut function, here you go.

First of all, you need to create chart design in WebChart.

elements_annotation

After that, you will get following XML code.

<?xml version=”1.0″ encoding=”UTF-8″?>
<pieChart depth=”Double” style=”Solid” type=”MediumNut” angle=”314″ altText=”">
<dataLabels style=”Pattern” placement=”Inside” autoControl=”true” font=”Arial-10″>
<![CDATA[
$(colPercent)
]]>
</dataLabels>
<legend placement=”Right”>
<decoration style=”None” foreColor=”white”/>
<![CDATA[
$(colLabel)
]]>
</legend>
<elements drawOutline=”false” drawShadow=”true”>
<morph morph=”Grow” stage=”Cols”/>
</elements>
<table>
<heatmap isEnabled=”false” minLevel=”0.0″ maxLevel=”0.0″/>
</table>
<popup decoration=”Round” background=”white” foreground=”black”/>
<paint palette=”Pastel” paint=”Plain”/>
</pieChart>

Once you got this code, set it into <cfsavecontent> like as follow:

<cfsavecontent variable=”chartStyle”>
<?xml version=”1.0″ encoding=”UTF-8″?>
<pieChart depth=”Double” style=”Solid” type=”MediumNut” angle=”314″ altText=”">
<dataLabels style=”Pattern” placement=”Inside” autoControl=”true” font=”Arial-10″>
<![CDATA[
$(colPercent)
]]>
</dataLabels>
<legend placement=”Right”>
<decoration style=”None” foreColor=”white”/>
<![CDATA[
$(colLabel)
]]>
</legend>
<elements drawOutline=”false” drawShadow=”true”>
<morph morph=”Grow” stage=”Cols”/>
</elements>
<table>
<heatmap isEnabled=”false” minLevel=”0.0″ maxLevel=”0.0″/>
</table>
<popup decoration=”Round” background=”white” foreground=”black”/>
<paint palette=”Pastel” paint=”Plain”/>
</pieChart>
</cfsavecontent>

So, create like <cfchart> as follow:

<cfchart format=”png” style=”doughnutChart1.xml”>
<cfchartseries type=”pie”>
<cfchartdata item=”2000″ value=”100.0″>
<cfchartdata item=”2001″ value=”200.0″>
<cfchartdata item=”2002″ value=”100.0″>
<cfchartdata item=”2003″ value=”180.0″>
<cfchartdata item=”2004″ value=”200.0″>
</cfchartseries>
</cfchart>

Ok, that’s all. How..?? Easy, isn’t it?

WebChart integrate with CFML

September 2, 2009 ppshein Leave a comment

As you know, chart functions are available in CFMX. But, not completely cool. That’s why I’ve been solving how to make which cool chart can be integrate with CFML. I gave 6 hours for this research. Finally, I gotcha this website GreenPoint. This site actually support to developers who wanna make cool chart.

Learn here how to integrate webchart with CFML. HERE.

Following are cool charts I currently make.

Pie Chart integrate with CFML

Pie Chart integrate with CFML

Pyramid chart integrate with CFML

Pyramid chart integrate with CFML