selvi subramanian

selvi subramanian

  • NA
  • 799
  • 574.9k

how to find the difference in time

Oct 25 2012 1:47 AM
Design

<%@ Page Language="C#" MasterPageFile="~/MasterPage/Team Lead.master" AutoEventWireup="true" CodeFile="TimePerformance.aspx.cs" Inherits="TeamLeaderModule_Default" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MLM_Logo" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" runat="server"
    contentplaceholderid="FullContentArea">


</asp:Content>
<asp:Content ID="Content4" runat="server" contentplaceholderid="ContentReport">
   <script type ="text/javascript">
    function CheckOne(obj)
    {
        var grid = obj.parentNode.parentNode.parentNode;
        var inputs = grid.getElementsByTagName("input");
        var hck=document.getElementById('ctl00_ContentReport_Gridview1_ctl02_CheckBox1').value;
           if(hck=="")
        {
        alert('se');
        return false;
        }
       
        for(var i=0;i<inputs.length;i++)
        {
            if (inputs[i].type =="checkbox")
            {
                if (obj.checked && inputs[i] != obj && inputs[i].checked) {
                    inputs[i].checked = false;
                }
            }
        }
       
    
    }
</script>
 <script type="text/javascript" language="javascript">
function validateCheckBoxes()
{
var isValid = false;
var gridView = document.getElementById('<%= Gridview1.ClientID %>');
for (var i = 1; i < gridView.rows.length; i++)
 {
var inputs = gridView.rows[i].getElementsByTagName('input');
if (inputs != null)
 {
if (inputs[0].type == "checkbox")
{
if (inputs[0].checked)
{
isValid = true;
return true;
}
}
}
}
alert("Please Select atleast one checkbox to Allocate Task");
return false;
}
</script>

    <%--<script type="text/javascript">
function ddd()
{
if(document.getElementById("ddlattendanceslot").value=="0")
{
txttimein.en
}

}
</script>--%>
<asp:MultiView ID="MultiView1" runat="server">
    <asp:View ID="View1" runat="server">
    <form id="Form1" runat="server"  >
                            <table align="center" style="border-color: #1d599e; height: 50px; border-style: inherit;
        border-width: thin; " width="100%">
                     <tr style="background: #1d599e;">
            <td align="center">
                <span class="style9">
                <strong>EMPLOYEE TIME PERFORMANCE</strong></span></td>
        </tr>
     
     <%--   <tr>
            <td style="height: 5px;" align="left">
                <asp:Label ID="Label19" runat="server" Text="To View Attendance:"></asp:Label>
                &nbsp;<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Click
                Here</asp:LinkButton>
            </td>

        </tr>--%>
        </table>
    </form>
</asp:View>        
      <asp:View ID="View2" runat="server">
