Tuesday, July 24, 2007

Store and Retrieve Application Settings

I used to store some constant values or messages in Resource file for Web application. It seems a little bit different for Windows application, and I think using this application settings is the alternative.

To Store Settings:

1. Right click on the project file, and select "Properties".

2. Select "Settings" tab.

Here, I've added the connection string, where I select the type to be "(Connection String)". You can also specify the scope as Application or User.

To Retrieve Settings:

You can bind application settings to Windows Forms controls.

1. Select the control, expand the (Application Settings) property, then click on the (PropertyBinding) button to display the Application Settings dialog box below.

2. Select the property that you want to bind to, and select the application settings from the dropdownlist.

OR

You can also select the control, expand the (Application Settings) property, only the bindable property will be shown. Just select the Application Setting that you want to bind from the dropdownlist.

To access the application settings programmatically:

MyExpenseTracker.Properties.Settings.Default.CONNECTIONSTRING

where MyExpenseTracker is the namespace.


OK, the 3 items for last week task have been done. Now, I need to work harder for this week's tasks. Tongue

The other 2 weekly Task for week 16/07/2007 - 22/07/2007:
* How to launch application in Visual Studio 2005?
* DataGridView Prototype

Monday, July 23, 2007

DataGridView prototype

This is the first time I created Windows application using Visual Studio 2005. There are some differences between Windows application development and Web application development.

In order to build a database system, I must learn how to deal with DataGridView which is provided in Windows Application. (Web applications are using GridView.)

This is the prototype I've built based on this tutorial - Presenting Data with the DataGridView Control in .NET 2.0.

Download DataGridView prototype (DataGridViewPrototype.zip : 1.3MB)

I've also included the tutorial which I copied into the Word document, where you just click on the "Open tutorial in Word document" link to launch it. The prototype is not error-free, but hopefully it helps when you want to build a windows application and use this DataGridView control. Happy

Saturday, July 21, 2007

Music-Lyrics Manager

I suddenly have this idea popped up in my mind, simply because we like to listen to songs and sing. But, there's always no lyrics, or we need to search for it. So, I'm thinking of building a small application just to manage the lyrics, and tie it to the song.

I haven't think of the name for the application yet - Music-Lyrics Manager / My Playlist / Music-Lyrics Bank.

These are some ideas in my mind:

- Add music
- Add lyrics
- Link music and lyrics
- Add song to playlist
- While playing the song, display lyrics
- Open windows media player
- Rename filename

Tables:
Song/Lyrics - id, filename, title, artist, language, dateAdded,type (song/lyrics)
SongLyrics - id, songId, lyricsId

I'm still working on another application - MyExpenseTracker. Perhaps I'll start this after I've completed that. Just to jot down what's in my mind first, in case I forget later. Smile

Wednesday, July 18, 2007

How to Launch application in Visual Studio 2005?

In VB6, I was using this ShellExecute API to launch an external application, such as opening a Word document.

I was searching around, and finally I found this method, and it's so simple.

Just use System.Diagnostics.Process.Start() to launch the application.

string filename = Application.StartupPath + "\\Tutorials\\DataGridViewTutorial01.doc";
System.Diagnostics.Process.Start(filename);

 

As for the Application.StartupPath, it actually refers to the "bin\Debug" folder. (It depends on the build configuration, it refers to "bin\Release" folder if the build configuration is set to "Release".) In order to get the filename correctly, I've made some changes on the document properties.



1. Add the document to the project.

2. Select the document and look for its properties.

3. There are three options for the "Copy to Output Directory" property: Do not copy, Copy always, and Copy if newer. You may select "Copy always" or "Copy if newer", so that whenever you build your project, the latest version will be copied to the output directory. And Application.StartupPath is actually referring to this output directory.


Weekly Task

When I was in my ex-company, there was once we have to submit 3 assignments per week together with 3 proposals for the next week assignments. I think this is a good idea to improve our programming skills and also motivate ourselves. But, too bad, the plan didn't really go well, I think just two or three weeks, then it died.

Just now when I was sitting in the car, suddenly this idea popped up in my mind. I always agree that it's a good idea, so why not I myself implement it?

OK. This is the plan.

- 3 items a week.
- Item can be prototype, function, java script, tip, tutorial, knowledge, news, just anything that I've learnt regarding software development.

I was thinking, even though when I'm busy with work, I'll definitely learn something. So, it's always good to build the habit to keep record of what I've learnt.

