As we all know, there are may more ways to skin a cat, here is my version of a CFC
that wraps a table. I'm in the process of writing a page that looks at a table and
writes this code for me. So, I too am looking for a code critique. I just hope this
doesn't end up on ShittyCode.com ;) Thanks!
<cfcomponent displayname="Shipper Services" output="no">
<cffunction name="getByGUID" access="public" returntype="any" output="No">
<cfargument name="ShipperServiceGUID" type="string" required="yes">
<cfquery name="qryThisRecord" datasource="#request.lp.dsSQL#">
SELECT * FROM Shipper_Services WHERE ShipperServiceGUID =
'#arguments.ShipperServiceGUID#'
</cfquery>
<cfscript>
returnThis =
createObject('component','inetcfc.shipping.Service');
returnThis.setData(qryThisRecord,1);
return returnThis;
</cfscript>
</cffunction>
<cffunction name="getArray" access="public" returntype="array" output="No">
<cfquery name="qryRecords" datasource="#request.lp.dsSQL#">
SELECT * FROM Shipper_Services ORDER BY Ranking
</cfquery>
<cfscript>
returnArray = ArrayNew(1);
for(q=1; q lte qryRecords.recordCount; q=q+1){
arrayAppend(returnArray,createObject('component','inetcfc.shipping.Service'));
returnArray[q].setData(qryRecords,q);
}
return returnArray;
</cfscript>
</cffunction>
<cffunction name="setData" access="public" output="No">
<cfargument name="qry" type="query" required="Yes">
<cfargument name="row" type="numeric" required="Yes">
<cfscript>
this.ShipperServiceGUID =
arguments.qry.ShipperServiceGUID[arguments.row];
this.ShipperGUID = arguments.qry.ShipperGUID[arguments.row];
this.ServiceName = arguments.qry.ServiceName[arguments.row];
this.ServiceCode = arguments.qry.ServiceCode[arguments.row];
this.ServiceCharge =
arguments.qry.ServiceCharge[arguments.row];
this.Active = arguments.qry.Active[arguments.row];
//this. = arguments.qry.[arguments.row];
</cfscript>
</cffunction>
<cffunction name="getGUID" access="public" returntype="string" output="No">
<cfreturn this.ShipperServiceGUID>
</cffunction>
<cffunction name="getShipperGUID" access="public" returntype="string"
output="No">
<cfreturn this.ShipperGUID>
</cffunction>
<cffunction name="getShipper" access="public" returntype="any" output="No">
<cfscript>
if(not isDefined("this.objShipper")){
this.objShipper =
createObject('component','inetcfc.shipping.Shipper').getByGUID(getShipperGUID());
}
return this.objShipper;
</cfscript>
</cffunction>
<cffunction name="getServiceName" access="public" returntype="string"
output="No">
<cfreturn this.ServiceName>
</cffunction>
<cffunction name="getServiceCode" access="public" returntype="string"
output="No">
<cfreturn this.ServiceCode>
</cffunction>
<cffunction name="getServiceCharge" access="public" returntype="numeric"
output="No">
<cfreturn this.ServiceCharge>
</cffunction>
<cffunction name="isActive" access="public" returntype="numeric" output="No">
<cfreturn this.Active>
</cffunction>
<cffunction name="insertRecord" access="public" output="No">
<cfargument name="ShipperGUID" type="string" required="Yes">
<cfargument name="ServiceName" type="string" required="Yes">
<cfargument name="ServiceCode" type="string" required="Yes">
<cfargument name="ServiceCharge" type="string" required="Yes">
<cfargument name="UserGUID" type="string" required="Yes">
<cfargument name="Active" type="numeric" required="no" default="1">
<cfloop collection="#arguments#" item="i">
<cfset "arguments.#i#" = trim(arguments[i])>
</cfloop>
<cfquery name="qryInsert" datasource="#request.lp.dsSQL#">
INSERT INTO Shipper_Services (ShipperGUID, ServiceName,
ServiceCode, ServiceCharge, CreatedUserGUID, Active)
VALUES ('#arguments.ShipperGUID#', '#arguments.ServiceName#',
'#arguments.ServiceCode#', #arguments.ServiceCharge#, '#arguments.UserGUID#',
#arguments.Active#)
</cfquery>
</cffunction>
<cffunction name="updateRecord" access="public" output="No">
<cfargument name="ShipperServiceGUID" type="string" required="Yes">
<cfargument name="ShipperGUID" type="string" required="Yes">
<cfargument name="ServiceName" type="string" required="Yes">
<cfargument name="ServiceCode" type="string" required="Yes">
<cfargument name="ServiceCharge" type="string" required="Yes">
<cfargument name="UserGUID" type="string" required="Yes">
<cfargument name="Active" type="numeric" required="Yes">
<cfloop collection="#arguments#" item="i">
<cfset "arguments.#i#" = trim(arguments[i])>
</cfloop>
<cfquery name="qryUpdate" datasource="#request.lp.dsSQL#">
UPDATE Shipper_Services
SET
ShipperGUID = '#arguments.ShipperGUID#',
ServiceName = '#arguments.ServiceName#',
ServiceCode = '#arguments.ServiceCode#',
ServiceCharge = #arguments.ServiceCharge#,
UpdatedUserGUID = '#client.UserGUID#',
UpdatedDate = #Now()#,
Active = #arguments.Active#
WHERE ShipperServiceGUID = '#arguments.ShipperServiceGUID#'
</cfquery>
</cffunction>
</cfcomponent>
Justin Hansen
~~~~~~~~~~~~~~~~~~~~~~
Uhlig Communications
Systems Engineer
[EMAIL PROTECTED]
~~~~~~~~~~~~~~~~~~~~~~
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]