Total Pageviews

12 April 2012

Daily Report in asp.net

Image Report


Deafault.aspx=>
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>
  
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script language="javascript" type="text/javascript">
    function expandcollapse(obj, row) {
        var div = document.getElementById(obj);
        var img = document.getElementById('img' + obj);
        if (div.style.display == "none") {
            div.style.display = "block";
            if (row == 'alt') {
                img.src = "Images/minus.gif";
            }
            else {
                img.src = "Images/minus.gif";
            }
            img.alt = "Close to view other Purchase Orders";
        }
        else {
            div.style.display = "none";
            if (row == 'alt') {
                img.src = "Images/plus.gif";
            }
            else {
                img.src = "Images/plus.gif";
            }
            img.alt = "Expand to show Job NetPayble";
        }
    }
    </script>
    </asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td align="center">
                <asp:Button ID="btnMail" runat="server"
                    Text="Send  Invoice" />
                <asp:Button ID="btnReport" runat="server"
                    Text="View Invoice Report" />
                <asp:Button ID="btnReturn" runat="server" onclick="btnReturn_Click"
                    Text="Return to Home page" />
            </td>
        </tr>
        <tr>
            <td align="center">
                <asp:GridView ID="GridView1" AllowPaging="True" BackColor="#F1F1F1"
            AutoGenerateColumns=False DataSourceID="AccessDataSource1" DataKeyNames="Date1"
            style="Z-INDEX: 101; LEFT: 8px; " ShowFooter=True Font-Size=Small
            Font-Names="Verdana" runat="server" GridLines=None OnRowDataBound="GridView1_RowDataBound"
            OnRowCommand = "GridView1_RowCommand" OnRowUpdating = "GridView1_RowUpdating" BorderStyle=Outset
            OnRowDeleting = "GridView1_RowDeleting" OnRowDeleted = "GridView1_RowDeleted"
            OnRowUpdated = "GridView1_RowUpdated" AllowSorting=True Height="276px" Width="862px"
                   >
            <RowStyle BackColor="Gainsboro" />
            <AlternatingRowStyle BackColor="White" />
            <HeaderStyle BackColor="#0083C1" ForeColor="White"/>
            <FooterStyle BackColor="White" />
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <a href="javascript:expandcollapse('div<%# Eval("Date1") %>', 'one');">
                            <img id="imgdiv<%# Eval("Date1") %>" alt="Click to Job Details for Employee <%# Eval("Date1") %>"  width="9px" border="0" src="Images/plus.gif"/>
                        </a>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Invoice Submit Date" SortExpression="Date1">
                    <ItemTemplate>
                        <asp:Label ID="lblDate" Text='<%# Eval("Date1") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                   
                    <EditItemTemplate>
                        <asp:TextBox ID="txtDate" Text='<%# Eval("Date1") %>' runat="server"/>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtDate" Text='' runat="server" BackColor="Gray" ReadOnly="True"></asp:TextBox>
                    </FooterTemplate>
                   
                </asp:TemplateField>
                <asp:TemplateField HeaderText="AccountHolderName" SortExpression="Emp_ID">
                    <ItemTemplate><%# Eval("Emp_ID") %></ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtEmp_ID" Text='<%# Eval("Emp_ID") %>' runat="server" ReadOnly="True" BackColor="Gray"/>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtEmp_ID" Text='50' runat="server" BackColor="Gray" ReadOnly="True"></asp:TextBox>
                    </FooterTemplate>
                   
                </asp:TemplateField>                                          
                             
                <asp:TemplateField HeaderText="First Name" SortExpression="First_Name">
                    <ItemTemplate><%# Eval("First_Name")%></ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtFirst_Name" Text='<%# Eval("First_Name") %>' runat="server" ReadOnly="True" BackColor="Gray"></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtFirst_Name" Text='Amrit' runat="server" BackColor="Gray" ReadOnly="True"></asp:TextBox>
                    </FooterTemplate>
                   
                </asp:TemplateField>               
                <asp:TemplateField HeaderText="Last Name" SortExpression="Last_Name">
                    <ItemTemplate><%# Eval("Last_Name") %></ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtLast_Name" Text='<%# Eval("Last_Name") %>' runat="server" ReadOnly="True" BackColor="Gray"></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtLast_Name" Text='Yadav' runat="server" BackColor="Gray" ReadOnly="True"></asp:TextBox>
                    </FooterTemplate>
                   
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Designation" SortExpression="Designation">
                    <ItemTemplate><%# Eval("Designation")%></ItemTemplate>
                    <EditItemTemplate>
                       
                        <asp:TextBox ID="txtDesignation" Text='<%# Eval("Designation") %>' runat="server" ReadOnly="True" BackColor="Gray" ></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtDesignation" Text='Programmer' runat="server" BackColor="Gray" ReadOnly="True"></asp:TextBox>
                    </FooterTemplate>
                   
                </asp:TemplateField>
               
                <asp:TemplateField HeaderText="Add">                 
                    <FooterTemplate>
                        <asp:LinkButton ID="linkAddPO" CommandName="AddPO" runat="server">Add</asp:LinkButton>
                    </FooterTemplate>
                </asp:TemplateField>
               
      
      
      
      
       <asp:TemplateField>
           <ItemTemplate>
               <tr>
                            <td colspan="100%">
                                <div id="div<%# Eval("Date1") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" >
                                    <asp:GridView ID="GridView2" AllowSorting="true" BackColor="White" Width=100% Font-Size=X-Small
                                        AutoGenerateColumns=false Font-Names="Verdana" runat="server" DataKeyNames="Date1" ShowFooter=true
                                        OnPageIndexChanging="GridView2_PageIndexChanging" OnRowUpdating = "GridView2_RowUpdating"
                                        OnRowCommand = "GridView2_RowCommand" OnRowEditing = "GridView2_RowEditing" GridLines=None
                                        OnRowUpdated = "GridView2_RowUpdated" OnRowCancelingEdit = "GridView2_CancelingEdit" OnRowDataBound = "GridView2_RowDataBound"
                                        OnRowDeleting = "GridView2_RowDeleting" OnRowDeleted = "GridView2_RowDeleted" OnSorting = "GridView2_Sorting"
                                        BorderStyle=Double BorderColor="#0083C1">
                                        <RowStyle BackColor="Gainsboro" />
                                        <AlternatingRowStyle BackColor="White" />
                                        <HeaderStyle BackColor="#0083C1" ForeColor="White"/>
                                        <FooterStyle BackColor="White" />
                                        <Columns>
                                            <asp:TemplateField HeaderText="Job ID" SortExpression="Task_id">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblPO_Task_id" Text='<%# Eval("Task_id") %>' runat="server"></asp:Label>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:Label ID="lblPO_Task_id" Text='<%# Eval("Task_id") %>' runat="server"></asp:Label>
                                                </EditItemTemplate>
                                               
                                            </asp:TemplateField>
                                           
                                            <asp:TemplateField HeaderText="Description" SortExpression="Description">
                                                <ItemTemplate><%# Eval("Description")%></ItemTemplate>
                                                <ItemTemplate><asp:Label id="lbDes" runat="server" Text='<%# Eval("Description")%>'/></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtDescription" Text='<%# Eval("Description")%>' runat="server" TextMode="MultiLine"></asp:TextBox>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtDescription" Text='' runat="server" TextMode="MultiLine"></asp:TextBox>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                           
                                            <asp:TemplateField HeaderText="Status" SortExpression="Status">
                                            <ItemTemplate><asp:Label id="lbStatus" runat="server" Text='<%# Eval("Status")%>'/></ItemTemplate>                                               
                                                <ItemTemplate><%# Eval("Status")%></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:DropDownList ID="ddlStatus" Text='<%# Eval("Status")%>' runat="server">
                                                    <asp:ListItem Value="Completed"></asp:ListItem>
                            <asp:ListItem Value="Pending"></asp:ListItem>
                            <asp:ListItem Value="In Progress"></asp:ListItem>
                            <asp:ListItem Value="Not Yet Initiated"></asp:ListItem>
                            </asp:DropDownList>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:DropDownList ID="ddlStatus" runat="server">
                                                    <asp:ListItem Value="Completed"></asp:ListItem>
                            <asp:ListItem Value="Pending"></asp:ListItem>
                            <asp:ListItem Value="In Progress"></asp:ListItem>
                            <asp:ListItem Value="Not Yet Initiated"></asp:ListItem>
                            </asp:DropDownList>
                                                </FooterTemplate>
                                            </asp:TemplateField>                                           
                                           
                                           
                                            <asp:TemplateField HeaderText="Time Hours" SortExpression="Time_Hours">
                                            <ItemTemplate><asp:Label id="lbTHrs" runat="server" Text='<%# Eval("Time_Hours")%>'/></ItemTemplate>
                                                <ItemTemplate><%# Eval("Time_Hours")%></ItemTemplate>
                                                <EditItemTemplate>
                                                <asp:DropDownList ID="ddlTime_Hours" runat="server">
                                                 <asp:ListItem Value="0"></asp:ListItem>      
                                                <asp:ListItem Value="1"></asp:ListItem>
                            <asp:ListItem Value="2"></asp:ListItem>
                            <asp:ListItem Value="3"></asp:ListItem>
                            <asp:ListItem Value="4"></asp:ListItem>
                            <asp:ListItem Value="5"></asp:ListItem>
                            <asp:ListItem Value="6"></asp:ListItem>
                            <asp:ListItem Value="7"></asp:ListItem>
                            <asp:ListItem Value="8"></asp:ListItem>
                            <asp:ListItem Value="9"></asp:ListItem>
                            <asp:ListItem Value="10"></asp:ListItem>
                            <asp:ListItem Value="11"></asp:ListItem>
                            <asp:ListItem Value="12"></asp:ListItem>
                                                </asp:DropDownList>
                                                   
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                   <asp:DropDownList ID="ddlTime_Hours" runat="server">
                                                 <asp:ListItem Value="0"></asp:ListItem>
                                                 <asp:ListItem Value="1"></asp:ListItem>
                            <asp:ListItem Value="2"></asp:ListItem>
                            <asp:ListItem Value="3"></asp:ListItem>
                            <asp:ListItem Value="4"></asp:ListItem>
                            <asp:ListItem Value="5"></asp:ListItem>
                            <asp:ListItem Value="6"></asp:ListItem>
                            <asp:ListItem Value="7"></asp:ListItem>
                            <asp:ListItem Value="8"></asp:ListItem>
                            <asp:ListItem Value="9"></asp:ListItem>
                            <asp:ListItem Value="10"></asp:ListItem>
                            <asp:ListItem Value="11"></asp:ListItem>
                            <asp:ListItem Value="12"></asp:ListItem>
                                                </asp:DropDownList>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Time Minutes" SortExpression="Time_Minutes">
                                                <ItemTemplate><%# Eval("Time_Minutes")%></ItemTemplate>
                                                <ItemTemplate><asp:Label id="lbTMins" runat="server" Text='<%# Eval("Time_Minutes")%>'/></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:DropDownList ID="ddlTime_Minutes" Text='<%# Eval("Time_Minutes")%>' runat="server">
                             <asp:ListItem Value="0"></asp:ListItem>
                             <asp:ListItem Value="5"></asp:ListItem>                      
                            <asp:ListItem Value="10"></asp:ListItem>
                            <asp:ListItem Value="15"></asp:ListItem>
                            <asp:ListItem Value="20"></asp:ListItem>
                            <asp:ListItem Value="25"></asp:ListItem>
                            <asp:ListItem Value="30"></asp:ListItem>
                            <asp:ListItem Value="35"></asp:ListItem>
                            <asp:ListItem Value="40"></asp:ListItem>
                            <asp:ListItem Value="45"></asp:ListItem>
                            <asp:ListItem Value="50"></asp:ListItem>
                            <asp:ListItem Value="55"></asp:ListItem>
                            <asp:ListItem Value="60"></asp:ListItem>
                                                </asp:DropDownList>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:DropDownList ID="ddlTime_Minutes" runat="server">
                            <asp:ListItem Value="0"></asp:ListItem>
                            <asp:ListItem Value="5"></asp:ListItem>                                                   
                            <asp:ListItem Value="10"></asp:ListItem>
                            <asp:ListItem Value="15"></asp:ListItem>
                            <asp:ListItem Value="20"></asp:ListItem>
                            <asp:ListItem Value="25"></asp:ListItem>
                            <asp:ListItem Value="30"></asp:ListItem>
                            <asp:ListItem Value="35"></asp:ListItem>
                            <asp:ListItem Value="40"></asp:ListItem>
                            <asp:ListItem Value="45"></asp:ListItem>
                            <asp:ListItem Value="50"></asp:ListItem>
                            <asp:ListItem Value="55"></asp:ListItem>
                            <asp:ListItem Value="60"></asp:ListItem>
                                                </asp:DropDownList>
                                                </FooterTemplate>
                                            </asp:TemplateField>                                 
                                            <asp:TemplateField HeaderText="Total Time" SortExpression="Total_Time">
                                                <ItemTemplate><%# Eval("Total_Time")%></ItemTemplate>
                                                <ItemTemplate><asp:Label id="lbTT" runat="server" Text='<%# Eval("Total_Time")%>'/></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtTotal_Time" Text='<%# Eval("Total_Time")%>' runat="server" ReadOnly="True" BackColor="Gray"></asp:TextBox>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtTotal_Time"  ReadOnly="True" BackColor="Gray" runat="server"></asp:TextBox>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                           
                                            <asp:TemplateField HeaderText="Time_Duration" SortExpression="Time_Duration">
                                                <ItemTemplate><%# Eval("Time_Duration")%></ItemTemplate>
                                                <ItemTemplate><asp:Label id="lbTD" runat="server" Text='<%# Eval("Time_Duration")%>'/></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtTime_Duration" Text='<%# Eval("Time_Duration")%>' runat="server"></asp:TextBox>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtTime_Duration" Text='' runat="server"></asp:TextBox>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Remarks" SortExpression="Remarks">
                                                <ItemTemplate><%# Eval("Remarks")%></ItemTemplate>
                                                <ItemTemplate><asp:Label id="lbRemarks" runat="server" Text='<%# Eval("Remarks")%>'/></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtRemarks" Text='<%# Eval("Remarks")%>' runat="server"></asp:TextBox>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtRemarks"  runat="server" ></asp:TextBox>
                                                </FooterTemplate>
                                            </asp:TemplateField>                                           
                                                                                      
                                   <asp:TemplateField ShowHeader="False"> 
                                            <ItemTemplate> 
                                                    <asp:LinkButton ID="linkEdit" runat="server" CausesValidation="False" CommandName="Edit"  Text="Edit"></asp:LinkButton> 
                                            </ItemTemplate>
                                            <EditItemTemplate> 
                                                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update"></asp:LinkButton> 
                                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton> 
                                            </EditItemTemplate> 
                                            </asp:TemplateField>
                                   <asp:TemplateField HeaderText="Delete">    
                                                 <ItemTemplate> 
                                                 <table>
                                                    <tr>
                                                        <td>    
                                                        <asp:LinkButton ID="linkDeletePO" CommandName="Delete" runat="server">Delete</asp:LinkButton>    
                                                        </td>
                                                    </tr>                                                   
                                                 </table> 
                                                 </ItemTemplate>
                                                 <FooterTemplate>
                                                    <asp:LinkButton ID="linkAddJob" CommandName="AddJob" runat="server">Add</asp:LinkButton>
                                                 </FooterTemplate>     
                                            </asp:TemplateField>
                                        </Columns>
                                   </asp:GridView>
                                </div>
                             </td>
                        </tr>
           </ItemTemplate>         
       </asp:TemplateField>      
   </Columns>
        </asp:GridView>
                <asp:AccessDataSource ID="AccessDataSource1" runat="server"
                    DataFile="~/App_Data/DR_Details_amrit.mdb"
                    SelectCommand="SELECT * FROM [Emp_Details]"></asp:AccessDataSource>
            </td>
        </tr>
    </table>
               
