-->

Thursday, February 26, 2015

Custom login control using edmx file in windows forms application C#

Introduction

Login contol provide some privilege to the project or you can say its a entry point of the project. Though this form we can move to the next form. If your input text is valid then move to the next but if your input is wrong then move failed. So, the main function of the project is check each entry of the table with the TextBox.

Design login control in windows form


  1. Add Two TextBox with the label control.
  2. Add one button control with click event , Look like
login control in windows form

Add EDMX file with the help of following steps:

  1. Add ADO.NET Entity Data Model by the add new item component.
  2. Add ADO.NET Entity Data Model
  3. Now, select EF designer from database in the entity data model wizard.
  4. select EF designer from database
  5. Now create the connection by pressing the 'new connection' button , also select the check box where your connection string save into your application configuration file. Now, press to next button.
  6. Now create the connection by pressing the 'new connection' button
  7. Select entity framework version , i select 5.0 in the project.
  8. Select entity framework version , i select 5.0 in the project.
  9. Select table, views , stored procedure in the appeared window.
  10. Select table, views , stored procedure in the appeared window.
  11.  Now, your model look likeentity data model

Copy and paste the below code inside the button click event.


private void button1_Click(object sender, EventArgs e)
        {
            Student_DBEntities dc = new Student_DBEntities();
            if (usrBox.Text != string.Empty && pwdBox.Text != string.Empty)

            {
                var existuser = dc.admins.FirstOrDefault(a => a.userName.Equals(usrBox.Text));
                if(existuser!=null)
                {
                    if (existuser.Password.Equals(pwdBox.Text))
                        MessageBox.Show("Login Sucess");
                    else
                        MessageBox.Show("try again later");
                }

            }
        }

Here,
  1. Student_DBEntities is a DataContext , which is take connection string in the constructor. Also take public property of the model class, through this we can access all the data from database table.
  2. admins is the public property of data context class.
Code generate the following output - please see the video:

Sunday, February 22, 2015

C language: Searching in graph

Similar to traversal of graph two searching techniques of the graph are used which are Breadth First Search and Depth First Search. Both the techniques are same as respective traversal techniques. In case of breadth first search the traversal algorithm for breadth first is used. The algorithm is terminated with a message search successful whenever the deleted item from QUEUE is the node to be searched otherwise the algorithm is terminated with a message search unsuccessful when the QUEUE is empty. The formal algorithm for BFS is:

GRAPHBFS
[goal node is the node to be searched]
Mark the start node and insert it in the QUEUE
If the start node is the goal node Then:
Write: 'Search Successful' ; Exit
[End of If]
Repeat While QUEUE is not empty
Delete QUEUE
If deleted node is the goal node Then:
Write: ' Search successful;; Exit.
Else
Mark the unmarked adjacent nodes of the deleted node.
Insert the marked nodes(if any) of the deleted node in the QUEUE.
[End of If]
[End of While]
Write: 'Search unsuccessful'
Exit.

In case of depth first search the traversal algorithm for depth first is used. The algorithm is terminated with a message search successful whenever the popped item from STACK  is the node to be searched otherwise the algorithm is terminated with a message search unsuccessful when the STACK is empty. The formal algorithm for DFS is:

GRAPHDFT
[goal node is the node to be searched]
Mark the start node and push it on to the STACK
If the start node is the goal node Then:
Write: 'Search Successful'; Exit
[End of If]
Repeat While STACK is not empty
POP STACK.
If popped node is the goal node Then:
Write: ' Search successful'; Exit.
Else
Mark the unmarked adjacent nodes of the popped node. 
Push the marked nodes of the deleted node(if any) on to the STACK.
[End of While]
Write: 'Search unsuccessful'
Exit. 

C Language: Depth First Traversal in Graph

This traversal techniques is based on the fact of visiting all the nodes of graph in the depth of it. It means start from the start node of the graph and reach to last node of the graph in its depth (so that no further unexplored adjacent node exist). From the start node explore all the adjacent nodes but visit one of the adjacent nodes. From the visited adjacent node further explore all the adjacent nodes of it and again select one of the adjacent nodes and further explore it. In this way the exploration of the adjacent node carried till to reach the last node. Once the last node is reached then back track from the last node to previous node to visit the next adjacent node of it. The data structure stack is used in this type of traversal. 
Consider the following graph:
Depth First Traversal in Graph
The adjacent nodes of node
The adjacent nodes of node

