Monday, February 14, 2011

Creating Picture Slide Show in HTML by using JavaScript

The following HTML Content will demonstrate how to Set up a Picture Slide Show in HTML by using JavaScript:
Steps:
1. Create an images source array
2. Create one image element.
3.write a function in javascript to call the images source from array
4.use this "return document.images.slide.src=eval("image"+step+".src")"

Note : ("image"+step+".src") here step is next slide

HTML Code:
=========
<html>
<head>
<title>Images Slide Show in HTML by using Simple JavaScript</title>
<script type="text/javascript">
<!--
var image1=new Image()
image1.src="http://www.maniacworld.com/amazing-cars.jpg"
var image2=new Image()
image2.src="http://t3.gstatic.com/images?q=tbn:ANd9GcRmWwe3v7C2chaFhcS1mS5js5maQ2mZhpIrx37n5Q3I1vxK6QjUyA&t=1"
var image3=new Image()
image3.src="http://www.walkthroughindia.com/wp-content/uploads/2011/01/Honda-Jazz.jpg"
//-->
</script>
</head>
<body>
<center>
<img width="60%" height="60%" src="http://im.rediff.com/movies/2008/apr/01spotted.jpg" name="slide" width="100" height="56" />
</center>
<script>
<!--
//variable that will increment through the images
var step=1
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return document.images.slide.src=eval("image"+step+".src")
if (step<3)
step++
else
step=1
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",2500)
}
slideit()
//-->
</script>
</body>
</html>






Live Example by RamasubbaReddy



Tuesday, February 8, 2011

Other Blogs from RamaSubbaReddy

DotNet Related Issues:
                       DotNet World
Telugu Entertainment World:

  Latest Telugu Movies and Comedy Movies and Comedy Video Clips Video Songs 
                                         Latest Telugu Movies\Comedy\Videos Clips Click here
 

Monday, February 7, 2011

LINQ to XML Example with Source Code

Download Source Code
ASP.NET XML Tutorial

This tutorial will show you how to use LINQ to XML to read and also add data to an external XML file, in C#. 

XML can make a great storage medium for smaller, less sensitive data. In this tutorial, you will learn how to use LINQ to XML in ASP.NET 3.5 to add data to an external XML file, and also display the data on the page.
We will start by creating a new C# web application project in Visual Studio, and then add an XML file by right-clicking on the project in Solution Explorer, then choose Add New Item.. XML File.
In this example, we will use the XML file to store the names, city and age of numerous people. Our XML structure will look like this:

<?xml version="1.0" encoding="utf-8"?>
<Persons>
<Person>
<Name>Ella</Name>
<City>LA</City>
<Age>13</Age>
</Person>
<Person>
<Name>Ingrid</Name>
<City>Oslo</City>
<Age>63</Age>
</Person>
</Persons>
Next, we will build our ASPX page to be able to display the XML data as well as add new nodes. We will use textboxes and a button to add new data, and then a Literal control to display the existing data:
<form id="form1" runat="server">
<strong>Add to XML</strong><br />
Name:<br />
<asp:TextBox ID="txtName" runat="server" /><br />
City:<br />
<asp:TextBox ID="txtCity" runat="server" /><br />
Age:<br />
<asp:TextBox ID="txtAge" runat="server" /><br />
<asp:Button ID="butAdd" runat="server" Text="Add" /><br />
<asp:Label ID="lblStatus" runat="server" />
<br /><br />
<strong>Read XML:</strong><br />
<asp:Button ID="butRead" runat="server" Text="Read" /><br />
<asp:Literal ID="litResults" runat="server" />
</form>

Now if we go into Design view of our ASPX page, we can double-click on the buttons to create the on click event handlers for them. This will add the following into the back-end, and also add the onclick attributes to the ASPX page:
protected void butRead_Click(object sender, EventArgs e)
{

}

protected void butAdd_Click(object sender, EventArgs e)
{

}
<asp:Button ID="butAdd" runat="server" Text="Add" onclick="butAdd_Click" /><br />
..
<asp:Button ID="butRead" runat="server" Text="Read" onclick="butRead_Click" /><br />
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
In the code-behind, we will add a method that will read the XML data from the file:
protected void readXML()
{
XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml"));

var persons = from person in xmlDoc.Descendants("Person")
select new
{
Name = person.Element("Name").Value,
City = person.Element("City").Value,
Age = person.Element("Age").Value,
};

litResults.Text = "";
foreach (var person in persons)
{
litResults.Text = litResults.Text + "Name: " + person.Name + "<br />";
litResults.Text = litResults.Text + "City: " + person.City + "<br />";
litResults.Text = litResults.Text + "Age: " + person.Age + "<br /><br />";
}

if (litResults.Text == "")
litResults.Text = "No Results.";
}

