Saturday 12 April 2014

Enums in C#

An enum is kind of construct that you can use to make your code easier to work with. The enum construct is useful when you want to create a method that has multiple modes. A good example is the constructor for the CryptoStream class. The CryptoStream constructor accepts CryptoStreamMode.Read or CryptoStreamMode.Write as one of its arguments. This is a simple enum.

Enum is short form enumerator. Enumerating something literally means assigning numbers to it. An enum takes meaningful names and assigns numbers to them.

An enum object doesn't take up any more memory than a standard int variable, so there is no good reason not to use them to make your code clearer and easier to understand. As well as making your code more readable, enums also make methods easier to use; this makes them particularly useful in class libraries.

Friday 11 April 2014

Garbage Collector

The Garbage Collector is a special feature of C# that automatically clears objects from memory when they are no longer needed. For example: once a method is finished executing, the garbage collector removes any variables it used from the memory. Thanks to the garbage collector it is very rare for C# applications to suffer from memory leak issues when the program uses up more and more memory until it overloads the system.

The garbage collector will work automatically without you needing to do anything but you can send commands to it by using the GC class. The GC class can also provide some useful information about memory usage.
It is important to note that using the GC class can potentially make your project less memory efficient. The garbage collector files your objects into one of three categories or generations.

Generation 0 contains objects that will be disposed off quickly such as variables within methods. Generation 1 contain objects that are expected to remain in memory for longer, a public property of a class might be a generation 1 object. Generation 2 contains objects that are expected to remain in memory for a very long time such as static classes.

When the garbage collector cleans up memory, it promotes any object that is still in use to the next generation. Misusing the GC class can lead to objects being promoted to inappropriate generations and remaining in memory for longer than they should.

Monday 7 April 2014

Difference between Class and Struct

A struct is a construct that is almost identical to a class.
The major difference is that structs are value type objects while classes are reference type objects. This means that when you pass a struct object to a method, the method will receive a copy of the object and wont be able to make changes to it outside the method.
It is usually best to use classes instead of structs as there are many features of classes that aren't supported by struct objects. However it is not possible to pass a class object by value so if there is s special need to do this you may find struct more appropriate.

The limitations of structs are that they cannot have constructor methods without any arguments and they cannot extend classes nor can classes extend structs.

Because structs are value type objects, this means that they are stored in the stack. Whereas class objects are stored in the heap. Because struct objects are stored in the stack they will generally be slightly faster than class objects. It is best to avoid using large structs as there is a limited amount of space in the stack, you should only use structs for small constructs that need to be accessed quickly.

Sunday 6 April 2014

C# Lazy Class

When you create a variable in C# it immediately reserves a space in memory even if you don't assign a value to it. For example: if you create an int variable it immediately reserves 32 bit of memory. It is very rare for this to be an issue but there may be cases when you need to work with a class that consumes enormous amount of memory.

In these cases you can use the Lazy class to prevent the object from being loaded into memory until it is needed. This is called Lazy instantiation. If you follow good coding practices, its extremely unlikely that you'll ever need to make use of the lazy class.

An important note when working with Lazy objects is that their constructor methods will not run until they are loaded into memory.

Friday 4 April 2014

C# Tuple Class

The Tuple class is a new feature of ASP .NET 4.0 that enables you to very quickly create custom data structures similar to classes. Tuple objects can't contain methods, they are only structures for data storage. It is best practice to avoid using Tuple as where possible as they don't have the flexibility of real classes and can make your code harder to understand.

Tuple objects offer an easy way to return multiple values from a method. It is important to note however that it is better to do this using either the out keyword or ideally returning a custom class.
Tulple objects have a limit of eight properties, although you can nest Tuple objects by using Tuple as a property type within another Tuple. You need to set the values of a Tuple object's properties when you create it. After the Tuple object has been created it's values will be read only.
Once a Tuple object is created, it will behave in exactly the same way as any other object that has read-only properties.

As well as creating a Tuple object using the standard method of instantiating a class, you can also use the Tuple.Create method. The only reason to use this method is to cut down on the amount of code you need to type as the Create method will automatically select the correct data types for the values you provide.

Thursday 3 April 2014

ASP .NET Master Pages

A Master Page is a way of storing your site layout in a single file which you can then assign to many pages. The site that is automatically generated when you create a new ASP.NET web application includes a master page. By using a master page you can avoid having to manually update each page when a minor change is made to your site layout.
The disadvantage of master pages is that you lose the ability to completely customize each page.

The ContentPlaceHolder is a special control that is only available on master pages. It is used to define areas that can be edited on pages that use the master page. The ContentPaceHolder appears in the standard category of the toolbox.

Tuesday 1 April 2014

Difference between Web Application Project and Website Project

Web Application projects are generally a better option then website projects for two reasons: Firstly because website projects are not compiled; the web server has to compile them as the site is viewed, this makes websites slightly slower then web applications.
Secondly because web application projects are compiled; so the code of the website they produce will not be easy to edit, this prevents the website from being tampered with and allows you to protect your source code.

