Monday, June 8, 2015

Code Of Project

Program

Reverce Array String :                                  public static stringReverseString1 (string str)
{
   char[] chars = str.ToCharArray();
   char[] result = newchar[chars.Length];
   for (int i =0, j = str.Length - 1; i < str.Length; i++, j--)
   {
      result[i] = chars[j];
   }
   return new string(result);
}
int countSpaces = mystring.Count(Char.IsWhiteSpace); // 6
int countWords = mystring.Split().Length; // 7

Count Character : int count = myString.TakeWhile(c => c == '$').Count();
var count = mystring.Count(x => x == '$')

Program --- #######################

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $("[src*=plus]").live("click", function () {
            $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
            $(this).attr("src", "images/minus.png");
        });
        $("[src*=minus]").live("click", function () {
            $(this).attr("src", "images/plus.png");
            $(this).closest("tr").next().remove();
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <asp:Label ID="lblMessage" runat="server" Text="" ForeColor="Red"></asp:Label>
        <br />

        <div>
            <asp:GridView runat="server" ID="grdCustomer" AutoGenerateColumns="False" ShowFooter="True" AllowSorting="True"
                CssClass="grid" AllowPaging="True"
                DataKeyNames="CustomerId" CellPadding="4" ForeColor="#333333" OnSorting="grdCustomer_Sorting" OnRowDataBound="grdCustomer_RowDataBound" OnRowCancelingEdit="grdCustomer_RowCancelingEdit" OnRowEditing="grdCustomer_RowEditing" OnRowCommand="grdCustomer_RowCommand">
                <AlternatingRowStyle BackColor="#C3A2DB" />
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <img alt="" style="cursor: pointer" src="images/plus.png" />
                            <asp:Panel ID="pnlOrders" runat="server" Style="display: none">
                                <asp:GridView ID="grdProduct" runat="server" AutoGenerateColumns="false">
                                    <Columns>
                                        <asp:BoundField ItemStyle-Width="150px" DataField="ProductName" HeaderText="Product Name" />
                                        <asp:BoundField ItemStyle-Width="150px" DataField="Price" HeaderText="Price" />
                                        <asp:BoundField ItemStyle-Width="150px" DataField="Quantity" HeaderText="Quantity" />
                                    </Columns>
                                </asp:GridView>
                            </asp:Panel>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Customer Name" SortExpression="CustomerName">
                        <ItemTemplate>
                            <asp:Label ID="lblCustomerName" runat="server" Text='<%# Bind("CustomerName") %>'></asp:Label>
                            <%--<asp:LinkButton runat="server" ID="lnkCustomerName" Text='<%# Bind("CustomerName") %>'></asp:LinkButton>--%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("CustomerName") %>' MaxLength="50"></asp:TextBox>
                           <%-- <asp:RequiredFieldValidator ID="valFirstName" runat="server" ControlToValidate="txtFirstName"
                                Display="Dynamic" ErrorMessage="First Name is required." ForeColor="Red" SetFocusOnError="True"
                                ValidationGroup="editGrp">*</asp:RequiredFieldValidator>--%>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Customer City" SortExpression="City">
                        <ItemTemplate>
                            <asp:Label ID="lblCity" runat="server" Text='<%# Bind("City") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtCity" runat="server" Text='<%# Bind("City") %>' MaxLength="50"></asp:TextBox>
                           <%-- <asp:RequiredFieldValidator ID="valCity" runat="server" ControlToValidate="txtCity"
                                Display="Dynamic" ErrorMessage="City is required." ForeColor="Red" SetFocusOnError="True"
                                ValidationGroup="editGrp">*</asp:RequiredFieldValidator>--%>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Contact Number">
                        <ItemTemplate>
                            <asp:Label ID="lblContactNo" runat="server" Text='<%# Bind("ContactNo") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtContactNo" runat="server" Text='<%# Bind("ContactNo") %>' MaxLength="50"></asp:TextBox>
                           <%-- <asp:RequiredFieldValidator ID="valContactNo" runat="server" ControlToValidate="txtContactNo"
                                Display="Dynamic" ErrorMessage="First Name is required." ForeColor="Red" SetFocusOnError="True"
                                ValidationGroup="editGrp">*</asp:RequiredFieldValidator>--%>
                        </EditItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Total Amount">
                        <ItemTemplate>
                            <asp:Label ID="lblAmount" runat="server" Text="0"></asp:Label>
                        </ItemTemplate>
                     
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Edit">
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandArgument='<%# Bind("CustomerId") %>' CommandName="Edit" Text="EDIT"></asp:LinkButton>
                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false"  CommandName="Edit" Visible="false" Text=""></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
    </form>
</body>
</html>
######################################################################3

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Annet
{
    public partial class CustomerMaster1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            grdCustomer.PageIndexChanging += grdCustomer_PageIndexChanging;

            if (!IsPostBack)
            {
                BindGrid();
                ViewState["SortDirection"] = "ASC";
            }
            lblMessage.Text = "";
        }

        void grdCustomer_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grdCustomer.PageIndex = e.NewPageIndex;
            BindGrid();
        }

        void BindGrid()
        {
            using (var Context = new SampleEntities())
            {
                var query = Context.CustomerMasters.Select(m => m);

                grdCustomer.DataSource = query.ToList();
                grdCustomer.AllowPaging = true;
                grdCustomer.PageSize = 3;
                grdCustomer.DataBind();

            }
        }


        protected void grdCustomer_Sorting(object sender, GridViewSortEventArgs e)
        {
            string Direction = ViewState["SortDirection"].ToString();

            switch (e.SortExpression)
            {
                case "CustomerName":
                    using (var Context = new SampleEntities())
                    {
                        if (Direction == "ASC")
                        {
                            var query = Context.CustomerMasters.OrderBy(c => c.CustomerName);
                            grdCustomer.DataSource = query.ToList();
                        }
                        else
                        {
                            var query = Context.CustomerMasters.OrderByDescending(c => c.CustomerName);
                            grdCustomer.DataSource = query.ToList();
                        }
                    }
                    break;

                case "City":
                    using (var Context = new SampleEntities())
                    {
                        if (Direction == "ASC")
                        {
                            var query = Context.CustomerMasters.OrderByDescending(c => c.City);
                            grdCustomer.DataSource = query.ToList();
                        }
                        else
                        {
                            var query = Context.CustomerMasters.OrderByDescending(c => c.City);
                            grdCustomer.DataSource = query.ToList();
                        }
                    }
                    break;
            }
            grdCustomer.AllowPaging = true;
            grdCustomer.PageSize = 3;
            grdCustomer.DataBind();


            if (ViewState["SortDirection"].ToString() == "ASC")
            {
                ViewState["SortDirection"] = "DEC";
            }
            else if (ViewState["SortDirection"].ToString() == "DEC")
            {
                ViewState["SortDirection"] = "ASC";
            }
            // BindGrid("CustomerName", "ASC");
        }

        protected void grdCustomer_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                int customerId = Convert.ToInt32(grdCustomer.DataKeys[e.Row.RowIndex].Value);
                GridView gvProduct = e.Row.FindControl("grdProduct") as GridView;

                LinkButton lblUnitsInStock = (LinkButton)e.Row.FindControl("LinkButton2");


                if (lblUnitsInStock.Text == "editmode")
                {
                    e.Row.RowState = DataControlRowState.Edit;

                }

                using (var Context = new SampleEntities())
                {
                    var query = Context.ProductMasters.Where(c => c.CustomerId == customerId);
                    gvProduct.DataSource = query.ToList();

                    DataTable dt = new DataTable();
                    dt.Columns.Add("Total", typeof(int));

                    foreach (var item in query)
                    {
                        dt.Rows.Add(item.Price * item.Quantity);
                    }

                    object sumObject;
                    sumObject = dt.Compute("Sum(Total)", "");
                    e.Row.Cells[4].Text = sumObject.ToString();

                    gvProduct.DataBind();
                }
            }
        }

        protected void grdCustomer_RowEditing(object sender, GridViewEditEventArgs e)
        {
            grdCustomer.EditIndex = e.NewEditIndex;
            BindGrid();
        }

        protected void grdCustomer_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grdCustomer.EditIndex = -1;
            BindGrid();
        }

        protected void grdCustomer_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                //Button Btn = (Button)e.CommandSource;
                 GridViewRow row = grdCustomer.Rows[index];

                 LinkButton txtLastName = row.FindControl("LinkButton2") as LinkButton;
                 txtLastName.Text = "editmode";
                 BindGrid();
               
               //  BoundField bb = (BoundField)row.Cells[0].Controls[1];

            }
        }
    }
}

