Saturday, October 10, 2009

Simple way of using Flash file in ASP.Net web application

You can easily use flash movie file in our asp.net web application. For this purpose I am using FlashControl.dll which is downloadable from here. Download free version. It works fine.

First, you have to add this control to visual studio 2008 toolbox. To do this, put FlashControl.dll file to folder of your choice. I am kept it to C:\Program Files\Microsoft ASP.NET\. Now in Visual Studio, open the Toolbox window, right-click on a tab. Select “Add Tab” option. Name it “Flash” and click ok to add new tab named “Flash”. Now right-click on “Flash” tab and select "Choose items..." option. Choose Toolbox Items dialog box opens. On the ".Net Framework components" tab click "Browse..." and select the "FlashControl.dll" file from the location you kept it. I this case it is C:\Program Files\Microsoft ASP.NET\. Check that flash control is added in the list and is selected. Click OK button to add it to toolbox.

Now take a new website project. Open your default.aspx file. Now drag and drop it on your page and set MovieUrl properties to your .swf file path. In this case MovieUrl= "~/Movie/8311.swf". Optionally you can set height and width. Note that in your source page added two tags:

<%@ Register Assembly="FlashControl" Namespace="Bewise.Web.UI.WebControls" TagPrefix="Bewise" %>

<Bewise:FlashControl ID="FlashControl1" runat="server" MovieUrl="~/Movie/8311.swf" Height="223px" Width="363px" Loop="True" />

If you don't want to have FlashControl in Visual Studio Toolbox, you can do this way:

Add a reference to FlashControl.dll in your web project, then cut and paste the following code in the source view of your aspx page:

<%@ Register Assembly="FlashControl" Namespace="Bewise.Web.UI.WebControls" TagPrefix="Bewise" %>

<Bewise:FlashControl ID="FlashControl1" runat="server" MovieUrl="~/Movie/8311.swf" Height="223px" Width="363px" Loop="True" />

You can change any FlashControl’s properties (Height, Width, Menu, Loop, Scale ...) in the designer view, by using the Smart Tag or in the Properties Window.

Now run your application to enjoy flash movie on you ASP.Net web applicat

Monday, August 17, 2009

Organization chart generator

A common requirements in most of software's is to generate an hierarchical chart for example organization chart. Rotem Sapir written a DLL to make the task easier and it was published in codeproject. Rotem demonstrated the way of generating tree with text. I have modified his DLL so that we can display both picture and text so that the diagram representation becomes more appealing. Now it will generate chart like following one:



















You can get updated component from here. For details of how it works please read Rotem's article from codeproject.

Friday, August 7, 2009

Create Single Instance Application using Mutex

Mutex is a windows kernel level object typically used for thread synchronization across AppDomain and Process boundaries. We can easily use Mutex to confirm that only one instance of our application will run at a time. Following code snippet shows the way of achieving the goal:
using System;
using System.Windows.Forms;
using System.Threading;

namespace SingleInstanceApp
{
static class Program
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Mutex objMutex = null;
const string MutexName = "THEONE";
try
{
//Open Mutex if already exists
objMutex = Mutex.OpenExisting(MutexName);
}
catch (WaitHandleCannotBeOpenedException)
{
//Cannot be opened because no Mutex exists
}
if (objMutex == null)
{
//Create a new instance of Mutex
objMutex = new Mutex(true, MutexName);
}
else
{
//Close Mutex because one instance already exists
objMutex.Close();
return;
}
Application.Run(new MainForm());
}
}
}

Wednesday, July 15, 2009

Design Enterprise Application with VS2008

Microsoft Visual Studio 2008 gives us easy way design an enterprise application. Here I will demonstrate step by step process of designing application using MS Visual Studio 2008.

Create a new application design project:
1. From File menu select New>Project.
2. From new project dialog box select Distributed System project type and Application Design from templates.
3. Put ERP in name and press OK button. Application design window opens.


Design the system:
1. From Toolbox drag an ASP.NetWebApplication to Application Design window.
Set the following properties:
Name: ERP
Project: ERP
Default Class Namespace: Erp.Web.UI
Language: Visual C#
Project Location Type: File System
Target Framework: .NET Framework 3.5
Template: ASP.NET Web Site
Web Content: Dynamic

2. Drag an ASP.NetWebService to Application Design window.
Set the following properties:
Name: POSService
Project: POSService
Default Class Namespace: POSService
Language: Visual C#
Project Location Type: File System
Target Framework: .NET Framework 3.5
Template: Empty Web Site
Web Content: Dynamic

3. Drag another ASP.NetWebService to Application Design window.
Set the following properties:
Name: ParserService
Project: ParserService
Default Class Namespace: ParserService
Language: Visual C#
Project Location Type: File System
Target Framework: .NET Framework 3.5
Template: Empty Web Site
Web Content: Dynamic

4. Drag a WindowsApplication to Application Design window.
Set the following properties:
Name: POSClient
Project: POSClient
Language: Visual C#
Target Framework: .NET Framework 3.5
Template: Windows Forms Application

5. Drag another WindowsApplication to Application Design window.
Set the following properties:
Name: ParserClient
Project: ParserClient
Language: Visual C#
Target Framework: .NET Framework 3.5
Template: Windows Forms Application

6. Drag an External Database and set name properties to ErpDB.

The design should look like the following figure:





























Now we will connect each application end point.

Connect ASP.NetWebApplication to Database:
1. Right click on ASP.NetWebApplication.
2. Select Connect. Create connection window appears.
















3. Select ErpDB from Application drop down list in Connect to panel and click OK.
4. SQL Server Connection Properties window will appear. Provide your connection information and click OK button. Connection to ERP and ErpDB will be established.

This way connect:
POSService to ERP ,
POSClient to POSService,
ParserService to ERP and
ParserClient to ParserService .

Match your design to following figure:






























Our design is OK. Now we will implement the design so that we get application framework.
Implement the design:
1. Right click on design window. Select Implement All Applications.
2. Confirm Application Implementation dialog box appears. Press OK button.

Notice that in Solution Explorer, you will see five new projects added. Now your framework is ready and go ahead with further coding.

Monday, July 13, 2009

Increase database performance with proper indexing (A practical experience explained)

Relational databases used index to find out data quickly. An Index is an underlying structure that determines how data is stored. Proper Indexing can increase your database's overall performance when your database becomes larger. Recently I have worked with a medical customer who uses software for their Pathology department developed by other party. Problem with that software was that it becomes slower by the end of month when data size overcomes 150MB. I was engaged to solve the problem.

I have changed inline queries to stored procedure which increased performance a bit. But when I have created Index, performance increased drastically.

Let’s see how to identify fields for indexing:

I have identified queries on tables that have heavy data load. Then I have identified fields of the table that are not primary key or don’t contain foreign key reference but they are used in query's where clause or group by clause. For example, I have a table named "
RequestCompositList" with primary key field "ID" and I have following queries on this table that is called frequently:

SELECT ID, ReqID, CID,
FROM RequestCompositList
WHERE ReqID='0152435' AND CID ='546466'

or

SELECT Count(ID), ReqID
FROM RequestCompositList
GROUP BY
ReqID

In this table I have created two non-clustered index on RequestCompositList table for example: IX_RequestCompositList_ReqID and IX_RequestCompositList_CID, this drastically increases my query performance on this table.

I kept some consideration in mind while creating index on this database:
1. Index a field which is frequently used for searching.
2. No indexing on tables with little data.

This worked for me. Hope will work for others also.