In your professional career you might have to work on a website project that was created by another developer, in this case it is useful to convert it into a web application project.

Monday 31 March 2014

Why C# is a Type-Safe Language

"It is impossible to write unsafe code in C#". Some programmers think that this statement is not 100% correct but it is correct and C# is definitely a type-safe language.

C# enforces its variable types very strongly for ex: this means that C# is always aware that an int variable will contain a whole number and nothing else; because of this C# is considered a type-safe language. Some other programming languages allow variable to be created without fixed data types which can lead to errors that are very hard to debug.

Saturday 29 March 2014

Global.asax

Global.asax contains event handlers that are related to your applications and user sessions. Global.asax also contains an event handler that runs whenever an error happens anywhere in your application. By using Global.asax you can intercept every error that happens on your site. There are other event handlers in Global.asax that can also be useful.

Application_Start:
Runs when your site is started by the web server.

Application_End:
Runs when your site is stopped by the web server.

Application_Error:
Whenever there is a server error on your site.

Session_Start:
Runs when a user arrives at your site and start a new session.

Session_End:
Runs when a user session ends.

The most likely use of the Session_Start and Session_End events would be to log details of users when they arrive at your site.

You can also add other event handlers to Global.asax. There are many other application events that Global.asax can handle. A useful example is the Application_AuthenticateRequest event which runs before any page is served to a user, some programmers use this to implement their own custom login systems when they have special requirements that go beyond the built-in security features.

Friday 28 March 2014

Stored Procedures

Store Procedures are similar to methods but are stored inside the database. Store Procedures contains SQL code that can manipulate data in ways that would be difficult using C#. In a team environment store procedures are usually written by the DBA.

Store Procedures can have arguments and return values just like any other method. Store Procedures can do everything LINQ can do and usually be faster and more efficient. Using Store Procedures for everything might seem ideal but having hundred's of store procedures in a database often becomes unmanageable and difficult to maintain. I recommend using LINQ for simple everyday queries and store procedures for anything more complicated or if you see performance issues.

Using Store Procedures centralizes your SQL code on the database server and makes it easier to maintain your code if the database changes.

Thursday 27 March 2014

Collections Vs. Arrays

Collections are a more advanced way of storing multiple values inside a single object. Unlike arrays which have a fixed size once they are created, you can add and remove items from collections.
For most purposes collections are more convenient to work with then arrays.

Monday 24 March 2014

How to Configure Default Routing


We are given the above topology and we have to implement the following:

  1. Create default route on ISP router to the RISE STAR Enterprise Company. 
  2. Apply command show ip route to verify your configuration. 
Default Routing is very similar to the Static Routing as the pattern of configuring the Default Routing is identical to the Static Routing.

Now to start, click the ISP router and go to the CLI tab and type the following:

ISP>en
ISP#conf t
ISP(config) #ip route 0.0.0.0 0.0.0.0 se0/0/0
ISP(config) #ex
ISP#

Now click LAB_A router, go to the CLI tab and type the following:

LAB_A>en
LAB_A#conf t
LAB_A(config) #ip route 0.0.0.0 0.0.0.0 se0/0/0
LAB_A(config) #ip route 0.0.0.0 0.0.0.0 se0/0/1
LAB_A(config) #ex
LAB_A#

Now click on LAB_B router and go to the CLI tab and type the following:

LAB_B>en
LAB_B#conf t
LAB_B(config) #ip route 0.0.0.0 0.0.0.0 se0/0/0
LAB_B(config) #ip route 0.0.0.0 0.0.0.0 fa0/0
LAB_B(config) #ex
LAB_B#

Finally click on LAB_C router and go to the CLI tab and type the following:

LAB_C>en
LAB_C#conf t
LAB_C(config) #ip route 0.0.0.0 0.0.0.0 fa0/0
LAB_C(config) #ex
LAB_C#

Note that the first address(0.0.0.0) is used for the default address and the second(0.0.0.0) is used for the default sub-net mask and fa0/0 is the next hop address.
The task 1 is completed here.

Now the second task is to verify the configuration. To do this simply go to every router one by one and type the command show ip route in the CLI tab as shown below:


As you can see in the highlighted area the default routing is configured. If this line does not appear, it means you have not configured the routers correctly.

Sunday 23 March 2014

LINQ

Stands for Language Integrated Query. LINQ is a relatively new addition to .NET which makes working with databases much easier.

Before LINQ, programmers would usually create their own set of classes to generate the SQL needed to interact with the database, this took a lot of time and effort. ASP.NET's LINQ classes automatically create the SQL needed to interact with your data making it unnecessary to learn SQL. LINQ also streamlines the development process by removing the need to create your own data access classes.

It is important to note that although it is very easy to create LINQ data classes, they do not automatically update when the structure of a database changes; by structure I mean the design of the database not the data that is held inside it. The only way to update LINQ data classes is to recreate the entire dbml file, you can do this by simply deleting the old file and creating a new one. In theory it is possible to refresh individual items but I have found that this occasionally causes problems that prevent the project from building. For this reason I recommend that you always recreate the entire dbml file if your database structure changes.

