Sunday, 29 October 2017

All Keyboard Shortcuts of Windows 7 at one place.

Windows 7 have lots of keyboard shortcuts which can be used to make our daily task much easier, interactive, and efficiently saves our time & effort. Keyboard shortcut is nothing but just combinations of two or more keys. When the combination is pressed a task is performed which may require a mouse or other pointing device.


In general accelerator keys are used with menus and other commands to make the programs easier. Accelerator keys can be seen in case any letter in a menu is underlined which means if we press ALT key in combination with that underlined key will do the same job as clicking that menu item.
List of keyboard shortcuts of Windows 7 available are given below with their categories:

Ease of Access keyboard shortcuts


General keyboard shortcuts
Dialog box keyboard shortcuts
Windows logo key keyboard shortcuts
Windows Explorer keyboard shortcuts
Taskbar keyboard shortcuts
Magnifier keyboard shortcuts
Remote Desktop Connection keyboard shortcuts
Paint keyboard shortcuts
WordPad keyboard shortcutsCalculator keyboard shortcutsWindows Journal keyboard shortcuts
Windows Help viewer keyboard shortcuts


Tuesday, 17 October 2017

Why 'using namespace std' used in cpp

Lets Start With Scopes

Named entities, such as variables, functions, and compound types need to be declared before being used in C++. The point in the program where this declaration happens influences its visibility:

An entity declared outside any block has global scope, meaning that its name is valid anywhere in the code. While an entity declared within a block, such as a function or a selective statement, has block scope, and is only visible within the specific block in which it is declared, but not outside it.

Variables with block scope are known as local variables.

For example, a variable declared in the body of a function is a local variable that extends until the end of the the function (i.e., until the brace } that closes the function definition), but not outside it:

1
2
3
4
5
6
7
8
9
10
11
12
13
int foo;        // global variable

int some_function ()
{
  int bar;      // local variable
  bar = 0;
}

int other_function ()
{
  foo = 1;  // ok: foo is a global variable
  bar = 2;  // wrong: bar is not visible from this function
}


In each scope, a name can only represent one entity. For example, there cannot be two variables with the same name in the same scope:

1
2
3
4
5
6
7
int some_function ()
{
  int x;
  x = 0;
  double x;   // wrong: name already used in this scope
  x = 0.0;
}


The visibility of an entity with block scope extends until the end of the block, including inner blocks. Nevertheless, an inner block, because it is a different block, can re-utilize a name existing in an outer scope to refer to a different entity; in this case, the name will refer to a different entity only within the inner block, hiding the entity it names outside. While outside it, it will still refer to the original entity. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// inner block scopes
#include <iostream>
using namespace std;

int main () {
  int x = 10;
  int y = 20;
  {
    int x;   // ok, inner scope.
    x = 50;  // sets value to inner x
    y = 50;  // sets value to (outer) y
    cout << "inner block:\n";
    cout << "x: " << x << '\n';
    cout << "y: " << y << '\n';
  }
  cout << "outer block:\n";
  cout << "x: " << x << '\n';
  cout << "y: " << y << '\n';
  return 0;
}
inner block:
x: 50
y: 50
outer block:
x: 10
y: 50


Note that y is not hidden in the inner block, and thus accessing y still accesses the outer variable.

Variables declared in declarations that introduce a block, such as function parameters and variables declared in loops and conditions (such as those declared on a for or an if) are local to the block they introduce.

Namespaces

Only one entity can exist with a particular name in a particular scope. This is seldom a problem for local names, since blocks tend to be relatively short, and names have particular purposes within them, such as naming a counter variable, an argument, etc...

But non-local names bring more possibilities for name collision, especially considering that libraries may declare many functions, types, and variables, neither of them local in nature, and some of them very generic.

Namespaces allow us to group named entities that otherwise would have global scope into narrower scopes, giving them namespace scope. This allows organizing the elements of programs into different logical scopes referred to by names.

The syntax to declare a namespaces is:


namespace identifier
{
  named_entities
}

