Archive for November, 2006

Persistent objects in .Net

This year my enterprise is growing very fast and a lot of new software requests are coming every month. Unfortunately we couldn’t get new employees, we’re a small company, so we looked around for something that could speed up the development process. This month i found a very interesting .net library, DevExpress XPO.
This library is something fantastic, with it you can have a total abstraction from the database layer of your applications so you don’t have to write a single row of code to add, modify, delete records from databases!

The only thing to do is a good Object Orientet Programming analysis for your application but i thing that everyone using .Net is familiar with it :)

All you have to do is:

  • Provide the connection string to a database (if you don’t provide it XPO will create an ACCESS .MDB database as default)
  • Design your classes inheriting from XPObject class
  • Call the Save, Delete method of your new class to store or delete data, it’s done!!!
  • Querying is really simple, i’ll show you later

An example:

public class User _
inherits XPObject

public Name as string
public Surname as string
public Phone as string
end class

In your program you just have to:

dim newUser as new User
newUser.Name=”John”
newUser.Surname=”Smith”
newUser.Save()

DONE!

Querying records:

If we want the full Users list we just need to do this:

dim Users as new XPCollection(Of User)

for each usr as User in Users
MessageBox.Show(usr.Name + ” ” + usr.Surname)
next

If you want to delete the 4th user you can just call Users(3).Delete() and it’s done (index starts from ZERO)

More complex queryes can be done using a Criteria, it’s long to explain you can find complete infos on www.devexpress.com

Personal experience
I bought Devexpress XPO last week so i have to be considered a newbie but it’s so easy that i finished a complete software in four days. My customer paid me so i can say i made a great choice, i spent 180$ and i earned 3500$ in few days. Without XPO my project progress would have been about 20%.

Great choice, i suggest it to everyone that needs TIME! Consider that you’ll be able to deliver 3 projects in the time you needed to deliver just 1.

Last consideration
Last but not less important thing i forgot is that if you use XPO you can change the database platform without writing a single row of code. XPO creates databases, tables, records everything database related!!!

Supported DB Engines

  • SQL Server
  • Access
  • MySQL
  • Oracle
  • PostgreSQL
  • Firebird
  • PervasiveSQL
  • VistaDB
  • SQL Anywhere
  • Advantage
  • DB2
  • Sybase

In each moment you can decide to make a different DB Engine version of your software just changing the connection string, no other rows of code needs to be touched!!!


TAGS: Asp.net, dotnet, code snippet, seo, search engine optimization, visual studio.net, sample code, c#, vb.net

Software for technical attendance of household-electric

This month we finished our new software GECAT.
It’s a management software for tecnical attendance specialized centers.

GECAT functionalities:

  • Manage incoming attendance request calls
  • Manage technicians appointments
  • Manage warranties
  • Manage product store
  • Manage store transfers
  • Manage cash
  • Reports

GECAT is an easy to use software developed in vb.net and mysql using the .Net framework 1.0
Our software is designed for GIAS associate attendance centers (CANDY) but it can be modified to be used by other trademarks attendance centers like ARISTON, HOOVER, etc…

We’re looking for a foreign publisher to sell our product in Europe, all requests are welcome.

To give a look at software brochure visit www.gecat.it or www.ryhab.com


TAGS: Asp.net, dotnet, code snippet, seo, search engine optimization, visual studio.net, sample code, c#, vb.net

AJAX in .Net - ATLAS

The most boring thing of websites is the continuos page reloading, it takes a lot of bandwidth and when site users number grows you can experience notable slowdowns. In the past i tried to use Remote Scripting but it was time expensive considering the project delivery time, so i decided to give up. With ATLAS (it’s Microsoft AJAX Library) everything becomes really easy and powerful. First thing i tried was to fill a combobox when i changed the selectedindex of another combobox. The result was really nice, no more full page reloading!!!
Try to thing a situation like Country selection, then City selection. When the country changes you have to fill the Cities combo to let the user choose it. If your website has a lot of graphics it could be very boring using the traditional postback approach.

HOW TO START
Download and install the ATLAS library, you can find it on google, search for “ASPAJAXExtSetup.msi”

NEW CONTROLS IN VISUAL STUDIO
After the installation you can find in Visual Studio.net 2005 a new tab of controls named AJAX EXTENSIONS.
Try to create a new website selecting “ASP.NET AJAX-Enabled website”.

THE NEW ATLAS CONTROLS
In the controls toolbar you can find the new tab AJAX Extensions with the following new controls:

  • Timer
    Very useful functionality to execute temporized tasks
  • ScriptManager
    This is a fundamental ATLAS control, you have to instanciate it in each page you want to have the ATLAS support. If you are using MasterPages you can place it inside the MasterPage so you have no need to put it in each website page.
  • ScriptManagerProxy
    You may have a ScriptManager on your master page, but you may want to add additional script or service references in your content page. However, you can only have one ScriptManager on your page. Therefore we have the accompanying ScriptManagerProxy control.
  • UpdateProgress
    This is useful if you want to show something during the update progress. If you have a button lo fill a datagrid, when you click it the updateprogress content will be shown, then when the datagrid is filled the updateprogress content disappear
  • UpdatePanel
    This is the most important ATLAS control, everything you put inside it will be AJAX enabled. Consider the above example of Country/City, if you put the two comboboxes inside an UpdatePanel you’ll se that the page will not be completely reloaded on the Country postback, you’ll just see the City combobox content changing.