Tuesday, September 4, 2012

What is Constructor ?


Constructor is a member function with the same name as its class.

1] Constructor is a special type of function because its name is same as class name.
2] Constructor calls itself when instance of that class is called.
3] There r three type of constructor which r copy, default, parameterized constructor
4] its allocate memory when it called.
5]The constructor member function should not return a value.

Friday, August 3, 2012

All About OOPS Concepts

OOPS have following features

1. Object   - Instance of class
2. Class    - Blue print of Object
3. Data Encapsulation  - Protecting our data
4. Polymorphism   - Different behaviors at diff. instances
5. Data Abstraction    - Hidding our irrelavance data
6. Inheritance    - one property of object is aquring to another property of object
  • Objects
Software objects are often used to model the real-world objects that you find in everyday life. Real-world objects share two characteristics: They all have state and behavior.
  • Class
A class is the blueprint from which the individual objects are created. Class is composed of three things: a name, attributes, and operations.
  • Data encapsulation
Hiding internal state and requiring all interaction to be performed through an object’s methods is known as data encapsulation — a fundamental principle of object-oriented programming
  • Polymorphism   
Polymorphism means "one name, multiple forms". Using one name u can do multiple of actions.

Example of Compile Time Polymorphism : Method Overloading
Example of
Run Time Polymorphism          : Method Overriding

