-->

Saturday, March 28, 2015

Button Enable disable when we write some text into TextBox in ASP.NET

I mean to say, we have three controls, two TextBoxes and one Button control. When we run the source code in the browser button is disabled by default. If we want to enable button at run time then we must to input some text in both TextBoxes. For this type of problem we should go for java script.


<%@ Page Language="C#" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>
        function change(textb,buttont)
        {
            var firstt = document.getElementById('<%= TextBox1.ClientID %>');
            var secondt = document.getElementById('<%= TextBox2.ClientID %>');
            if ((textb.value.length>=1 && firstt.value.length >= 1) && (textb.value.length>=1 && secondt.value.length >= 1))

                document.getElementById(buttont).disabled = false;
            else
                document.getElementById(buttont).disabled = true;

        }



    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onkeyup="change(this,'Button1');"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"  onkeyup="change(this,'Button1');"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" Enabled="false" />
    </div>
    </form>
</body>
</html>

Here,

  1.  onkeyup() function call when we input character into text box.
  2.  change() function have two parameter first is TextBox instance and second is button reference.
  3. Access both TextBoxes by using document.getElementById( ) method.
  4.  Now, check the length of the string which is entered in the TextBox.
  5. If, Length is greater than equal to 1 then Button is enable otherwise disable.

Monday, March 16, 2015

How to create pdf file in windows form c#

If you wan to create pdf file in windows form as well as web application , you must to add iTextSharp.dll file as a reference. In iTextSharp , we have a Document class through which we can create a new document. Also provide PdfWriter class, through which we can create a pdf file in a specified path. Now, you can use Paragraph class for creating text. Now, use this code and Generate pdf file:

Document d1 = new Document();
            PdfWriter.GetInstance(d1, new FileStream("E:/t1.pdf", FileMode.Create));
            d1.Open();
            Paragraph p1 = new Paragraph("Hello World");
            d1.Add(p1);
            d1.Close();


Video cover all such things which is i mentioned in above. Also provide the link where you can download the iTextSharp.dll file and where you will put the mentioned code in function.

Thursday, March 12, 2015

How to write something on image in windows form c#

Using Graphics class we can write something on image. Graphics class object invoke drawing objects, like String, Rectangle, oval etc. For DrawString( ) method, we need some parameter like string text, font, point where you want to display string on image. Now copy this code



            Image img = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);

            var font = new Font("TimesNewRoman", 25, FontStyle.Bold, GraphicsUnit.Pixel);

            var graphics = Graphics.FromImage(img);

            graphics.DrawString("Hello World! " , font, Brushes.Red, new Point(0, 0));

            this.pictureBox1.Image = img;

Here

  1. First to add the picture box in the form.
  2. Now, using the Bitmap class we can pick the resolution parameter of picture box then assign these parameter to Image class instance.
  3. Take Font class for making highly visualize text in the image.
  4. Use graphics class to Draw the string on the image.
  5. Before Drawing must to assign the image to the Graphics class.
The following mentioned video contain full implementation guide:



Monday, March 9, 2015

Tips for program designing in C language

Now, let us see "What are the tips to design a good program?"
Although the program design involves several stages, the following are the few important tips to design a good program:

I Tip: Make a program readable. It is a combination of the following:

  1. Careful choice of data structure or data type.
  2. Careful choice of variable names.
  3. Generous use of remarks or comments.
  4. Program indentation.
  5. General program design


II Tip: Stepwise refinement of a solution

  1. Break a problem into a sequence of relatively self-contained or independent sub-problems.
  2. Follow orderly flow of stepwise refinement.


III Tip: Avoid 'goto' statement to jump around, forward and backward, into and out of loops or blocks of statements. The blocks are also called compound statements.

  1. The programs using 'goto' are difficult to read and debug.
  2. The programs using 'goto' are called unstructured programs. Always hate such unstructured programs.


Coupling in borland C language

Coupling measures the strength of all relationships between functional units. It is the measure of the interdependence of one module to that of another. The program should have low coupling. Low coupling minimize the cause of errors in other modules. The errors in the other modules are caused because of the change in one module.

Definition: Coupling can be defined as the degree of interdependence between two or more modules. The reduction in coupling reduces the complexity of the program. While designing a program, make each module as independent as possible eliminating unnecessary relationships.

