Programming Notes – Matt Jorgensen

November 1, 2007

coldfusion sleep method

Filed under: coldfusion — Tags: — flexprimer @ 6:51 pm

custom tag to force sleep mode for specified interval:

http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&loc=en_us&extid=1000436

Peter Freitag also says you can do it via a native java method:

<cfset thread = CreateObject("java", "java.lang.Thread")>
About to sleep for 5 seconds...<cfflush>
<cfset thread.sleep(5000)>
Done sleeping.

.NET ajax autosave

Filed under: ajax, dotNet — Tags: — flexprimer @ 1:36 pm

Ajax list application for .NET. First download the ajax template for visual studio (or visual web dev).
master page:

<%@ Master Language=”C#” AutoEventWireup=”true” CodeFile=”MasterPage.master.cs” Inherits=”MasterPage” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<h2>List App</h2>
<form id=”form1″ runat=”server”>
<div>
<asp:contentplaceholder id=”ContentPlaceHolder1″ runat=”server”>
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

default.aspx page:

<%@ Page Language=”C#” MasterPageFile=”~/MasterPage.master” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” Title=”Untitled Page” %>

<asp:Content ID=”Content1″ ContentPlaceHolderID=”ContentPlaceHolder1″ Runat=”Server”>

<div class=”body”>

<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
</asp:ScriptManager>

<p>This application lets users build to-do lists. It was built in .NET and utilizes Ajax interaction.</p><br />

<strong>List items:</strong>

<br /><br />

Status
<asp:DropDownList ID=”DropDownList1″ runat=”server” AutoPostBack=”True” style=”background-color: beige”>
<asp:ListItem Selected=”True” Value=”False”>View Active Items</asp:ListItem>
<asp:ListItem Value=”True”>View Completed Items</asp:ListItem>
</asp:DropDownList>

<br /><br />

<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server”>
<ContentTemplate>
<asp:GridView ID=”GridView1″ runat=”server” AllowPaging=”True” AllowSorting=”True” AutoGenerateColumns=”False” DataKeyNames=”TaskId”
DataSourceID=”ObjectDataSource1″ AlternatingRowStyle-BackColor=Beige GridLines=”Vertical” BackColor=”White” BorderColor=”#DEDFDE” BorderStyle=”None” BorderWidth=”1px” CellPadding=”4″ ForeColor=”Black”>
<Columns>
<asp:CommandField ShowEditButton=”True” />
<asp:BoundField DataField=”TaskId” HeaderText=”TaskId” InsertVisible=”False” ReadOnly=”True”
SortExpression=”TaskId” />
<asp:BoundField DataField=”Name” HeaderText=”Name” SortExpression=”Name” />
<asp:CheckBoxField DataField=”Complete” HeaderText=”Complete” SortExpression=”Complete” />
</Columns>
<FooterStyle BackColor=”#CCCC99″ />
<RowStyle BackColor=”#F7F7DE” />
<SelectedRowStyle BackColor=”#CE5D5A” Font-Bold=”True” ForeColor=”White” />
<PagerStyle BackColor=”#F7F7DE” ForeColor=”Black” HorizontalAlign=”Right” />
<HeaderStyle BackColor=”#6B696B” Font-Bold=”True” ForeColor=”White” />
<AlternatingRowStyle BackColor=”White” />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID=”DropDownList1″ EventName=”SelectedIndexChanged” />
</Triggers>
</asp:UpdatePanel>

<p></p><br />

<strong>Insert new item:</strong>

<br /><br />

<asp:UpdatePanel ID=”UpdatePanel2″ runat=”server” UpdateMode=Conditional>
<ContentTemplate>
<asp:DetailsView ID=”DetailsView1″ runat=”server” Height=”50px” Width=”125px” AutoGenerateRows=”False” DataKeyNames=”TaskId” DataSourceID=”ObjectDataSource1″ DefaultMode=”Insert” GridLines=None>
<Fields>
<asp:BoundField DataField=”TaskId” HeaderText=”TaskId” InsertVisible=”False” ReadOnly=”True”
SortExpression=”TaskId” />
<asp:BoundField DataField=”Name” HeaderText=”Name” SortExpression=”Name” />
<asp:CheckBoxField DataField=”Complete” HeaderText=”Complete” SortExpression=”Complete” />
<asp:CommandField ShowInsertButton=”True” />
</Fields>
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>