Before LINQ, databases were usually accessed using the System.Data.SqlClient namespace of the .NET Library. System.Data.SqlClient is still available but it requires a lot more code to use. This method also requires you to either use Store Procedures or SQL code. LINQ has made System.Data.SqlClient obsolete but you may still see it being used in older projects.

Saturday 22 March 2014

DES Key Generation

Download the DES Key Generator to generate the Key with the help of Sub-Key.
Click the Link below to download the DES Key Generator.

DES Key Generator

DES Sub-Key Generation

Download the DES Sub-Key Generator to generate the Sub-Key 1 and Sub-Key 2 with the help of Key.
Click the Link below to download the DES Sub-Key Generator.

Thursday 13 March 2014

S-DES Encryption

Download the S-DES Encryption tool to encrypt the plain text with the help of Key.
If you do not have the key don't worry, it can also generate Key, Sub-Key 1 and Sub-Key 2.
If you have Sub-Key 2 you can find Sub-Key 1 and Key and if you have the Key, you can find Sub-Key 1 and Sub-Key 2 using the following tool.
Click the Link below to download the S-DES Encryption Tool.

S-DES ENCRYPTION TOOL

Wednesday 12 March 2014

Constructor in C#

A constructor is a method that runs whenever an instance of a class is created.

public MyClass()
{

}

This is a simple constructor, any code you put inside it will run when an instance of the class is created. In order to be recognized as a constructor the method must have the same name as the class it belongs to.

Notice how the syntax differs from a normal method, there is no void or other return value type specified before the method name. This syntax is peculiar to constructors.

public MyClass()
{
IntProperty = 15;// This will set the IntProperty property to 15 whenever a new instance of the class is created.
}

Just like any other method,constructors can have arguments.

public MyClass(int StartingNumber)//This adds an argument to the constructor called StartingNumber
{
IntProperty = StartingNumber;//This sets the IntProperty property to the number provided in the argument.
}

This should look very similar to you, it is exactly the same as adding arguments to any other method.

protected void Page_Load(object sender, EventArgs e)
{
MyClass MyClassInstance = new MyClass(15);//This provides the number 15 as the constructor argument. 
}

This means that when the constructor runs it will set the value of IntProperty to 15.

Sunday 9 March 2014

C# Dispose Method

Many classes have a method called Dispose(). The Dispose method is used to clear the class from memory. Some classes do not have dispose methods, this is usually because they don't have any properties that stay in memory. A link data class like the Form1DataContext class can load a lot of data into memory when it is used so it is good practice to dispose of it as soon as you no longer need it.

protected void ButtonSubmit_Click(object sender, EventArgs e)
{
Form1DataContext Data = new Form1DataContext();//This creates a new instance of the Form1DataContext class called Data. 
Data.SubmitChanges();// This method is just an example of a method that you might call from the Data instance.
Data.Dispose();//This will remove the Data instance from memory.
}
Note that If you try to work with the Data instance after Data.Dispose(); line you would cause an exception.

As well as disposing of instances using the Dispose method you can use a using statement to automatically dispose of an instance.
Note that working with using statements inside your code is different to the using statements at the top of your page.

protected void ButtonSubmit_Click(object sender, EventArgs e)
{
using(Form1DataContext Data = new Form1DataContext())//This creates a new instance of the Form1DataContext class called Data. 
{
Data.SubmitChanges();// This method is just an example of a method that you might call from the Data instance.
}
}

This does exactly the same thing as calling the Dispose method but is much easier to understand and work with. The using statement creates the Data instance and then automatically disposes of it after the last curly bracket.
Note that C# has a garbage collector that automatically disposes of objects that are no longer in scope. In this case for example the C# garbage collector would always dispose of the data instance after the ButtonSubmit_Click event handler was finished since it wouldn't be usable anymore. Despite this it is always best to dispose of instances where possible since the garbage collector doesn't always clean up memory immediately.

Thursday 6 March 2014

C# StringBuilder

The StringBuilder object is the more advanced version of the string variable that is designed to work better with very large strings. It is in the System.Text namespace so it is not easily available by default.

It is an auxiliary object used for manipulating characters. It contains a buffer, typically initialized with a string but usually larger than that string. This buffer can be manipulated in place without creating a new string: You can insert, append, remove, and replace characters. When you're done manipulating the characters, use StringBuilder's ToString method to extract the finished string from it.

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

namespace StringBuilderClass
{
    class Program
    {
        static void Main(string[] args)
        {
            String TestStringBuilder;
            StringBuilder OtherStringBuilder = new StringBuilder("Hello");
            OtherStringBuilder.Remove(2, 3); // produces "He"
            OtherStringBuilder.Insert(2, "lp"); // produces "Help"
            OtherStringBuilder.Replace('l', 'a'); // produces "Heap"
            TestStringBuilder = OtherStringBuilder.ToString();
        }
    }
}

Wednesday 5 March 2014

