Tuesday, September 29, 2009

Creating n-tier application

Create Abstract Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace RRL
{
public abstract class Abstract
{
#region private variables
DataTable genrelist = null;
DataTable websiteslist = null;
DataTable youtubelist = null;
DataTable decadelist = null;
DataTable charitylist = null;
DataTable foundationlist = null;
DataTable akalist = null;
DataTable addresslist = null;
DataTable timelinelist = null;
DataTable editorslist = null;
DataTable venuelist = null;
DataTable creatorlist = null;
DataTable designerlist = null;
DataTable manufacturerlist = null;
DataTable ownerlist = null;
DataTable personbandcomp = null;
DataTable recordedlabellist = null;
DataTable recordingstudioslist = null;
DataTable authorlist = null;
DataTable engineerlist=null;
DataTable producerlist = null;
DataTable publisherlist = null;
DataTable samplesongslist = null;
DataTable bookformats = null;
DataTable mediaformats = null;
DataTable videogameversionlist = null;
DataTable rtvendroslist = null;
DataTable producerslist = null;
DataTable tourmanagerslist = null;
DataTable founderlist = null;
DataTable memberslist = null;
DataTable accesslevelslist = null;
DataTable objectslist = null;
DataTable permissionslist = null;
DataTable statuslist = null;


String blogurl, twitterurl, facebookurl, myspaceurl, archiveurl, hi5url;
#endregion



public DataTable VIDEOGAMEVERSIONLIST
{
get { return videogameversionlist; }
set { videogameversionlist = value; }
}
public DataTable OBJECTSLIST
{
get { return objectslist; }
set { objectslist = value; }
}
public DataTable PERMISSIONSLIST
{
get { return permissionslist; }
set { permissionslist = value; }
}
public DataTable STATUSLIST
{
get { return statuslist; }
set { statuslist = value; }
}


public DataTable ACCESSLEVELSLIST
{
get { return accesslevelslist; }
set { accesslevelslist = value; }
}


public DataTable MEMBERSLIST
{
get { return memberslist; }
set { memberslist = value; }
}
public DataTable PRODUCERSLIST
{
get { return producerslist; }
set { producerslist = value; }
}
public DataTable TOURMANAGERSLIST
{
get { return tourmanagerslist; }
set { tourmanagerslist = value; }
}
public DataTable RTVENDORSLIST
{
get { return rtvendroslist; }
set { rtvendroslist = value; }
}


public DataTable BOOKFORMATS
{
get { return bookformats; }
set { bookformats = value; }
}

public DataTable MEDIAFORMATS
{
get { return mediaformats; }
set { mediaformats = value; }
}

public DataTable PersonBandComp
{
get { return personbandcomp; }
set { personbandcomp = value; }
}
public DataTable ENGINEERLIST
{
get { return engineerlist; }
set { engineerlist = value; }
}
public DataTable PRODUCERLIST
{
get { return producerlist; }
set { producerlist = value; }
}

public DataTable SAMPLESONGSLIST
{
get { return samplesongslist; }
set { samplesongslist = value; }
}
public DataTable RECORDINGSTUDIOSLIST
{
get { return recordingstudioslist; }
set { recordingstudioslist = value; }
}

public DataTable RECORDEDLABELLIST
{
get { return recordedlabellist; }
set { recordedlabellist = value; }
}

public DataTable OWNERLIST
{
get { return ownerlist; }
set { ownerlist = value; }
}


public DataTable VENUELIST
{
get { return venuelist; }
set { venuelist = value; }
}
public DataTable CREATORLIST
{
get { return creatorlist; }
set { creatorlist = value; }
}
public DataTable DESIGNERLIST
{
get { return designerlist; }
set { designerlist = value; }
}

public DataTable GENRELIST
{
get { return genrelist; }
set { genrelist = value; }
}
public DataTable WEBSITESLIST
{
get { return websiteslist; }
set { websiteslist = value; }
}
public DataTable YOUTUBELIST
{
get { return youtubelist; }
set { youtubelist = value; }
}
public DataTable DECADELIST
{
get { return decadelist; }
set { decadelist = value; }
}


public DataTable PUBLISHERLIST
{
get { return publisherlist; }
set { publisherlist = value; }
}
public DataTable CHARITYLIST
{
get { return charitylist; }
set { charitylist = value; }
}
public DataTable FOUNDATIONLIST
{
get { return foundationlist; }
set { foundationlist = value; }
}
public DataTable AKALIST
{
get { return akalist; }
set { akalist = value; }
}
public DataTable ADDRESSLIST
{
get { return addresslist; }
set { addresslist = value; }
}
public DataTable AUTHORLIST
{
get { return authorlist; }
set { authorlist = value; }
}
public DataTable TIMELINELIST
{
get { return timelinelist; }
set { timelinelist = value; }
}
public DataTable FOUNDERLIST
{
get { return founderlist; }
set { founderlist = value; }
}
public String BlogUrl
{
get { return blogurl; }
set { blogurl = value; }
}
public String TwitterUrl
{
get { return twitterurl; }
set { twitterurl = value; }
}
public String FaceBookUrl
{
get { return facebookurl; }
set { facebookurl = value; }
}
public String MySpaceUrl
{
get { return myspaceurl; }
set { myspaceurl = value; }
}
public String Hi5Url
{
get { return hi5url; }
set { hi5url = value; }
}
public String ArchiveUrl
{
get { return archiveurl; }
set { archiveurl = value; }
}
public DataTable AuthorList
{
get { return authorlist; }
set { authorlist = value; }
}
public DataTable EditorList
{
get { return editorslist; }
set { editorslist = value; }
}




}
}

-----------------------