This method makes use of LINQ to select all the data from the XML file, and then display it in the Literal control by looping through each item.
Next, we can add code to the button handlers. For the Read button, we will simply reference the method we just created, then set the status label to nothing:
protected void butRead_Click(object sender, EventArgs e)
{
readXML();
lblStatus.Text = "";
}
The Add button will make use of LINQ also, after checking to see if all text boxes were filled, opening the XML file and adding a new node to the file:
protected void butAdd_Click(object sender, EventArgs e)
{
try
{
if(txtName.Text == "" || txtCity.Text == "" || txtAge.Text == "")
lblStatus.Text = "Please complete the form.";
else
{
XDocument xmlDoc = XDocument.Load(Server.MapPath("People.xml"));

xmlDoc.Element("Persons").Add(new XElement("Person", new XElement("Name", txtName.Text),
new XElement("City", txtCity.Text), new XElement("Age", txtAge.Text)));

xmlDoc.Save(Server.MapPath("People.xml"));
lblStatus.Text = "Data successfully added to XML file.";
readXML();
}
}
catch
{
lblStatus.Text = "Sorry, unable to process request. Please try again.";
}
}

Sunday, January 30, 2011

Differences between Interface and Abstract class with Example


here are some similarities and differences between an interface and an abstract class that I have arranged in a table for easier comparison:
Feature
Interface
Abstract class
Multiple inheritance
A class may inherit several interfaces.
A class may inherit only one abstract class.
Default implementation
An interface cannot provide any code, just the signature.
An abstract class can provide complete, default code and/or just the details that have to be overridden.
Access ModfiersAn interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as publicAn abstract class can contain access modifiers for the subs, functions, properties
Core VS Peripheral
Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovableinterface.
An abstract class defines the core identity of aclass and there it is used for objects of the same type.
Homogeneity
If various implementations only share method signatures then it is better to use Interfaces.
If various implementations are of the same kind and use common behaviour or status then abstractclass is better to use.
Speed
Requires more time to find the actual method in the corresponding classes.
Fast
Adding functionality (Versioning)
If we add a new method to an Interface then we have to track down all the implementations of theinterface and define implementation for the new method.
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
Fields and ConstantsNo fields can be defined ininterfacesAn abstract class can have fields and constrants defined

Using the Code

Let me explain the code to make it a bit easier. There is an Employee abstract class and an IEmployee interface. Within the Abstract class and the Interface entity I am commenting on the differences between the artifacts.
I am testing both the Abstract class and the Interface by implementing objects from them. From the Employee abstract class, we have inherited one object: Emp_Fulltime. Similarly from IEmployee we have inherited one object: Emp_Fulltime2.
In the test code under the GUI, I am creating instances of both Emp_Fulltime and Emp_Fulltime2 and then setting their attributes and finally calling the calculateWage method of the objects.

Abstract Class Employee

 Collapse
using System;

namespace AbstractsANDInterfaces
{
    /// 


    /// Summary description for Employee.

    /// 

    
    public abstract class Employee
    {
        //we can have fields and properties 


        //in the Abstract class

        protected String id;
        protected String lname;
        protected String fname;

        //properties


        public abstract String ID
        {
            get;
            set;
        }

        public abstract String FirstName
        {
            get;
            set;
        }
        
        public abstract String LastName
        {
            get;
            set;
        }
        //completed methods


        public String Update()
        {
            return "Employee " + id + " " + 
                      lname + " " + fname + 
                      " updated";
        }
        //completed methods


        public String Add()
        {
            return "Employee " + id + " " + 
                      lname + " " + fname + 
                      " added";
        }
        //completed methods


        public String Delete()
        {
            return "Employee " + id + " " + 
                      lname + " " + fname + 
                      " deleted";
        }
        //completed methods


        public String Search()
        {
            return "Employee " + id + " " + 
                      lname + " " + fname + 
                      " found";
        }

        //abstract method that is different 


        //from Fulltime and Contractor

        //therefore i keep it uncompleted and 

        //let each implementation 

        //complete it the way they calculate the wage.


        public abstract String CalculateWage();
        
    }
}

Interface Employee

 Collapse
using System;


namespace AbstractsANDInterfaces
{
    /// <summary>


    /// Summary description for IEmployee.

    /// </summary>

    public interface IEmployee
    {
        //cannot have fields. uncommenting 


        //will raise error!
        //        protected String id;
        //        protected String lname;
        //        protected String fname;


        //just signature of the properties 

        //and methods.

        //setting a rule or contract to be 

        //followed by implementations.


        String ID
        {
            get;
            set;
        }

        String FirstName
        {
            get;
            set;
        }
        
        String LastName
        {
            get;
            set;
        }
        
        // cannot have implementation