Displaying Data from Multiple Tables


  • Write a query to display the last name, department number, and department name for all employees.
SELECT e.last_name, e.department_id, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id;
  • Create a unique listing of all jobs that are in department 30. Include the location of department 90 in the output.
SELECT DISTINCT job_id, location_id
FROM employees, departments
WHERE employees.department_id = departments.department_id
AND employees.department_id = 80;
  • Write a query to display the employee last name, department name, location ID, and city of all employees who earn a commission.
SELECT e.last_name, d.department_name, d.location_id, l.city
FROM employees e, departments d, locations l
WHERE e.department_id = d.department_id
AND d.location_id = l.location_id
AND e.commission_pct IS NOT NULL;
  • Display the employee last name and department name for all employees who have an a (lowercase) in their last names.
SELECT last_name, department_name
FROM employees, departments
WHERE employees.department_id = departments.department_id
AND last_name LIKE '%a%';
  • Write a query to display the last name, job, department number, and department name for all employees who work in Toronto.
SELECT e.last_name, e.job_id, e.department_id, d.department_name
FROM employees e JOIN departments d
ON (e.department_id = d.department_id)
JOIN locations l
ON (d.location_id = l.location_id)
WHERE LOWER(l.city) = 'toronto';
  • Display the employee last name and employee number along with their manager’s last name and manager number. Label the columns Employee, Emp#, Manager, and Mgr#, respectively. 
SELECT w.last_name "Employee", w.employee_id "EMP#", m.last_name "Manager", m.employee_id "Mgr#"
FROM employees w join employees m
ON (w.manager_id = m.employee_id);
  • Modify above query to display all employees including King, who has no manager.
SELECT w.last_name "Employee", w.employee_id "EMP#", m.last_name "Manager", m.employee_id "Mgr#"
FROM employees w
LEFT OUTER JOIN employees m
ON (w.manager_id = m.employee_id);
  • Create a query that displays employee last names,department numbers, and all the employees who work in the same department as a given employee. Give each column an appropriate label. 
SELECT e.department_id department, e.last_name employee, c.last_name colleague
FROM employees e JOIN employees c
ON (e.department_id = c.department_id)
WHERE e.employee_id <> c.employee_id
ORDER BY e.department_id, e.last_name, c.last_name;
  • Show the structure of the JOB_GRADES table. Create a query that displays the name, job, department name, salary, and grade for all employees. 
DESC JOB_GRADES
SELECT e.last_name, e.job_id, d.department_name, e.salary, j.grade_level
FROM employees e, departments d, job_grades j
WHERE e.department_id = d.department_id
AND e.salary BETWEEN j.lowest_sal AND j.highest_sal;
  • Create a query to display the name and hire date of any employee hired after employee Davies.
SELECT e.last_name, e.hire_date
FROM employees e, employees davies
WHERE davies.last_name = 'Davies'
AND davies.hire_date < e.hire_date;
  • Display the names and hire dates for all employees who were hired before their managers, along with their manager’s names and hire dates. Label the columns Employee, Emp Hired, Manager, and Mgr Hired, respectively.
SELECT w.last_name, w.hire_date, m.last_name, m.hire_date
FROM employees w, employees m
WHERE w.manager_id = m.employee_id
AND w.hire_date < m.hire_date;

Saturday 1 March 2014

Single-Row Functions

  • Write a query to display the current date. Label the column Date.
SELECT sysdate "DATE" 
FROM dual;


  • For each employee display the employee ID number, last name, salary and salary increased by 15% and expressed as a whole number. Label the column New Salary.
SELECT employee_id, last_name, salary, ROUND(salary * 1.15, 0) "New Salary" 
FROM employees;


  • Modify above query to add a column that subtracts the old salary from the new salary. Label the column Increase.
SELECT employee_id, last_name, salary, ROUND(salary * 1.15, 0) "New Salary", ROUND(salary * 1.15, 0) - salary "Increase" 
FROM employees;


  • Write a query that displays the employee's last name with the first letter capitalized and all other letters lower case and the length of the names, for all employees whose name starts with J, A or M. Give each column an appropriate label. Sort the results by employee's last names.
SELECT INITCAP(last_name) "Name", LENGTH(last_name) "Length" 
FROM employees 
WHERE last_name LIKE 'J%' 
OR last_name LIKE 'A%' 
OR last_name LIKE 'M%' 
ORDER BY last_name;


  • For each employee display the employee's last name, and calculate the number of months between today and the date the employee was hired. Label the column MONTHS_WORKED. Order your results by the number of months employed. Round the number of months up to the closest whole number.