As you can see it’s really simple to add AJAX functionalities to your websites :)
This is just the starting point of the ATLAS programming but it can be useful to know what you can do…

CONSIDERATIONS
AJAX functionalities are really nice but consider that the extensions are in beta release so you may experience bugs.
A known bug is that the FileUpload control doesn’t work if placed inside an UpdatePanel but there will be something else :)


TAGS: Asp.net, dotnet, code snippet, seo, search engine optimization, visual studio.net, sample code, c#, vb.net

High quality thumbnails in VB.Net

When i started .Net programming i appreciated all the new functionalities of the framework, everything was easier and faster to do. I tought the same thing about thumbnails generation when i found the GetThumbnailImage method of the System.Drawing.Bitmap class but giving a deeper look at it’s behaviour i understood it was not so easy.

WHY IT WASN’T SO EASY
The GetThumbnailImage method isn’t so useful because image formats like JPG can store the thumbnail image inside the same file. A lot of graphics softwares store the thumbnail version of the image into the .JPG file and you can’t choose it’s width, height and quality. The GetThumbnailImage method checks if there’s a thumbnail image stored into the file and, if the thumb is found, it returns that thumbnail version scaled to the width and height you requested. If the thumbnail version of the image is smaller then the size you asked for you can imagine what will be the result, a very low quality and pixelated image. If you want to have the full control over the thumbnail quality you have to use something different by the GetThumbnailImage method.

THE APPROACH
What we have to do is to load the JPG file into a System.Drawing.Image object, scale it to the desired width and height preserving a good quality and save it to a new file.

To preserve the image quality we have to follow these few steps:

  • Load the original file into a System.Drawing.Image object
  • Create the target image with the desired size as System.Drawing.Bitmap
  • Create a System.Drawing.Graphics object from the target Bitmap to draw the scaled image
  • Set the System.Drawing.Graphics object property SmoothingMode to HighQuality
  • Set the System.Drawing.Graphics object property CompositingQuality to HighQuality
  • Set the System.Drawing.Graphics object property InterpolationMode to High
  • Draw the original image into the target Graphics object scaling to the desired width and height
  • Get the System.Drawing.Imaging.ImageCodecInfo object of the JPEG file format
  • Set the Codec param System.Drawing.Imaging.Encoder.Quality to the desired quality (for jpg is 0-100)
  • Save the new image using the Codec and the filled quality parameter

THE CODE
I wrote a simple class CImageHelper where i put all the imaging routines, here there’s a simple version with the SaveImage function to save ThumbNails (or scaled versions of any image) with a very high quality.

Click here to download the code


TAGS: Asp.net, dotnet, code snippet, seo, search engine optimization, visual studio.net, sample code, c#, vb.net

Master Pages in VB.Net 2.0

This month i wrote just one article because i was very busy to develop an ecommerce software. I just finished it and i learned new interesting things.

I had to Develop two ecommerce sites for my customer so i preferred to make a really versatile ecommerce solution that could be skinned with templates.

I thought that i had to make something that could cover these aspects:

  • Fully skinnable ecommerce solution so i just need to make html for new customers commerce sites
  • Fully customizable database connections
  • Fully object oriented to make easier to change things
  • Fully customizable email messages
  • Fully customizable payment methods
  • Fully customizable products structure so the customer could sell everything giving the maximum parameters details
  • Unlimited category tree

In the next articles i’ll wrote i’ll cover all the single aspects of this development experience but now i’d like to talk about the more interesting thing i found in asp.net 2.0, the MasterPage architecture.

The main things to understand about MasterPages are these:

  • A MasterPage is a special asp.net 2.0 page (a template page) that can be filled with the HTML Layout of the site so you’ll never need to copy HTML in each site’s page.
  • In a Master Page you can define the content areas using the new ContentPlaceHolder control (it’s just a container where the site “pieces” will be placed).
  • A Master Page acts as a base class for all the site pages you’ll create, so you can write common source code inside it. Ex.: You can check user authentication in the master page if you prefer
  • A website can have all the MasterPages you want and you can load the master page at runtime too. It’s very useful if you plan to use multiple template sites.

Whe you add a new asp.net page to your project, visual studio asks you which master page to use for the new page, you just have to choose one. Consider to make a default template master page and assign it to each page of your site.

Create a simple Asp.net website project and try to add a new MasterPage, fill it with HTML, create ContentPlaceHolders and then add a new WebForm choosing the Master Page. In your new page you’ll see the HTML layout (not editable) and the content placeholders where you can place the page specific content.

A really important thing is the Master Page loading at runtime. I found this functionality really exciting because it solved all my problems.

How to load a master page at runtime

Loading a master page at runtime is really simple, you just have to create the PreInit function for your new pages:

Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
Me.MasterPageFile = Application(“Template”) + “.master”
End Sub

As you can see i have the template name into Application, Application(”Template”).

You can change the site template with just one row of code:

Application(”Template”)=”TemplateBlue”

or

Application(”Template”)=”MyNewTemplate”

remember that to have this functionality you’ll need to write two masterpages:
TemplateBlue.master and MyNewTemplate.master

In this article i’ll not write source code, it’s really simple to do this, just try and in 10 minutes you’ll finish it :)


TAGS: Asp.net, dotnet, code snippet, seo, search engine optimization, visual studio.net, sample code, c#, vb.net