Tuesday, 15 January 2013

Bind Accrodian Dynamically

 Bind Accrodian Dynamically

<html>
<head><Title>Dynamically bind Accrodian</title>
</head>
<body>
<tr style="vertical-align: top;">
                    <td valign="top" style="width: 5%;">
                    </td>
                    <td valign="top" style="width: 90%;" align="center">
                        <cc1:Accordion ID="Accordion1" runat="server" CssClass="accordion" Width="100%" HeaderCssClass="accordionHeader"
                            Height="100%" HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent">
                        </cc1:Accordion>
                    </td>
                    <td valign="top" style="width: 5%;">
                    </td>
                </tr>
</head>
</body>

void bindData()
    {
        dt = new DataTable();
        cmd = new SqlCommand("selectEachCust_TablesID", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@MainID", MainID);
        con.Open();
        da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        con.Close();
        if (dt.Rows.Count > 0)
        {
            bindAccordian(dt);
        }
    }

    void bindAccordian(DataTable dt1)
    {
        int i = 0;
        for (int j = 0; j < dt1.Columns.Count; j++)
        {
            if ((dt1.Rows[0][j].ToString()!="") && (Convert.ToInt64(dt1.Rows[0][j].ToString()) > 0))
            {
                AccordionPane p1 = new AccordionPane();

                p1.Style.Add("overflow", "scroll");
                //p1.Style.Add("Height", "100%");
                p1.ID = "AccordionPane" + i;
                Label lblHeader = new Label();
                lblHeader.ID = "lblHeader" + i;
                HiddenField hdnFld_tblName = new HiddenField();
                hdnFld_tblName.ID = "hdnFld_tblName" + i;
                if (dt1.Columns.Count > 1 && (tablename == "Sales" || tablename == "Service"))
                {
                    if (j == 0)
                    {
                        lblHeader.Text = "BSO Sales Order";
                        hdnFld_tblName.Value = "tblBsoSalesOrder";
                    }
                    else if (j == 1)
                    {
                        lblHeader.Text = "Billing Address";
                        hdnFld_tblName.Value = "tblBsoBillingAddress";
                    }
                    else if (j == 2)
                    {
                        lblHeader.Text = "Delivery Address";
                        hdnFld_tblName.Value = "tblBsoDeliveryAddress";
                    }
                    else if (j == 3)
                    {
                        lblHeader.Text = "Product Details";
                        hdnFld_tblName.Value = "tblBsoProducts";
                    }
                    else if (j == 4)
                    {
                        lblHeader.Text = "Spare Details";
                        hdnFld_tblName.Value = "tblBsoSpares";
                    }
                    else if (j == 5)
                    {
                        lblHeader.Text = "Charges";
                        hdnFld_tblName.Value = "tblBsoCharges";
                    }
                  
                      
                }
                else
                {
                    if (j == 0 && tablename == "AMC")
                    {
                        lblHeader.Text = "AMC Details";
                        hdnFld_tblName.Value = "tblAmc";
                    }
                    if (j == 1 && tablename == "AMC")
                    {
                        lblHeader.Text = "All AMC Details";
                        hdnFld_tblName.Value = "tblAmcDetails";
                    }
                    else if (j == 0 && tablename == "Query")
                    {
                        lblHeader.Text = "Query Details";
                        hdnFld_tblName.Value = "tblQuery";
                    }
                }
                p1.HeaderContainer.Controls.Add(lblHeader);
                DataTable dt2 = new DataTable();
                cmd = new SqlCommand("selectEachTableDetails", con);
                cmd.CommandType = CommandType.StoredProcedure;
                if (j != 3 && j != 4)
                    cmd.Parameters.AddWithValue("@MainID", dt1.Rows[0][j].ToString());
                else
                    cmd.Parameters.AddWithValue("@MainID", MainID);
                cmd.Parameters.AddWithValue("@TableName", hdnFld_tblName.Value.ToString());
                con.Open();
                da = new SqlDataAdapter(cmd);
                da.Fill(dt2);
                con.Close();
                if (hdnFld_tblName.Value == "tblBsoProducts")
                {
                    dt3 = dt2;
                    grv_Product.DataSource = dt2;
                    grv_Product.DataBind();
                    grv_Product.Visible = true;
                    p1.ContentContainer.Controls.Add(grv_Product);
                }
                else if (hdnFld_tblName.Value == "tblBsoSpares")
                {
                    dt4 = dt2;
                    grv_Spare.DataSource = dt2;
                    grv_Spare.DataBind();
                    grv_Spare.Visible = true;
                    p1.ContentContainer.Controls.Add(grv_Spare);
                }
              
                else if (dt2.Rows.Count < 2)
                {
                    dt6 = dt2;
                    GridView grid_AmcNew = new GridView();

                    grid_AmcNew.DataSource = dt2;
                    grid_AmcNew.DataBind();
                    grid_AmcNew.Visible = true;
                    CssClass_GridView(grid_AmcNew);
                    p1.ContentContainer.Controls.Add(grid_AmcNew);
                }
                Accordion1.Panes.Add(p1);
                i++;
            }
        }

Tuesday, 8 January 2013

Onkeypress textbox and value show in label

 Onkeypress on textbox and value show in label

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup,
  menu, nav, section { display: block; }
</style>
<script type="text/javascript">
    $(function () {
        $('#txt1').keyup(function () {
         $('#output1').text($(this).val());
         $('#p1').text($(this).val());
        });
        $('#txt2').keyup(function () {
            $('#output2').text($(this).val());
            $('#p2').text($(this).val());
        });
        $('#txt3').keyup(function () {
            $('#output3').text($(this).val());
            $('#p3').text($(this).val());
        });
    });

</script>
</head>
<body>
<form id="form1" runat="server">
 <%-- <input id="txt1" type="text" />--%>
  <asp:TextBox ID="txt1" runat="server"></asp:TextBox><br />
  <asp:Label ID="output1" runat="server"></asp:Label><br />
   <asp:TextBox ID="txt2" runat="server"></asp:TextBox><br />
  <asp:Label ID="output2" runat="server"></asp:Label><br />
   <asp:TextBox ID="txt3" runat="server"></asp:TextBox><br />
  <asp:Label ID="output3" runat="server"></asp:Label>
  <br /><br />
 
   <div>
   <p id="p1"></p><br />
    <p id="p2"></p><br />
     <p id="p3"></p>
   </div>

  </form>
</body>
</html>

Wednesday, 2 January 2013

Procedure for Calculate Age

Procedure for Calculate Age


alter procedure pn_getDatedifference
(
@startdate datetime
)
as
begin

declare @monthToShow int
declare @dayToShow int
declare @enddate datetime
--set @startdate='01/21/1934'
set @enddate=getdate()

if(DAY(@startdate) > DAY(@enddate))
begin
set @dayToShow=0

if (month(@startdate) > month(@enddate))
begin
set @monthToShow= (12-month(@startdate)+ month(@enddate)-1)
end
else if (month(@startdate) < month(@enddate))
begin
set @monthToShow= ((month(@enddate)-month(@startdate))-1)
end
else
begin
set @monthToShow= 11
end
set @monthToShow= convert(int, DATEDIFF(mm,0,DATEADD(dd,DATEDIFF(dd,0,@enddate)- DATEDIFF(dd,0,@startdate),0)))-((convert(int,FLOOR(DATEDIFF(day, @startdate, @enddate) / 365.25))*12))-1
if(@monthToShow<0)
begin
set @monthToShow=0
end



declare @amonthbefore integer
set @amonthbefore=Month(@enddate)-1
if(@amonthbefore=0)
begin
set @amonthbefore=12
end

if(@amonthbefore in(1,3,5,7,8,10,12))
begin
set @dayToShow=31-DAY(@startdate)+DAY(@enddate)
end
if(@amonthbefore=2)
begin
IF (YEAR( @enddate ) % 4 = 0 AND YEAR( @enddate ) % 100 != 0) OR YEAR( @enddate ) % 400 = 0
begin
set @dayToShow=29-DAY(@startdate)+DAY(@enddate)
end
else
begin
set @dayToShow=28-DAY(@startdate)+DAY(@enddate)
end
end
if(@amonthbefore in (4,6,9,11))
begin
set @dayToShow=30-DAY(@startdate)+DAY(@enddate)
end

end
else
begin
set @monthToShow=convert(int, DATEDIFF(mm,0,DATEADD(dd,DATEDIFF(dd,0,@enddate)- DATEDIFF(dd,0,@startdate),0)))-((convert(int,FLOOR(DATEDIFF(day, @startdate, @enddate) / 365.25))*12))
if(month(@enddate)< month(@startdate))
begin
set @monthToShow=12+(month(@enddate)-month(@startdate))
end
else
begin
set @monthToShow= (month(@enddate)-month(@startdate))
end

set @dayToShow=DAY(@enddate)-DAY(@startdate)
end


SELECT
--FLOOR(DATEDIFF(day, @startdate, @enddate) / 365.25) as [yearToShow],
--@monthToShow as monthToShow ,@dayToShow as dayToShow ,
convert(varchar,FLOOR(DATEDIFF(day, @startdate, @enddate) / 365.25)) +' Year ' + convert(varchar,@monthToShow) +' months '+convert(varchar,@dayToShow)+' days ' as age
end



Friday, 21 December 2012

Java Script for GridView Pager

Java Script for GridView Pager


<script src='<%=Page.ResolveUrl("~/Scripts/tablesorter.js") %>' type="text/javascript"></script>
     <script src='<%=Page.ResolveUrl("~/Scripts/jquery.tablesorter.pager.js") %>' type="text/javascript"></script>



<script type="text/javascript">

    $(document).ready(function () {
        var rowsCount = '<%=Grid_Subscription.Rows.Count %>';
        var s = document.getElementById('<%= Grid_Subscription.ClientID %>');
        $("#" + s.id.toString()).tablesorter({ sortList: [[0, 0]], headers: { 6: { sorter: false }, 7: { sorter: false }, 8: { sorter: false}} }).tablePagination({ optionsForRows: [10, 25, 50, 100, rowsCount] });
    });
</script>

Tuesday, 4 December 2012

Javascript Validation of Numeric,Phone,Albhabet,Date

Javascript Validation of Numeric,Phone,Albhabet,Date

<html>
<head><title>Javascript validation</title>

<script language="javascript" type="text/javascript">
        function isCurrency(evt, txtid) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            var ctrl = document.getElementById(txtid)
            if (ctrl.value.indexOf('.') == -1 && charCode == 46)
                true;
            else if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                alert(" you can enter Only Numeric character..!!!");
                return false;
            }
            return true;
        }
        function CheckDate(sender, args) {
            if (sender._selectedDate > new Date()) {
                alert("Please Select Valid Birth Date...!!");
                sender._selectedDate = new Date();
                sender._textbox.set_Value(sender._selectedDate.format(sender._format));
            }
        }
        function OnlyAlphabets(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if ((charCode >= 97 && charCode <= 122) || (charCode >= 65 && charCode <= 90) || (charCode <= 32))
                true;
            else {
                alert("Only Alhaphet Characters Are Allowed To Enter..!!!");
                return false;
            }
            return true;
        }

        function DisableButton(buttonElem) {
            buttonElem.value = "Please Wait....";
            buttonElem.disabled = true;

        }
        function isName(evt, txtid) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            var ctrl = document.getElementById(txtid)
            if ((charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || (charCode == 32) || (charCode == 46)) {
                return true;
            }
            else
                alert("You Can Enter Only Alphabets,Space,Or Dot(.)");
            return false;
        }
        function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                alert("you can enter Only Numeric character..!!!");
                return false;
            }
            return true;
        }
        function isPhoneNo(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode == 45) return true;
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                alert("you can enter Only Numeric characters and '-' ...!!!");
                return false;
            }
            return true;
        }

        function NoNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode >= 48 && charCode <= 57) {
                alert("Digits are not allowed..!!!");
                return false;
            }
            return true;
        }

    </script>