        // cannot have modifiers public 

        // etc all are assumed public

        // cannot have virtual


        String Update();

        String Add();

        String Delete();

        String Search();

        String CalculateWage();
    }
}

Inherited Objects

Emp_Fulltime:
 Collapse
using System;

namespace AbstractsANDInterfaces
{
    /// 


    /// Summary description for Emp_Fulltime.

    /// 

     
    //Inheriting from the Abstract class

    public class Emp_Fulltime : Employee
    {
        //uses all the properties of the 


        //Abstract class therefore no 

        //properties or fields here!


        public Emp_Fulltime()
        {
        }


        public override String ID
        {
            get

            {
                return id;
            }
            set
            {
                id = value;
            }
        }
        
        public override String FirstName
        {
            get

            {
                return fname;
            }
            set
            {
                fname = value;
            }
        }

        public override String LastName
        {
            get

            {
                return lname;
            }
            set
            {
                lname = value;
            }
        }

        //common methods that are 

        //implemented in the abstract class

        public new String Add()
        {
            return base.Add();
        }
        //common methods that are implemented 


        //in the abstract class

        public new String Delete()
        {
            return base.Delete();
        }
        //common methods that are implemented 


        //in the abstract class

        public new String Search()
        {
            return base.Search();
        }
        //common methods that are implemented 


        //in the abstract class

        public new String Update()
        {
            return base.Update();
        }
        
        //abstract method that is different 


        //from Fulltime and Contractor

        //therefore I override it here.

        public override String CalculateWage()
        {
            return "Full time employee " + 
                  base.fname + " is calculated " + 
                  "using the Abstract class...";
        }
    }
}
Emp_Fulltime2:
 Collapse
using System;

namespace AbstractsANDInterfaces
{
    /// 

    /// Summary description for Emp_fulltime2.


    /// 

    
    //Implementing the interface

    public class Emp_fulltime2 : IEmployee
    {
        //All the properties and 


        //fields are defined here!

        protected String id;
        protected String lname;
        protected String fname;

        public Emp_fulltime2()
        {
            //


            // TODO: Add constructor logic here

            //

        }

        public String ID
        {
            get

            {
                return id;
            }
            set
            {
                id = value;
            }
        }
        
        public String FirstName
        {
            get
            {
                return fname;
            }
            set

            {
                fname = value;
            }
        }

        public String LastName
        {
            get
            {
                return lname;
            }
            set
            {
                lname = value;
            }
        }

        //all the manipulations including Add,Delete, 


        //Search, Update, Calculate are done

        //within the object as there are not 

        //implementation in the Interface entity.

        public String Add()
        {
            return "Fulltime Employee " + 
                          fname + " added.";
        }

        public String Delete()
        {
            return "Fulltime Employee " + 
                        fname + " deleted.";
        }

        public String Search()
        {
            return "Fulltime Employee " + 
                       fname + " searched.";
        }

        public String Update()
        {
            return "Fulltime Employee " + 
                        fname + " updated.";
        }
        
        //if you change to Calculatewage(). 


        //Just small 'w' it will raise 

        //error as in interface

        //it is CalculateWage() with capital 'W'.

        public String CalculateWage()
        {
            return "Full time employee " + 
                  fname + " caluculated using " + 
                  "Interface.";
        }
    }
}

Code for Testing

 Collapse
//This is the sub that tests both 

//implementations using Interface and Abstract

private void InterfaceExample_Click(object sender, 
                                System.EventArgs e)
{
    try

    {

        IEmployee emp;

        Emp_fulltime2 emp1 = new Emp_fulltime2();

        emp =  emp1;
        emp.ID = "2234";
        emp.FirstName= "Rahman" ;
        emp.LastName = "Mahmoodi" ;
        //call add method od the object


        MessageBox.Show(emp.Add().ToString());
        
        //call the CalculateWage method

        MessageBox.Show(emp.CalculateWage().ToString());


    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

}

private void cmdAbstractExample_Click(object sender, 
                                   System.EventArgs e)
{

    Employee emp;

    emp = new Emp_Fulltime();
    

    emp.ID = "2244";
    emp.FirstName= "Maria" ;
    emp.LastName = "Robinlius" ;
    MessageBox.Show(emp.Add().ToString());

    //call the CalculateWage method


    MessageBox.Show(emp.CalculateWage().ToString());

}

Conclusion

In the above examples, I have explained the differences between an abstract class and an interface. I have also implemented a demo project which uses both abstract class and interface and shows the differences in their implementation.

Tuesday, January 4, 2011

DotNet and Java Projects by RamaSubbaReddy

Complete DotNet and Java Projects by RamaSubbaReddy
Here i am posting some useful project for students

Click here to download

Note : If your unable to download click on this Link
Click here