The depth first traversal of the above graph, assuming node 'A' as start node is:

A     E      D      C     B

You can observe from the traversal result that the first node visited is the starting node. Then the next node visited is 'E' one of the adjacent nodes of the start node 'A'. Then the adjacent nodes of 'E' that are not marked are explored. The only marked node is 'D'. It is visited. There are no further adjacent nodes of 'D'  that are not marked . So, we have reached the other end of the graph. Now backtrack from 'D' to 'E' no adjacent nodes of 'E' are left to be visited. Again backtrack from 'E' to 'A'. There are two adjacent nodes left that are not visited. So, node 'C' is visited next. There are no adjacent nodes of node 'C' that are left for visiting. Again backtrack from 'C' to 'A' and visited the last node 'B' which is adjacent of 'A' all the nodes of the graph are visited and the traversal is complete. 

As we backtrack in the technique of depth first traversal it is necessary to use the last in first out data structure that is stack to store the nodes that are to be backtracked.
You can again remember that the traversal result may be different to the one given above. It differs because the adjacent nodes of a visited node may be pushed on the stack in any order. So, the other result of depth first traversal of the above graph are:

A        B       D       C        E
A        C       D       B        E     etc.

The formal algorithm of DFT(Depth First Search) is : 
GRAPHDFT
[TA is the one dimensional array of size n where n is is the number of nodes in the given graph] 
Mark the start node and push it on to the stack 
Repeat While STACK is not empty
POP STACK 
Add popped node to TA at the next position. 
Mark the unmarked adjacent adjacent nodes of the popped node.
Push the marked nodes of the deleted node (if any) on to the STACK.
[End of While] 
Print TA from the first position as traversal.
Exit.

The above algorithm works in the following manner. 
Consider the following graph
Consider the following graph

Let us assuming the start node as node 'A' let us mark and push the node 'A' on to the stack. So, the stack is:
Depth First Traversal in Graph

when pop stack is executed, the node obtained is 'A'. It is added to the traversed array. So, the traversed array is:
Depth First Traversal in Graph


The marked adjacent nodes to popped node 'A' are, 'B', 'C' and 'E'. Mark and push the nodes 'B', 'C' and 'E' on to the stack (in any order). So, the stack is:
Depth First Traversal in Graph

stack is not empty the processes is repeated.
When pop stack is executed, the node obtained is 'E'. It is added to the traversed array. So the traversed array is:
Depth First Traversal in Graph

The marked adjacent node of popped node 'E' is 'D' mark and push it on to the stack. So, the stack is:
Depth First Traversal in Graph

Stack is not empty the processes is repeated. When pop stack is executed, the node obtained is 'D'. It is added to the traversed array. So, the traversed array is :
Depth First Traversal in Graph

The adjacent nodes of poped node 'D' are 'B' and 'C' but they are already marked node. So, no nodes are pushed. So, the stack is:

Depth First Traversal in Graph

Stack is not empty the proceses is repeated. When pop stack is executed, the node obtained is 'C'. It is added to the traversed array. So, the traversed array is:
Depth First Traversal in Graph

The adjacent node of poped node 'C' are 'A' and 'D' but they are already marked nodes. So, no nodes are pushed. So, the stack is
stack is not empty the processes is repeated. When popped stack is executed, the node obtained is 'B'. It is added to the traversed array. So, the traversed array is 
Depth First Traversal in Graph

the adjacent node of popped node 'B' is 'D' but it is already marked. So, no node are pushed. So, the stack is:
Depth First Traversal in Graph

Stack is empty stop the process. When the TA array is printed we get the Depth first traversal as:

Successors of C language

C and even B have several direct descendants, through they do not rival pascal. One side branch developed early. When Steven Johnson visited the University of Waterloo on sabbatical in 1972, he brought B with him. It became popular on the Honeywell machines there, and later spawned Eh and Zed (the Canadian answers to 'what follows B?'). When Johnson returned to Bell Labs in 1973, he was disconcerted to find the language whose seeds he brought to Canada had evolved back home; even his own yacc program had been rewritten in C, by Alan Snyder.

