|
|||||||||||||||||||||
|
|||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionThis article describes an ASP.NET web module along with some chunks of Javascripts and ...Ajax to create a Rating System. This can be added /customized for any table to add a rating/score module. I was quite amazed, when i first saw the capability of rating multiple items at amazon website without refreshing the page. That nice piece of functionality followed me like destiny, till i needed to implement it in a web application. Well ! putting it in a live scenario needs much more than just javascript. I started with a bit of frenzied hacking. To understand how exactly it works, by scanning the javascript from online asynchronous rating websites. That was just the beginning, on the way i learned much more than earlier imagined. Here is the result of the effort. The target was to create a cross browser rating/score system like amazon or better:
In ActionTo hold your interest, here is how it will look (for single record), once completed
AssumptionsThose were the initial thoughts, but to make it a general reusable and extensible module, I made some assumptions:
Rating table structure
web.config structure The web.config has four keys, one for the connection string and the other for the name of the fields for RatedBy (for the number of user who rated the record) and Score (For total Score) and the table from which you want to apply the Rating system.
Required images ( included with the source) Final Scores
Pretty self explainatory final score can be in decimals 1, 2.5, 2, 4.5 etc, though while rating the images should be only 1-5 ActionsThese are the actions which make the whole module:
Data access classThere is a standard data access class, clsDataAccess.cs, which handles all the data related actions. Code: I have kept here only the names of the functions, just to give you a glimpse of the data access methods. using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Rating
{
public class clsDataAccess
// Class defination
{
public clsDataAccess()
{ }
SqlConnection mycon = new SqlConnection(
ConfigurationSettings.AppSettings["ConnectionString"]);
// Opens database connection with in SQL SERVER
public bool openConnection()
// Closes database connection with in SQL SERVER
public void closeConnection()
// Getdata from the table required(given in query).
public SqlDataReader getData(string query)
// Save data usually,inserts and updates the data in table.
public void saveData(string query)
// Save data usually,inserts and updates the data.
public void saveNewData(string query)
// Delete data in database depending on the tablename.
public int DeleteData(string query)
// Get data by paging using datagrid.
public SqlDataAdapter getDataforUpdate(string query)
// Get data by paging using datagrid.
public DataSet getDatabyPaging(string query)
// check a particular value to see the validity.
public int getCheck(string query)
// Get a value of limit from the database table.
public string getValue(string query,int j)
//Log in method
public SqlDataReader Login(string query)
// dynamically get all table names
public DataTable getTablenames()
// For Table operations
public int TableWrite(string query)
}
}
Creating rating Images with mouse over: | ||||||||||||||||||||