<form id="Form2" runat="server" onsubmit="return CheckOne(obj)">
                <asp:GridView ID="Gridview1" runat="server"
                    AllowSorting="True" AutoGenerateColumns="false" CellPadding="4" DataKeyNames="Pk"
                    ForeColor="#333333" GridLines="None"
                  AllowPaging="true" PageSize="3"
                    style="height: 189px"
                    Width="292px"
                    onrowcommand="Gridview1_RowCommand" onrowdatabound="Gridview1_RowDataBound">
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                        <asp:TemplateField HeaderText="Checkbox">
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server" />
                                  </ItemTemplate>
                        </asp:TemplateField>
                       
                        <asp:TemplateField HeaderText="SlNo">
                            <ItemTemplate>
                                <asp:Label ID="lbpppk" runat="server" Text="<%#bind('Pk') %>"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                        <asp:TemplateField HeaderText="Date">
                            <ItemTemplate>
                                <asp:Label ID="lbdatee" runat="server" Text="<%#bind('Date') %>"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="EmpId">
                            <ItemTemplate>
                                <asp:Label ID="lbeid" runat="server" Text="<%#bind('EmployeeId') %>"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="EmpName">
                            <ItemTemplate>
                                <asp:Label ID="lename" runat="server" Text="<%#bind('EmployeeName') %>"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Attened Hours">
                            <ItemTemplate>
                                <asp:TextBox ID="txtah" runat="server" Enabled="False" Width="100px"/>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Worked Hours">
                            <ItemTemplate>
                                <asp:TextBox ID="txtwh" runat="server" Enabled="False" Width="100px" ReadOnly="true"
                                    AutoPostBack="True" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Effective Hours">
                            <ItemTemplate>
                                <asp:TextBox ID="txteffh" runat="server" Enabled="False" Width="100px"
                                    AutoPostBack="True" ontextchanged="txteffh_TextChanged"/>
                            </ItemTemplate>
                        </asp:TemplateField>
                         <asp:TemplateField HeaderText="Difference">
                            <ItemTemplate>
                                <asp:TextBox ID="txtdfrec" runat="server" Enabled="False" Width="100px"
                                    AutoPostBack="True"/>
                            </ItemTemplate>
                        </asp:TemplateField>
                      
                       
                        <asp:TemplateField HeaderText="SUBMIT">
                            <ItemTemplate>
                            <asp:button id="button1" runat="server" text="Submit"  /> 
                            </ItemTemplate>
                        </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
              </form>
   
           </asp:View>
          
          
           <%-- <asp:View ID="view3" runat="server">
            <table align="center" style="border-color: #1d599e; height: 50px; border-style: inherit;
        border-width: thin; " width="100%">
            <tr align="center">
            <td>
                <asp:Label ID="Label1" runat="server" Text=""></asp:Label> 
            </td>
           
            </tr>
           
            <tr align="center">
            <td>
                <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
            </td>
            </tr>
           
            </table>
           
           
           
                    </asp:View>--%>
                                
</asp:MultiView>
    


</asp:Content>







Code

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Globalization;

public partial class TeamLeaderModule_Default : System.Web.UI.Page
{
    REMO obj = new REMO();
    string s=ConfigurationManager.AppSettings["RM"].ToString();
    SqlConnection con;
  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            MultiView1.SetActiveView(View2);
            Grid();

        }
    }
   


    private void Grid()
    {         
        string q = "select convert([varchar],getdate(),(103)) as Date,Pk,EmployeeId,EmployeeName from EmpPersonal";
        DataSet ds = new DataSet();
        ds = obj.GETDS(q);
        Gridview1.Visible = true;
        Gridview1.DataSource = ds;
        Gridview1.DataBind();
        foreach (GridViewRow gvr in Gridview1.Rows)
        {
           TextBox AttenedHourst = (TextBox)(Gridview1.Rows[gvr.RowIndex].Cells[4].FindControl("txtah"));
            TextBox WorkedHourst = (TextBox)(Gridview1.Rows[gvr.RowIndex].Cells[5].FindControl("txtwh"));
            TextBox EffectiveHourst = (TextBox)(Gridview1.Rows[gvr.RowIndex].Cells[6].FindControl("txteffh"));
            TextBox Differencet = (TextBox)(Gridview1.Rows[gvr.RowIndex].Cells[7].FindControl("txtdfrec"));
            AttenedHourst.Enabled = true;
            WorkedHourst.Enabled = true;
            EffectiveHourst.Enabled = true;
            Differencet.Enabled = true;
        }
    }
        
    protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            LinkButton ll = (LinkButton)e.CommandSource;
            if (ll != null)
            ll.Text = "Submitted";
        }
   }
    protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {    
      if (e.Row.RowType == DataControlRowType.DataRow)
            {
                    con = new SqlConnection(s);
                    con.Open();
                    string emid = ((Label)e.Row.FindControl("lbeid")).Text;
          string EffectiveHours = ((TextBox)e.Row.FindControl("txtwh")).Text;
          string AttenedHours = ((TextBox)e.Row.FindControl("txtah")).Text;
          string WorkedHours = ((TextBox)e.Row.FindControl("txtwh")).Text;
          string Difference = ((TextBox)e.Row.FindControl("txtdfrec")).Text;

                    DataSet ds = new DataSet();
                    string qry = "select HoursWorked from logout where EmployeeId='" + emid + "'";
                   ds= obj.GETDS(qry);
                   con.Close();
                   for(int i=0; i<ds.Tables[0].Rows.Count;  i++)
                    {

                   EffectiveHours = ds.Tables[0].Rows[i]["HoursWorked"].ToString();
                   }
                   ((TextBox)e.Row.FindControl("txtwh")).Text = EffectiveHours;
                   //((TextBox)e.Row.FindControl("txtah")).Text = AttenedHours;
                   //((TextBox)e.Row.FindControl("txtwh")).Text = WorkedHours;
                   //((TextBox)e.Row.FindControl("txtdfrec")).Text = Difference;
                      
            }
     
    }







    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow gvr in Gridview1.Rows)
        {
            string date = ((Label)gvr.FindControl("lbdatee")).Text;
            string emid = ((Label)gvr.FindControl("lbeid")).Text;
            string eename = ((Label)gvr.FindControl("lename")).Text;

            string AttenedHours = ((TextBox)gvr.FindControl("txtah")).Text;
            string WorkedHours = ((TextBox)gvr.FindControl("txtwh")).Text;
            string EffectiveHours = ((TextBox)gvr.FindControl("txteffh")).Text;
            //string Difference = ((TextBox)gvr.FindControl("txtdfrec")).Text;
            string lal5 = ((TextBox)gvr.FindControl("txtdfrec")).Text;
            ((TextBox)gvr.FindControl("txtdfrec")).Text = lal5;
            string ars = "insert into Timeperformamce(Date,EmpID,EmpName,TotalHours) values ('" + date;
            ars += "','" + emid;
            ars += "','" + eename;
            // ars += "','" + atence;
            // ars += "','" + AttenedHours;
            // ars += "','" + WorkedHours;
            // ars += "','" + EffectiveHours;
            ars += "','" + lal5;
            ars += "')";
            obj.Insert(ars);
        }
    }