More recent descendants of C proper include Concurrent C, Objective C, C* and especially C++. The language is also widely used as an intermediate representation (essentially, as a portable assembly language) for a wide variety of compilers, both for direct descendants like C++, and independent languages like Modula 3 and Eiffel. 

Saturday, February 21, 2015

C Language standards

C came into existence in between 1969-1973 in parallel with the development of UNIX operating system. The C Programming Language, in the middle of 1980s,was officially standardized by the ANSI X3J11 committee. Until the early 1980s, the language was almost exclusively associated with UNIX. Now, its use has spread much more widely, and today it is among the languages most commonly used in the industry.

BCPL the origination for C language was designed by Martin Richard in the mid-1960s and used during the early 1970s for several projects including OS6 operating system at OXford. The original BCPL compiler was transported both to Multics and to the GE-635 GECOS system by Rudd Canaday and others at Bell Labs. It was the language of choice among the group of people who involved with UNIX.

BCPL, B, and C all fit firmly in the traditional procedural family characterized by Fortan and Algo60. They are particularly oriented towards system programming. They are close to the machine. BCPL, B and C differ syntactically in many details, but broadly they are similar. Programs consist of a sequence of global declarations and function declarations. Several syntactic and lexical mechanism of BCPL are more elegent and regular than those of B and C. In spite of the differences , most of the statements and operators of BCPL map directly into corresponding B and C.

During the 1980s the use of the C language spread widely, and compiler became available on nearly every machine architecture and operating system; in particular it became popular as a programming tool for personal computers, both for manufactures of commercial software for these machine, and for end-users interested in programming.

Features of C Language

Definition: The capabilities and functionality provided by the C language are collectively called features of C Language. The features of C Language have made it popular.

Let us see, "What are the features of C language ?"

The C Language being a middle level language has many important features. It is said to be middle level language because of the following features:


  • The C language has the capabilities of assembly Language (Low Level Language)
  • It provide the functionality of a High Level Language.

As it is near to machine as well as to the user it is called middle level language. The capabilities of the low level language of C help in designing the program
especially required system management. It means the system software can be developed very easily using the C Language.

As It is also near to the user, most general purpose programs can be developed easily. So, the application programs can also be developed using C language.

In addition to the above mentioned features, C Language also has the following features:


  • Implementation of modular programming technique is very easy in case of C language because of the easy designing and handling of modules in the form of functions.
  • Each and every task using C Language is solved by means of function only so, C is called as functional language.
  • Users can define their own tasks in the form of user defined functions.
  • It has large collection of built-in or library functions that makes the programming task easier.
  • More and more user defined functions can be added to the library of the C to make the programs extendable.
  • C language is rich in operators containing very common arithmetic operators to system level bit-wise operators.
  • The programs written using C language are portable and can be executed at different platform.
  • C is a case sensitive language. All the keywords, data type means and built-in function names are written only using lower-case letters.
  • Most importantly the debugging, testing and maintenance activities of programs development can be performed easily on the program developed using C Language.
  • Implementation of structured programming technique is easy here because of the rich availability of the sequential, branching and looping structures.

How to use ComboBox in windows forms application c#

ComboBox in windows forms application -Introduction

A ComboBox display a editable TextBox with ListBox. You can select item from the list also you can search item by using TextBox. The default style of ComboBox is drop-down list. You can change the style of ComboBox with the help of DropDownStyle property. That property contain three enumerated value, If you select Dropdown list box then you can not edit text portion. Now, take a simple example to add items in the Combo Box-please see the video



Video contains different ways to add item in the ComboBox like, using show smart tag, items property, add item at run time using add method.
For adding items at run time in ComboBox:
 comboBox1.Items.Add(String text);
If you want to change the DropdownStyle at design as well as run time- please see the following video:


I you want to access or retrieve selected item from the comboBox then see this video. In this video i have a comboBox with some fruit items and a button control. When we press the button then selected item show in the messageBox.
Note : If you have to press buton without select any item then get the error message. Video also solve this problem with the help of selectedIndex property. So in this video you will see the example of SelectedIndex property.

 Now, come to the DataSource property of comboBox. Bind the combobox with the class and enumeration type. Video contain example of both type.


If you want to add thousand of item without any intrupt then use beginUpdate() and EndUpdate() method of it. This video contain example of both, also contain findString method example.

© Copyright 2013 Computer Programming | All Right Reserved