Thursday, November 02, 2006

SQL Helper


If you’re still one of the few that don't use DeKlarit you'll probably like this tool. I called it SQL Helper, and basically what it does is create the SQL statements you need in order to INSERT, UPDATE, DELETE or SELECT your own objects to a database.

I've been having this idea for a long time now, but it was a few weeks/months ago that my friend Alvarenga introduced to me the PropertyInfo class and it all became clear then.
There are only a few rules you must be careful with in order to use this tool. First of all there’s a naming convention, there's always one, and I'll explain how it works with an example.
Let's say you have to manage Clients. You'll probably have a ‘Client’ class with properties like FirstName, LastName, BirthDate, and so on. In order to get the appropriate SQL statements you'll have to name a table ‘Client’ like your class, and all the columns in that table must be name as the class' attributes. So, for our example, you'll also have a ‘Class’ table with FirstName, LastName and BirthDate as columns/attributes.
If you created that scenario you'll be able to call all the functions from the DDLStatement class.
For the UPDATE, DELETE and SELECT statements there are two functions. One of them gets the object you want the sentence to be created from, and the second parameter is the name of the attribute that holds the primary key in your database. In short, the 'WHERE' part of the sentence.
But if you're starting from scratch you can make your domain classes inherit from 'IDKeyObject'. This is an abstract class that it only has one attribute, 'ID', which is the one I assume is your PK. So, if you pass an instance of any derived class there's no need to tell the PK attribute.
Give it a try, and let me know how can I improve it. It's only been tested in SQL Server, but I think I'm using standard ANSII SQL, so, it should work for every DBMS.

Well, actually there's a function of the DDLStatement class which returns the CREATE TABLE statement to create a table from a class, and the data types I use there are the ones from SQL Server, I guess I could have parameterized than :(

Download SQLHelper



Read Full Post

Friday, September 01, 2006

.Net vs. J2EE (again)

I'm glad Joel wrote about this subject again... but what makes me happier is the fact that he arrived to same same conclusion we had arrived when a little debate took place after my ".Net vs. J2EE, why?" post.
I totally agree with his comments about the people... people are responsible for making a project fail or succeed, not the chosen technology.

BTW: I still prefer .net and I don't see that changing anytime soon ;)

Read Full Post

Tuesday, August 29, 2006

Seinfeld & Superman

...just the best of two worlds ;)
Check out this videos and you'll see what I'm talking about... (yeap, a little off dev topic I know)

The Green Lantern





Episode 1





Episode 2




Read Full Post

Monday, August 21, 2006

Ever heard of Diggnation?






I try to listen every now and then some interesting podcast, but this one I believe it's the best podcast around.Obviously I haven't heard'em all, so feel free to recommend all the podcast you'll find interesting.Understand that the wide concept of interesting, from this one (diggnation) to the TikiBar (watch the videos).
Diggnation is about two guys that read and comment the top dug stories of the week in digg.comSo chek'em out, they are funny as hell, if you can try to downloads their videos.

The banner above is a game made by one of the fans, play with Alex and try to beat Kevin in this drinking contest. Click on Johny Johny (Tiki Bar) to get shots.

Read Full Post

Monday, July 17, 2006

Localize This!

Localization, that's pretty much what I've been doing since I got in the DeKlarit team. I've been working on it for win and web forms and I must say that it's really simple in .net framework 2.0.
There are different techniques in order to achieve that, one of them is to generate a resource file for every form in your app. Even though this approach is less complex, I don't like the idea of having as many resource files as forms in my application, so I'll describe how to achieve localization with a different approach.


First of all, create a simple win app and add some controls to the main Fomr (Form1). Add some labels some buttons and what ever you want.
Now create a resource file and name it StringResources.resx. Edita that file with VS2005 and add all the strings you want to localize, ok, cancel, HelloWorld, etc...
In order to localize your form create a method (called form the Page_Load method) where all texts are going to be set. In order to do that write the following sentence for every control you may have in your form:
btnOK.Text = StringResources.NewCaption;
Once you run the application you should see every text you've entered in your resource file.
I now what you're going to say, so, this is the cool part? nope, this is the hard part, to cool part is coming right now. From the Solution Explorer Copy and Paste your resource file and rename it as StringResource.es.resx. Change the values of that file to spanish, Aceptar, Cancelar, HolaMundo, etc. Now change you regional settings so your default language is spanish.
Rerun you app and that's it!, your app should now be displaying all the controls in spanish, or what ever you've entered in the resource file.
In order to get the same result for web applications you can do two things. One is to do exactly what we just did and the other one is to set the "call" to the resource file right on you aspx of ascx file. To do that just change the text attribute of the control for something like this:
Text="<%$Resources:StringResources,NewCaption%>"
You may need to Databind the control in order for the text to be displayed.

So there yo have it, your own application with localization features. Start playing with it and add it to your applications, you never know where's your next buyer from ;)

Read Full Post