<asp:ObjectDataSource ID=”ObjectDataSource1″ runat=”server” DeleteMethod=”Delete”
InsertMethod=”Insert” OldValuesParameterFormatString=”original_{0}” SelectMethod=”GetTasksByStatus”
TypeName=”TasksDataSetTableAdapters.TasksTableAdapter” UpdateMethod=”Update”>
<DeleteParameters>
<asp:Parameter Name=”Original_TaskId” Type=”Int32″ />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name=”Name” Type=”String” />
<asp:Parameter Name=”Complete” Type=”Boolean” />
<asp:Parameter Name=”Original_TaskId” Type=”Int32″ />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID=”DropDownList1″ Name=”IsComplete” PropertyName=”SelectedValue”
Type=”Boolean” />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name=”Name” Type=”String” />
<asp:Parameter Name=”Complete” Type=”Boolean” />
</InsertParameters>
</asp:ObjectDataSource>

<br /><br />-Matt Jorgensen (http://excession.wordpress.com/about/)

</div>

</asp:Content>

October 29, 2007

coldfusion ajax autosave using prototype

Filed under: ajax, coldfusion — Tags: — flexprimer @ 4:14 pm

Coldfusion autosave using prototype javascript library. Need to first download prototype.js.

ajax.cfm page:

<html>
<head>
<title>AJAX Zip Checker </title>

<script src=”prototype.js” language=”JavaScript” type=”text/javascript”></script>
<script type=”text/javascript” language=”JavaScript”>

function checkZip(strTextbox) {
txtControl = strTextbox;
var txt = txtControl.name;
var url = ”;
switch(txt)
{
case”zip”:
{
url = ‘checkzip.cfm’;
break;
}
case”something”:
{
url = ‘checksomething.cfm’;
break;
}
}
//var url = ‘checkzip.cfm’;
var params = txtControl.name +’=’ + txtControl.value;
var ajax = new Ajax.Updater(
{success: ‘ajaxResult’},
url,
{method: ‘get’, parameters: params, onFailure: reportError});

}

function reportError(request) {
$F(‘ajaxResult’) = “Error”;
}

//overloaded function

function checkThis(strTextbox, seqnbr) {
txtControl = strTextbox;
var txt = txtControl.name;
var url = ”;
var params;
switch(txt)
{
case”zip”:
{
url = ‘checkzip.cfm’;
//params = ‘zip=’ + $F(‘zip’)+ ‘&recID=’ + $F(‘recID’) ;
break;
}
case”something”:
{
url = ‘checksomething.cfm’;
//params = ‘something=’ + $F(‘something’);
break;
}
}
//var url = ‘checkzip.cfm’;

txtSeq = eval(‘document.Form1.’+seqnbr);
var params = txtControl.name +’=’ + txtControl.value + ‘&recID=’+ txtSeq.value;

var ajax = new Ajax.Updater(
{success: ‘ajaxResult’},
url,
{method: ‘get’, parameters: params, onFailure: reportError});

}

//Handle Errors
function reportError(request) {
$F(‘ajaxResult’) = “Error”;
}

</script>
</head>
<body>
<form name=”Form1″>

<table width=”400″ border=”1″>
<tr>
<td><label for=”label”>zip:</label></td>
<td><input type=”text” name=”zip” id=”zip2″ onChange=”checkThis(this, ‘recID’);” />
<input type=”hidden” name=”recID” value = “1″></td>
</tr>
<tr>
<td> </td>
<td><input type=”text” name=”something”id=”something2″ onChange=”checkZip(this);” ></td>
</tr>
<tr>
<td colspan=”2″><div id=”ajaxResult”></div></td>
</tr>
</table>

</form>
</body>
</html>

checkzip.cfm page:

<cfinclude template=”application_include.cfm”>
<cfif NOT IsDefined(“url.zip”) OR NOT IsNumeric(url.zip)>
<div class=”badzip”>Please enter a valid zip code.</div><cfabort>
</cfif>
<cfquery datasource=”#datasource#” name=”mysql_test”>
SELECT * from tableName
WHERE id = <cfqueryparam cfsqltype=”cf_sql_integer” value=”#url.zip#”>
</cfquery>
<cfif mysql_test.recordcount>
<cfoutput>#mysql_test.fname#, #mysql_test.lname# — #url.RecID#</cfoutput>
<cfelse>
<div class=”goodzip”>Name not found.</div>
</cfif>

.NET data access layer

Filed under: dotNet — Tags: — flexprimer @ 4:09 pm

Good overview of the .NET data access layer, by Scott Mitchell:

http://www.asp.net/learn/data-access/tutorial-01-cs.aspx

October 22, 2007

another autosave in coldfusion

Filed under: coldfusion — Tags: — flexprimer @ 7:16 pm

Another way of doing an autosave in older versions of coldfusion. This creates an artificial gateway to the action code via an iframe, triggered by an onchange on the form element.

Code for form page:

<iframe width=”400″ height=”100″ name=”idServer” id=”idServer”
frameBorder=”0″ frameSpacing=”0″ marginWidth=”0″ marginHeight=”0″>
<ilayer name=”idServer” width=”400″ height=”100″ visibility=”Hide”
id=”idServer”></ilayer>
</iframe>

<script type=”text/javascript”>

function doUpdate(a){

// the URL of the script on the server to run
var sURL = “myActionPage.cfm”;
// if you need to pass any variables to the script, then populate the following string with a
// valid query string
var sQueryString = “”;
var sQSDelim = “?”;

// if the query string variable isn’t blank, then append it to the URL
if( sQueryString.length > 0 ){
sURL = sURL + “?” + sQueryString;
sQSDelim = “&”;
}
// this will append a random number to the URL string that will ensure the document isn’t cached
sURL = sURL + sQSDelim + Math.random();

// if IE then change the location of the IFRAME
if( document.all ){
// this loads the URL stored in the sURL variable into the hidden frame
document.idServer.location = sURL;

var testFrame = document.getElementById(“idServer”);
var doc = testFrame.Form1;
if (doc == undefined || doc == null)
doc = testFrame.contentWindow.document;
doc.open();
doc.write(a);
//doc.close();
// otherwise, change Netscape v6′s IFRAME source file
} else if( document.getElementById ){
// this loads the URL stored in the sURL variable into the hidden frame
document.getElementById(“idServer”).contentDocument.location = sURL;

// otherwise, change Netscape v4′s ILAYER source file
} else if( document.layers ){
// this loads the URL stored in the sURL variable into the hidden frame
document.idServer.src = sURL;
}

}

</script>

<form method=”post”>

<textarea name=”myName” cols=”50″ rows=”2″ onchange=”doUpdate(this.form.myName.value)”><cfif isDefined(“sumData.myName”)><cfoutput>#sumData.myName#</cfoutput></cfif></textarea>

</form>

October 18, 2007

query to check for duplicate rows

Filed under: sql server — Tags: — flexprimer @ 7:36 pm

SELECT     columnName, COUNT(columnName) AS Expr1
FROM         tableName
GROUP BY columnName
HAVING      (COUNT(columnName) > 1)

October 10, 2007

restore sql server backup

Filed under: sql server — Tags: , — flexprimer @ 6:09 pm

Code to restore Sql Server from backup without overwriting the current database.

restore filelistonly
from disk = ‘d:\someLocation\oldDbName.bak’

restore database oldDbName from disk = ‘D:\someLocation\currentDb_db_200709190200.BAK’
with move ‘currentDb’ to ‘d:\Microsoft SQL Server\MSSQL\data\oldDbName_Data.MDF’,
move ‘currentDb_Log’ to ‘d:\Microsoft SQL Server\MSSQL\data\oldDbName_Log.LDF’

autosave in coldfusion

Filed under: coldfusion — Tags: , — flexprimer @ 5:58 pm

For older versions of coldfusion, the tag below does an autosave at specified intervals via a popup, but can be modified to work in other ways.

http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=1003278

about

Filed under: Uncategorized — flexprimer @ 4:48 pm

This is where I’m now collecting my various programming-related notes. -Matt Jorgensen (http://excession.wordpress.com/about/)

« Newer Posts

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.