-->

Monday, April 14, 2014

Address Book Project in Windows Forms with C#

Download this project

Project cost : 300Rs or $10
Pay me at:

Via bank transfer
 
ICICI bank account number is :    153801503056
Account holder name is :                 Tarun kumar saini
IFSC code is :                                   ICIC0001538

SBBJ bank detail :                             61134658849
Account holder name:                        Tarun kumar saini
IFSC code :                                        SBBJ0010398

CONTACT ME

Introduction:

Sometimes we can’t remember all of the detail of each of our friend. We have to store them, so that we can remind the details when we want. If we talk about our personal computer then it will be the safest place for us to store them in a file.
Address Book is a windows application which stores all the details of your friends. It saves their common fields like name, father name, age, date of birth and etc. Of course we are the administrator of our computer that’s why we can trust our computer.

Features of Project:


  • One can add/modify/remove an address from the database easily.
  • Search option is available for larger databases.
  • User can print the list of his/her friends using a single click.
  • It have its own username and password that is known only to the administrator.


System Requirements:


  • Visual Studio 2010 or higher
  • SqlServer 2008 or higher
  • DotNet Framework 4.0 or higher (pre-loaded with Visual Studio)

Run the project:

It is a windows form application, so either press F5 or click on Start button. It will load the login window, which requires username and password. Username is “admin” and password is “password”, click on login button and the manage options window will be shown to you.

Screenshots:

Gives you the brief description of the project.

Login Window

Address Book Project in Windows Forms with C#

Manage options: 

Provides basic three options i.e. list of addresses, search and print option.

Address Book Project in Windows Forms with C#

List of addresses: 

Contains list of addresses your address book have, you can add, edit or remove any record that is selected in the list.
Address Book Project in Windows Forms with C#

There are some more forms like edit window, search and print window.
If you want to purchase this please contact me on :  narenkumar851@gmail.com

Create a Simple WPF application

Windows Presentation Foundation (WPF) is a new graphical subsystem for rendering user interfaces in windows based application developed in Visual Studio. WPF is a next generation presentation system for building windows client applications. WPF should be very familiar if you have previously built applications with .NET Framework using ASP.NET and Windows Forms.

XAML is a declarative XML based language that is used for initializing structured values and objects. When used in WPF, XAML is used to describe visual user interfaces. WPF allows for the definition of both 2D and 3D objects, rotations, animations, and a variety of other effects and features.

These simple steps can be followed to create a new WPF application:
  1. Start Visual Studio "the version you have".
  2. From the menu bar go to File>>New>>Project. A dialog box will appear.
  3. From the drop down list you can select the framework in which you want to work. In the left side pane expand Visual C#, and then select Windows.

    Select new WPF application template as a new project
  4. There is a middle pane including a list of templates. Select WPF Application template.
  5. You can specify a name and location for the project in the Name and Location textbox respectively.
  6. Click OK and MainWindow of the new project will appear.

    The default UI environment of new WPF application

A new project has been created with some files like other project. A file named MainWindow.xaml is already open as in our above screenshot, it will be shown first when launching the application. App.xaml is central starting point, can be used to change the first window.

You can run the application now to see the empty window because our XAML code consists nothing to show. To show a simple message “My First WPF Application”, we have to write the following code in between the Grid panel.
<Grid>
<TextBlock Text="My First WPF Application"></TextBlock>
</Grid>

Run the application now and our message is displayed in the top left corner of the window. We have used a single Text property of the Text block and that is it.
WPF first message shown when run the application

StackPanel Overview in WPF

Layouts in WPF

WPF layout, a mostly used component of an application, is basically used to arranging controls on fixed pixels. Users can not resize the places which are placed in these layouts. There are five built-in panels i.e. Stack Panel, Canvas, Wrap Panel, Grid and Dock Panel resides in System.Windows.Controls namespace.


Stack Panel:

A very popular panel because of its simplicity and usefulness. As its name suggests it simply place its children into a stack. This panel is used in the same way as stacks in C programming. It places its children from the right/bottom most side, previous element will move when new one comes, and so on.


StackPanel in WPF

By default the orientation property of any stackpanel is vertical, if we want to show our contents in horizontal then we have to change the orientation of stackpanel. As in above diagram I have placed three button in both of the views one by one. By using simple code in xaml I can use a stack panel as in above window.
<StackPanel>
<Button Content="First " Width="70"></Button>
<Button Content="Second " Width="70"></Button>
<Button Content="Third " Width="70"></Button>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="First " Height="50"></Button>
<Button Content="Second " Height="50"></Button>
<Button Content="Third " Height="50"></Button>
</StackPanel>
There are some cases in which we have to use nested stack panel like to show a person’s image and some information. 
<StackPanel>
<Image Source="...." Name="image"></Image>
<StackPanel >
<Label Content="Name"></Label>
<Label Content="Age"></Label>
<Label Content="Father Name"></Label>
</StackPanel>
</StackPanel>
Wrap panel

How to Use Checkbox in WPF