</head>
<body>
<form id="from1" runat="server">
<div>
<table>
<tr>
<td>User Name:</td>
<td>
 <asp:TextBox ID="txt_username" runat="server" CssClass="txt" MaxLength="10"
  onkeypress="return OnlyAlphabets(evt);" Width="116px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Mobile:</td>
<td>
 <asp:TextBox ID="txt_Mobile" runat="server" CssClass="txt" MaxLength="10"
  onkeypress="return isNumberKey(event);" Width="116px"></asp:TextBox>
</td>
</tr>
</div>
</form>
</body>
</html>

Select DOB from dropdownlist Year,Month,Date

Select DOB from dropdownlist Year,Month,Date


<asp:UpdatePanel ID="updatepanel2" runat="server">
        <ContentTemplate>
        <asp:DropDownList ID="ddlBirthyear" runat="server" AutoPostBack="True" ToolTip="Select Year" TabIndex="13"
                                            onselectedindexchanged="ddlBirthyear_SelectedIndexChanged">
                                              <asp:ListItem Text="-- Year --" Value=""> </asp:ListItem>
                                        </asp:DropDownList>
                                        <asp:DropDownList ID="ddlBirthmonth" runat="server" AutoPostBack="True" ToolTip="Select Month" TabIndex="14"
                                            onselectedindexchanged="ddlBirthmonth_SelectedIndexChanged">
                                              <asp:ListItem Text="-- Month --" Value=""> </asp:ListItem>
                                        </asp:DropDownList>
                                         <asp:DropDownList ID="ddlBirthdate" runat="server" ToolTip="Select Date" TabIndex="15" >
                                          <asp:ListItem Text="-- Date --" Value=""> </asp:ListItem>
                                        </asp:DropDownList>
        </ContentTemplate>
        </asp:UpdatePanel>