The following figure shows the types of coupling that exists in programming:
Types of Coupling:
1. No direct coupling
2. Normal coupling
    2.1   Data coupling
    2.2   Stamp coupling
    2.3   Control coupling
3. Common coupling
4. Content coupling

No direct coupling: These are the independent modules of the program. They are not really components of a single program.

Normal coupling: Two modules, X and Y, are normally coupled if X calls Y, Y returns to X and all information passed between them is by parameters in the call.

Data coupling: Two modules are said to be data coupled if they communicate by passing parameters. This is the most common type of coupling. Try to keep the parameters as minimum as possible.

Stamp coupling: Two modules are said to be stamp coupled if they communicate through a passed data structure that contains more information than necessary for them to perform their operations. A complete piece of data is passed between the modules.

Control coupling: Two modules are said to be control coupled if they communicate with the help of at least one "control flag". The control flag controls internal logic of the module.

Common coupling: Two modules are said to be common coupled if both of them share the same global data area. This type of coupling is really undesirable. Problem or error in one module can affect the other modules. Even it is difficult to identify the affected modules.

Content coupled: Two modules are content coupled if one module changes a statement in another, one module references or alters data contained inside another module or one module branches into another module.

The cohesion exists is within the modules where as the coupling exists between modules within the program. The law of program development is:

"Minimize the COUPLING and Maximize the COHESION"

Pointer introduction in C language

Introduction

Pointer is one of the important feature available in C language. Almost all the program in the software industry are written only using pointer, But many people think that pointer concept is difficult. The correct understanding and use of pointer is very much required for successful C programming. Pointers are one of the strongest and also one of the most dangerous features(if not used properly) available in C. Due to its important and dangerous feature, the concept of pointer is dealt in detail. Now , let us understand the concept of pointers.

Pointer concept 

Definition  : The basic data types in C languages are int, float, char , double , and void. Pointer is a special data type which is derived from these basic data types. So, pointer is called derived data type. The pointer takes the values from 0 to 65535 (Memory address) if the size of the RAM is 64K. The pointers are always associated with the following three concepts:

Pointer concept

  • Pointer Constants
  • Pointer Values 
  • Pointer Variables 

Linear Search in C language

Searching

Before writing the algorithm or program for searching , let us see, “ What is searching? What are the searching techniques?”
Definition : More often we will be working with the large amount of data. It may be necessary to determine whether a particular item is present in the large amount of data or not. This process of finding a particular item in the large amount of data is called searching. The two important and simple searching techniques are linear search and binary search.

SQL Video Channel : Download all SQL Video


Linear search (Sequential search)
“What is the linear search?”
Definition: Linear search is a simple searching techniques in which we search for a given key item in the list in linear order(Sequential order) i.e. one after the other. The item to be searched is often called key item. The linear search is also called sequential search.

For example , if key=10 and the list is 20,10,40,25 after searching we say that key is present . If key =100 after searching we say that key is not present.
“How to search for an item in a list of elements?” The procedure is as follows.

Linear/Sequencial Search in C


Procedure: Assume 10 is the item to be searched in the list of items 50,40,30,60,10. Observe from above figure that, 10 has to be compared with a[0], a[1], a[2], a[3], a[4].
But, once the value of I is greater than or equal to 5, it is an indication that item is not present and display the message “Unsuccessful Search”.

Note: In general the terminal condition in the for loop i<5 can be replaced by i<n.
You are already familiar with the algorithm and flowchart of linear search . Now, the C program for linear search is shown below:

#include<stdio.h>
#include<conio.h>
main()
{
int i,n,key,a[20];
printf("Enter the value of n.");
scanf("%d",&n);
printf("Enter n values:\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter item to search:");
scanf("%d",&key);
/* Search the key in array */
for(i=o;i<n;i++)
{
if(a[i]==key)
{
printf("item found");
exit(0);
}
}
printf("Not found");
}

Output
Linear Search in C

Linear Search in C

Advantage of linear search

  • Very simple approach
  • Works well for small array
  • Used to search when the elements are not sorted (not in any order)
Disadvantage of linear search

  • Less efficient if the array size is large
  • If the elements are already sorted, linear search is not efficient.

Note : When the elements are not sorted and size is very less, linear search is used . if the elements are sorted , a better method or technique binary search can be used.

Binary Search in C
Selection Search in C
© Copyright 2013 Computer Programming | All Right Reserved