Royco Cup of Soup

By Tommy at February 07, 2010 11:19
Filed Under: Videos

Nothing can explain this video, I think.

BlogEngine Update

By Tommy at February 03, 2010 07:45
Filed Under: General

Blog Engine was updated to v1.6 last night.  This morning I made the CSS changes and a few edits to all the themes.  All the downloads how now been updated to v1.6 and removed the 1.5 versions.

2010 Brings New Themes

By Tommy at January 24, 2010 19:55
Filed Under: Themes

Hey everyone, it's a new year and that means it's time to crank out some more themes. I'm going to start categorizing these themes a little better. Eventually I still want to do more with this site, but this is easier since I'm doing it partially for work anyways. Enjoy!

 

Preview | Download

Last theme of the 2009

By Tommy at December 06, 2009 19:06
Filed Under: Themes

Hey everyone.  In keep with my random release schedule, here is another theme.  I tried to keep this one to a more minimal look. Again, I'm bad at naming these things. So I just called it SimpleGrey. It's modified/ported from themeforest.com link

 

Preview | Download

It's Business Time

By Tommy at October 27, 2009 20:00
Filed Under: Themes

Second post in October! Amazing!  Actually I was going over some CSS and tossed together a new greenish theme. It's some odd coloring, but I like it.

Business Time

Last Windows XP Themes

By Tommy at October 18, 2009 14:49
Filed Under: General

So I found out that there was 2 other XP Themes that I did not know about.  These are offical ones that replace the default Luna theme. Hopefully Windows 7 will have some cooler looking ones eventually.

Embedded.exe (500 KB)

RoyaleNoir.Rar (232 KB)

Been a few days since the last theme

By Tommy at July 30, 2009 18:00
Filed Under: Themes

I apparently really love making themes for BlogEngine.  This one is a little bit more on the professional side.

Clear Brown

I love XP

By Tommy at July 21, 2009 18:00
Filed Under: Themes

So, I wanted to do a window like theme for some time now. I decided to slap something together. Maybe someone will take it and improve the graphics a little bit. That would be pretty sweet. I know XP is finally going to die with Windows 7 just around the corner. Tragic.

Royal Blue (XP)

One More Theme

By Tommy at June 25, 2009 19:00
Filed Under: Themes

Hey everyone. I converted a Drupal theme to BlogEngine and once again gave it a crazy name.

The layout is heavily inspired by the great work @ Steven Kuhn

Enjoy!

Mean Green Tea

CodeBits: Object to SqlParameters Extension with Reflection

By Tommy at June 18, 2009 19:00
Filed Under: CodeBits

Don't get me wrong, code generators are a good thing.  However sometimes they generate pages and pages of code that are really redundant thanks to reflection.

Especially for generating a DAL for you application.  Consider the following extension:

 

public static List<SqlParamter> BuildParameters(this object obj)
{
    List<SqlParameter> collection = new List<SqlParameter>();

    foreach (PropertyInfo propertyInfo in obj.GetType().GetProperties())
    {
        if (propertyInfo.GetValue(obj, null) = null)
        {
            collection.Add(new SqlParameter(propertyInfo.Name, DBNull.Value));
        }
        else
        {
            collection.Add(new SqlParameter(propertyInfo.Name, propertyInfo.GetValue(obj, null)));
        }
    }

    return collection;
}

This will take any object, and create a list of sql parameters from all properties. This might sound a little overboard, but consider the following function.

 

public static void ExecuteNonQuery(string query, string connection, List<SqlParameter> parameters)
{
    using (SqlConnection connection = new SqlConnection(connection))
    {
        using (SqlCommand command = new SqlCommand(query, connection))
        {
            command.CommandType = CommandType.Text;
            for (int i = 0; i < parameters.Count; i++)
            {
                command.Parameters.Add(parameters[i]);
            }

            command.Connection.Open();
            int rowsAffected = command.ExecuteNonQuery();
            command.Connection.Close();
        }
    }
}

Now I've wrapped the sqlcommand class into a static helper. What I have done is basically removed any need for generated classes (or manually coded... ugh!) functions to create parameters for a sqlcommand. It would probably work for any DBCommand. The point is and DAL generated code is pointless because we can boil it down to a few functions thanks to reflection. Then usage would be something as follows :

 

 
public function Main()
{
    // Read object from Database or create new object
    // Then manipulate said object
    // Update or Insert object into the Database
    
    DalWrapper.ExecuteNonQuery(queryUpdateOrInsert, connection, obj.BuildParameters());
}

Of course my query should really be a store procedure name. At least my BLL / DAL has been condensed by about 75% of what the auto-generated code was, and makes adding new tables and records a breeze since all I really have to do is strong type my object and define the stored procedures.