Where identifier is any valid identifier and named_entities is the set of variables, types and functions that are included within the namespace. For example:

1
2
3
4
namespace myNamespace
{
  int a, b;
}


In this case, the variables a and b are normal variables declared within a namespace called myNamespace.

These variables can be accessed from within their namespace normally, with their identifier (either a or b), but if accessed from outside the myNamespace namespace they have to be properly qualified with the scope operator ::. For example, to access the previous variables from outside myNamespace they should be qualified like:

1
2
myNamespace::a
myNamespace::b 


Namespaces are particularly useful to avoid name collisions. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// namespaces
#include <iostream>
using namespace std;

namespace foo
{
  int value() { return 5; }
}

namespace bar
{
  const double pi = 3.1416;
  double value() { return 2*pi; }
}

int main () {
  cout << foo::value() << '\n';
  cout << bar::value() << '\n';
  cout << bar::pi << '\n';
  return 0;
}
5
6.2832
3.1416


In this case, there are two functions with the same name: value. One is defined within the namespace foo, and the other one in bar. No redefinition errors happen thanks to namespaces. Notice also how pi is accessed in an unqualified manner from within namespace bar (just as pi), while it is again accessed in main, but here it needs to be qualified as bar::pi.

Namespaces can be split: Two segments of a code can be declared in the same namespace:

1
2
3
namespace foo { int a; }
namespace bar { int b; }
namespace foo { int c; }


This declares three variables: a and c are in namespace foo, while b is in namespace bar. Namespaces can even extend across different translation units (i.e., across different files of source code).

using

The keyword using introduces a name into the current declarative region (such as a block), thus avoiding the need to qualify the name. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// using
#include <iostream>
using namespace std;

namespace first
{
  int x = 5;
  int y = 10;
}

namespace second
{
  double x = 3.1416;
  double y = 2.7183;
}

int main () {
  using first::x;
  using second::y;
  cout << x << '\n';
  cout << y << '\n';
  cout << first::y << '\n';
  cout << second::x << '\n';
  return 0;
}
5
2.7183
10
3.1416


Notice how in main, the variable x (without any name qualifier) refers to first::x, whereas y refers to second::y, just as specified by the using declarations. The variables first::y and second::x can still be accessed, but require fully qualified names.

The keyword using can also be used as a directive to introduce an entire namespace:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// using
#include <iostream>
using namespace std;

namespace first
{
  int x = 5;
  int y = 10;
}

namespace second
{
  double x = 3.1416;
  double y = 2.7183;
}

int main () {
  using namespace first;
  cout << x << '\n';
  cout << y << '\n';
  cout << second::x << '\n';
  cout << second::y << '\n';
  return 0;
}
5
10
3.1416
2.7183


In this case, by declaring that we were using namespace first, all direct uses of x and y without name qualifiers were also looked up in namespace first.

using and using namespace have validity only in the same block in which they are stated or in the entire source code file if they are used directly in the global scope. For example, it would be possible to first use the objects of one namespace and then those of another one by splitting the code in different blocks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// using namespace example
#include <iostream>
using namespace std;

namespace first
{
  int x = 5;
}

namespace second
{
  double x = 3.1416;
}

int main () {
  {
    using namespace first;
    cout << x << '\n';
  }
  {
    using namespace second;
    cout << x << '\n';
  }
  return 0;
}
5
3.1416

Namespace aliasing

Existing namespaces can be aliased with new names, with the following syntax:

namespace new_name = current_name;

The std namespace

All the entities (variables, types, constants, and functions) of the standard C++ library are declared within the stdnamespace. Most examples in these tutorials, in fact, include the following line:

 
using namespace std;


This introduces direct visibility of all the names of the std namespace into the code. This is done in these tutorials to facilitate comprehension and shorten the length of the examples, but many programmers prefer to qualify each of the elements of the standard library used in their programs. For example, instead of:

 
cout << "Hello world!";


It is common to instead see:

 
std::cout << "Hello world!";