.cs code

 protected void Page_Load(object sender, EventArgs e)
    {
        #region DOB DDL

        for (int i = 1; i <= 31; i++)
        {
            ddlBirthdate.Items.Add(i.ToString());
        }

        int[] n = (int[])Enum.GetValues(typeof(Month));

        foreach (int x in n)
        {
            ddlBirthmonth.Items.Add(new ListItem(Enum.Parse(typeof(Month), x.ToString()).ToString(), x.ToString()));
        }


        //for (int i = 1; i <= 12; i++)
        //{

        //    ddlBirthmonth.Items.Add(i.ToString());
        //}
        for (int i = DateTime.Now.Year; i >= 1960; i--)
        {
            ddlBirthyear.Items.Add(i.ToString());
        }

        #endregion
    }

    #region  DDL DOB - Binds Drop down for date of birth

    public enum Month
    {
        January = 1,
        February = 2,
        March = 3,
        April = 4,
        May = 5,
        June = 6,
        July = 7,
        August = 8,
        September = 9,
        October = 10,
        November = 11,
        December = 12
    }

    private bool CheckLeap(int year)
    {
        if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
            return true;
        else
            return false;
    }

    private void BindDays(int year, int month)
    {
        int i;
        System.Collections.ArrayList AlDay = new System.Collections.ArrayList();

        switch (month)
        {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                for (i = 1; i <= 31; i++)
                    AlDay.Add(i);
                break;
            case 2:
                if (CheckLeap(year))
                {
                    for (i = 1; i <= 29; i++)
                        AlDay.Add(i);
                }
                else
                {
                    for (i = 1; i <= 28; i++)
                        AlDay.Add(i);
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                for (i = 1; i <= 30; i++)
                    AlDay.Add(i);
                break;
        }

        ddlBirthdate.DataSource = AlDay;
        ddlBirthdate.DataBind();
        ddlBirthdate.Items.Insert(0, new ListItem("-- Date --"));

    }

    protected void ddlBirthyear_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlBirthyear.SelectedIndex != 0)
        {
            int year = Int32.Parse(ddlBirthyear.SelectedValue);
            int month = 1;
            try { month = Int32.Parse(ddlBirthmonth.SelectedValue); }
            catch { }
            BindDays(year, month);
        }
        else
        {
            ddlBirthdate.SelectedIndex = 0;
        }

    }

    protected void ddlBirthmonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlBirthmonth.SelectedIndex != 0)
        {
            int year = 2000;
            try { year = Int32.Parse(ddlBirthyear.SelectedValue); }
            catch { }
            int month = Int32.Parse(ddlBirthmonth.SelectedValue);
            BindDays(year, month);
        }
        else
        {
            ddlBirthdate.SelectedIndex = 0;

        }
    }

    #endregion
  
    protected void btnsave_Click(object sender, EventArgs e)
    {
        String DOB = ddlBirthdate.SelectedItem.Text + "/" + ddlBirthmonth.SelectedValue + "/" + ddlBirthyear.SelectedValue;
    }
}

