by Sameera 6/18/2008 7:22:00 PM

I have made a few updates for my Generic Database Wrapper class. The update contains a bug fix along with several additional methods for supporting DbParameters.

The new source file can be downloaded here. I have also updated the file linked to the original post.

by sameera 2/15/2008 9:08:20 PM

After weeks of inactivity, I finally managed to get a demo project in place for the BreadCrumbs controls. You can download it here. The code includes few updates I have made since the last version. For the sake of flexibility, I have kept the basic control as simple as possible. In the demo, I have added few additional helper classes to provide the full functionality desired.

Extending the control is pretty simple too. For instance, to display the menus for each of the sub items in a list item, you handle the SubItemClicked event. The SubItemClickedEventArgs passed to you along with this event provides you with the row index, column index and the bottom-left corner pixel coordinates of the sub item. In the demo app, this event handled as;

[code:c#]
void ListBox_SubItemClicked(object sender, BreadCrumbsListBox.SubItemClickedEventArgs e)
{
    ContextMenuStrip menu = null;
    if (e.ColumnIndex == 1 && breadCrumbsList.ListBox.SelectedItem != null)
        menu = GetTemplateMenu(breadCrumbsList.ListBox.SelectedIndex);
    else
        menu = _entityMenu;
    menu.Show(breadCrumbsList, breadCrumbsList.PointToClient(e.BottomLeftCorner));
}
[/code]

Here, the _entityMenu is a pre-constructed menu while as the "Template Menu" is reconstructed every time based on the selection.

by sameera 12/1/2007 9:16:00 AM

Due to a life changing experience that I ran into 2 weeks ago, I've been unable to continue on with my regular R&D work. I've got a small breather that might last the rest of the week and so figured I should try to finish up some of my projects: 1st off, I managed some work on the Bread Crumbs list control.

Here's what the control looks right now:

image
Items support Hot-Tracking
image
Vista's Windows Explorer style item selection
image
Sub-item selection
image
Sub-item Menu Support

Also added support for item editing:

image

Design

The controls design is pretty basic and the code not overly elegant at this stage.

BreadCrumbsDesign

Each row on the List Box is an instance of the BreadCrumbsItem class. The BreadCrumbsItem holds an array of strings with each element corresponding to  an individual column. The list box requires that you insert only items with equal number of columns. Otherwise an exception will be thrown.

I had trouble getting the scrollbars inherent in UserControl/ContainerControl to function properly. The OnScroll method wasn't receiving the proper scroll value and was reverting to 0 all the time. So, I had to go with adding a vertical scroll bar manually. Anyway, check out the code (49.5 KB zipped folder).

by Sameera 11/7/2007 7:28:00 PM

As a guy who started programming back in the days of DAO, I have nothing but love for ADO.NET. But let's face it, you can still end up writing pretty lousy code with it. Not everybody's fully aware of the best uses of the ADO.NET. One of the most common problems I keep stumbling onto in other peoples code is the poor use of ADO.NET Connection Pooling feature.

Somewhere, down the line Microsoft probably started noticing that their cool new data access model wasn't being fully utilized. The birth of the Microsoft Enterprise Library was probably due to this.

As cool as the Enterprise Library is, I've found it to be an over kill for most of my projects. In fact one of my favorite projects featured on CodeProject, was because Enterprise Library's Offline Application Block was so clunky (and very limited).

Around the same time that I worked on on the SCOAB (Smart Client Offline Application Block), I also wrote a ADO.NET wrapper similar to the Enterprise Library. It pretty much follows the public interface of the Enterprise Library, but it's a very tiny wrapper compared to the enormous DAAB (Data Access Application Block).

You can download the .cs file here: AbstractDatabase.zip (1.88 kb)

This contains a generic abstract base class called AbstractDatabase. You can extend this class to use it with any type of relational database type. If you take a look at my SQLite Membership Provider, you'll find this class derived to be used with SQLite ADO.NET Wrapper. I have simply called that class Database, and it's code looks something like this:

[code:c#]
public class Database : AbstractDatabase<SQLiteConnection, SQLiteCommand, SQLiteDataAdapter>
{
    protected override string  GetConnectionString()
    {
        return string.Format(ConfigurationManager.ConnectionStrings["BlogEngine"].ConnectionString,
                            HttpContext.Current.Server.MapPath("~/App_Data"));
    }
}
[/code]

As you see, the only member you need to override is the GetConnectionString() method. This brings up the question as to why I made this abstract. Why not read the connection string value from the web.config? Well, I've done this because I use this class on both web and desktop projects. And in some cases, especially with WinForms applications, the database is SQLite and resides in the application directory. When that happens, I can always hard code the database file name.

Here's a example of the the Database class's usage (taken from the SQLiteBlogProvier class).

[code:c#]
using (Database db = new Database())
    using (DbTransaction txn = db.BeginTransaction())
    {
        DbCommand cmd = db.GetSqlStringCommand("DELETE FROM be_Settings"); // SQLite doesn't support TRUNCATE
        db.ExecuteNonQuery(cmd, txn);

        cmd = db.GetSqlStringCommand(
            "INSERT INTO be_Settings (SettingName, SettingValue) VALUES (@name, @value)");
        db.AddInParameter(cmd, "@name", DbType.String, "");
        db.AddInParameter(cmd, "@value", DbType.String, "");
        foreach (string key in settings.Keys)
        {
            cmd.Parameters[0].Value = key;
            cmd.Parameters[1].Value = settings[key];
            cmd.ExecuteNonQuery();
        }
        txn.Commit();
    }
[/code]

A quick rundown of the public interface of AbstractDatabase class:

[code:c#]
void AddInParameter(System.Data.Common.DbCommand, string, System.Data.DbType, object)
void AddInParameter(System.Data.Common.DbCommand, string, System.Data.DbType, int, object)
DbTransaction BeginTransaction()
void Dispose()
DataSet ExecuteDataSet(System.Data.Common.DbCommand)
int ExecuteNonQuery(System.Data.Common.DbCommand)
ExecuteNonQuery(System.Data.Common.DbCommand, System.Data.Common.DbTransaction)
DbReader ExecuteReader(System.Data.Common.DbCommand)
ExecuteReader(System.Data.Common.DbCommand, System.Data.CommandBehavior)
T ExecuteScalar<T>(System.Data.Common.DbCommand, T)
abstract string GetConnectionString()
DbCommand GetSqlStringCommand(string)
DbCommand GetSqlStringCommand(string, params object[])
DbCommand GetStoredProcedureCommand(string)
Connection { get; }
[/code]

Update (June 20, 2008): I have updated this class with a minor bug fix and have added support for other parmeter types including Output and InputOuput parameters (Thanks Yordan).

by Sameera 10/20/2007 5:01:00 PM

Click here to download the project (2.9 MB ZIP file).

Files that were harmed during the makings of BlogEngine.NET 1.2 SQLite Edition Big Grin:

Moved

  • Moved TinyMCE out of Admin folder (which has restircted accesses) to a new Common folder. This was done to fix the problem of simlies being hidden from non-member users.

Added/Deleted

  • None

Modified

  • Take a look at this comprehensive folder comparison report (2.8 MB compressed folder containing folder comparison report in HTML format).

The above files are hosted on my SkyDrive.

Next Up:

There are few configuration steps that you'd need to go through before using BE.NET with SQLite. Hopefully, I'd be able to explain them in my next post. I seem to have messed up the live preview for comments.Oops! I'd have to check that out now.

About the author
Sameera Perera Sameera Perera Feed
Code, art and a whole lot of attitude...

E-mail me Send mail

Calendar
<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar
Recent comments
Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

All forms of source code published on Codoxide.com and CodeOfDefiance.com are distributed under the Apache License, Version 2.0 unless otherwise stated.
The rest of the content are published under a Creative Commons Attribution 3.0 License.
Creative Commons License

Sign in


CodoxideTM
Powered by BlogEngine.NET 1.2.0.0