Whether the elements in the std namespace are introduced with using declarations or are fully qualified on every use does not change the behavior or efficiency of the resulting program in any way. It is mostly a matter of style preference, although for projects mixing libraries, explicit qualification tends to be preferred.

Storage classes

The storage for variables with global or namespace scope is allocated for the entire duration of the program. This is known as static storage, and it contrasts with the storage for local variables (those declared within a block). These use what is known as automatic storage. The storage for local variables is only available during the block in which they are declared; after that, that same storage may be used for a local variable of some other function, or used otherwise.

But there is another substantial difference between variables with static storage and variables with automatic storage:
- Variables with static storage (such as global variables) that are not explicitly initialized are automatically initialized to zeroes.
- Variables with automatic storage (such as local variables) that are not explicitly initialized are left uninitialized, and thus have an undetermined value.

For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
// static vs automatic storage
#include <iostream>
using namespace std;

int x;

int main ()
{
  int y;
  cout << x << '\n';
  cout << y << '\n';
  return 0;
}
0
4285838


The actual output may vary, but only the value of x is guaranteed to be zero. y can actually contain just about any value (including zero).

Monday, 16 October 2017

Difference Between Response.Redirect() and Server.Transfer() Methods in ASP.NET

 

Introduction

Both Response.Redirect and Server.Transfer methods are used to transfer a user from one web page to another web page. Both methods are used for the same purpose, but still there are some differences as follows.
The Response.Redirect method redirects a request to a new URL and specifies the new URL while the Server.Transfer method for the current request, terminates execution of the current page and starts execution of a new page using the specified URL path of the page.
Both Response.Redirect and Server.Transfer have the same syntax like:
Response.Redirect("UserDetail.aspx");
Server.Transfer("UserDetail.aspx");

HTTP Status Codes

Before touching on more points, I want to explain some HTTP status codes, these are important for the understanding of the basic differences between these two. The HTTP status codes are the codes that the Web server uses to communicate with the Web browser or user agent.
  1. HTTP 200 OK
    This is the most common HTTP status message. It indicates that the request was successful and the server was able to deliver on the request. The information returned with the response is dependent on the method used in the request. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.
  2. HTTP 302 Found
    The HTTP response status code 302 Found is a common way of performing a redirection. The 302 status code indicates that the resource you are requesting has redirected to another resource.

Response.Redirect and Server.Transfer Request Handling

Response.Redirect sends an HTTP request to the browser, then the browser sends that request to the web server, then the web server delivers a response to the web browser. For example, suppose you are on the web page "UserRegister.aspx" page and it has a button that redirects you to the "UserDetail.aspx" web page.
HTTP request to the browser
Figure 1.1 Request and Response using Response.Redirect method
You can notice in Figure 1.1 that when you run the application, then you get a web page successfully so the HTTP status code is "HTTP 200 OK". Then you click on the button that redirects to another page using the Response.Redirect method. The Response.Redirect method first sends a request to the web browser so it is the "HTTP 302 Found" status, then the browser sends a request to the server and the server delivers a response so it is "HTTP 200 OK". It is called a round trip. Let's see that in Figure 1.2.
Round Trip by Response.Redirect method
Figure 1.2 Round Trip by Response.Redirect method.
Server.Transfer sends a request directly to the web server and the web server delivers the response to the browser.
Request and Response using Server.Transfer method
Figure 1.3 Request and Response using Server.Transfer method
Now Figure 1.3 explains that the first request goes to the web server and then gets a response so the round-trip is not made by the Server.Transfer method. You get the same page response but different content. That means your web page URL in the address bar will not be changed. For example, see Figure 1.3 showing you get the same page as the previous request page so the previous page still remains while in Response.Redirect, you get a different page in the response (see Figure 1.1 ). That means the address bar URL will be changed in the Response.Redirect method and also updates the browser history so you can move back from the browser back button.
Server.Transfer method request and response
Figure 1.4 Server.Transfer method request and response
Response.Redirect can be used for both .aspx and HTML pages whereas Server.Transfer can be used only for .aspx pages and is specific to ASP and ASP.NET.
Response.Redirect can be used to redirect a user to an external website. Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.