Sunday, 2 December 2012

Mail sending code with Cc, Bcc and multiple dynamic File Attachments

Mail sending code with Cc, Bcc and multiple dynamic File Attachments


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<script type = "text/javascript">
    var counter = 0;
    function AddFileUpload() {
        var div = document.createElement('DIV');
        div.innerHTML = '<input id="file' + counter + '" name = "file' + counter +
                     '" type="file" />' +
                     '<input id="Button' + counter + '" type="button" ' +
                     'value="Remove" onclick = "RemoveFileUpload(this)" />';
        document.getElementById("FileUploadContainer").appendChild(div);
        counter++;
    }
    function RemoveFileUpload(div) {
        document.getElementById("FileUploadContainer").removeChild(div.parentNode);
    }
</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div>
<br />
<table>
<tr>
<td style="width:25px">&nbsp;</td>
    <td>
        To</td>
    <td><asp:TextBox ID="txtto" runat="server" Width="250px" Height="22px"></asp:TextBox></td>
</tr>
<tr>
<td style="width:25px">&nbsp;</td>
    <td>
        CC</td>
    <td><asp:TextBox ID="txtcc" runat="server" Width="250px" Height="22px"></asp:TextBox></td>
</tr>
<tr>
<td style="width:25px">&nbsp;</td>
    <td>
        BCC</td>
    <td><asp:TextBox ID="txtbcc" runat="server" Width="250px" Height="22px"></asp:TextBox></td>
