Tuesday, August 05, 2008

Simple reflection form

Haven't you had some poco's (plain old CLR object) you just want to edit, but you had to make a form for each object?

The solution to this is dot net's reflection. The SimpleReflectionForm takes an object like the Customer below and shows this in a form.


public class Customer
{
public Guid Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public bool Married { get; set; }
}

Just call the form:


Customer c = new Customer
{
Id = Guid.NewGuid(),
Name = "Frank",
Age = 31,
Married = true
};

using (SimpleReflectionForm f
= new SimpleReflectionForm(c, "Id"))
{
f.ShowDialog();
}

The following form is shown:


As you can see the Id is ignored, by the optional parameter string[] propertiesToExclude.
The form supports all native .net types (int, string, datetime, guid etc). Guid and numeric types are verified when the Ok button is pressed.


You can download the source of SimpleReflectionForm
here.

Enjoy!

Monday, August 04, 2008

UNION with DISTINCT via ODBC to ORACLE

In a VBA application (MS Access XP) with linked tables to Oracle the following query completely crashes Access!

SELECT A1.V_ID, A1.PR_ID, A1.AREA_ID, A1.TYPE,
A1.AREA, A1.AREA_MAIN_ID, A1.ACTIVE
FROM AREAS AS A1
UNION SELECT DISTINCT A2.V_ID, A2.PR_ID,
-1 AS AREA_ID, A2.TYPE, '' AS AREA,
A2.AREA_MAIN_ID, -1 AS ACTIVE
FROM AREAS AS A2;


Solution: convert the distinct to a group by

SELECT A1.V_ID, A1.PR_ID, A1.AREA_ID, A1.TYPE,
A1.AREA, A1.AREA_MAIN_ID, A1.ACTIVE
FROM AREAS AS A1
UNION (
SELECT A2.V_ID, A2.PR_ID, -1 AS AREA_ID, A2.TYPE,
'' AS AREA, A2.AREA_MAIN_ID, -1 AS ACTIVE
FROM AREAS AS A2
GROUP BY A2.V_ID, A2.PR_ID, A2.TYPE, A2.AREA_MAIN_ID);