SELECT last_name, ROUND(MOTHS_BETWEEN(sysdate, hire_date)) "MONTHS_WORKED" 
FROM employees 
ORDER BY MONTHS_BETWEEN(sysdate, hire_date);


  •  Write a query that produces the following for each employee:
    <employee last name> earns <salary> monthly but wants <3 times salary>.
     Label the column Dream Salaries.
    Dream Salaries
    King earns $24,000.00 monthly but wants $72.000.00.
    Kochhar earns $17,000.00 monthly but wants $51.000.00.
    De Haan earns $17,000.00 monthly but wants $51.000.00.
    Hunold earns $9,000.00 monthly but wants $27.000.00.
    Emst earns $6,000.00 monthly but wants $18.000.00.
    Lorentz earns $4,200.00 monthly but wants $12.600.00.
    Morgous earns $5,800.00 monthly but wants $17.400.00.
SELECT last_name ||' earns '|| TO_CHAR(salary, 'fm$99,999.00') ||' monthly but wants '|| TO_CHAR(salary * 3, 'fm$99,999.00') ||'.' 
FROM employees;


  •  Create a query to display the last name and salary for all employees. Format the salary to be 15.
      
    LAST_NAME
    SALARY
    King
    $$$$$$$$$$24000
    Kochhar
    $$$$$$$$$$17000
    De Haan
    $$$$$$$$$$17000
    Hunold
    $$$$$$$$$$$9000
    Emst
    $$$$$$$$$$$6000
    Lorentz
    $$$$$$$$$$$4200
    Morgous
    $$$$$$$$$$$5800
SELECT last_name, LPAD(salary, 15, '$') "SALARY" 
FROM employees;


  • Display each employee's last name, hire date and salary review date, which is the first Monday after six months of service. Label the column Review. Format the dates to appear similar to "Monday, the Thirty-First of July, 2000."
SELECT last_name, hire_date, TO_CHAR(NEXT_DAY(ADD_MONTHS(hire_date, 6), 'MONDAY'), 'fmDay, "the" Ddspth "of" Month, YYYY') "REVIEW" 
FROM employees; 


  • Display the last name, hire date and day of the week on which the employee started. Label the column DAY. Order the results by the day of the week starting with Monday.
SELECT last_name, hire_date, TO_CHAR(hire_date, 'DAY') "DAY" 
FROM employees 
ORDER BY TO_CHAR(hire_date -1, 'd');


  • Create a query that displays the employees last names and commission amounts. If an employee does not earn commission, put "No Commission." Label the column COMM. 
SELECT last_name, NVL(TO_CHAR(commission_pct), 'No Commission') "COMM" 
FROM employeees;


  •  Create a query that displays the employees last names and indicates the amounts of their annual salaries with asterisks. Each asterisk signifies a thousand dollars. Sort the data in descending order of salary. Label the column EMPLOYEES_AND_THEIR_SALARIES.
SELECT last_name ||' '|| RPAD(' ', salary/1000+1, '*') "EMPLOYEES_AND_THEIR_SALARIES"
FROM employees 
ORDER BY salary DESC;


  • Using the DECODE function, write a query that displays the grade of all employees based on the value of the column JOB_ID,as per the following data.
     
    Job
    Grade
    AD_PRES
    A
    ST_MAN
    B
    IT_PROG
    C
    SA_REP
    D
    ST_CLERK
    E
    None of the above
    0
 SELECT job_id, decode (job_id, 
                                             'ST_CLERK',       'E', 
                                             'SA_REP',           'D', 
                                             'IT_PROG',          'C', 
                                             'ST_MAN',           'B', 
                                             'AD_PRES',         'A', 
                                                                        '0') "G"     
FROM employees;


  • Rewrite the statement in the preceding question using the CASE syntax
SELECT job_id, CASE job_id 
               WHEN   'ST_CLERK'     THEN 'E' 
               WHEN   'SA_REP'         THEN 'D' 
               WHEN   'IT_PROG'       THEN 'C' 
               WHEN   'ST_MAN'        THEN 'B' 
               WHEN   'AD_PRES'      THEN 'A' 
               ELSE      '0'    END "G" 
FROM employees;

Friday 28 February 2014

ASP .NET Controls

LinkButton Control:
The link button control behaves in exactly the same way as the button but the server will convert it into an HTML <a> tag rather than an HTML input submit control. This control appears to be a hyper link but acts like a button, unlike a hyper link it posts back by using JavaScript code.

Image Button Control:
The image button control as you might expect is a button that uses an image. Note that unlike the link button control the image button doesn't need to use any JavaScript to submit the form.
The alternate test property of image button control is exclusive to images. Alternate text was originally intended for users of text only browsers where the browser couldn't display an image the alternate text is displayed instead. Although today every major web browser is able to display images, alternate text is still useful for two reasons: one is that the search engines use alternate text to identify which keywords to attach to an image, the second reason is that visually impaired users can use alternate text in conjunction with speech detect software.
The button, link button and image button controls provide a choice of three different appearances for your buttons.

Label and Literal Control:
It doesn't have any text so a place holder is shown instead. Label and Literals controls normally display their text property on the page. Visual studio adds place holder text when the text property is empty as otherwise you wouldn't be able to the control in the design view. A label control has its text property set to 'Label' when it is created, if you clear the text property of label control it will still appear in design view with its ID property. A literal control's text property is blank when it is first created. It appears in design view with its ID property until the text property has been set. When the text property is blank the control won't acctually display any text in the user's browser. The label control is the best choice when you simply want to display text in the user's browser.

