Thursday, December 18, 2008

ADO.Net to create unique DataTable values

The application I'm building uses a .NET BLL referenced by Flex to build views. I've come upon a situation where a series of table queries creates a duplicate list of what are unique values. This throws an error from .NET. The layer queries generate column values that begin as non-unique and become unique upon subsequent table queries.

I have been looking into solutions to update my BLL to remove duplicates of the offending column before the subsequent queries. Initially, as late as 2005, developers suggested writing a custom routine to do this. Here is one written in VB from Julie Lerman:

(note - the int32_key is in there as a reminder in case I need to create another one for non-int keys)

Public Function DistinctRows_Int32_Key(ByVal dt As DataTable, ByVal keyfield As String) As DataTable
Dim newTable As DataTable = dt.Clone
Dim keyval As Int32 = 0
Dim dv As DataView = dt.DefaultView
dv.Sort = keyfield
If dt.Rows.Count > 0 Then
For Each dr As DataRow In dt.Rows
If Not dr.Item(keyfield) = keyval Then
newTable.ImportRow(dr)
keyval = dr.Item(keyfield)
End If
Next
Else
newTable = dt.Clone
End If
Return newTable
End Function


It has since been shoehorned into an ADO.NET 2.0 method called ToTable that works thus:


ADO.Net 2.0 prevents this difficulty by exposing method called DataView.ToTable() with 4 overloads.

DataView.ToTable ()
Creates and returns a new DataTable based on rows in an existing DataView.

DataView.ToTable (String)
Creates and returns a new DataTable based on rows in an existing DataView.

DataView.ToTable (Boolean, String[])
Creates and returns a new DataTable based on rows in an existing DataView.

DataView.ToTable (String, Boolean, String[])
Creates and returns a new DataTable based on rows in an existing DataView.


This is an improvement over writing a custom routine. The hitch is getting the resultant table back to the correct datatype in order to call the row values by name. Here's my solution:

DataView tempView = stronglyTypedTableInstance.DefaultView;

stronglyTypedTableInstance = (StronglyTypedDataTable)(StronglyTypedTableInstance.DefaultView.ToTable(true, "name"));

foreach (StronglyTypedRow stronglyTypedRowInstance in stronglyTypedTableInstance)
{
runLogic...
}
return newlyBuiltTable;


And so on and so forth.

Tuesday, December 16, 2008

Now using email settings

Publishing by email today. For some new content, you could visit Adobe Site of the Day.

ToolTips in Flex 3

Tooltips. They pop up to provide contextual expansion. They enhance your workspace. They gratify you with sleek utility. They're an integral Flex component. You will probably be customizing them.

Flex Docs is a good starter on custom and standard tooltips:
http://www.adobe.com/devnet/flex/quickstart/using_tooltips/

Adobe docs are not so great when it comes to positioning custom tooltips, but fear not, it's simple once you know how :).

Just be sure to utilize both the toolTipCreate AND toolTipShow methods of the mx.events.ToolTipEvent class and you'll be golden.

Another plus, tooltips are a great use of MVC and you can encapsulate calls to events via event.toolTip.

Another good tutorial resource:
http://blog.flexmonkeypatches.com/2008/09/10/flex-custom-tooltip-speech-bubble/

Happy tooltipping.

Wednesday, December 10, 2008

Examination of the Model-View-Controller model

The MVC is supposed to make life easy, but it's often hard to visualize.

Model View Controller requires the M, the V and the C.

The "Model" component holds the generic interface.
The "View" event returns the data to the application.
The "Controller" application implements the component with specific data.

So
Model = interface
View = event
Controller = application

Now that that's out of the way, here's a simple example of MVC in action.

Thursday, December 4, 2008

Time Spent on Technology

My most recent client project tossed me headlong me into the programmer's briar patch. And there were some sharp thorns in there. C Sharp to be exact. (C# is the programming language of ASP.NET).

Digressions aside, there's an unmistakable Pyhrric thorn in a technical victory. Namely, it is not a visual victory. It is only part of the solution.

Design | Develop.

Web projects are a calico of the visual and the symbolic. Envisioning a project requires understanding it inside out. Learning the development side dispels the magic inside the application. When you have parsed it, it's obvious.

On the other hand, a technical project might drain visual creativity or vice versa. Math may diminish poetry, or medicine smoking. If a designer develops, can a developer design?

In a word, yes.

(but it takes more time)