Monday 20 April 2009

jQuery Plugin For Fixing ASP.NET Tables

When asp.net renders a table it puts the header cells into the tbody like shown below.

<table id="table" border="0">
<tbody><tr>
<th>Header cell</th>
</tr><tr>
<td>Cell</td>
</tr>
</tbody></table>

I have written a jquery plugin which will fix this issue.

http://code.google.com/p/jqueryaspxtablefix/

It takes the first row and adds moves it into a thead element.

Wednesday 1 April 2009

c# Querystring and Form Library

This is a class that I created in order to make it easier and quicker when getting things from the querystring and form items.

public static class QueryStringFormLibrary
{
#region Querystrings
/// <summary>
/// Returns the value from the querystring if it exists if not returns the default value
/// </summary>
/// <param name="queryName">Querystring item to get</param>
/// <param name="defaultValue">Default Value</param>
/// <returns></returns>
public static string getQuerystring(string queryName, string defaultValue)
{
string returnvalue = defaultValue;

if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString.Get(queryName)))
{
returnvalue = HttpContext.Current.Request.QueryString.Get(queryName);
}

return returnvalue;
}

/// <summary>
/// Returns the value from the querystring if it exists if not returns the default value
/// </summary>
/// <param name="queryName">Querystring item to get</param>
/// <param name="defaultValue">Default Value</param>
/// <returns></returns>
public static int getQuerystring(string queryName, int defaultValue)
{
int returnvalue = defaultValue;

string currentValue = getQuerystring(queryName, "");
string pattern = "^(\\d){1,}$";
Regex rx = new Regex(pattern);
if (rx.Match(currentValue).Success)
{
returnvalue = int.Parse(currentValue);
}

return returnvalue;
}

/// <summary>
/// Returns the value from the querystring if it exists if not returns the default value
/// </summary>
/// <param name="queryName">Querystring item to get</param>
/// <param name="defaultValue">Default Value</param>
/// <returns></returns>
public static float getQuerystring(string queryName, float defaultValue)
{
float returnvalue = defaultValue;

string currentValue = getQuerystring(queryName, "");
string pattern = "^(\\d){1,}(\\.){0,1}(\\d){0,}$";
Regex rx = new Regex(pattern);
if (rx.Match(currentValue).Success)
{
returnvalue = float.Parse(currentValue);
}

return returnvalue;
}

/// <summary>
/// Returns the value from the querystring if it exists if not returns the default value
/// </summary>
/// <param name="queryName">Querystring item to get</param>
/// <param name="defaultValue">Default Value</param>
/// <returns></returns>
public static bool getQuerystring(string queryName, bool defaultValue)
{
bool returnvalue = defaultValue;

switch (getQuerystring(queryName, "false").ToLower())
{
case "t":
case "1":
case "on":
case "true":
returnvalue = true;
break;
default:
returnvalue = false;
break;
}

return returnvalue;
}
#endregion

#region Form
/// <summary>
/// Returns the value from the FormItem if it exists if not returns the default value
/// </summary>
/// <param name="formItemName">FormItem item to get</param>
/// <param name="defaultValue">Default Value</param>
/// <returns></returns>
public static string getFormItem(string formItemName, string defaultValue)
{
string returnvalue = defaultValue;

if (!string.IsNullOrEmpty(HttpContext.Current.Request.Form.Get(formItemName)))
{
returnvalue = HttpContext.Current.Request.Form.Get(formItemName);
}

return returnvalue;
}

/// <summary>
/// Returns the value from the FormItem if it exists if not returns the default value
/// </summary>
/// <param name="formItemName">FormItem item to get</param>
/// <param name="defaultValue">Default Value</param>
/// <returns></returns>
public static int getFormItem(string formItemName, int defaultValue)
{
int returnvalue = defaultValue;

string currentValue = getFormItem(formItemName, "");
string pattern = "^(\\d){1,}$";
Regex rx = new Regex(pattern);
if (rx.Match(currentValue).Success)
{
returnvalue = int.Parse(currentValue);
}

return returnvalue;
}

/// <summary>
/// Returns the value from the FormItem if it exists if not returns the default value
/// </summary>
/// <param name="formItemName">FormItem item to get</param>
/// <param name="defaultValue">Default Value</param>
/// <returns></returns>
public static float getFormItem(string formItemName, float defaultValue)
{
float returnvalue = defaultValue;

string currentValue = getFormItem(formItemName, "");
string pattern = "^(\\d){1,}(\\.){0,1}(\\d){0,}$";
Regex rx = new Regex(pattern);
if (rx.Match(currentValue).Success)
{
returnvalue = float.Parse(currentValue);
}

return returnvalue;
}

/// <summary>
/// Returns the value from the FormItem if it exists if not returns the default value
/// </summary>
/// <param name="formItemName">FormItem item to get</param>
/// <param name="defaultValue">Default Value</param>
/// <returns></returns>
public static bool getFormItem(string formItemName, bool defaultValue)
{
bool returnvalue = defaultValue;

switch (getFormItem(formItemName, "false").ToLower())
{
case "t":
case "1":
case "on":
case "true":
returnvalue = true;
break;
default:
returnvalue = false;
break;
}

return returnvalue;
}
#endregion

/// <summary>
/// Checks to see if the querystring has a value
/// </summary>
/// <param name="queryName">querystring to check</param>
/// <returns></returns>
public static bool hasQuerystring(string queryName)
{
bool returnvalue = false;

if (!string.IsNullOrEmpty(getQuerystring(queryName, "")))
{
returnvalue = true;
}
return returnvalue;
}

/// <summary>
/// Checks to see if the form item has a value
/// </summary>
/// <param name="formItemName">form item to check</param>
/// <returns></returns>
public static bool hasFormItem(string formItemName)
{
bool returnvalue = false;

if (!string.IsNullOrEmpty(getFormItem(formItemName, "")))
{
returnvalue = true;
}

return returnvalue;
}
}

Monday 30 March 2009

Customers

A customer brought in some mini pcs today, they were really dirty. Looked like they took them to the beach. I can't understand how people could let them get like that. The thing was they were wanting software installed on them so they could take them to an exhibition.



Thursday 19 February 2009

Import CSV file to DataTable

http://tinyurl.com/dagek3

Int To Enum

DayOfWeek weekDay = (DayOfWeek)Enum.ToObject(typeof(DayOfWeek), 1);