TextBox Control:
It is one of the most common controls in ASP.NET. The text box control provides the easiest way to provide users of your site to input text.

CheckBox Control:
A CheckBox is simply a box that a user can check or uncheck, you have probably seen them while browsing the internet. In the same way as all ASP .NET controls, the CheckBox is converted into HTML when the page is sent to a web browser. The checkbox control is based on the HTML input(checkbox) control but has more features. Although it is possible to use the controls from HTML category in ASP .NET, its almost always better to use ASP .NET equivalent from the standard category of the tool box.
Note if you want to create a page with lots of CheckBox choices you should be aware of the CheckBoxList control. CheckBoxList controls works very similarly to DropDown list controls except the items are shown as the check boxes instead of a drop down menu.

RadioButton Control:
Radio buttons are very similar to check boxes but only allow user to choose one option at a time. The RadioButtonList control is similar to the CheckBox list control as it allows you to create a group of radio buttons in the same way as you create a DropDown list control. In most cases the RadioButtonList control is preferable to the RadioButton control as it automatically assigns the radio buttons to the same group. The events for all of the radio buttons are also grouped together.

DropDownList Control:
DropDownList control is similar to the CheckBox and RadioButton controls. Items in DropDownList are allowed to have both a text value that is shown to the user and another value that is hidden from the user but is visible to your C# code. The value is specially used when your DropDownList control is linked to items in a database. Each item in the DropDownList control is automatically assigned a unique index number.

RequiredFieldValidator Control:
One thing you often want to do with online forms is to validate the user's input to make sure that they are entering everything correctly. Although you could validate input using a combination of C# and JavaScript. ASP .NET provides a series of controls that will automatically generate the validation code for you, the RequiredFieldValidator is one of those. A RequiredFieldValidator simply make sure that the user has entered something into the control it validates.

RangeValidator Control:
The RabgeValidator Control allows you to check that the user has entered correct type of value and allows you to restrict the value to a range. The ValidationSummary control lets you easily display a list of validation error messages to let the user know what they have entered incorrectly. The RangeValidator control is intended to restrict a value to a specific type and range.

CompareValidator Control:
The CompareValidator control is used when you want to validate by comparing one control with another.

CustomValidator Control:
The CustomValidator control allows you to enter your own JavaScript code to be used for validation.

RegularExpressionValidator Control:
The RegularExpressionValidator control allows you to validate using a regular expression.

ValidationSummary Control:
You can use a ValidationSummary control to show a list of validation problems.

Note that these are the details of the most commonly and frequently used controls. You can easily find the details of all the ASP .NET controls on the internet.

Monday 24 February 2014

ASP .NET Page Life Cycle Events

When a page request is send to a web server, the page tuns through a series of events during its creation and disposal.
Here are some important ASP .NET page life cycle events.

1) PreInit 
The entry point of the page life cycle is the pre-initialization phase called "PreInit". This is the only event where programmatic access to master pages and themes is allowed.  You can dynamically set the values of master pages and themes in this event.  You can also dynamically create controls in this event.

2) Init
This event fires after each control has been initialized. You can use this event to change initialization values for controls. The "Init" event is fired first for the most bottom control in the hierarchy, and then fired up the hierarchy until it is fired for the page itself.

3) Load
The Load event fired after the Init event. Code inside the page load event typically checks for PostBack and then sets control properties appropriately. This method is typically used for most code, since this is the first place in the page lifecycle that all values are restored. Most code checks the value of IsPostBack to avoid unnecessarily resetting state. You may also wish to call Validate and check the value of IsValid in this method. You can also create dynamic controls in this method.

4) PostBack event handling
If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page. (There is an exception to this sequence: the handler for the event that caused validation is called after validation.)

5) Render
This is a method of the page object and its controls (and not an event). At this point, ASP.NET calls this method on each of the page's controls to get its output. The Render method generates the client-side HTML, Dynamic Hypertext Markup Language (DHTML), and script that are necessary to properly display a control at the browser.

Note: Right click on the web page displayed at client's browser and view the Page's Source. You will not find any aspx server control in the code. Because all aspx controls are converted to their respective HTML representation. Browser is capable of displaying HTML and client side scripts.

6) Unload
The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.

Note that these are the general page life-cycle events. There are some more events like:(Init complete, PreLoad, LoadComplete etc)which you can easily find on the internet. But these six events are the basic and most important events that you must have some knowledge about.

Sunday 23 February 2014

Restricting and Sorting Data


  • Create a query to display the last name and salary of employees earning more than $12,000.
SELECT last_name, salary 
FROM employees
WHERE salary>12000;


  •  Create a query to display the employee last name and job code for employee number 176.
SELECT last_name, job_id 
FROM employees 
WHERE employee_id=176;


  • Create a query to display the last name and salary form all employees whose salary is not in the range of $5,000 and $12,000.
