Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version

Rating Demystified: Ajax Way, Amazon Way*

, 16 Aug 2008 CPOL
Ever wondered, how the amazon rating system works with multiple items in the same page, here is a simple article to describe the basic bare bones needed to create an asynchronous rating module using ASP.NET , SQL Server and ..... AJAX
Rating.zip
Rating
bin
Rating.dll
Rating.pdb
Global.asax
images
0.gif
0rating.gif
0star.gif
1.gif
1star.gif
2.gif
2star.gif
3.gif
3star.gif
4.gif
4star.gif
5.gif
5star.gif
ajax.jpg
morestars.jpg
morestars.psd
saved.gif
spacer.gif
stars0.gif
stars1.5.gif
stars1.gif
stars2.5.gif
stars2.gif
stars3.5.gif
stars3.gif
stars4.5.gif
stars4.gif
stars5.gif
Thumbs.db
Rating.csproj.webinfo
Rating.suo
//*****************************************************************************************************************
//Class name : clsDataAccess 
//Defination : This class is the most important class as it does all the updating,Inserting,deleting,Retrieving
//part in the database.The methods in this class is called by all the other methods in other classes.Connection
//with the database is set up here only.Added this class after analysis phase.
//any attributes in any class the only thing which is used is
//a query and nothing else. 
//Date Added : 11/23/03
//Author     : Rajesh Lal Connectrajesh@hotmail.com 
//*****************************************************************************************************************

using System;
using System.Configuration;
using System.Data; 
using System.Data.SqlClient; 

namespace Rating
{
	/// Summary description for clsDataAccess.
	
	public class clsDataAccess // Class defination
	{
		public clsDataAccess()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		 
		SqlConnection mycon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);  
 		
		public bool openConnection() // Opens database connection with Granth in SQL SERVER
		{
			mycon.Open();
 		return true;
		}
		public void closeConnection() // Closes database connection with Granth in SQL SERVER
		{
		mycon.Close(); 
		mycon = null;
		}
		public SqlDataReader getData(string query) // Getdata from the table required(given in query)in datareader
		{
			SqlCommand sqlCommand = new SqlCommand();
			sqlCommand.CommandText= query;
			sqlCommand.Connection=mycon;
			SqlDataReader myr = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
            return myr;
			 
		}
		public void saveData(string query) // Save data usually,inserts and updates the data in table given in query
		{
			SqlCommand sqlCommand = new SqlCommand();
			sqlCommand.CommandText= query;
			sqlCommand.Connection=mycon;
			sqlCommand.ExecuteNonQuery();
			sqlCommand.Dispose();  
			
		}
		public void saveNewData(string query) // Save data usually,inserts and updates the data in table given in query
		{
			SqlCommand sqlCommand = new SqlCommand();
			sqlCommand.CommandText= query;
			sqlCommand.Connection=mycon;
			sqlCommand.ExecuteNonQuery();
			sqlCommand.Dispose();  
			
		}
		
		public int DeleteData(string query) // Delete data in database depending on the tablename given in query.
		{
			SqlCommand sqlCommand = new SqlCommand();
			sqlCommand.CommandText= query;
			sqlCommand.Connection=mycon;
			return sqlCommand.ExecuteNonQuery();
			
		}
		public DataSet getDatabyPaging(string query) // Get data by paging using datagrid which returns the dataset in datagris
		{
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(query,mycon);
			DataSet dataSet = new DataSet();
			sqlDataAdapter.Fill(dataSet,"Media");
			return dataSet;
			
		}
		public int getCheck(string query) // check a particular value to see the validity of mediaid and userid.This method is called in media and user class.
		{
			int i;
			SqlCommand sqlCommand = new SqlCommand();
			sqlCommand.CommandText= query;
			sqlCommand.Connection=mycon;
			i = Convert.ToInt32(sqlCommand.ExecuteScalar());
			return i;
		}
		public SqlDataAdapter getDataforUpdate(string query) // Get data by paging using datagrid which returns the dataset in datagris
		{
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(query,mycon);
			DataSet dataSet = new DataSet();
			//sqlDataAdapter.Fill(dataSet,"NewData");
			return sqlDataAdapter;
		}
		public string getValue(string query,int j) // Get a value of limit from the database table Employees to check before issuing media.
		{
			string i ="0";
			
			SqlCommand sqlCommand = new SqlCommand();
			sqlCommand.CommandText= query;
			sqlCommand.Connection=mycon;
			SqlDataReader myReader = sqlCommand.ExecuteReader();
			
			if( myReader.Read()==true)
			{
				
				i=myReader.GetValue(j).ToString();
				
			}
			myReader.Close(); 
			return i;
		}
		
		public string getCategory(int i)
		{
			string Category ="none";
			if (i ==1)
				Category  = "General";
			else if (i ==2)
				Category = "Freshers / College graduates";
			else if (i ==3)
				Category = "Accounting/Finance";
			else if (i ==4)
				Category = "Computer Hardware";
			else if (i ==5)
				Category = "Computer Software / Internet";
			else if (i ==6)
				Category = "Electric/Electronic";
				
			else if (i ==8)
				Category = "Graphics/Multimedia";
			else if (i ==9)
				Category = "Health Care/Medical";
			else if (i ==10)
				Category = "Human Resources";
			else if (i ==11)
				Category = "IQ/EQ/Behavioral";
			else if (i ==12)
				Category = "Law/Legal";
			else if (i ==13)
				Category = "Management/Consulting";
			else if (i ==14)
				Category = "Sales/Marketing";
			else if (i ==15)
				Category = "Visa Interview";
			else if (i ==16)
				Category = "Others";
			else if (i ==18)
				Category = "Elite Members";
			return Category;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 16 Aug 2008
Article Copyright 2006 by Raj Lal
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid