Wednesday, October 19, 2005

C# post coming soon.

Yesterday I had a problem with a screen not repainting quickly. I was pulling back data and I wanted to have the screen paint immediately, then refresh when the data retrieval was complete. I'll clean the code up and remove the project specific portions so I can post a demonstration.

Thursday, October 13, 2005

Javascript Custom Sort

In case you ever find yourself trying to handle a custom sort where you are moving countries around (like I described in my previous post) but you want to keep the US and Canada on top of the list, then you can use this code.

function move(fromBox, toBox)
{
// The lookup array has the value needed for each item.
// It is used to set the value of the option in the listbox.
var arrLookup = new Array();
var arrfromBox = new Array();
var arrtoBox = new Array();
var idx;

// Populate arrLookup and arrtoBox from the to listbox.
for( idx = 0; idx < toBox.options.length; idx++ )
{
arrLookup[ toBox.options[idx].text ] = toBox.options[idx].value;
arrtoBox[idx] = toBox.options[idx].text;
}

for( idx = 0; idx < fromBox.options.length; idx++)
{
// Add to the lookup array items from the fromBox.
arrLookup[ fromBox.options[idx].text ] = fromBox.options[idx].value;
if( fromBox.options[idx].selected && fromBox.options[idx].value != "" )
{
// put selected items into the toBox array at the end.
arrtoBox[arrtoBox.length] = fromBox.options[idx].text;
}
else
{
// Else put the item into the fromBox array.
arrfromBox[arrfromBox.length] = fromBox.options[idx].text;
}
}
// Sort the arrays.
arrfromBox.sort();
arrtoBox.sort();

// clear the list boxes
fromBox.length = 0;
toBox.length = 0;

arrfromBox = CustomSort(arrfromBox)
arrtoBox = CustomSort(arrtoBox)

// Add all of the items into the from box.
for(idx = 0; idx < arrfromBox.length; idx++)
{
var opt = new Option();
opt.value = arrLookup[ arrfromBox[idx] ];
opt.text = arrfromBox[idx];
fromBox[idx] = opt;
}

// Add all of the items into the to box.
for(idx = 0; idx < arrtoBox.length; idx++)
{
var opt = new Option();
opt.value = arrLookup[ arrtoBox[idx] ];
opt.text = arrtoBox[idx];
toBox[idx] = opt;
}
}

// --------------------------------------------------
function CustomSort(arrItems)
{
var arrExclusions = new Array();
// a for loop has a shortfall it only evaluates the length property once,
// But we need it to be fluid.
var checkLength = arrItems.length;
currentIdx = 0;
while( currentIdx < checkLength )
{
if( arrItems[currentIdx] == "USA" || arrItems[currentIdx] == "Canada" )
{
// populate the exclusion array with the items that should appear at the top.
arrExclusions[arrExclusions.length] = arrItems[currentIdx];
arrItems.splice(currentIdx, 1);
checkLength--;
}
else
{
// only increment if the value did not get removed.
// if it was removed, we need to check the same record.
currentIdx++
}
}
arrItems = arrExclusions.concat(arrItems);
return arrItems;
}

Wednesday, October 12, 2005

Javascript coming soon.

I was working on a problem with Client Side Javascript last night that I thought was just a wonderful example of something that happens.

The problem is that there are 2 listboxes and between them are the standard ">>" and "<<" buttons to move items back and forth, which was being done with Javascript. However, the site owners had a few common items that they wanted to appear at the top of each list for ease of selection.

If you can imagine, it's like having each country in the list, but you know that the USA is the most common, so you want it at the top. However, you want it to stay at the top when items are moved around. I'll clean up my code and post it soon.

Monday, October 10, 2005

CSharp Script

I just read a really great article about using c# in script. The concept is that there is an exe that just calls the compiler against the script file. The reason was so the code could be modified without having to be recompiled, but I don't really see the difference between compiling it ahead of time, or at run time with the front end .exe. It is still a cool idea, if you are interested, you can read about the C# Scripter here.

Friday, October 07, 2005

Dashboard Design (continued)

The listview that is going to store the results can have a standard list of icons for different statuses. This could easily be driven from an enumeration that each plugin .dll has to use. WArning, Error, All's Well, Suspended.

Warning could be a potential problem, sometimes the data can show that something may not be right, but with time it will correct itself.
Error - obviously.
All's Well - Obviously.
Suspended - Each plugin would have the ability to only monitor during a certain time period. For example if an application is only supposed to run between 8 AM and noon, then any other time it would be in a suspended state. In reality the plugin is checking every 1 minute or 10 minutes still, but until it's inside the specified time period, the status is suspended.