Overriding is the concept of having functions of same name and signature in different classes. one in the super class can be made virtual and other can override the functionality of virtual one.

Overloading is the concept of having functions of same name, but different signature in same class. They are differentiated by the compiler by their signatures.
  • Data Abstraction
Abstraction defines way to abstract or hide your data and members from outside world.
 Simply speaking Abstraction is hiding the complexities of your class or struct or in a generic term Type from outer world. This is achieved by means of access specifiers.
Interview Definition: - Hiding the complexities of your type from outside world.
How to Abstract: - By using Access Specifiers

.Net has five access specifiers:-
Public -- Accessible outside the class through object reference.
Private -- Accessible inside the class only through member functions.
Protected -- Just like private but Accessible in derived classes also through member functions.
Internal -- Visible inside the assembly. Accessible through objects.
Protected Internal -- Visible inside the assembly through objects and in derived classes outside the assembly through member functions.
  • Inheritance
Inheritance is the process that allows a type or a table to acquire the properties of another type or table.
The type or table that inherits the properties is called the subtype or sub table.
The type or table whose properties are inherited is called the super type or super table.
Inheritance allows for incremental modification so that a type or table can inherit a general set of properties and add properties that are specific to it.
You can use inheritance to make modifications only to the extent that the modifications do not alter the inherited super types or super tables.





What is OOPS ?

  • OOPs is an Object Oriented Programming language, which is the extension of Procedure Oriented Programming language.
  • OOPS reduce the code of the program because of the extensive feature of Polymorphism. 
  • OOPS have many properties such as Data-Hiding, Inheritance, Data Abstraction, Data Encapsulation and many moreEverything in the world is an object. 
  • The type of the object may vary. In OOPS, we get the power to create objects of our own, as & when required.