Well, just do it from now onwards. Hope that I can get some friends to join my plan later, so that we'll learn more and get motivated from others. Party

Monday, July 16, 2007

OOAD UML

OOAD UML OOAD UML - For Architects & Designers

I've just found this website for Object-Oriented Analysis & Design.
There is this Free Books section that you can find some good tutorials regarding OOAD.
There are also articles and forum for more useful resources.

The site seems to be quite new, hopefully it'll continue to grow.

Wednesday, July 11, 2007

Free Visual Studio 2005 Express editions

I didn't know this Express software has become free forever.
This is a good news for those who want to learn the programming, but do not need to buy the software.
I can't remember what the limitations are, coz after not long I downloaded the Express version, my company bought the full version. As long as we can use this Express version to learn programming, I guess it's quite enough. Moreover, you can also download the SQL Server Express.

Click here to find more information or download the Express edition softwares:
http://msdn.microsoft.com/vstudio/express/

I just found out these good resources, which can help us to learn throughout the way:
* Beginner Developer Learning Center
* How-To Reference Library
* Kids' Corner (This is cool! You can even teach your kids to do programming now)

Thursday, July 5, 2007

My First Ajax Application

This is considered as my first Ajax application, though it's very simple.
My boss was complaining the page keeps flickering when users perform some actions on the website.
It's because the users always need to request something from the server, so many controls trigger post-back.
This solution can definitely please him. :p
Actually I should have looked into Ajax earlier, coz it's very easy to implement.

Prerequisite: Installed Ajax Extensions 1.0.
Firstly, create a new website.
Select "ASP.NET AJAX-Enabled Web Site" under the Visual Studio installed templates category.
New Ajax Website

Once you've installed Ajax Extensions, you'll see a tab "AJAX Extensions" added in your toolbox.
Drag and drop the "UpdatePanel" to your web form.
UpdatePanel

I've made a very simple example here, to demonstrate the difference between with Ajax and without Ajax methods.

I've used the following controls:
(1) DropDownList - to list the selection items
(2) Button - to select the particular item
(3) Label - to display the selected item
Ajax example
Well, I don't know what's the "ScriptManager" about, it was automatically added when I first created the website. I just put the three controls in the UpdatePanel for Ajax demo.

In the example, you'll see with Ajax components, the page doesn't flicker when you send request to the server.

Ajax example

Tuesday, July 3, 2007

Create DataSet

I always wanted to create the DataSet manually, without having to fill the DataSet from the DataAdapter.

The example is to get all 12 months, this is how the DataSet looks like:
DataSet
This is how I did it:

public static DataSet GetAllMonths()
{
//Create new DataSet
DataSet dsMonth = new
DataSet ();
//Create new DataTable
DataTable dtMonth =
new DataTable ("Month");
//Create two DataColumns: Id & Month
DataColumn dcMonth =
new DataColumn ("Month");
DataColumn dcId = new DataColumn ("Id");

//Add the columns to the DataTable
dtMonth.Columns.Add(dcId);
dtMonth.Columns.Add(dcMonth);

//Add the 12 months to the DataTable
_AddMonthToDataTable(ref dtMonth, 1, "January");
_AddMonthToDataTable(
ref dtMonth, 2, "February");
_AddMonthToDataTable(
ref dtMonth, 3, "March");
_AddMonthToDataTable(
ref dtMonth, 4, "April");
_AddMonthToDataTable(
ref dtMonth, 5, "May");
_AddMonthToDataTable(
ref dtMonth, 6, "June");
_AddMonthToDataTable(
ref dtMonth, 7, "July");
_AddMonthToDataTable(
ref dtMonth, 8, "August");
_AddMonthToDataTable(
ref dtMonth, 9, "September");
_AddMonthToDataTable(
ref dtMonth, 10, "October");
_AddMonthToDataTable(
ref dtMonth, 11, "November");
_AddMonthToDataTable(
ref dtMonth, 12, "December");

//Add the DataTable to DataSet
dsMonth.Tables.Add(dtMonth);

return dsMonth;
}

private static void _AddMonthToDataTable(
ref DataTable dt, int id, string month)
{
//Create new DataRow to the DataTable
DataRow dr = dt.NewRow();
//Assign values to the data columns
dr["Id"] = id;
dr["Month"] = month;
//Add the DataRow to the DataTable
dt.Rows.Add(dr);
}