Create Abstract Data Access

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccess
{
public abstract class AbstractDA
{
#region privatevariables
SqlConnection con = new SqlConnection();
ConnectionDA varCon = new ConnectionDA();
Exception varEx = new Exception();
#endregion
public AbstractDA()
{
con.ConnectionString = varCon.GetConnection;
}




public DataTable GetCountryList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from countryentitydetail", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetAuthorList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from entity_authors", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetEngineerList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from entity_engineers", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetProducerList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from entity_Producers", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetSampleSongs()
{

SqlDataAdapter da = new SqlDataAdapter("select * from song_samples", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetArtifactList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from artifacttypes", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable MEDIAFORMATS()
{
SqlDataAdapter da = new SqlDataAdapter("select * from entity_mediaformats", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;

}

public DataTable RECORDLABEL()
{
SqlDataAdapter da = new SqlDataAdapter("select * from companyentitydetail where companytypeid=1", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;

}

public DataTable RECORDINGSTUDIOSLIST()
{

SqlDataAdapter da = new SqlDataAdapter("select * from companyentitydetail where companytypeid=4", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

public DataTable GetStateList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from stateentitydetail", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

public DataTable GetStatesofCountry(string countryid)
{

SqlDataAdapter da = new SqlDataAdapter("select * from stateentitydetail where countryentityid=@countryentityid", con);
DataTable dt = new DataTable();
da.SelectCommand.Parameters.AddWithValue("@countryentityid", countryid);
da.Fill(dt);
return dt;
}

public string GetCountryofState(string stateid)
{
SqlCommand cmd = new SqlCommand("select CountryEntityId from stateentitydetail where entityid=@stateid", con);
cmd.Parameters.AddWithValue("@stateid", stateid);
if(con.State==ConnectionState.Closed)
con.Open();
return cmd.ExecuteScalar().ToString();
if(con.State==ConnectionState.Open)
con.Close();
}

public string GetStateofCity(string cityid)
{
SqlCommand cmd = new SqlCommand("select stateEntityId from cityentitydetail where entityid=@cityid", con);
cmd.Parameters.AddWithValue("@cityid", cityid);
if (con.State == ConnectionState.Closed)
con.Open();
return cmd.ExecuteScalar().ToString();
if (con.State == ConnectionState.Open)
con.Close();
}

public DataTable GetCitiesofState(string stateid)
{

SqlDataAdapter da = new SqlDataAdapter("select * from cityentitydetail where stateentityid=@stateentityid", con);
DataTable dt = new DataTable();
da.SelectCommand.Parameters.AddWithValue("@stateentityid", stateid);
da.Fill(dt);
return dt;
}


public DataTable GetCityList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from Cityentitydetail", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetNeighborhoodList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from Neighborhoodentitydetail", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetSongList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from Songentitydetail", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}


public DataTable GetDecadesList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from Decades", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}


public string GetASINObject(string ENTITYID)
{
string ASIN = string.Empty;
//SqlDataAdapter da = new SqlDataAdapter("select commonname,friendlyname,id from Entity,entity_authors,entitytype where entity.id=entity_authors.entityid and entity.entitytypeid=entitytype.id and entity_authors.entityid=@eid", con);
SqlCommand cmd = new SqlCommand("select ASIN from Amazon_ASIN where entityid=@id", con);
cmd.Parameters.AddWithValue("@id", ENTITYID);
try
{if(con.State==ConnectionState.Closed)
con.Open();
ASIN = cmd.ExecuteScalar().ToString();
}
catch
{

//No ASIN Available
}
finally
{if(con.State==ConnectionState.Open)
con.Close();
}
return ASIN;
}


public DataTable GetAuthorsListofObject(string ENTITYID)
{

//SqlDataAdapter da = new SqlDataAdapter("select commonname,friendlyname,id from Entity,entity_authors,entitytype where entity.id=entity_authors.entityid and entity.entitytypeid=entitytype.id and entity_authors.entityid=@eid", con);
SqlDataAdapter da = new SqlDataAdapter("select Person_Band_CompId as id,(select commonname from entity where id=a.Person_Band_CompId) as Name from Entity_Authors a where entityid=@id", con);
da.SelectCommand.Parameters.AddWithValue("@id", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
public DataTable GetEngineersListofObject(string ENTITYID)
{

//SqlDataAdapter da = new SqlDataAdapter("select commonname,friendlyname,id from Entity,entity_authors,entitytype where entity.id=entity_authors.entityid and entity.entitytypeid=entitytype.id and entity_authors.entityid=@eid", con);
SqlDataAdapter da = new SqlDataAdapter("select PersonEntityId as id,(select commonname from entity where id=a.PersonEntityId) as Name from Entity_Engineers a where entityid=@id", con);
da.SelectCommand.Parameters.AddWithValue("@id", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
public DataTable GetProducersListofObject(string ENTITYID)
{

//SqlDataAdapter da = new SqlDataAdapter("select commonname,friendlyname,id from Entity,entity_authors,entitytype where entity.id=entity_authors.entityid and entity.entitytypeid=entitytype.id and entity_authors.entityid=@eid", con);
SqlDataAdapter da = new SqlDataAdapter("select Person_BandEntityId as id,(select commonname from entity where id=a.Person_BandEntityId) as Name from Entity_producers a where entityid=@id", con);
da.SelectCommand.Parameters.AddWithValue("@id", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
public DataTable GetSong_SamplesListofObject(string ENTITYID)
{

//SqlDataAdapter da = new SqlDataAdapter("select commonname,friendlyname,id from Entity,entity_authors,entitytype where entity.id=entity_authors.entityid and entity.entitytypeid=entitytype.id and entity_authors.entityid=@eid", con);
SqlDataAdapter da = new SqlDataAdapter("select samplesongid as id,(select commonname from entity where id=a.SampleSongId) as Name from Song_Samples a where songid=@id", con);
da.SelectCommand.Parameters.AddWithValue("@id", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
public DataTable GetEditorsListofObject(string ENTITYID)
{

//SqlDataAdapter da = new SqlDataAdapter("select commonname,friendlyname,id from Entity,entity_authors,entitytype where entity.id=entity_authors.entityid and entity.entitytypeid=entitytype.id and entity_authors.entityid=@eid", con);
SqlDataAdapter da = new SqlDataAdapter("select Band_PersonId as id,(select commonname from entity where id=e.Band_PersonId) as Name from Entity_Editor e where entityid=@id", con);
da.SelectCommand.Parameters.AddWithValue("@id", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
public DataTable GetBookFormatsList()
{

SqlDataAdapter da = new SqlDataAdapter("select * from BookFormats", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

public DataTable GetBookformatsListofObject(string ENTITYID)
{
SqlDataAdapter da = new SqlDataAdapter("select * from book_bookformats where bookid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}


public DataTable GetMediaFormatsList()
{
SqlDataAdapter da = new SqlDataAdapter("select * from MediaFormats", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

public DataTable GetMediaFormatListofObject(string ENTITYID)
{
SqlDataAdapter da = new SqlDataAdapter("select * from entity_mediaformats where entityid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

public DataTable GetAudioFormatsList()
{
SqlDataAdapter da = new SqlDataAdapter("select * from Aud_Rec_Formats", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

public DataTable GetRighty_LeftyList()
{
SqlDataAdapter da = new SqlDataAdapter("select * from RightyLefty", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetRatingsList()
{
SqlDataAdapter da = new SqlDataAdapter("select * from Ratings", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

public DataTable GetCompanyType()
{
SqlDataAdapter da = new SqlDataAdapter("select * from companytype", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetPresident()
{
SqlDataAdapter da = new SqlDataAdapter("select * from company", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}


//Access Levels

public DataTable GetAccessLevels()
{
SqlDataAdapter da = new SqlDataAdapter("select * from accesslevels", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

//Objects
public DataTable GetUserObjects()
{
SqlDataAdapter da = new SqlDataAdapter("select * from entitytype", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

//Permissions

public DataTable GetUserPermissions()
{
SqlDataAdapter da = new SqlDataAdapter("select * from permissionlevels", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}

//Status
public DataTable GetUserStatus()
{
SqlDataAdapter da = new SqlDataAdapter("select * from entity_state", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}


public DataTable GetAllLanguages()
{
SqlDataAdapter da = new SqlDataAdapter("select * from mb_language", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetAllSoundTypes()
{
SqlDataAdapter da = new SqlDataAdapter("select * from soundtypes", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetPublisherListofObject(string ENTITYID)
{
SqlDataAdapter da = new SqlDataAdapter("select Band_or_Person_CompId as id from entity_people_band_comp where entityid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable GetPublishersList()
{
SqlDataAdapter da = new SqlDataAdapter("select * from companyentitydetail where companytypeid=18", con);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}


public DataTable GetGENRELISTofObject(string ENTITYID)
{
SqlDataAdapter da = new SqlDataAdapter("select genreid as id from entity_genres where entityid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}
public DataTable GetWEBSITESLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select url,urlname,urldescription,urltypeid,isofficialurl from entity_urls where entityid=@eid and urltypeid=1 ", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}
public DataTable GetDecadesListofObject(string ENTITYID)
{
SqlDataAdapter da = new SqlDataAdapter("select decadeid as id from entity_decades where entityid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}
public DataTable GetYOUTUBELISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select youtubeid as id,(select youtubesrc from youtube where id=e.youtubeid ) as name from entity_youtubes e where entityid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}

public DataTable GetTIMELINELISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select timelineid as id,(select timelineurl from timelines where id=e.timelineid ) as name from entity_timelines e where entityid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}


public DataTable GetCHARITYLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select entityid,CompanyName from companyentitydetail where entityid in(select compid from entity_charity where entityid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}
public DataTable GetFOUNDATIONLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select entityid,CompanyName from companyentitydetail where entityid in(select compid from entity_foundation where entityid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}

public DataTable GetVENUELISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select entityid,CompanyName from companyentitydetail where entityid in(select compid from entity_venues where entityid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}
public DataTable GetCREATORLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select id,CommonName as name from entity where id in(select creatorid from entity_creators where entityid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}


public DataTable GetTOURMANAGERSLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select id,CommonName as name from entity where id in(select managerid from tour_managers where tourid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}

public DataTable GetPRODUCERSLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select id,CommonName as name from entity where id in(select person_bandentityid from entity_producers where entityid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}





public DataTable GetDESIGNERLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select id,CommonName as name from entity where id in(select designerid from entity_designer where entityid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}
public DataTable GetOWNERLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select id,CommonName as name from entity where id in(select Person_Band_CompId from entity_Owner where entityid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}

public DataTable GetPeople_Band_CompListofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select id,CommonName as name from entity where id in(select Band_or_Person_CompId from entity_people_band_comp where entityid=@eid)", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}



public DataTable GetAKALISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select AkaText,IsDefault from Entity_Akas where entityid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}
public DataTable GetADDRESSLISTofObject(string ENTITYID)
{

SqlDataAdapter da = new SqlDataAdapter("select AddressTypeId,(select AddresstypeName from AddressType where id=e.AddressTypeId) as TypeName,Address1,Address2,Address3,PlaceId,(select commonname from entity where id=e.PlaceId) as PlaceName,postalCode from Entity_Addresses e where entityid=@eid", con);
da.SelectCommand.Parameters.AddWithValue("@eid", ENTITYID);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];

}


public string GetBlogUrlofObject(string ENTITYID)
{
string BlogUrl = string.Empty;
try
{
if (con.State == ConnectionState.Closed)
con.Open();
SqlCommand cmd_blog = new SqlCommand("select url from entity_urls where entityid=@eid and urltypeid=2 ", con);
cmd_blog.Parameters.AddWithValue("@eid", ENTITYID);

SqlDataReader dr_blog = cmd_blog.ExecuteReader();
if (dr_blog.HasRows)
{

while (dr_blog.Read())
BlogUrl = dr_blog[0].ToString();
}
}
catch
{

}

finally
{
if (con.State == ConnectionState.Open)
con.Close();

}
return BlogUrl;
}



public string GetTwitterUrlofObject(string ENTITYID)
{
string TwitterUrl = string.Empty;
try
{
if (con.State == ConnectionState.Closed)
con.Open();
SqlCommand cmd_twitter = new SqlCommand("select url from entity_urls where entityid=@eid and urltypeid=3 ", con);
cmd_twitter.Parameters.AddWithValue("@eid", ENTITYID);
SqlDataReader dr_twitter = cmd_twitter.ExecuteReader();
if (dr_twitter.HasRows)
{
while (dr_twitter.Read())
TwitterUrl = dr_twitter[0].ToString();
}
}
catch
{

}

finally
{
if (con.State == ConnectionState.Open)
con.Close();

}
return TwitterUrl;

}

public string GetFacebookUrlofObject(string ENTITYID)
{
string FaceBUrl = string.Empty;
try
{
if (con.State == ConnectionState.Closed)
con.Open();
SqlCommand cmd_facebook = new SqlCommand("select url from entity_urls where entityid=@eid and urltypeid=4 ", con);
cmd_facebook.Parameters.AddWithValue("@eid", ENTITYID);
SqlDataReader dr_facebook = cmd_facebook.ExecuteReader();
if (dr_facebook.HasRows)
{
while (dr_facebook.Read())
FaceBUrl = dr_facebook[0].ToString();
}
}
catch
{

}

finally
{
if (con.State == ConnectionState.Open)
con.Close();

}
return FaceBUrl;

}


public string GetHi5UrlofObject(string ENTITYID)
{
string Hi5Url = string.Empty;
try
{
if (con.State == ConnectionState.Closed)
con.Open();
SqlCommand cmd_hi5 = new SqlCommand("select url from entity_urls where entityid=@eid and urltypeid=5 ", con);
cmd_hi5.Parameters.AddWithValue("@eid", ENTITYID);
SqlDataReader dr_Hi5 = cmd_hi5.ExecuteReader();
if (dr_Hi5.HasRows)
{
while (dr_Hi5.Read())
{
Hi5Url= dr_Hi5[0].ToString();
}
}
}
catch
{

}

finally
{
if (con.State == ConnectionState.Open)
con.Close();

}
return Hi5Url;


}

public string GetArchiveUrlofObject(string ENTITYID)
{
string ArchiveUrl = string.Empty;
try
{

if (con.State == ConnectionState.Closed)
con.Open();
SqlCommand cmd_Archive = new SqlCommand("select url from entity_urls where entityid=@eid and urltypeid=7 ", con);
cmd_Archive.Parameters.AddWithValue("@eid", ENTITYID);
SqlDataReader dr_Archive = cmd_Archive.ExecuteReader();
if (dr_Archive.HasRows)
{
while (dr_Archive.Read())
ArchiveUrl = dr_Archive[0].ToString();
}

}
catch
{

}

finally
{
if (con.State == ConnectionState.Open)
con.Close();

}
return ArchiveUrl;

}


public string GetMySpaceUrlofObject(string ENTITYID)
{
string myspaceurl=string.Empty;
try
{

if (con.State == ConnectionState.Closed)
con.Open();
SqlCommand cmd_myspace = new SqlCommand("select url from entity_urls where entityid=@eid and urltypeid=7 ", con);
cmd_myspace.Parameters.AddWithValue("@eid", ENTITYID);
SqlDataReader dr_myspace = cmd_myspace.ExecuteReader();
if (dr_myspace.HasRows)
{
while(dr_myspace.Read())
myspaceurl =dr_myspace[0].ToString();
}

}
catch
{

}

finally
{
if (con.State == ConnectionState.Open)
con.Close();

}
return myspaceurl;

}

}
}
--------------------------------------

Step 1: First Create Object File means with database fields
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RRL
{
public class City : Abstract
{
string entityid;
string entitytypeid;
string citytext;
string stateentityid;
string abbreviation;
string archive;
string decades;
string tagline;
string vanityurl;
bool editorpick;
string tags;
public string ENTITYID
{
get
{
return entityid;
}
set
{
entityid = value;
}
}
public string STATEENTITYID
{
get
{
return stateentityid;
}
set
{
stateentityid = value;
}
}
public string DECADES
{
get
{
return decades;
}
set
{
decades = value;
}
}
public string ENTITYTYPEID
{
get
{
return entitytypeid;
}
set
{
entitytypeid = value;
}
}
public string CITYTEXT
{
get
{
return citytext;
}
set
{
citytext = value;
}
}
public string ABBREVIATION
{
get
{
return abbreviation;
}
set
{
abbreviation = value;
}
}
public string ARCHIVE
{
get
{
return archive;
}
set
{
archive = value;
}

}
public string TAGLINE
{
get
{
return tagline;
}
set
{
tagline = value;
}
}
public string VANITYURL
{
get
{
return vanityurl;
}
set
{
vanityurl = value;
}
}
public bool EDITORPICK
{
get
{
return editorpick;
}
set
{
editorpick = value;
}
}
public string TAGS
{
get
{
return tags;
}
set
{
tags = value;
}
}
}
}
---------------------------------
Step 2: Create Data Access Layer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RRL;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess
{
public class CityDA :AbstractDA
{
City vCity= null;
SqlConnection con = new SqlConnection();
ConnectionDA objCon = new ConnectionDA();
SqlCommand cmd_entity;

#region ICityDA Members
public CityDA(City vnewCity)
{
vCity = vnewCity;
con.ConnectionString = objCon.GetConnection;
}
public CityDA()
{

con.ConnectionString = objCon.GetConnection;
}

public bool CreateNewCity()
{



SqlTransaction Tran = null;
try
{
con.Open();

Guid newguid = Guid.NewGuid();
//First Inserting values in Entity Tables
SqlCommand cmd_entity = new SqlCommand("insert into entity(id,entitytypeid,entitystateid,commonname,createddate,createdby,ownerid,IsEditorsPick,VanityUrl,Tags) values(@id,@entitytypeid,@entitystateid,@commonname,@createddate,@createdby,@ownerid,@IsEditorsPick,@VanityUrl,@Tags)", con);
cmd_entity.Parameters.AddWithValue("@id", newguid);
cmd_entity.Parameters.AddWithValue("@entitytypeid", vCity.ENTITYTYPEID);
cmd_entity.Parameters.AddWithValue("@entitystateid", 1);
cmd_entity.Parameters.AddWithValue("@commonname",vCity.CITYTEXT.Replace("'", "''"));
cmd_entity.Parameters.AddWithValue("@createddate", DateTime.Now.ToString());
cmd_entity.Parameters.AddWithValue("@createdby", 1);
cmd_entity.Parameters.AddWithValue("@ownerid", 1);
cmd_entity.Parameters.AddWithValue("@IsEditorsPick", vCity.EDITORPICK);
cmd_entity.Parameters.AddWithValue("@VanityUrl", vCity.VANITYURL);
cmd_entity.Parameters.AddWithValue("@Tags", vCity.TAGS);

Tran = con.BeginTransaction();

cmd_entity.Transaction = Tran;
cmd_entity.ExecuteNonQuery();

// Tran.Save("CreateEntity");
//Inserting Unique Values
cmd_entity.CommandText = "insert into CityEntityDetail values(@entityid,@StateEntityId,@citytext,@Abbreviation,@archive,@TagLine)";
cmd_entity.Parameters.AddWithValue("@entityid", newguid);
if (vCity.STATEENTITYID != "")
cmd_entity.Parameters.AddWithValue("@StateEntityId", new Guid(vCity.STATEENTITYID));
else
cmd_entity.Parameters.AddWithValue("@StateEntityId", Guid.Empty);
cmd_entity.Parameters.AddWithValue("@CityText", vCity.CITYTEXT.Replace("'", "''"));
cmd_entity.Parameters.AddWithValue("@Abbreviation", vCity.ABBREVIATION.Replace("'", "''"));
cmd_entity.Parameters.AddWithValue("@archive", vCity.ARCHIVE.Replace("'", "''"));
cmd_entity.Parameters.AddWithValue("@TagLine", vCity.TAGLINE.Replace("'", "''"));


cmd_entity.ExecuteNonQuery();

//Tran.Save("CreatePerson");
//cmd_entity.Dispose();

//Inserting Relationships

//Websites
InsertWebsites(vCity.WEBSITESLIST, newguid, cmd_entity);

//AKA List
InsertAKAs(vCity.AKALIST, newguid, cmd_entity);
//Genres
InsertGenres(vCity.GENRELIST, newguid, cmd_entity);

//YOUTUBELIST
InsertYoutubes(vCity.YOUTUBELIST, newguid, cmd_entity);

//TIMELINELIST
InsertTimeLines(vCity.TIMELINELIST, newguid, cmd_entity);
//Decades
InsertDecades(vCity.DECADELIST, newguid, cmd_entity);


Tran.Commit();
return true;
}

catch
{
Tran.Rollback();
return false;
}

finally
{
con.Close();
}
}

public void InsertAKAs(DataTable AKALIST, Guid guid, SqlCommand cmd_entity)
{
foreach (DataRow dr in AKALIST.Rows)
{
cmd_entity.CommandText = "insert into entity_AKAs values('" + guid + "','" + dr["AKAText"].ToString().Replace("'", "''") + "','" + bool.Parse(dr["IsDefault"].ToString()) + "')";

cmd_entity.ExecuteNonQuery();

}
}
public bool UpdateCity()
{
SqlTransaction Tran = null;

try
{
con.Open();

Guid oldguid = new Guid(vCity.ENTITYID);
//First Inserting values in Entity Tables
SqlCommand cmd_entity = new SqlCommand("update entity set modifieddate=@modifieddate,modifiedby=@modifiedby,ownerid=@ownerid,IsEditorsPick=@IsEditorsPick,VanityUrl=@VanityUrl,Tags=@Tags where id=@id", con);
cmd_entity.Parameters.AddWithValue("@id", oldguid);
cmd_entity.Parameters.AddWithValue("@modifieddate", DateTime.Now.ToString());
cmd_entity.Parameters.AddWithValue("@modifiedby", 1);
cmd_entity.Parameters.AddWithValue("@ownerid", 1);
cmd_entity.Parameters.AddWithValue("@IsEditorsPick", vCity.EDITORPICK);
cmd_entity.Parameters.AddWithValue("@VanityUrl", vCity.VANITYURL);
cmd_entity.Parameters.AddWithValue("@Tags", vCity.TAGS);

Tran = con.BeginTransaction();
cmd_entity.Transaction = Tran;
cmd_entity.ExecuteNonQuery();

//Tran.Save("CreateEntity");

//Inserting Unique Values


cmd_entity.CommandText = "update CityEntityDetail set entityid=@entityid,stateentityid=@stateentityid,citytext=@citytext,abbreviation=@abbreviation,archive=@archive,TagLine=@TagLine where entityid=@entityid";
//SqlCommand cmd_person = new SqlCommand("insert into personentitydetail values(@entityid,@stagename,@firstname,@middlename,@lastname,@prefix,@postfix,@birthday,@birthmonth,@birthyear,@placeofbirth,@deathday,@deathmonth,@deathyear,@placeofdeath,@circumstancesofdeath,@rightylefty)", con);
cmd_entity.Parameters.AddWithValue("@entityid", oldguid);
cmd_entity.Parameters.AddWithValue("@stateentityid", vCity.STATEENTITYID);
cmd_entity.Parameters.AddWithValue("@citytext", vCity.CITYTEXT);
cmd_entity.Parameters.AddWithValue("@abbreviation", vCity.ABBREVIATION);
cmd_entity.Parameters.AddWithValue("@archive", vCity.ARCHIVE);
cmd_entity.Parameters.AddWithValue("@TagLine", vCity.TAGLINE);

cmd_entity.ExecuteNonQuery();

//Tran.Save("CreatePerson");
//cmd_entity.Dispose();

//Inserting Relationships
//Websites
cmd_entity.CommandText = "delete from entity_urls where entityid='" + oldguid + "'";
cmd_entity.ExecuteNonQuery();
InsertWebsites(vCity.WEBSITESLIST, oldguid, cmd_entity);


//AKA List
cmd_entity.CommandText = "delete from entity_AKAs where entityid='" + oldguid + "'";
cmd_entity.ExecuteNonQuery();
InsertAKAs(vCity.AKALIST, oldguid, cmd_entity);

//Genres
cmd_entity.CommandText = "delete from entity_Genres where entityid='" + oldguid + "'";
cmd_entity.ExecuteNonQuery();
InsertGenres(vCity.GENRELIST, oldguid, cmd_entity);

//YOUTUBELIST
cmd_entity.CommandText = "delete from entity_Youtubes where entityid='" + oldguid + "'";
cmd_entity.ExecuteNonQuery();
InsertYoutubes(vCity.YOUTUBELIST, oldguid, cmd_entity);


//TIMELINELIST
cmd_entity.CommandText = "delete from entity_TimeLines where entityid='" + oldguid + "'";
cmd_entity.ExecuteNonQuery();
InsertTimeLines(vCity.TIMELINELIST, oldguid, cmd_entity);

//DecadLIST
cmd_entity.CommandText = "delete from entity_decades where entityid='" + oldguid + "'";
cmd_entity.ExecuteNonQuery();
InsertDecades(vCity.DECADELIST, oldguid, cmd_entity);
Tran.Commit();
return true;
}

catch
{
Tran.Rollback();
return false;
}

finally
{
con.Close();
}
}
public bool DeleteCity()
{
return false;
}
public City GetCityDetails()
{

SqlCommand cmd_entity = new SqlCommand("select * from entity where id=@id", con);
cmd_entity.Parameters.AddWithValue("@id", vCity.ENTITYID);
con.Open();
SqlDataReader dr_entity = cmd_entity.ExecuteReader();
if (dr_entity.HasRows)
{
while (dr_entity.Read())
{


if (dr_entity["IsEditorsPick"].ToString() != "")
vCity.EDITORPICK = bool.Parse(dr_entity["IsEditorsPick"].ToString());
else
vCity.EDITORPICK = false;
vCity.VANITYURL = dr_entity["VanityUrl"].ToString();
vCity.TAGS = dr_entity["Tags"].ToString();
}
}
dr_entity.Close();
SqlCommand cmd = new SqlCommand("select * from cityentitydetail where entityid=@eid", con);
cmd.Parameters.AddWithValue("@eid", vCity.ENTITYID);


SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
vCity.ENTITYID = dr["entityid"].ToString();
vCity.STATEENTITYID = dr["stateentityid"].ToString();
vCity.CITYTEXT = dr["citytext"].ToString();
vCity.ABBREVIATION = dr["Abbreviation"].ToString();
vCity.ARCHIVE = dr["Archive"].ToString();
vCity.TAGLINE = dr["tagline"].ToString();

}
}
dr.Close();
con.Close();
vCity.WEBSITESLIST = GetWEBSITESLISTofObject(vCity.ENTITYID);
vCity.GENRELIST = GetGENRELISTofObject(vCity.ENTITYID);
vCity.YOUTUBELIST = GetYOUTUBELISTofObject(vCity.ENTITYID);
vCity.TIMELINELIST = GetTIMELINELISTofObject(vCity.ENTITYID);
vCity.AKALIST = GetAKALISTofObject(vCity.ENTITYID);
vCity.ArchiveUrl = GetArchiveUrlofObject(vCity.ENTITYID);
vCity.DECADELIST = GetDecadesListofObject(vCity.ENTITYID);
return vCity;

}

public void InsertWebsites(DataTable WEBSITESLIST, Guid guid, SqlCommand cmd_entity)
{

foreach (DataRow dr in WEBSITESLIST.Rows)
{
cmd_entity.CommandText = "insert into entity_urls values('" + guid + "','" + dr["Url"].ToString().Replace("'", "''") + "','" + dr["UrlName"].ToString().Replace("'", "''") + "','" + dr["UrlDescription"].ToString().Replace("'", "''") + "'," + int.Parse(dr["UrlTypeId"].ToString()) + ",'" + bool.Parse(dr["IsOfficialUrl"].ToString()) + "')";

cmd_entity.ExecuteNonQuery();
}
}

public void InsertGenres(DataTable GenresList, Guid guid, SqlCommand cmd_entity)
{
foreach (DataRow dr in GenresList.Rows)
{
cmd_entity.CommandText = "insert into entity_Genres values('" + guid + "','" + dr["Id"].ToString() + "')";

cmd_entity.ExecuteNonQuery();

}
}
public void InsertDecades(DataTable DECADELIST, Guid guid, SqlCommand cmd_entity)
{
foreach (DataRow dr in DECADELIST.Rows)
{
cmd_entity.CommandText = "insert into entity_Decades values('" + guid + "','" + dr["Id"].ToString() + "')";

cmd_entity.ExecuteNonQuery();

}
}
public void InsertYoutubes(DataTable YOUTUBELIST, Guid guid, SqlCommand cmd_entity)
{
foreach (DataRow dr in YOUTUBELIST.Rows)
{
cmd_entity.CommandText = "insert into entity_Youtubes values('" + guid + "','" + dr["Id"].ToString() + "')";

cmd_entity.ExecuteNonQuery();

}
}
public void InsertTimeLines(DataTable TIMELINELIST, Guid guid, SqlCommand cmd_entity)
{
foreach (DataRow dr in TIMELINELIST.Rows)
{
cmd_entity.CommandText = "insert into entity_TimeLines values('" + guid + "','" + dr["Id"].ToString() + "')";

cmd_entity.ExecuteNonQuery();

}

}

#endregion


}
}
-------------------------------
Step 3: Creating Business Layer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RRL;
using System.Data;
using DataAccess;

namespace Business
{
public class CityBL
{
CityDA varcityDA= null;
public CityBL(City varNCity)
{

varcityDA =new CityDA(varNCity);
}
public CityBL()
{

varcityDA = new CityDA();
}
#region ICityBL Members
public bool CreatenewCity()
{
return varcityDA.CreateNewCity();
}

public bool UpdateCity()
{
return varcityDA.UpdateCity();
}
public bool DeleteCity()
{
return varcityDA.DeleteCity();
}
public City getCityDetails()
{
return varcityDA.GetCityDetails();
}

public DataTable GetDecades()
{
return varcityDA.GetDecadesList();
}
public DataTable GetAllCountries()
{
return varcityDA.GetCountryList();
}
public DataTable GetStatesofCountry(string countryid)
{
return varcityDA.GetStatesofCountry(countryid);
}
public string GetCountryofState(string stateid)
{
return varcityDA.GetCountryofState(stateid);
}
public string GetStateofCity(string cityid)
{
return varcityDA.GetStateofCity(cityid);
}

#endregion
}
}
------------------
Step 4: Creating Presentation Layer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using RRL;
using Business;
using System.Xml;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;

public partial class NewTemplate : System.Web.UI.Page
{

CityBL vcity = new CityBL();
City ct = new City();


// PersonBL obj = null;
static string Mode, editentity;
protected void Page_Load(object sender, EventArgs e)
{
Mode = "Edit";
//Charity
//uc_Charity.ENTITYTYPEID = "8";

//Foundation
//uc_Foundation.ENTITYTYPEID = "7";

//YouTube

uc_Youtube.searchtable = "YouTube";
uc_Youtube.conditioncolumn = "YouTubesrc";

//TimeLine
uc_TimeLine.searchtable = "TimeLines";
uc_TimeLine.conditioncolumn = "TimeLineUrl";




if (!IsPostBack)
{
//Country();
//////Edit Mode Specific//////////////////////////////
if (Mode == "Edit")
{
btn_Delete.Visible = true;
//PersonBL newobject = new PersonBL();
string id = "729EF489-0084-4ED5-8912-5ACFC9AB054A";
// Person p = new Person();
editentity = id;
ct.ENTITYID = id;

//get First Requirements


//newobject = new PersonBL(ps);
vcity = new CityBL(ct);
ct = vcity.getCityDetails();


//DataTable dt=getp.GetWebsites();
//Populating

txt_Name.Text = ct.CITYTEXT;
txt_Tagline.Text = ct.TAGLINE;

txt_Archive.Text = ct.ARCHIVE;
txt_Abbrevation.Text = ct.ABBREVIATION;
txt_Tags.Text = ct.TAGS;
txt_Vanityurl.Text = ct.VANITYURL;

Loadcountries();
ddl_Country.SelectedValue = vcity.GetCountryofState(vcity.GetStateofCity(ct.ENTITYID));
LoadStates();
ddl_State.SelectedValue = vcity.GetStateofCity(ct.ENTITYID);

//Load AKAs

DataTable newdt = new DataTable();
DataColumn akatext = new DataColumn("AKAText");
DataColumn isdefault = new DataColumn("IsDefault");
newdt.Columns.Add(akatext);
newdt.Columns.Add(isdefault);
foreach (DataRow dr1 in ct.AKALIST.Rows)
{
DataRow dr2 = newdt.NewRow();
dr2["AKAText"] = dr1["AKAText"];
dr2["IsDefault"] = dr1["IsDefault"];
newdt.Rows.Add(dr2);
}
uc_AKAs.AssignAKAs(newdt);

//Load Decades

DataTable dt = ct.DECADELIST;
LoadDecades();
foreach (DataRow dr in dt.Rows)
{
foreach (ListItem li in cbl_Decades.Items)
{
if (li.Value == dr["id"].ToString())
li.Selected = true;
}
}

//Load Normal Websites

DataTable WebsitesTable = new DataTable();
DataColumn Url = new DataColumn("Url");
DataColumn UrlName = new DataColumn("UrlName");
DataColumn UrlTypeId = new DataColumn("UrlTypeId");
DataColumn UrlDesc = new DataColumn("UrlDescription");
DataColumn IsOfficial = new DataColumn("IsOfficialUrl");
WebsitesTable.Columns.Add(Url);
WebsitesTable.Columns.Add(UrlName);
WebsitesTable.Columns.Add(UrlDesc);
WebsitesTable.Columns.Add(IsOfficial);
WebsitesTable.Columns.Add(UrlTypeId);
foreach (DataRow dr1 in ct.WEBSITESLIST.Rows)
{
DataRow dr2 = WebsitesTable.NewRow();
dr2["Url"] = dr1["Url"];
dr2["UrlName"] = dr1["UrlName"];
dr2["UrlDescription"] = dr1["UrlDescription"];
dr2["IsOfficialUrl"] = dr1["IsOfficialUrl"];
dr2["UrlTypeId"] = dr1["UrlTypeId"];
WebsitesTable.Rows.Add(dr2);
}
uc_Websites.AssignWebsites(WebsitesTable);



DataTable dt_genres = ct.GENRELIST;

LoadGenres();
foreach (DataRow dr in dt_genres.Rows)
{
foreach (ListItem li in cbl_Genres0.Items)
{
if (li.Value == dr["id"].ToString())
li.Selected = true;
}
}



//Load Youtube

uc_Youtube.LoadTable(ct.YOUTUBELIST);

//Load TimeLine

uc_TimeLine.LoadTable(ct.TIMELINELIST);

chb_EPick.Checked = ct.EDITORPICK;
txt_Vanityurl.Text = ct.VANITYURL;

btn_CreateCity.Text = "Update";

}
else
{

uc_Websites.ClearWebsites();
uc_AKAs.ClearAKAs();
LoadGenres();//Genres

LoadDecades();//Decades

btn_Delete.Visible = true;
Loadcountries();
// ddl_Country.SelectedValue = vcity.GetCountryofState(vcity.GetStateofCity(ct.ENTITYID));

}
}
}

public void LoadDecades()
{
CityBL vcity = new CityBL();
DataTable Decades = vcity.GetDecades();
cbl_Decades.DataSource = Decades;
cbl_Decades.DataTextField = "Decade";
cbl_Decades.DataValueField = "Id";
cbl_Decades.DataBind();

}
public void LoadGenres()
{
GenreBL vGENRELIST = new GenreBL();
DataTable Genres = vGENRELIST.GetGENRELIST();
cbl_Genres0.DataSource = Genres;
cbl_Genres0.DataTextField = "GenreName";
cbl_Genres0.DataValueField = "Id";
cbl_Genres0.DataBind();
}


protected void btn_CreateCity_Click(object sender, EventArgs e)
{

City vNewCity = new City();
vNewCity.ENTITYTYPEID = "6";

vNewCity.CITYTEXT = txt_Name.Text;
vNewCity.STATEENTITYID = ddl_State.SelectedValue;

vNewCity.TAGLINE = txt_Tagline.Text;
vNewCity.TAGS = txt_Tags.Text;
vNewCity.VANITYURL = txt_Vanityurl.Text;
vNewCity.ABBREVIATION = txt_Abbrevation.Text;
vNewCity.ARCHIVE = txt_Archive.Text;
vNewCity.EDITORPICK = chb_EPick.Checked;



//DataTable Youtubes = uc_Youtube.RESULTSTABLE();
//vNewState.YOUTUBELIST = Youtubes;

DataTable AKAs = uc_AKAs.GetAKAs();
vNewCity.AKALIST = AKAs;




DataTable Websites = uc_Websites.GetWebsites();
vNewCity.WEBSITESLIST = Websites;


//Genres
DataTable Genres = new DataTable();
DataColumn dc1 = new DataColumn("Id");
Genres.Columns.Add(dc1);
foreach (ListItem li in cbl_Genres0.Items)
{
if (li.Selected == true)
{
DataRow dr = Genres.NewRow();
dr["Id"] = li.Value;
Genres.Rows.Add(dr);
}
}
//Genres Ends.........
vNewCity.GENRELIST = Genres;



//You Tubes
DataTable Youtubes = uc_Youtube.RESULTSTABLE();
vNewCity.YOUTUBELIST = Youtubes;

//Time Lines
DataTable TimeLines = uc_TimeLine.RESULTSTABLE();
vNewCity.TIMELINELIST = TimeLines;


//Decades
DataTable Decades = new DataTable();
DataColumn dc_decade = new DataColumn("Id");
Decades.Columns.Add(dc_decade);
foreach (ListItem li in cbl_Decades.Items)
{
if (li.Selected == true)
{
DataRow dr = Decades.NewRow();
dr["Id"] = li.Value;
Decades.Rows.Add(dr);
}
}
//Decades Ends Here
vNewCity.DECADELIST = Decades;
//vNewCountry.COUNTRYENTITYID = ddl_Country.SelectedValue;


CityBL citybl = new CityBL(vNewCity);
if (btn_CreateCity.Text.ToLower() != "update")
{

if (citybl.CreatenewCity())
//ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "");
Response.Write("Success!");
else
Response.Write("insertion Failed");
}
else
{
vNewCity.ENTITYID = "729EF489-0084-4ED5-8912-5ACFC9AB054A";
if (citybl.UpdateCity())
//ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "");
Response.Write("Success!");
else
Response.Write("insertion Failed");
}
}
protected void btn_Delete_Click(object sender, EventArgs e)
{

City vNewcity = new City();
string id = "729EF489-0084-4ED5-8912-5ACFC9AB054A";
ct.ENTITYID = id;
CityBL vca = new CityBL(vNewcity);
if (vca.DeleteCity())
//ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "");
Response.Write("Delete Success!");
else
Response.Write("Deletion Failed");
}
void Loadcountries()
{

CityBL nbl = new CityBL();
ddl_Country.DataSource = nbl.GetAllCountries();
ddl_Country.DataTextField = "countrytext";
ddl_Country.DataValueField = "EntityId";

ddl_Country.DataBind();

ddl_Country.Items.Insert(0, "Select");
}


public void LoadStates()
{
ddl_State.Items.Clear();
if (ddl_Country.SelectedIndex > 0)
{
CityBL nbl = new CityBL();
ddl_State.DataSource = nbl.GetStatesofCountry(ddl_Country.SelectedValue);
ddl_State.DataTextField = "statetext";
ddl_State.DataValueField = "entityid";
ddl_State.DataBind();
ddl_State.Items.Insert(0, "Select");
}
}


protected void ddl_Country_SelectedIndexChanged(object sender, EventArgs e)
{
LoadStates();
}
}

-------------------------------

Tuesday, June 16, 2009

Developing and Using a Custom Server Control

•Create an ASP.NET server control.
•Add metadata to the control and its members to control security and design-time behavior.
•Use the App_Code directory in an ASP.NET Web site to test your control without manual compilation steps.
•Specify a tag prefix in a configuration file and in the control's assembly.
•Compile the control into an assembly and add it to the Bin directory.
•Embed a bitmap into the control's assembly as the toolbox icon for a visual designer.
•Use the compiled control in a page.

To create the code for the custom server control
1. In Visual Studio or Visual Web Developer Express Edition, create a Web site and name it ServerControlsTest.
2. Create an App_Code directory directly under the root directory of your Web site.
ASP.NET dynamically compiles code included in the App_Code directory under an ASP.NET Web site's root. Classes in source files in App_Code can therefore be accessed from pages without being manually compiled into assemblies.
3. In the App_Code directory, create a class named WelcomeLabel.cs or WelcomeLabel.vb.
4. Add the following code to the source file for the control:
Visual Basic

Copy Code
' WelcomeLabel.vb
Option Strict On
Imports System
Imports System.ComponentModel
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB.Controls
< _
AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal), _
AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal), _
DefaultProperty("Text"), _
ToolboxData( _
"<{0}:WelcomeLabel runat=""server""> ") _
> _
Public Class WelcomeLabel
Inherits Label
< _
Bindable(False), _
Category("Appearance"), _
Description("The text to use if the user is not authenticated."), _
DefaultValue(""), _
Localizable(True) _
> _
Public Property NameForAnonymousUser() As String
Get
Dim s As String = CStr(ViewState("NameForAnonymousUser"))
If s Is Nothing Then s = String.Empty
Return s
End Get
Set(ByVal value As String)
ViewState("NameForAnonymousUser") = value
End Set
End Property

Protected Overrides Sub RenderContents( _
ByVal writer As HtmlTextWriter)
writer.WriteEncodedText(Text)
If Context IsNot Nothing Then
Dim s As String = Context.User.Identity.Name
If (s IsNot Nothing) AndAlso (s <> String.Empty) Then
Dim split() As String = s.Split("\".ToCharArray)
Dim n As Integer = split.Length - 1
If (split(n) <> String.Empty) Then
writer.Write(", ")
writer.Write(split(n))
End If
Else
If (NameForAnonymousUser <> String.Empty) Then
writer.Write(", ")
writer.Write(NameForAnonymousUser)
Else
writer.Write("!")
End If

End If
End If

End Sub
End Class
End Namespace

C#

Copy Code
// WelcomeLabel.cs
using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Samples.AspNet.CS.Controls
{
[
AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("Text"),
ToolboxData("<{0}:WelcomeLabel runat=\"server\"> ")
]
public class WelcomeLabel : Label
{

[
Bindable(false),
Category("Appearance"),
Description("The text to use if the user is not authenticated."),
DefaultValue(""),
Localizable(true)
]
public string NameForAnonymousUser
{
get
{
string s = (string)ViewState["NameForAnonymousUser"];
return (s == null) ? String.Empty : s;
}
set
{
ViewState["NameForAnonymousUser"] = value;
}
}

protected override void RenderContents(HtmlTextWriter writer)
{
writer.WriteEncodedText(Text);
if (Context != null)
{
string s = Context.User.Identity.Name;
if (s != null && s != String.Empty)
{
string[] split = s.Split('\\');
int n = split.Length - 1;
if (split[n] != String.Empty)
{
writer.Write(", ");
writer.Write(split[n]);
}
}
else
{
if (NameForAnonymousUser != String.Empty)
{
writer.Write(", ");
writer.Write(NameForAnonymousUser);
}
else
{
writer.Write("!");
}
}
}
}
}
}
Code Discussion

If your control renders a user interface (UI) element or any other visible element on the client, you should derive your control from System.Web.UI.WebControls..::.WebControl (or a derived class). If your control renders an element that is not visible in the browser, such as a hidden element or a meta element, derive your control from System.Web.UI..::.Control. The WebControl class derives from Control and adds style-related properties such as Font, ForeColor, and BackColor. In addition, a control that derives from WebControl participates in the themes features of ASP.NET without any extra work on your part.

If your control extends the functionality of an existing control, such as the Button, Label, or Image controls, you can derive from that control.
From Label, WelcomeLabel inherits the Text property. WelcomeLabel overrides the RenderContents method to provide the logic for creating the text to display. The parameter passed into the RenderContents method is an object of type HtmlTextWriter, which is a utility class that has methods for rendering tags and other HTML (and HTML-variant) markup.

The WelcomeLabel uses view state to store the value for the NameForAnonymousUser property. Using view state persists the value of NameForAnonymousUser across postbacks. On each postback, the page is recreated and the value is restored from view state. If the value was not stored in view state, the value would be set to its default, Empty, on each postback. The ViewState property inherited from WebControl is a dictionary that saves data values. Values are entered and retrieved by using a String key. In this case, "NameForAnonymousUser" is used as the key. Items in the dictionary are typed as Object, which you must then cast to the property type. For more information, see ASP.NET State Management Overview.

Notice that WelcomeLabel makes successive calls to the Write method of the HtmlTextWriter object, instead of performing string concatenation and then invoking the Write method. This improves performance because the HtmlTextWriter object writes directly to the output stream. String concatenation requires time and memory to create the string, and then writes to the stream. When you implement rendering in your controls, you should follow the pattern illustrated in this walkthrough.

The attributes applied to WelcomeLabel contain metadata that is used by the common language runtime and by design-time tools. At the class level, WelcomeLabel is marked with the following attributes:

•AspNetHostingPermissionAttribute is a code-access security attribute. It causes the just-in-time (JIT) compiler to check that code that links to WelcomeLabel is granted the AspNetHostingPermission permission. All public ASP.NET classes are marked with this attribute. You should apply AspNetHostingPermissionAttribute to your controls as a security check against partially trusted callers. For more information, see Code Access Security. For more information about the JIT compiler, see Compiling MSIL to Native Code.

•DefaultPropertyAttribute is a design-time attribute that specifies the default property of a control. In visual designers, the property browser typically highlights the default property when a page developer clicks the control on the design surface.

•ToolboxDataAttribute specifies the format string for the element. The string becomes the control's markup when the control is double-clicked in the toolbox or dragged from the toolbox onto the design surface. For WelcomeLabel, the attribute creates this element:



The WelcomeLabel control also inherits two attributes from the WebControl base class, ParseChildrenAttribute and PersistChildrenAttribute. They are applied as ParseChildren(true) and PersistChildren(false). These two attributes work together so that child elements are interpreted as properties and properties are persisted as attributes.
The following attributes applied to the NameForAnonymousUser property of WelcomeLabel are standard design-time attributes that you will generally apply to public properties of your controls:

•BindableAttribute, specified as true or false, specifies for visual designers whether it is meaningful to bind the property to data. For example, in Visual Studio, if a property is marked with Bindable(true), the property is displayed in the DataBindings dialog box. If a property is not marked with this attribute, the property browser infers the value to be Bindable(false).

•CategoryAttribute specifies how to categorize the property in the visual designer's property browser. For example, Category("Appearance") tells the property browser to display the property in the Appearance category when the page developer uses the category view of the property browser. You can specify a string argument corresponding to an existing category in the property browser or create your own category.

•DescriptionAttribute specifies a brief description of the property. In Visual Studio, the property browser displays the description of the selected property at the bottom of the Properties window.

•DefaultValueAttribute specifies a default value for the property. This value should be the same as the default value that you return from the property accessor (getter). In Visual Studio, the DefaultValueAttribute allows a page developer to reset a property value to its default by displaying the shortcut menu in the Properties window and clicking the Reset button.

•LocalizableAttribute, specified as true or false, specifies for visual designers whether it is meaningful to localize the property. When a property is marked Localizable(true), the visual designer includes it when localized resources are being serialized. The designer will persist the property value to the culture-neutral resource file or other localization source when the control is polled for localizable properties.

To add a tag prefix mapping in a Web page
•In the Default.aspx page, add the following code after the @ Page directive:
[C#]
Copy Code
<%@ Register TagPrefix="aspSample"
Namespace="Samples.AspNet.CS.Controls"%>
[Visual Basic]

Copy Code
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls"%>

Creating a Page to Use the Control
You can now use the custom control in an ASP.NET Web page.

To create a page that uses the custom control

1.Copy the following markup into the Default.aspx file and save the file.
Visual Basic

Copy Code


WelcomeLabel Test




runat="server" BackColor="Wheat" ForeColor="SaddleBrown" />




C#

Copy Code


WelcomeLabel Test




runat="server" BackColor="Wheat" ForeColor="SaddleBrown" />




2.View Default.aspx in your browser.

In addition to the WelcomeLabel control's Text property that was explicitly defined in the markup that you copied, you can see from the control instance in the page that it has BackColor and ForeColor properties that you did not define. The WelcomeLabel control gets these and other style-related properties by inheritance from the WebControl base class. In addition, WelcomeLabel can be assigned a skin and be part of a theme without any work on your part.


Compiling the Control into an Assembly

The App_Code directory enables you to test your control without compiling it. However, if you want to distribute your control as object code to other developers, you must compile it. In addition, a control cannot be added to the toolbox of a visual designer unless it is compiled into an assembly.
You can provide a default tag prefix that a visual designer should use for your control by including the assembly-level System.Web.UI..::.TagPrefixAttribute attribute. The tag prefix is registered with the page the first time the control is double-clicked in the toolbox or dragged from the toolbox onto the page.

If you decide to use the TagPrefixAttribute attribute, you can specify it in a separate file that is compiled with your controls. By convention, the file is named AssemblyInfo.languageExtension, such as AssemblyInfo.cs or AssembyInfo.vb. The following procedure describes how to specify the TagPrefixAttribute metadata.

To prepare the control for compiling and provide a default tag prefix
1. Create a new directory named CustomControls that is not in the Web site.
2. Create a file that is named AssemblyInfo.cs or AssemblyInfo.vb in the directory and add the following code to the file.
C#

Copy Code
using System;
using System.Web.UI;
[assembly: TagPrefix("Samples.AspNet.CS.Controls", "aspSample")]
Visual Basic

Copy Code
Imports System

Imports System.Web.UI

The TagPrefix attribute creates a mapping between the namespace Samples.AspNet.CS.Controls or Samples.AspNet.VB.Controls and the prefix aspSample.
3. Copy the WelcomeLabel.cs or WelcomeLabel.vb file from App_Code to the CustomControls directory.
4. Delete the WelcomeLabel.cs or WelcomeLabel.vb file in the App_Code folder of the Web site.

If you do not delete the source files from the App_Code folder, your control's type will occur in both the compiled assembly and in the dynamically generated assembly created by ASP.NET. This will create an ambiguous reference when your control is loaded, and any page in which the control is used will generate a compiler error.

A visual designer such as Visual Studio typically uses a default icon (such as an image of a gear) to display a control in the toolbox. As an option for your control, you can customize the appearance of your control in the toolbox by embedding a 16-by-16-pixel bitmap in your control's assembly. By convention, visual designers use the lowermost left pixel of the bitmap as the transparent color.

To create a toolbox icon

1. Create or obtain a 16-by-16-pixel bitmap as the toolbox icon for your control.
2. Name the bitmap WelcomeLabel.bmp.
3. Add the bitmap file to the CustomControls directory where you have the source files for the WelcomeLabel control.
When compiling the code, you embed the bitmap as a resource in the assembly.
To compile the control into an assembly and embed the icon
1. Open the Visual Studio Command Prompt window. For more information, see Command-line Building With csc.exe.
2. At the command line, switch to the directory that contains the custom control class files.
3. Run the following command.
C#

Copy Code

csc /res:WelcomeLabel.bmp,Samples.AspNet.CS.Controls.WelcomeLabel.bmp /t:library /out:Samples.AspNet.CS.Controls.dll /r:System.dll /r:System.Web.dll *.cs
Visual Basic

Copy Code
vbc /res:WelcomeLabel.bmp,Samples.AspNet.VB.Controls.WelcomeLabel.bmp /t:library /out:Samples.AspNet.VB.Controls.dll /r:System.dll /r:System.Web.dll *.vb

The /res compiler option embeds a resource in the assembly. In this example, the bitmap is embedded as a resource. You specify a name for the resource in the second parameter of the /res option. You must name the embedded bitmap resource the same as the namespace-qualified name of the control with which it is associated. For example, if the name of the control is Samples.AspNet.CS.Controls.WelcomeLabel, the name of the embedded bitmap must be Samples.AspNet.CS.Controls.WelcomeLabel.bmp.

This naming convention causes a visual designer to automatically use the bitmap as your control's toolbox icon. If you do not use the naming convention, you must apply the ToolboxBitmapAttribute to the control to specify the name of the embedded bitmap resource.

The /t:library compiler option tells the compiler to create a library instead of an executable assembly. The /out option provides a name for the assembly and the /r option lists the assemblies that are linked to your assembly.

To keep the example self-contained, this walkthrough asks you to create an assembly with a single control. In general, the .NET Framework design guidelines recommend that you do not create assemblies that contain only a few classes. For ease of deployment, you should create as few assemblies as possible.
4. When you have finished compiling the class files, close the Command line window.
Using the Compiled Custom Control in an ASP.NET Page
To test the compiled version of your custom control, you must make your control's assembly available to pages in the Web site.
To make your control's assembly available to the Web site and add it to the toolbox
1. Return to Visual Studio.
2. Create a Bin directory under the root of the Web site.
3. Right-click the Bin directory and select Add Existing Item.
4. Navigate to the directory that contains the control assembly (Samples.AspNet.CS.Controls.dll or Samples.AspNet.VB.Controls.dll) and select the assembly.
5. Right-click anywhere in the Toolbox and then click Add Tab.
6. Name the tab "CustomControl".
7. Right-click the CustomControl tab and then click Choose Items.
8. Click Browse and select the assembly that you copied to the Bin folder.
8. The WelcomeLabel control now appears in the Toolbox with the icon you created.
The assembly that you created in this walkthrough is referred to as a private assembly because it must be included in an ASP.NET Web site's Bin directory to enable pages in the Web site to use your control. The assembly cannot be accessed from other applications unless a copy is also installed with those applications. If you are creating controls for shared Web hosting applications, you will typically package your controls in a private assembly. However, if you create controls for use in a dedicated hosting environment or you create a suite of controls that an ISP makes available to all its customers, you might have to package your controls in a shared (strongly named) assembly that is installed in the global assembly cache. For more information, see Working with Assemblies and the Global Assembly Cache.
The custom control is now available from the Toolbox.
To use the custom control from the Toolbox
1. Delete Default.aspx to remove any code related to the custom control from the previous procedures.
2. Create a new Web page called Default2.aspx.
3. In Design view, drag the WelcomeLabel control from the Toolbox onto Default2.aspx.
4. Set the Text property to "Hello".
5. In Source view, notice that the @ Register directive was automatically added. The assembly attribute is set because the control no longer is in the App_Code folder.
6. View Default.aspx in a Web browser.





Monday, May 11, 2009

Short Cuts for Arc Gis 9.1, 9.2.

Note:If u cant visible font click on the image it will appear big









Sunday, May 10, 2009

Retrieving only file name from sql server database not full path

If we upload a photo using upload control and insert into database and again we want to retrieve the file name then we use below code it will not display the full path it displays only file name


FileInfo fileN = new FileInfo(dr["Map_Attach"].ToString());
lbl_Map.Text = fileN.Name;

To retrieve data as DD/MM/YYYY format from sql server Database

String b = string.Format("{0:dd/MM/yyyy}", DateTime.Parse(dr["Period_To"].ToString()));

lbl_Periodto.Text = b;

To retrieve data as DD/MM/YYYY format from sql server Database

String b = string.Format("{0:dd/MM/yyyy}", DateTime.Parse(dr["Period_To"].ToString()));

lbl_Periodto.Text = b;

Excel Short Cuts

Excel Keyboard Shortctus (239 Shortcuts)

Shortcuts for selecting cells, rows and columns and objects

1 CTRL+SPACEBAR Select the entire column

2 SHIFT+SPACEBAR Select the entire row

3 CTRL+A Select the entire worksheet

4 SHIFT+BACKSPACE With multiple cells selected, select only the active cell

5 CTRL+SHIFT+SPACEBAR With an object selected, select all objects on a sheet

6 CTRL+6 Alternate between hiding objects, displaying objects, and displaying placeholders for objects

7 CTRL+SHIFT+* Select the current region around the active cell (the data area enclosed by blank rows and blank columns). In a PivotTable report, select the
entire PivotTable report

8 CTRL+/ Select the array containing the active cell

9 CTRL+SHIFT+O Select all cells that contain comments

10 CTRL+\ In a selected row, select the cells that do not match the value in the active cell

11 CTRL+SHIFT+| In a selected column, select the cells that do not match the value in the active cell

12 CTRL+[ Select all cells directly referenced by formulas in the selection

13 CTRL+SHIFT+{ Select all cells directly or indirectly referenced by formulas in the selection

14 CTRL+] Select cells that contain formulas that directly reference the active cell

15 CTRL+SHIFT+} Select cells that contain formulas that directly or indirectly reference the active cell

16 ALT+; Select the visible cells in the current selection

17 F8 Turn extend mode on or off. In extend mode, EXT appears in the status line, and the arrow keys extend the selection

18 SHIFT+F8 Add another range of cells to the selection; or use the arrow keys to move to the start of the range you want to add, and then press F8 and the arrow keys to select the next range

19 SHIFT+ARROW KEYS Extend the selection by one cell

20 CTRL+SHIFT+ARROW KEYS Extend the selection to the last nonblank cell in the same column or row as the active cell

21 SHIFT+HOME Extend the selection to the beginning of the row

22 CTRL+SHIFT+HOME Extend the selection to the beginning of the worksheet

23 CTRL+SHIFT+END Extend the selection to the last used cell on the worksheet (lower-right corner)

24 SHIFT+PAGE DOWN Extend the selection down one screen

25 SHIFT+PAGE UP Extend the selection up one screen

26 END+SHIFT+ARROW KEYS Extend the selection to the last nonblank cell in the same column or row as the active cell

27 END+SHIFT+HOME Extend the selection to the last used cell on the worksheet (lower-right corner)

28 END+SHIFT+ENTER Extend the selection to the last cell in the current
row. This key sequence does not work if you have turned on transition navigation keys (Tools menu, Options command, Transition tab)

29 SCROLL LOCK+ SHIFT+HOME Extend the selection to the cell in the upper-left corner of the window

30 SCROLL LOCK+ SHIFT+END Extend the selection to the cell in the lower-right corner of the window

Excel Shortcuts for entering, editing, formatting and calculating data

31 ENTER Complete a cell entry and select the cell below

32 ALT+ENTER Start a new line in the same cell

33 CTRL+ENTER Fill the selected cell range with the current entry

34 SHIFT+ENTER Complete a cell entry and select the previous cell above

35 TAB Complete a cell entry and select the next cell to the right

36 SHIFT+TAB Complete a cell entry and select the previous cell to the left

37 ESC Cancel a cell entry

38 ARROW KEYS Move one character up, down, left, or right

39 HOME Move to the beginning of the line

40 F4 or CTRL+Y Repeat the last action

41 CTRL+SHIFT+F3 Create names from row and column labels

42 CTRL+D Fill down

43 CTRL+R Fill to the right

44 CTRL+F3 Define a name

45 CTRL+K Insert a hyperlink

46 CTRL+; Enter the date

47 CTRL+SHIFT+: Enter the time

48 ALT+ARROW DOWN Display a drop-down list of the values in the current column
of a range

49 CTRL+Z Undo the last action

50 ALT+0162 Enters the cent character

51 ALT+0163 Enters the pound sterling character

52 ALT+0165 Enters the yen symbol

53 ALT+0128 Enters the euro symbol

Shortcuts to enter and calculate formulas in Excel

54 = Start a formula

55 F2 Move the insertion point into the Formula Bar when editing in a cell is turned off

56 BACKSPACE In the Formula Bar, delete one character to the left

57 ENTER Complete a cell entry from the cell or Formula Bar

58 CTRL+SHIFT+ENTER Enter a formula as an array formula. Array formulas
are enclosed between braces { } and are entered by pressing CTRL+SHIFT+ENTER

59 ESC Cancel an entry in the cell or Formula Bar

60 SHIFT+F3 In a formula, display the Insert Function dialog box

61 CTRL+A When the insertion point is to the right of a function name in a formula, display the Function Arguments dialog box

62 CTRL+SHIFT+A When the insertion point is to the right of a function name in a formula, insert the argument names and parentheses

63 F3 Paste a defined name into a formula

64 ALT+= Insert an AutoSum formula with the SUM function

65 CTRL+SHIFT+" Copy the value from the cell above the active cell into the cell or the Formula Bar

66 CTRL+' Copies a formula from the cell above the active cell into the cell or the Formula Bar

67 CTRL+` Alternate between displaying cell values and displaying formulas

68 F9 Calculate all worksheets in all open workbooks

69 SHIFT+F9 Calculate the active worksheet

70 CTRL+ALT+F9 Calculate all worksheets in all open workbooks, regardless of whether they have changed since the last calculation

71 CTRL+ALT+SHIFT+F9 Rechecks dependent formulas and then calculates all cells in all open workbooks, including cells not marked as needing to be calculated

Keys for editing data and working with Excel cells

72 F2 Edit the active cell and position the insertion point at the end of the cell contents

73 ALT+ENTER Start a new line in the same cell

74 BACKSPACE Edit the active cell and then clear it, or delete the preceding character in the active cell as you edit cell contents

75 DELETE Delete the character to the right of the insertion point, or delete the selection

76 CTRL+DELETE Delete text to the end of the line

77 F7 Display the Spelling dialog box

78 SHIFT+F2 Edit a cell comment

79 ENTER Complete a cell entry and select the next cell below

80 CTRL+Z Undo the last action

81 ESC Cancel a cell entry

82 CTRL+SHIFT+Z When the AutoCorrect Smart Tags is displayed, undo or redo the last automatic correction

83 CTRL+C Copy the selected cells

84 CTRL+X Cut the selected cells

85 CTRL+V Paste copied cells

86 DELETE Clear the contents of the selected cells

87 CTRL+- Delete the selected cells

88 CTRL+SHIFT++ Insert blank cells

Shortcuts to format Excel data

89 ALT+' Display the Style dialog box

90 CTRL+1 Display the Format Cells dialog box

91 CTRL+SHIFT+~ Apply the General number format

92 CTRL+SHIFT+$ Apply the Currency format with two decimal places (negative numbers in parentheses)

93 CTRL+SHIFT+% Apply the Percentage format with no decimal places

94 CTRL+SHIFT+^ Apply the Exponential number format with two decimal places

95 CTRL+SHIFT+# Apply the Date format with the day, month, and year

96 CTRL+SHIFT+@ Apply the Time format with the hour and minute, and AM or PM

97 CTRL+SHIFT+! Apply the Number format with two decimal places, thousands
separator, and minus sign (–) for negative values
98 CTRL+B Apply or remove bold formatting

99 CTRL+I Apply or remove italic formatting

100 CTRL+U Apply or remove underlining

101 CTRL+5 Apply or remove strikethrough

102 CTRL+9 Hide the selected rows

103 CTRL+SHIFT+( Unhide any hidden rows within the selection

104 CTRL+0 Hide the selected columns

105 CTRL+SHIFT+) Unhide any hidden columns within the selection

106 CTRL+SHIFT+& Apply the outline border to the selected cells

107 CTRL+SHIFT+_ Remove the outline border from the selected cells


Excel Help Task Pane Shortcuts

108 F1 Display the Help task pane

109 F6 Switch between the Help task pane and the active application

110 TAB Select the next item in the Help task pane

111 SHIFT+TAB Select the previous item in the Help task pane

112 ENTER Perform the action for the selected item

113 ARROW DOWN, ARROW UP In a Table of Contents, select the next and previous item, respectively

114 ARROW RIGHT, ARROW LEFT In a Table of Contents, expand and collapse the selected item, respectively

115 ALT+ARROW LEFT Move back to the previous task Pane

116 ALT+ARROW RIGHT Move forward to the next task Pane

117 CTRL+SPACEBAR Open the menu of Pane options

118 CTRL+F1 Close and reopen the current task pane

119 ARROW RIGHT Expand a +/- list

120 ARROW LEFT Collapse a +/- list

Excel Shortcuts for the Help window

121 TAB Select the next hidden text or hyperlink, or Show All or Hide All at the top of a topic

122 SHIFT+TAB Select the previous hidden text or hyperlink, or the Browser View button at the top of a Microsoft Office Web site article

123 ENTER Perform the action for the selected Show All, Hide All, hidden text,
or hyperlink

124 ALT+ARROW LEFT Move back to the previous Help topic.

125 ALT+ARROW RIGHT Move forward to the next Help topic

126 CTRL+P Print the current Help topic

127 ARROW UP, ARROW DOWN Scroll small amounts up and down, respectively, within the currently-displayed Help topic

128 PAGE UP and PAGE DOWN Scroll larger amounts up and down, respectively, within the currently-displayed Help topic

129 ALT+U Change whether the Help window appears connected to (tiled) or separate from (untiled) the active application

130 SHIFT+F10 Display a menu of commands for the Help window; requires that the Help window have active focus (click an item in the Help window)

Shortcuts to access and use task panes

131 F6 Move to a task pane

132 CTRL+TAB When a menu or toolbar is active, move to a task pane. (You
may need to press CTRL+TAB more than once.)

133 TAB or SHIFT+TAB When a task pane is active, select the next or
previous option in the task pane

134 CTRL+SPACEBAR Display the full set of commands on the task pane menu

135 ARROW DOWN or ARROW UP Move among choices in a selected submenu; move among certain options in a group of options

136 SPACEBAR or ENTER Open the selected menu, or perform the action assigned to the selected button

137 SHIFT+F10 Open a shortcut menu open a drop-down menu for the selected gallery item

138 HOME or END When a menu or submenu is visible, select the first or last command on the menu or submenu
139 PAGE UP or PAGE DOWN Scroll up or down in the selected gallery list

140 CTRL+HOME or CTRL+END Move to the top or bottom of the selected gallery list

Access and use menus and toolbars with Shortcuts in Excel

141 F10 or ALT Select the menu bar or close an open menu and submenu at the same time

142 TAB or SHIFT+TAB When a toolbar is selected, select the next or previous button or menu on the toolbar

143 CTRL+TAB or CTRL+SHIFT+TAB When a toolbar is selected, select the next or previous toolbar

144 ENTER Open the selected menu, or perform the action for the selected button or command

145 SHIFT+F10 Display the shortcut menu for the selected item

146 ALT+SPACEBAR Display the Control menu for the Excel window

147 ARROW DOWN or ARROW UP When a menu or submenu is open, select the next or previous command

148 ARROW LEFT or ARROW RIGHT Select the menu to the left or right. When a submenu is open, switch between the main menu and the submenu
149 HOME or END Select the first or last command on the menu or submenu

150 ESC Close an open menu. When a submenu is open, close only the submenu

151 CTRL+ARROW DOWN Display the full set of commands on a menu

152 CTRL+7 Show or hide the Standard toolbar

Use Excel dialog boxes with Shortcuts

153 TAB Move to the next option or option group

154 SHIFT+TAB Move to the previous option or option group

155 CTRL+TAB or CTRL+PAGE DOWN Switch to the next tab in a dialog box

156 CTRL+SHIFT+TAB or CTRL+PAGE UP Switch to the previous tab in a dialog box

157 ARROW KEYS Move between options in an open drop-down list, or between
options in a group of options

158 SPACEBAR Perform the action for the selected button, or select or
clear the selected check box

159 ALT+LETTER Select an option, or select or clear a check box of underlined LETTER option

160 ALT+ARROW DOWN Open the selected drop-down list

161 ENTER Perform the action for the default command button in the dialog box (the button with the bold outline, often the OK button)

162 ESC Cancel the command and close the dialog box

Working with Excel edit boxes within dialog boxes

163 HOME Move to the beginning of the entry

164 END Move to the end of the entry

165 ARROW LEFT or ARROW RIGHT Move one character to the left or right

166 CTRL+ARROW LEFT Move one word to the left

167 CTRL+ARROW RIGHT Move one word to the right

168 SHIFT+ARROW LEFT Select or unselect one character to the left

169 SHIFT+ARROW RIGHT Select or unselect one character to the right

170 CTRL+SHIFT+ARROW LEFT Select or unselect one word to the left

171 CTRL+SHIFT+ARROW RIGHT Select or unselect one word to the right

172 SHIFT+HOME Select from the insertion point to the beginning of the entry

173 SHIFT+END Select from the insertion point to the end of the entry

Use the Open, Save As, and Insert Picture dialog boxes

174 ALT+1 Go to the previous folder

175 ALT+2 Up One Level button: open the folder up one level above the open
folder

176 ALT+3 Search the Web button: close the dialog box and open your Web search
page

177 ALT+4 Delete button: delete the selected folder or file

178 ALT+5 Create New Folder button: create a new folder

179 ALT+6 Views button: switch among available folder views

180 ALT+7 or ALT+L Tools button: show the Tools menu

181 SHIFT+F10 Display a shortcut menu for a selected item such as a folder
or file

182 TAB Move between options or areas in the dialog box

183 F4 or ALT+I Open the Look in list

184 F5 Refresh the file list

Keys for workbooks and worksheets

185 CTRL+P or CTRL+SHIFT+F12 Display the Print dialog box

186 SHIFT+F11 or ALT+SHIFT+F1 Insert a new worksheet

187 CTRL+PAGE DOWN Move to the next sheet in the workbook

188 CTRL+PAGE UP Move to the previous sheet in the workbook

189 SHIFT+CTRL+PAGE DOWN Select the current and next sheet. To cancel
selection of multiple sheets, press CTRL+PAGE DOWN or, to select a different sheet,
press CTRL+PAGE UP

190 SHIFT+CTRL+PAGE UP Select the current and previous sheet

191 ALT+O H R Rename the current sheet (Format menu, Sheet submenu, rename)

192 ALT+E M Move or copy the current sheet (Edit menu, Move or Copy
Sheet command)
193 ALT+E L Delete the current sheet (Edit menu, Delete Sheet command)

194 ARROW KEYS Move one cell up, down, left, or right

195 CTRL+ARROW KEYS Move to the edge of the current data region

196 HOME Move to the beginning of the row

197 CTRL+HOME Move to the beginning of the worksheet

198 CTRL+END Move to the last cell on the worksheet, in the bottom-most
used row of the rightmost used column
199 PAGE DOWN Move down one screen

200 PAGE UP Move up one screen

201 ALT+PAGE DOWN Move one screen to the right

202 ALT+PAGE UP Move one screen to the left

203 F6 Switch to the next pane in a worksheet that has been split (Window
menu, Split command)

204 SHIFT+F6 Switch to the previous pane in a worksheet that has been
split

205 CTRL+BACKSPACE Scroll to display the active cell

206 F5 Display the Go To dialog box

207 SHIFT+F5 Display the Find dialog box

208 SHIFT+F4 Repeat the last Find action (same as Find Next)

209 TAB Move between unlocked cells on a protected worksheet



Excel Shortkeys to move within a selected range

210 ENTER Move from top to bottom within the selected range

211 SHIFT+ENTER Move from bottom to top within the selected range

212 TAB Move from left to right within the selected range. If cells in a
single column are selected, move down

213 SHIFT+TAB Move from right to left within the selected range. If cells
in a single column are selected, move up

214 CTRL+PERIOD Move clockwise to the next corner of the selected range

215 CTRL+ALT+ARROW RIGHT In nonadjacent selections, switch to the next
selection to the right

216 CTRL+ALT+ARROW LEFT Switch to the next nonadjacent selection to the left



Use the Border tab in the Format Cells dialog box

217 CTRL+1 display this dialog box

218 ALT+T Apply or remove the top border

219 ALT+B Apply or remove the bottom border

220 ALT+L Apply or remove the left border

221 ALT+R Apply or remove the right border

222 ALT+H If cells in multiple rows are selected, apply or remove the
horizontal divider

223 ALT+V If cells in multiple columns are selected, apply or remove the
vertical divider

224 ALT+D Apply or remove the downward diagonal border

225 ALT+U Apply or remove the upward diagonal border



Working with the AutoFilter

226 ALT+ARROW DOWN In the cell that contains the drop-ARROW DOWN, displays the AutoFilter list for the current column

227 ALT+ARROW UP Closes the AutoFilter list for the current column

228 ARROW DOWN Selects the next item in the AutoFilter list

229 ARROW UP Selects the previous item in the AutoFilter list

230 HOME Selects the first item (All) in the AutoFilter list

231 END Selects the last item in the AutoFilter list

232 ENTER Filters the range based on the item selected from the AutoFilter list

Show, hide, and outline data

233 ALT+SHIFT+ARROW RIGHT Groups rows or columns

234 ALT+SHIFT+ARROW LEFT Ungroups rows or columns

235 CTRL+8 Displays or hides the outline symbols

236 CTRL+9 Hides the selected rows

237 CTRL+SHIFT+( Unhides any hidden rows within the selection

238 CTRL+0 Hides the selected columns

239 CTRL+SHIFT+) Unhides any hidden columns within the selection