//    protected void  txtdfrec_TextChanged(object sender, EventArgs e)
//{
//          foreach (GridViewRow gvr in Gridview1.Rows)
//        {
//            string date = ((Label)gvr.FindControl("lbdatee")).Text;
//            string emid = ((Label)gvr.FindControl("lbeid")).Text;
//            string eename = ((Label)gvr.FindControl("lename")).Text;

//            string AttenedHours = ((TextBox)gvr.FindControl("txtah")).Text;
//            string WorkedHours = ((TextBox)gvr.FindControl("txtwh")).Text;
//            string EffectiveHours = ((TextBox)gvr.FindControl("txteffh")).Text;
//            //string Difference = ((TextBox)gvr.FindControl("txtdfrec")).Text;
//            string lal5 = ((TextBox)gvr.FindControl("txtdfrec")).Text;
//            ((TextBox)gvr.FindControl("txtdfrec")).Text = lal5;
//            string ars = "insert into Timeperformamce(Date,EmpID,EmpName,TotalHours) values ('" + date;
//            ars += "','" + emid;
//            ars += "','" + eename;
//            // ars += "','" + atence;
//           // ars += "','" + AttenedHours;
//           // ars += "','" + WorkedHours;
//           // ars += "','" + EffectiveHours;
//            ars += "','" + lal5;
//            ars += "')";
//            obj.Insert(ars);
//        }
//}
protected void  txteffh_TextChanged(object sender, EventArgs e)
{

     foreach (GridViewRow gvr in Gridview1.Rows)
        {
            if(((CheckBox)gvr.FindControl("CheckBox1")).Checked ==true)
                {
            //string date = ((Label)gvr.FindControl("lbdatee")).Text;
            //string emid = ((Label)gvr.FindControl("lbeid")).Text;
            //string eename = ((Label)gvr.FindControl("lename")).Text;

            //string AttenedHours = ((TextBox)gvr.FindControl("txtah")).Text;
            //string WorkedHours = ((TextBox)gvr.FindControl("txtwh")).Text;
            //string EffectiveHours = ((TextBox)gvr.FindControl("txteffh")).Text;
            //string Difference = ((TextBox)gvr.FindControl("txtdfrec")).Text;
            string lal3 = "01-01-0001 " + ((TextBox)gvr.FindControl("txtwh")).Text;
            string lal4 = "01-01-0001 " + ((TextBox)gvr.FindControl("txteffh")).Text;
            string lal5 = ((TextBox)gvr.FindControl("txtdfrec")).Text;

           // string L = System.DateTime.Now.ToString();
           // string Difference = ((TextBox)gvr.FindControl("txtdfrec")).Text;
            DateTime d1 = DateTime.ParseExact(lal3, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);
            DateTime d2 = DateTime.ParseExact(lal4, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);

            TimeSpan tSpan = d2 - d1;
            lal5 = tSpan.ToString();

            //lal5 = tSpan.Tostring();
            ((TextBox)gvr.FindControl("txtdfrec")).Text = lal5;
              //  int a, b, c;
               // a = int.Parse(lal3);
               // b = int.Parse(lal4);

               // c = (a - b);
               // Difference = c.ToString();
                //((TextBox)gvr.FindControl("txteffh")).Text = EffectiveHours;
                //((TextBox)gvr.FindControl("txtwh")).Text = WorkedHours;
                //((TextBox)gvr.FindControl("txtdfrec")).Text = Difference;

                }

      
}
}
//protected void txteffh_TextChanged(object sender, EventArgs e)
//    {
//        foreach (GridViewRow gvr in Gridview1.Rows)
//        {
//            if(((CheckBox)gvr.FindControl("CheckBox1")).Checked ==true)
//                {
//            //string date = ((Label)gvr.FindControl("lbdatee")).Text;
//            //string emid = ((Label)gvr.FindControl("lbeid")).Text;
//            //string eename = ((Label)gvr.FindControl("lename")).Text;