SELECT last_name, salary 
FROM employees 
WHERE salary NOT BETWEEN 5000 AND 12000;


  •  Display the employee last_name, Job ID, and start date of employees hired between February 20, 1998, and May 1, 1998. Order the query in ascending order by start date.
SELECT last_name, job_code, hire_date 
FROM employees 
WHERE hire_date BETWEEN '20-Feb-98' AND '01-May-98' 
ORDER BY hire_date; 


  •  Display the last name and department number of all employees in departments 20 and 50 in alphabetical order by name.
SELECT last_name, department_id 
FROM employees 
WHERE department_id IN (20, 50) 
ORDER BY last_name; 


  •  Create a query to list the last name and salary of all employees who earn between $5,000 and $12,000, and are in department 20 or 50. Label the column Employee and Monthly Salary respectively. 
SELECT last_name "Employee", salary "Monthly Salary" 
FROM employees 
WHERE salary BETWEEN 5000 AND 12000 
AND department_id IN (20, 50);


  • Display the last name and hire date of every employee who was hired in 1994.
SELECT last_name, hire_date 
FROM employees 
WHERE hire_date LIKE '%94'; 


  •  Display the last name and job title of all employees who do not have a manager.
SELECT last_name, job_id 
FROM employees 
WHERE manager_id IS NULL;


  •  Display the last name, salary and commission for all employees who earn commissions. Sort the date in descending order of salary and commissions.
SELECT last_name, salary, commission_pct 
FROM employees 
WHERE commission_pct IS NOT NULL 
ORDER BY salary DESC, commission_pct DESC;


  • Display the last names of all employees where the third letter of the name is an a 
SELECT last_name 
FROM employees 
WHERE last_name LIKE '__a%' ;


  •  Display the last name of all employees who have an a and an e in their last name.
SELECT last_name 
FROM employees 
WHERE last_name LIKE '%a%' 
AND last_name LIKE '%e%' ;


  •  Display the last name, job and salary for all employees whoso job is sales representative or stock clerk and whose salary is not equal to $2,500, $3,500 or $7,000.
SELECT last_name, job_id, salary 
FROM employees 
WHERE job_id IN ('SA_REP', 'ST_CLERK') 
AND salary NOT IN (2500, 3500, 7000);


  •  Display the last name, salary and commission for all employees hose commission amount is 20%.
SELECT last_name, salary, commission_pct 
FROM employees 
WHERE commission_pct = .20 ;

Friday 21 February 2014

Writing Basic SQL SELECT Statements


  • Show the structure of the DEPARTMENTS table. Select all data from the table.
DESC departments;
SELECT * 
FROM departments;


  • Show the structure of the EMPLOYEES table. Write a query to display the last name, job code, hire date and employee number for each employee, with employee number appearing first
DESC employees;
SELECT employee_id, last_name, job_id, hire_date 
FROM employees; 


  • Create a query to display unique job codes from the EMPLOYEES table. 
SELECT DISTINCT job_id
FROM employees;


  • Write a query to display the column headings Emp #, Employee, Job, and Hire Date, respectively, from the EMPLOYEES table. 
SELECT employee_id "Emp #", last_name "Employee", job_id "Job", hire_date "Hire Date" 
FROM employees;
Note: You can also use AS to display the column with other name. For ex: in above query you can also write: SELECT employee_number AS "Emp #" from emp; 


  • Display the last name concatenated with the Job ID, separated by a comma and space, and name the column Employee and Title.
SELECT last_name||', '||job_id "Employee and Title" 
FROM employees;


  • Create a query to display all the data from the EMPLOYEES table. Separate each column by a comma. Name the column THE_OUTPUT. 
SELECT employee_id||','||last_name||','||job_id||','||manager_id||','||hire_date||','||salary||','||commission_pct "THE_OUTPUT" 
FROM employees;

Saturday 15 February 2014

How to Provide Web services to all Clients across the Network

Once you configured the DHCP services (How to Provide DHCP services to all Clients across the Network), then configuring Web services is very easy.
Now if you recall; we configured RIP(Routing Information Protocol) to the Routers to allow communication between clients and also to provide DHCP services across the Network and this is the only thing we need to do with the routers to provide Web services to the clients across the network, no need to provide any helper-address as we provided for the DHCP services.


Configuring the Web services:
Configuring the Web services for the network shown in the picture:

Step 1:
Click the Web server then go to the Config tab and turn off the DHCP services only.

Step 2:
Provide the IP-address from the Desktop tab of the Web server and make sure the IP scheme is different. Here the address is 110.0.0.1


Step 3:
Configure RIP in all the routers in order to make sure the Web services are available to all the clients across the network; which obviously you've done before when you configured the DHCP services.

Step 4:
Now click the DHCP server and under the Config tab click DHCP. Here you will see the pools that you had made when you configured the DHCP server. Now go into every pool one by one and provide the DNS server address; this is the address that you provided to Web server as shown in the picture above. After providing DNS server address your pools would look like this:


Step 5:
Now go into every Laptop and under the Desktop tab click the IP configuration tile and make the DHCP request again to make sure that our client(Laptop) has the DNS server address.