</tr>
<tr>
<td>&nbsp;</td>
    <td>
        Subject</td>
    <td><asp:TextBox ID="txtsubject" runat="server" Width="250px"
            ontextchanged="txtsubject_TextChanged"></asp:TextBox></td>
</tr>
<tr>
<td>&nbsp;</td>
    <td>
        &nbsp;</td>
        <td>
       
            <span style ="font-family:Arial">Click to add files</span>&nbsp;&nbsp;
    <input id="Button1" type="button" value="add" onclick = "AddFileUpload();" />
    <br /><br />
    <div id = "FileUploadContainer">
        <asp:FileUpload ID="fileUpload1" runat="server" />
    </div>
    <br />
        </td>

</tr>
<tr>
<td>&nbsp;</td>
    <td>
        Message</td>
    <td><asp:TextBox ID="txtmessage" runat="server" Width="350px" TextMode="MultiLine" Height="60px"></asp:TextBox></td>
</tr>
<tr>
<td>&nbsp;</td>
    <td colspan="2">
        <asp:Label ID="lblmsg" runat="server" Text=""></asp:Label>
    </td>
</tr>
<tr>
<td>
    &nbsp;</td>
    <td colspan="2">
        <center>
            <asp:Button ID="bensave" runat="server" onclick="bensave_Click" Text="Send" />
        </center>
    </td>
</tr>
</table>
</div>
    </div>
    </form>
</body>
</html>

Web.Config Configurations

<httpRuntime
  executionTimeout="110"
  maxRequestLength="4096"
  requestLengthDiskThreshold="80"
  useFullyQualifiedRedirectUrl="false"
  minFreeThreads="8"
  minLocalRequestFreeThreads="4"
  appRequestQueueLimit="5000"
  enableKernelOutputCache="true"
  enableVersionHeader="true"
  requireRootedSaveAsPath="true"
  enable="true"
  shutdownTimeout="90"
  delayNotificationTimeout="5"
  waitChangeNotification="0"
  maxWaitChangeNotification="0"
  enableHeaderChecking="true"
  sendCacheControlHeader="true"
  apartmentThreading="false"
/>

.cs Code

 protected void bensave_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(txtto.Text);
        if(txtcc.Text.Trim().Length!=0)
        {
            mail.CC.Add(txtcc.Text);
        }
        if (txtbcc.Text.Trim().Length != 0)
        {
            mail.Bcc.Add(txtbcc.Text);
        }
        mail.From = new MailAddress("salikrammaurya@gmail.com");
        mail.Subject = txtsubject.Text;
        mail.Body = txtmessage.Text;
        mail.IsBodyHtml = true;

        if (fileUpload1.HasFile)
        {
         

            for (int i = 0; i < Request.Files.Count; i++)
            {
                mail.Attachments.Add(new Attachment(fileUpload1.PostedFile.InputStream, fileUpload1.FileName));
             
            }

        }
 
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential("salikrammaurya@gmail.com", "password");
        //Or your Smtp Email ID and Password
        smtp.EnableSsl = true;
        smtp.Send(mail);
        lblmsg.Text = "Mail send successfully";
        clear();

    }
    public void clear()
    {
        txtto.Text = txtsubject.Text = txtmessage.Text = txtcc.Text = txtbcc.Text = string.Empty;
    }