Checkbox is a GUI element that permits the user to make a binary choice i.e. user may have to answer yes or no. Now a days programming have a new option to set the value to null. It means checkbox may be used as a three state which are checked, unchecked and intermediate.

The following screenshot shows three states of a checkbox

CheckBox control in WPF

In the above image all the three checkboxes have IsThreeState property to true and some more properties like the following code in xaml:
<CheckBox IsThreeState="True" Content="Checked" IsChecked="True"></CheckBox>
<CheckBox IsThreeState="True" Content="UnChecked" IsChecked="False"></CheckBox>
<CheckBox IsThreeState="True" Content="Intermediate" IsChecked="{x:Null}"></CheckBox>

IsChecked property is used to set the state of checkbox. You may have three options for these state values as I have used in above code snippet. Checkbox is mostly used in objective type answers or we can say Boolean type answers. Gender value may also be store through checkbox control.


We can perform the desired function, when the checkbox is checked or unchecked using the events respectively.
private void Checkbox_Checked(object sender, RoutedEventArgs e)
{
MessageBox.Show("Checkbox Checked");
}

private void Checkbox_Unchecked(object sender, RoutedEventArgs e)
{
MessageBox.Show("Checkbox Checked");
}
Each time when a checkbox is checked or unchecked, a message will be shown defined in the above code snippets. To add a checkbox dynamically with checked property true we can write the following code:

CheckBox chkBox = new CheckBox();
chkBox.Name = "checkBox";
chkBox.Content = "Checked";
chkBox.IsChecked = true;
chkBox.IsThreeState = true;
this.Content = chkBox;
The above code will replace all the content of the window with this checkbox. So if you want to add this to any other container like stackpanel or anything, then you have to add this as a children of that container.

Sunday, April 13, 2014

LINQ Grouping operator in ASP.NET

Introduction


The Grouping operators in LINQ are used to put data into groups so that the elements in each group share a common attribute. The Group clause is the Grouping operator used in LINQ. The Group clause returns a sequence of IGrouping<TKey, TElement> objects that contain zero or more items that match the key value for the group.
The syntax of using the GroupBy clause is:
 For C#
public static IEnumerable<IGrouping<K, T>> GroupBy<T, K>( Me IEnumerable<T> source, Function<T, K> keySeIector)

Lets take an simple example

<div>
    
        <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="Grouping Operator Linq" />
    
    </div>

Code behind code

protected void Button1_Click(object sender, EventArgs e)
    {
        string[] fruits = { "apple", "banana", "pineapple", "papaya", "blueberry", "cheery" };
        var groupword = from w in fruits
                        group w by w[0] into g
                        select new { FirstLetter = g.Key, fruits = g };
        foreach (var g in groupword)
        {
          ListBox1 .Items .Add ("Words that start from letter:"+g.FirstLetter .ToString());
            foreach (var w in g.fruits)
{
ListBox1 .Items .Add (w);
}
        }
    }

code generate the following output

LINQ Grouping operator in ASP.NET

According to above given example. Grouping index start from 0. Here we take two for-each loop first one for printing message with starting letter of English such as 'a' and second one for printing grouping letter words like 'a' for apple and 'p' for "pineapple" and "papaya". 

How to bind Dropdownlist Control in ASP.NET

In the previous example we have already discussed about  DropdownList like .

  1. How to change font name at runtime
  2. Bind DropdownList using XML file 

For binding DropdownList using ado.net you must use System.Data.SqlClient namespace, which is contains various classes like SqlConnection,SqlCommand etc.



<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            con.Open();
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.CommandText = "insrtdata";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Connection = con;
            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
            System.Data.DataSet ds = new System.Data.DataSet();
            da.Fill(ds);
            DropDownList1 .DataTextField ="Name";
        DropDownList1 .DataValueField  ="Id";
        DropDownList1 .DataSource =ds;
        DropDownList1 .DataBind ();        
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>  
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>  
    </div>
    </form>
</body>
</html>

Output
How to bind dropdownlist in asp.net

Saturday, April 12, 2014

How to insert string at specified position of existing string in ASP.NET

If you want to insert another string at 0 index of existing string, suppose you have a string like "jacob" and you want to insert another string like "hello" at 0 index , then you must use insert method of the StringBuilder class with 0 index.

<form id="form1" runat="server">
    <div>
 
        <asp:Button ID="Button1"
         runat="server"
          Height="29px"
          onclick="Button1_Click"
            Text="Button"
             Width="87px" />
 
    </div>
    <asp:Label ID="Label1"
     runat="server"
      BackColor="Yellow"
      Text="Label"></asp:Label>
    </form>

CodeBhindcode-

 protected void Button1_Click(object sender, EventArgs e)
    {
        System.Text.StringBuilder stringA = new System.Text.StringBuilder();
        stringA.Append("2nd string.");

        stringA.Insert(0, "include string in front of stringbuilder. ");

        Label1.Text = stringA.ToString();

    }

Output-

How to insert string at specified position of existing string in ASP.NET

© Copyright 2013 Computer Programming | All Right Reserved