//            //string AttenedHours = ((TextBox)gvr.FindControl("txtah")).Text;
//            //string WorkedHours = ((TextBox)gvr.FindControl("txtwh")).Text;
//            //string EffectiveHours = ((TextBox)gvr.FindControl("txteffh")).Text;
//            //string Difference = ((TextBox)gvr.FindControl("txtdfrec")).Text;
//            string lal3 = "01-01-0001 " + ((TextBox)gvr.FindControl("txtwh")).Text;
//            string lal4 = "01-01-0001 " + ((TextBox)gvr.FindControl("txteffh")).Text;
//            string lal5 = ((TextBox)gvr.FindControl("txtdfrec")).Text;
//           // string L = System.DateTime.Now.ToString();
//           // string Difference = ((TextBox)gvr.FindControl("txtdfrec")).Text;
//            DateTime d1 = DateTime.ParseExact(lal3, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);
//            DateTime d2 = DateTime.ParseExact(lal4, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);

//            TimeSpan tSpan = d2 - d1;
//            lal5 = tSpan.ToString();
//            //lal5 = tSpan.Tostring();
//            ((TextBox)gvr.FindControl("txtdfrec")).Text = lal5;
//              //  int a, b, c;
//               // a = int.Parse(lal3);
//               // b = int.Parse(lal4);

//               // c = (a - b);
//               // Difference = c.ToString();
//                //((TextBox)gvr.FindControl("txteffh")).Text = EffectiveHours;
//                //((TextBox)gvr.FindControl("txtwh")).Text = WorkedHours;
//                //((TextBox)gvr.FindControl("txtdfrec")).Text = Difference;

//                }

//        }





//    }
  
}


i need the differece in time is like (01:00:00-00:00:20) if i give 01:00:00 like this the worked hours is retrieve from another table and i give the worked hours it should be subtracted from effective hours . and the time difference should be show in the difference textbox .the value should not be inserted