Using the Code

When you use Server.Transfer, then the previous page also exists in server memory while in the Response.Redirect method, the previous page is removed from server memory and loads a new page in memory. Let's see an example.
We add some items in the context of the first page "UserRegister.aspx" and thereafter the user transfers to another page "UserDetail.aspx" using Server.Transfer on a button click. The user will then be able to request data that was in the context because the previous page also exists in memory. Let's see the code.
Code of the UserRegister.aspx.cs page:
using System;
public partial class UserRegister : System.Web.UI.Page
{
    protected void btn_Detail_Click(object sender, EventArgs e)
    {
        Context.Items.Add("Name", "Sandeep Singh Shekhawat");
        Context.Items.Add("Email", "sandeep.shekhawat88@gmail.com");
       Server.Transfer("UserDetail.aspx");
    }
} 
Code of the UserDetail.aspx.cs page:
 using System;
public partial class UserDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            Response.Write(string.Format("My name is {0} and email address is {1}",
                                          Context.Items["Name"].ToString(),
                                          Context.Items["Email"].ToString()));
        }
        catch (NullReferenceException ex)
        {
            Response.Write(ex.Message);
        }
    }
} 
Using the code above, we can get data from the previous page to the new page by the Context.Itemcollection. But if you use the Response.Redirect method, then you can't get context data on another page and get an exception object as null because the previous page doesn't exist in server memory.
Null Exception by Context object
Figure 1.5 Null Exception by Context object
Mostly the Server.Transfer method is preferable to use because Server.Transfer is faster since there is one less roundtrip, but some people say that Server.Transfer is not recommended since the operations typically flow through several different pages causing a loss of the correct URL of the page, but again it all depends on your requirement.
It is not a complete list. I wrote the basic differences between these two. If you know more differences, then please provide them in the comments.

Tuesday, 5 September 2017

Three tier architecture in asp.net using c# example

In this tutorial post we will demonstrate how to create 3 tier architecture using asp.net c#. Three tier architecture means dividing our project into three layers that is presentation layer (UI layer), Business Layer (Logic code layer) and datalayer (Layer which connects to database).
 There are lots of mails coming every day now and then asking for 3 tier architecture implementation. So this post is especially for those developers who are looking to develop a 3 tier implementation in their projects. Three tier architecture means dividing project in three layers User Interface Layer, Business Layer and Data Layer where we separate logic,data and user interface in three division. It means tomorrow if we replace sql server database with oracle database then we need to change only data layer OR if we change or user screen from windows application to website then we need to change only our user interface layer rest everything remain the same.
Kindly Note : Developer or coder need to be well versed with use of classes and objects in c-sharp.

How it works
Presentation layer is your user interface layer where you can design your interface using html web controls or windows controls or mobile controls. It can be your website or windows application or mobile application.This layer only communicates with business layer.

Application layer or Business Layer is the middle layer or bridge layer that connects database layer and presentation layer. In this layer you can write your business logic (logic written as per business requirement) or any validation code.This layer communicates with database layer and presentation layer.

Database layer which makes the connection to the database server. In this layer you can write database connection and sql queries or stored procedures. This layer only communicates with business layer.

When user post any data from from user interface (presentation page), data first goes to the business layer there data will be validated then validated data is posted to database layer to insert into the database.

When user request any data from the database then the request is first processed by the business layer validates the request and sends to database layer then database layer forwards it to the database server and fetches necessary records. Found records are loaded by the database layer and passes it back to the business layer then business layer passes those records to the presentation layer.

Advantages of using 3 tier architecture

It makes the logical separation between business layer and presentation layer and database layer.

Migration to new graphical environments is faster.

As each tier is independent it is possible to enable parallel development of each tier by using different sets of developers.

Easy to maintain and understand large project and complex project.

Since application layer is between the database layer and presentation layer so the database layer will be more secured and client will not have direct access to the database.

Posted data from presentation layer can be verified or validated at application layer before updating it to the database.

Database Security can be provided at application layer.

Application layer or middle layer or business layer can be a protection shield to the database.

