Sunday, 3 March 2013

Working with ASP

Sudeep had given us the task of creating an aspx page and connecting it to the database. I successfully managed to create my first aspx page within a day.. Then after i showed it to Sudeep he asked us to do some updations like putting validations,adding links of editing and deleting etc. I even completed that within a day too. Then after i showed that also to him he made it more challenging for me by asking me to add Menus. Now i am still working on it. Now its becoming more and more challenging for me and i am enjoying  working with challenges.

Thursday, 28 February 2013

Need of Abstract classes and Abstract Methods

The concept of abstract classes is an extension to the concept of inheritance. In inheritance the parent classes can be defined with attributes that are commonly required under multiple child classes providing reusability.

FIGURE
  • Rectangle
  • Circle
  • Triangle
  • Cone
In the above case when we want to define different entities representing various figures like Rectangle, Traingle, Circle, Cone etc in such cases first we identify the attributes that are commonly required and put them under a parent class.
The class Figure as it is the parent provides the attributes commonly required to all figures given reusability. Along with this we can also define any abstract in the parent class figure so that the child classes will implement the abstract members which is a restriction for the child classes and cannot escape from it.
   

Created .aspx pages and Connected to the Database

Sudeep gave us a task to create two .aspx pages, and to link the first page with the second page and then asked to connect this pages with the Database. So that if once connected to the database we can Add, Update, Delete the data in the table that is stored in the database.
I have created one table GetJob in my database 'DB1' with the following columns and inserted some values to it:
  • JobCode
  • Vacancy
  • Post
  • Company
  • City
After creating a table I have added two web forms by selecting Asp.Net Empty Web Application in Visual Studio. The forms are named as Entry.aspx and JobDetails.aspx.
In Entry.aspx I have taken a Gridview Control(GridView is use to accept, display and edit data on a web page) and one Button(ADD).
Then I have provided a link to the ADD button that will transfer directly to second page i.e JobDetails.aspx wherein I have created one table with the same number of columns as in the GetJob table and then  within the table i have taken 5  labels and 5 text boxes. Along with that one button(SAVE) to save the data to the database. When we click to SAVE button it saves the data in the database. This I Have done through connectivity with SQL Server.
 Sudeep also told us to make the entire process more clear and asked us to do the following:
  •  Some validations the the text boxes.
  • Assign a Primary key to the first column of a table i.e'JobCode' and also it should generate automatic values once we switch to the form wherein Details need t o add.
  • With the Add link there should be two more links Update and Delete.
  • Instead of taking textbox towards the label 'City' there should be a DropDown List to give a chance to select one from many cities. 
  • After saving a JobDetails that page should redirect to the Entry.aspx page to add another Vacancies if required.

Interfaces

  • This is also a user defined type same as a class but can contain only abstract members in it.
  • The abstract members of an Interface will be implemented by a child class of  the Interface so here also the Interface is imposing restrictions on the child class.
  • A child can be inherited either from another class or an Interface also. When a class is inheriting from another class it can inherit only from one class (Single Inheritance). When class is inheriting from an Interface it can be inherited from any number of interfaces (Multiple Inheritance).
  •  Inheritance is divided into two categories
  1.   Implementation Inheritance
  2.   Interface Inheritance
  • If a class is inheriting from another class we call it as implementation Inheritance and this provides reusibility because child classes can consume their parent class members.
  • If a class is inheriting from an Interface we call it as Interface Inheritance but Interface Inheritance does not provide any reusibility because here the child c lass is only implementing the methods of its parent Interface.
Syntax:
[<modifiers>]  Interface <Name>    
{
 Abstract class declaration
}   

Rules while working with Interfaces
  • We can not declare variables under an interface.
  • Default scope for a member of an Interface is public where as it is private in case of class.
  • Every member of an Interface is by default abstract so we don't require to declare explicitly.
  • An Interface can inherit from another Interface if required.
Add an Interface item template under the project by choosing Interface from the add new item window and name it interface1.cs

interface Interface1
    {
        void add(int x, int y);
        void sub(int x, int y);
    }

Add another interface interface2.cs and write the following code

interface Interface2
    {
        void mul(int x, int y);
        void div(int x, int y);
    }

Now to implement the members of both these interfaces add a class interclass.cs and write the following code
       
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApps
{
    class interclass: Interface1,Interface2
    {
        public void add(int x, int y)
        {
            Console.WriteLine(x + y);
        }
        public void sub(int x, int y)
        {
            Console.WriteLine(x - y);
        }
        public void mul(int x, int y)
        {
            Console.WriteLine(x * y);
        }
        public void div(int x, int y)
        {
            Console.WriteLine(x / y);
        }
        static void Main()
        {
            interclass c = new interclass();
            c.add(100,45);
            c.sub(89,26);
            c.mul(12,34);
            c.div(456,23);
            Console.ReadLine();
        }
    }
}

Wednesday, 27 February 2013

Abstract Methods and Abstract Classes

A method without any method body is known as a Abstract method. It will have only the defination for the method the method and to declare any method as abstract we need to use abstract modifier on the method.    
   A class under which we define abstract members is  known as a abstract class and it also has to be defined using abstract modifier.

 abstract modifier
{
   public abstract void Add(int x,int y);
}

The concept of abstract method is near similar to the concept of method overriding were in case of Method Overriding if any members of parent class are declared as virtual those methods can be re- implemented under the child class using the override modifier.

Add a classAbsParent.cs and write the following code:
using System;

namespace CSharpConsole
{
    abstract class AbsParent
    {
        public void Add(int x, int y)
        {
            Console.WriteLine(x + y);
        }
        public void Sub(int x, int y)
        {
            Console.WriteLine(x -y );
        }  

        public abstract void mul(int x, int y);
        public abstract void div(int x,int y);
        
    }
 }
//Add another class AbsChild.cs and write the following code:
using System;
namespace CSharpConsole
{
    class AbsChild: AbsParent
    {
        public override void  mul(int x, int y)
      {
       Console.WriteLine(x*y );
      }

        public override void  div(int x, int y)
      {
       Console .WriteLine (x/y );
      }
        
      static void Main()
        {
            AbsChild c = new AbsChild();
            c.Add(20, 12);
            c.Sub(15, 5);
            c.mul (5, 5);
            c.div (10, 5);
            Console.ReadLine();
      }
    }
}

Tuesday, 26 February 2013

Creating my first aspx page

         Yesterday Sudeep gave us the task of creating an aspx page and connecting it to the database. We have started working on it and will try to finish the task as soon as possible.
                

TSQL Programming

  From last two days,we have started learning TSQL Programming. TSQL is non procedural or 4th Generation language because in TSQL we need to specify only what is the problem to solve and no need to specify how to solve the problem step by step hence working with TSQL will be easy but because of non-procedural value it is not possible to solve some complex queries .
  To overcome this problem Microsoft provides programming language feature into SQL which also are collectively called as TSQL Programming.

We have done  some basic programming using :
  •  Conditional Control Statements
  • Looping Control Statements
  • Cursor
Since we completed practicing all basic queries, now we have started with TSQL Programming which is the last part of SQL Server.