Step 6:
Now click the Web server again and under the Config tab click DNS. There you will see two text boxes, one with a label of name and another is of address. In the name field enter any URL you want for ex:(www.cisco.com) and in the address field enter the same address that you provided the Web server, in our case this is:(110.0.0.1).


Step 7:
Web server is configured. Now it's time to check whether our clients can access the web services or not. Click on any Laptop(Client) and under the Desktop tab click the Web Browser and enter the URL that you provided above. You will see the page is displayed like shown below:




Saturday 8 February 2014

How to Provide DHCP services to all Clients across the Network

The Network is designed and configured in Cisco Packet Tracer version 5.3.0.0088
The Network feeds DHCP services to all the Clients of Network across all Routers.
The Network also has the Web server which feeds Web services to all the Clients across all Routers, but this is not a part of this post. It will be covered later.
In this post my focus is just on configuring DHCP server.


As shown above in the picture the network has four access points that are connected to the Routers and then the Routers are connected to one another, making a loop. While one access point is connected to the switch and we also have a DHCP server which is directly connected to that switch and then the switch is connected to the Router. Our clients(Laptops) are connected(wireless) to their respective access points.

Configuring the Network:

Step 1:
Configure the Routers. You can configure through CLI or trough the user interface, it's your choice. Make sure you have given different IP schemes to all the routers.

Step 2:
Once all routers are configured and all the ports turns green, apply RIP(Routing Information Protocol) to the Routers, to allow data communication and to feed DHCP services to the clients across all routers.

Step 3:
Click the DHCP server and provide IP and subnet mask(IP scheme must be different). Now as shown in the Picture we have five different sub-networks(five access points) so create five pools with Default gateway, Start IP address, Subnet Mask and Max Number of Users.
The default gateway IP is the one which you had given to the port of the router that is connected to the access point. Start IP address will be the network address(for ex: 40.0.0.0). Subnet Mask is the default mask for the IP class that you are using and Max Number of Users means the number of clients to provide IP's, give the value 256.


Step 4:
Now give the helper address to the ports of the Routers that are between path of the clients. The helper-address is the IP address of DHCP server. To provide helper-address, click the router and go to the CLI tab. Go to that port number(for ex: if you have the port number se1/0 type int se1/0). Then type ip helper-address 100.0.0.0(Note: this will be the IP address of your DHCP server). Give that address to all the ports one by one. The figure below will help you understand on what ports you have to give the helper-address, and what do I mean by the path.



Step 5:
Finally we are finished configuring the DHCP server. Now check on the Laptops one by one, you will see that the DHCP request successful message and the laptops are obtaining the IP address from the DHCP server.


Wednesday 5 February 2014

How to Unblock YouTube

There are many ways to unblock YouTube or any other website.

The best way of unblocking YouTube is to go to your browser and type: www.playit.pk and search any video you want to play and download. It also works perfectly on Android. You can also install playit.pk extension to Chrome. Once you installed it you just need to switch it on and you can watch any video you want on YouTube.

The second way is by proxy websites, for example: Go to internet browser and type the address https://12345proxy.com/ and in the page type www.youtube.com it will take you to the YouTube homepage.
Once you able to view the video you can then download it by going to http://en.savefrom.net/. Just paste the video link, select the video quality and download it. No need of any additional video downloading softwares.

Another way of unblocking the websites is to download and install the Google chrome extension named ZenMate. It will secure your connection and unblock any site you want. You just have to switch it on before typing the website address. It has five different locations so that you can set accordingly, depending on the data traffic.

Another way of unblocking YouTube is by installing Hotspot Shield. This will also secure your connection and unblock any website you want. But personally I do not recommend installing hotspot shield because this will degrade the performance of your system and also sometimes it does not work properly.

Hope this is helpful.


Tuesday 4 February 2014

How to Crack the Password of Root and Add Users in Linux


When you start the Linux Operating System, a screen will appear as shown below:




On this screen press e to edit commands before booting.
Hitting e will take you to the following screen. Here you have to make sure that kernel is highlighted, press up and down arrows keys to navigate through the menu and highlight the kernel mode and when the kernel mode is highlighted press e again.



It will take you to the following screen. On this screen just type single as shown below.



This will again take you to the previous screen where you pressed e but this time you have to press b in order to boot.



Now hitting ‘b’ will take you the following screen, on this screen first to crack the root password type passwd then it will ask you a new password, type a new password and then retype it, after this it will show you the message All authentication tokens updated successfully this means you have successfully changed the password of root.



Now we have to add another user and set a password. In order to accomplish this task we need to know the two commands highlighted below. First type the command useradd and after space type the name you want to give the user just like shown below, I have given the name os, this command will create a user you specified. Now to set a password of the user type passwd and name of the user you want to set a password to, just like highlighted below. This will successfully set a password and will show you a message All authentication tokens update successfully. In the end type init 6 to restart the system.



You can see that a user has been created with the name of os. Click this user and provide the password we set to it.