New rules or new validation rules can be defined any time and changes made to middle layer will not effect presentation layer.

Define any logic once within the business layer and that logic can be shared among any number of components in the presentation layer.

We can display only necessary methods from business layer in the presentation layer.

We can hide unnecessary methods from business layer in the presentation layer.

Easy to apply object oriented concept

Easy to update data provider queries.

Disadvantage of using 3 tier architecture

Time consuming : To implement even small part of application it will consume lots of time.

Need good expertise in object oriented concept (classes and objects).

It is more complex to build.

Why to use 3 tier architecture in projects

To Manage Large Projects becomes difficult : Lets suppose you have created a 1000 screen project without using 3 tier architecture and coded all codes in the presentation layer then suppose over period of time you want to migrate to windows to web application then again you need to write code  for all 1000 screens OR lets suppose tomorrow you database provider changes from sql server to oracle server then again where ever you have written sql connection in all 1000 screens in all that you need to make changes. Frankly speaking changing code in 1000 screens or re-writing code in 1000 screens is not easy it is time and money consuming job because your client or company will not pay that much or give that much time to code every time.

Difficult to understand : If a new developer joins you for the same project then it becomes very difficult to make him/her understand about the code and project (inspite of having documentation).

No proper templatization : It becomes very difficult to find any specific part of project code.

Security Threat : Our database server is not secured because database server code is directly written in the page level.

We are human beings we cannot remember all those codes which we have written in the different pages over the years (Large projects). So in order to maintain flexibility, migration facility, data security, proper maintenance and to understand project easily even after the years it is best practices to use 3 tier architecture in projects.

For small projects with 5 to 20 screens it is not necessary to implement three tier architecture. But for large projects it is recommended to use three tier implementation.

Step by step 3 tier architecture example

In this demonstration of the code we will use website as our presentation layer and class library project for both business layer and database layer.
 .
   So friends i hope you understood this complete tutorial on Three Tier Architecture in ASP.NET using c# language. If you have any doubts or queries kindly feel free to ask me through your comments.


             Coding Part I will Upload my next Article..
                                                             



Sunday, 4 September 2016

write a c program accept a number find revese factorial

//question is like that if accept 120 then show 5 beczz 120=1*2*3*4*5=5;
                                                  130   then not possible
                                   if            720 then   show 6 beczz 720=1*2*3*4*5*6=6;  

             LOGIC:-

                           main()
                                   {
                                           int n,fact=1,i=2;

                                             printf("enter number\n");
                                             scanf("%d",&n);

                                          while(fact<n)
                                                   {
                                                        fact=fact*i;
                                                        i++;
                                                                                }  
                          if(fact==n)
                               printf("reverse factorial of %d is %d", n,--i);
                        else 
                                                         reverse not possible;
                }                                      


write a program accept two numbers find the product of two number's without using multiplication operator

main()
{
  
int m,n,product=0;
printf('enter number's");
scanf("%d%d",&m,&n);
while(m)                                 //let m=4,n=3;
{
product=product+n;           //product=produt+3;
m--;                                      //m==3 after this m value assign to while condition and and this loop
                                            //itrating till tym when m eqalto 0 and condition become folse meanse loop itrating for time then product also add 3 for times...that is 3+3+3+3 that is nating bt same as 3*4 =12 
}
printf("%d",product");
getch();
}   

swap two numbers without using third variable

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;  

printf("\n enter two number");
scanf("%d%d",&a,&b);

BEST LOGIC:-
                    
                     b=(a+b)-(a=b);  //let a=10,b=20;
                                                //b=(10+20)-(a=20)    //now a become 20
                                                //b=30-20
                                                //finally b=10

    AVARAGE LOGIC

               a=a+b;                         //let a=10,20; then a=10+20=30
               b=a-b;                         //b=a-b=30-20=10;
               a=a-b;                         //a=a-b=30-10=20;

      printf("after swaping value of a=%d \n",a); 
      printf("after swaping value of b=%d \n",b); 
      getch();
}

     use any one but 1 is best..