</asp:Content>
Default.aspx.cs=>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
    float TV;
    float s4;
    string strTotal_Hours;
    string gvUniqueID = String.Empty;
    int gvNewPageIndex = 0;
    int gvEditIndex = -1;
    string gvSortExpr = String.Empty;
    private string gvSortDir
    {
        get { return ViewState["SortDirection"] as string ?? "ASC"; }
        set { ViewState["SortDirection"] = value; }
    }

    //This procedure returns the Sort Direction
    private string GetSortDirection()
    {
        switch (gvSortDir)
        {
            case "ASC":
                gvSortDir = "DESC";
                break;
            case "DESC":
                gvSortDir = "ASC";
                break;
        }
        return gvSortDir;
    }
    //This procedure prepares the query to bind the child GridView
    private AccessDataSource ChildDataSource(string strDate, string strSort)
    {
        string strQRY = "";
        AccessDataSource dsTemp = new AccessDataSource();
        dsTemp.DataFile = "~/App_Data/DR_Details_amrit.mdb";
        strQRY = "SELECT [Job_Details].[Date1],[Job_Details].[Task_id]," +
                                "[Job_Details].[Description], [Job_Details].[Status], [Job_Details].[Time_Hours], [Job_Details].[Time_Minutes], [Job_Details].[Total_Time],[Job_Details].[Time_Duration], [Job_Details].[Remarks] FROM [Job_Details]" +
                                " WHERE [Job_Details].[Date1] = '" + strDate + "'" +
                                "UNION ALL " +
                                "SELECT '" + strDate + "','','','','','','','','' FROM [Job_Details] WHERE [Job_Details].[Date1] = '" + strDate + "'" +
                                "HAVING COUNT(*)=0 " + strSort;
        dsTemp.SelectCommand = strQRY;
        return dsTemp;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ((TextBox)GridView1.FooterRow.FindControl("txtDate")).Text = DateTime.Now.ToLongDateString();
    }
    #region GridView1 Event Handlers
    //This event occurs for each row
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        GridViewRow row = e.Row;
        string strSort = string.Empty;
        // Make sure we aren't in header/footer rows
        if (row.DataItem == null)
        {
            return;
        }
        //Find Child GridView control
        GridView gv = new GridView();
        gv = (GridView)row.FindControl("GridView2");
        //Check if any additional conditions (Paging, Sorting, Editing, etc) to be applied on child GridView
        if (gv.UniqueID == gvUniqueID)
        {
            gv.PageIndex = gvNewPageIndex;
            gv.EditIndex = gvEditIndex;
            //Check if Sorting used
            if (gvSortExpr != string.Empty)
            {
                GetSortDirection();
                strSort = " ORDER BY " + string.Format("{0} {1}", gvSortExpr, gvSortDir);
            }
            //Expand the Child grid
            ClientScript.RegisterStartupScript(GetType(), "Expand", "<SCRIPT LANGUAGE='javascript'>expandcollapse('div" + ((DataRowView)e.Row.DataItem)["Date1"].ToString() + "','one');</script>");
        }
        //Prepare the query for Child GridView by passing the Report ID of the parent row
        gv.DataSource = ChildDataSource(((DataRowView)e.Row.DataItem)["Date1"].ToString(), strSort);
        gv.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //Check if Add button clicked
        if (e.CommandName == "AddPO")
        {
            try
            {
                //Get the values stored in the text boxes

                string strFirst_Name = ((TextBox)GridView1.FooterRow.FindControl("txtFirst_Name")).Text;
                string strLast_Name = ((TextBox)GridView1.FooterRow.FindControl("txtLast_Name")).Text;
                string strDesignation = ((TextBox)GridView1.FooterRow.FindControl("txtDesignation")).Text;
                string strEmp_ID = ((TextBox)GridView1.FooterRow.FindControl("txtEmp_ID")).Text;
                string strDate = ((TextBox)GridView1.FooterRow.FindControl("txtDate")).Text;


                //Prepare the Insert Command of the DataSource control
                string strSQL = "";
                strSQL = "INSERT INTO Emp_Details (Emp_ID, First_Name, Last_Name, " +
                        "Designation, Date1) VALUES ('" + strEmp_ID + "','" + strFirst_Name + "','" + strLast_Name + "','" + strDesignation + "','" + strDate + "')";
                AccessDataSource1.InsertCommand = strSQL;
                AccessDataSource1.Insert();
                ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Report added successfully');</script>");
                //Re bind the grid to refresh the data
                GridView1.DataBind();
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
            }
        }
    }
    //This event occurs on click of the Update button
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Get the values stored in the text boxes
        GridView1.FooterRow.Cells[1].Text = DateTime.Now.ToLongDateString();
        string strFirst_Name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtFirst_Name")).Text;
        string strLast_Name = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtLast_Name")).Text;
        string strDesignation = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtDesignation")).Text;
        string strDate = ((Label)GridView1.Rows[e.RowIndex].FindControl("txtDate")).Text;
        string strEmp_ID = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmp_ID")).Text;


        try
        {
            //Prepare the Update Command of the DataSource control
            string strSQL = "";
            strSQL = "UPDATE Emp_Details set First_Name = '" + strFirst_Name + "'" +
                     ",Last_Name = '" + strLast_Name + "'" +
                     ",Designation = '" + strDesignation + "'" +
                     ",Emp_ID = '" + strEmp_ID + "'" +

                     " WHERE Date1 = '" + strDate + "'";
            AccessDataSource1.UpdateCommand = strSQL;
            AccessDataSource1.Update();
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Report updated successfully');</script>");
        }
        catch { }
    }
    //This event occurs after RowUpdating to catch any constraints while updating
    protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        //Check if there is any exception while deleting
        if (e.Exception != null)
        {
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>");
            e.ExceptionHandled = true;
        }
    }
    //This event occurs on click of the Delete button
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //Get the value       
        string strDate = ((Label)GridView1.Rows[e.RowIndex].FindControl("txtDate")).Text;
        //Prepare the delete Command of the DataSource control
        string strSQL = "";
        try
        {
            strSQL = "DELETE from Emp_Details WHERE Date1 = '" + strDate + "'";
            AccessDataSource1.DeleteCommand = strSQL;
            AccessDataSource1.Delete();
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Report deleted successfully');</script>");
        }
        catch { }
    }
    //This event occurs after RowDeleting to catch any constraints while deleting
    protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        //Check if there is any exception while deleting
        if (e.Exception != null)
        {
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>");
            e.ExceptionHandled = true;
        }
    }
    #endregion
    #region GridView2 Event Handlers
    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView gvTemp = (GridView)sender;
        gvUniqueID = gvTemp.UniqueID;
        gvNewPageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "AddJob")
        {
            try
            {
                GridView gvTemp = (GridView)sender;
                gvUniqueID = gvTemp.UniqueID;
                //Get the values stored in the text boxes
                string strDate = gvTemp.DataKeys[0].Value.ToString();  //Report ID is stored as DataKeyNames
                string strStatus = ((DropDownList)gvTemp.FooterRow.FindControl("ddlStatus")).Text;
                string strTime_Minutes = ((DropDownList)gvTemp.FooterRow.FindControl("ddlTime_Minutes")).Text;
                string strTime_Duration = ((TextBox)gvTemp.FooterRow.FindControl("txtTime_Duration")).Text;
                string strTotal_Time = ((TextBox)gvTemp.FooterRow.FindControl("txtTotal_Time")).Text;
                string strDescription = ((TextBox)gvTemp.FooterRow.FindControl("txtDescription")).Text;
                string strTime_Hours = ((DropDownList)gvTemp.FooterRow.FindControl("ddlTime_Hours")).Text;
                string strRemarks = ((TextBox)gvTemp.FooterRow.FindControl("txtRemarks")).Text;
                //strTotal_Hours = ((TextBox)GridView1.FooterRow.FindControl("txtTotal_Hours")).Text;
                //string strTotal_Hours = ((TextBox)gvTemp.FooterRow.FindControl("txtTotal_Hours")).Text;

                float s1 = float.Parse(strTime_Minutes);
                float s2 = float.Parse(strTime_Hours);

                TV = (s2 + (s1 / 60));
                strTotal_Time = TV.ToString();

                //Prepare the Insert Command of the DataSource control
                string strSQL = "";
                strSQL = "INSERT INTO Job_Details (Date1, Description, Status, Time_Hours, Time_Minutes, Total_Time, Time_Duration, Remarks) VALUES ('" + strDate + "', '" + strDescription + "', '" + strStatus + "', '" + float.Parse(strTime_Hours) + "',  '" + float.Parse(strTime_Minutes) + "', '" + float.Parse(strTotal_Time) + "','" + strTime_Duration + "','" + strRemarks + "')";
                ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Job added successfully');</script>");
                AccessDataSource1.InsertCommand = strSQL;
                AccessDataSource1.Insert();
                GridView1.DataBind();

            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
            }
        }
    }
    protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView gvTemp = (GridView)sender;
        gvUniqueID = gvTemp.UniqueID;
        gvEditIndex = e.NewEditIndex;
        GridView1.DataBind();
    }
    protected void GridView2_CancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView gvTemp = (GridView)sender;
        gvUniqueID = gvTemp.UniqueID;
        gvEditIndex = -1;
        GridView1.DataBind();
    }
    protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            GridView gvTemp = (GridView)sender;
            gvUniqueID = gvTemp.UniqueID;
            //Get the values stored in the text boxes
            string strPO_Task_id = ((Label)gvTemp.Rows[e.RowIndex].FindControl("lblPO_Task_id")).Text;
            string strTime_Minutes = ((DropDownList)gvTemp.Rows[e.RowIndex].FindControl("ddlTime_Minutes")).Text;
            string strTime_Duration = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtTime_Duration")).Text;
            string strRemarks = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtRemarks")).Text;
            string strDescription = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtDescription")).Text;
            string strTime_Hours = ((DropDownList)gvTemp.Rows[e.RowIndex].FindControl("ddlTime_Hours")).Text;
            string strStatus = ((DropDownList)gvTemp.Rows[e.RowIndex].FindControl("ddlStatus")).Text;
            string strTotal_Time = ((TextBox)gvTemp.Rows[e.RowIndex].FindControl("txtTotal_Time")).Text;

            float s1 = float.Parse(strTime_Minutes);
            float s2 = float.Parse(strTime_Hours);

            float TV = (s2 + (s1 / 60));
            strTotal_Time = TV.ToString();
            float s3 = float.Parse(strTime_Hours) + float.Parse(strTotal_Time);

            //Prepare the Update Command of the DataSource control
            AccessDataSource dsTemp = new AccessDataSource();
            dsTemp.DataFile = "~/App_Data/DR_Details_amrit.mdb";
            string strSQL = "";
            strSQL = "UPDATE Job_Details set Total_Time = " + float.Parse(strTotal_Time) + "" +
                     ",Description = '" + strDescription + "'" +
                     ",Status = '" + strStatus + "'" +
                     ",Time_Hours = '" + float.Parse(strTime_Hours) + "'" +
                     ",Time_Minutes = '" + float.Parse(strTime_Minutes) + "'" +
                     ",Time_Duration = '" + strTime_Duration + "'" +
                     ",Remarks = '" + strRemarks + "'" +

                     " WHERE Task_id = " + strPO_Task_id;
            dsTemp.UpdateCommand = strSQL;
            dsTemp.Update();
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Job updated successfully');</script>");
            //Reset Edit Index
            gvEditIndex = -1;
            GridView1.DataBind();
        }
        catch { }
    }
    protected void GridView2_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
        //Check if there is any exception while deleting
        if (e.Exception != null)
        {
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>");
            e.ExceptionHandled = true;
        }
    }
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        GridView gvTemp = (GridView)sender;
        gvUniqueID = gvTemp.UniqueID;
        //Get the value       
        string strPO_Task_id = ((Label)gvTemp.Rows[e.RowIndex].FindControl("lblPO_Task_id")).Text;
        //Prepare the Update Command of the DataSource control
        string strSQL = "";
        try
        {
            strSQL = "DELETE from Job_Details WHERE Task_id = " + strPO_Task_id;
            AccessDataSource dsTemp = new AccessDataSource();
            dsTemp.DataFile = "~/App_Data/DR_Details_amrit.mdb";
            dsTemp.DeleteCommand = strSQL;
            dsTemp.Delete();
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Job deleted successfully');</script>");
            GridView1.DataBind();
        }
        catch { }
    }
    protected void GridView2_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
        //Check if there is any exception while deleting
        if (e.Exception != null)
        {
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + e.Exception.Message.ToString().Replace("'", "") + "');</script>");
            e.ExceptionHandled = true;
        }
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //Check if this is our Blank Row being databound, if so make the row invisible 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (((DataRowView)e.Row.DataItem)["Task_id"].ToString() == String.Empty) e.Row.Visible = false;
            DataRowView myRowView = ((DataRowView)e.Row.DataItem);
            if (myRowView["Date1"].ToString() != String.Empty && Convert.ToDateTime(myRowView["Date1"]).AddDays(3) < DateTime.Now)
            {
                e.Row.FindControl("linkEdit").Visible = false;
                e.Row.FindControl("linkDeletePO").Visible = false;
                //e.Row.FindControl("linkAddPO").Visible = false;
            }
        }
    }
    protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
    {
        GridView gvTemp = (GridView)sender;
        gvUniqueID = gvTemp.UniqueID;
        gvSortExpr = e.SortExpression;
        GridView1.DataBind();
    }
    #endregion
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        Response.Redirect("Report_PO.aspx");
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("Start_Menu.aspx");
    }
    protected void btnReport_Click1(object sender, EventArgs e)
    {
        Response.Redirect("Report_DR_amrit.aspx");
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
    }
    protected void btnMail_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow r in GridView1.Rows)
        {
            DateTime time = Convert.ToDateTime((r.FindControl("lblDate") as Label).Text);
            if (time.ToLongDateString() == DateTime.Today.ToLongDateString())
            {
                GridView gv = (GridView)r.FindControl("GridView2");
                StringBuilder SB = new StringBuilder();
                StringWriter SW = new StringWriter(SB);
                HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
                gv.RenderControl(htmlTW);
                string grid = SB.ToString();
                SmtpClient smtpClient = new SmtpClient();
                MailMessage message = new MailMessage();
                message.From = new MailAddress("amrit7686@gmail.com");
                message.To.Add("amrit7686@gmail.com");
                message.CC.Add("amrit7686@gmail.com");
                message.Subject = "amrit-Daily Report Sheet";
                message.IsBodyHtml = true;
                message.Body = grid;
                smtpClient.Host = "209.62.85.9";
                smtpClient.Send(message);
            }
        }
    }
}

Contact Form

Name

Email *

Message *