4) For outsideInside.aspx
DataBase Changes
alter proc [dbo].[TimeCalculator]
@Id int,
@User_Id int=null,
@Timing datetime=null,
@ByTime datetime=null,
@StartDate datetime=null,
@EndDate datetime=null,
@Status nvarchar(50)=null,
@Spend_time nvarchar(50)=null,
@Company_Purpose nvarchar(50)=null,
@Actiontype char(10)
as
begin
if(@Actiontype='Out')
begin
insert into tbl_Spend_Time(User_Id,Timing,Status,Spend_time,Company_Purpose) values (@User_Id,@Timing,@Status,@Spend_time,@Company_Purpose)
end
else if(@Actiontype='select1')
begin
select * from tbl_Spend_Time where User_Id=@User_Id
end
else if(@Actiontype='In')
begin
insert into tbl_Spend_Time(User_Id,Timing,Status,Spend_time,Company_Purpose) values (@User_Id,@Timing,@Status,@Spend_time,@Company_Purpose)
end
else if(@Actiontype='Select2')
begin
select * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) = cast(getdate() as Date) and (Company_Purpose='' or Company_Purpose='Nan')
end
else if(@Actiontype='ctime')
begin
select * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) = cast(getdate() as Date) and (Company_Purpose!='' and Company_Purpose!='Nan')
end
else if(@Actiontype='Select4')
begin
select * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) between cast(@StartDate as Date) and cast(@EndDate as Date)
end
else if(@Actiontype='Select5')
begin
select * from tbl_Spend_Time where cast(Timing as Date) between cast(@StartDate as Date) and cast(@EndDate as Date)
end
else if(@Actiontype='Select3')
begin
select * from tbl_Spend_Time where cast(Timing as Date) = cast(getdate() as Date)
end
else if(@Actiontype='lasttime')
begin
select top 1 * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) = cast(getdate() as Date) order by Timing desc
end
else if(@Actiontype='select6')
begin
select Timing, DATEADD(dd, 0, DATEDIFF(dd, 0, Timing)) as Timing,Id,User_Id,Status,Spend_time,Company_Purpose from tbl_Spend_Time where User_Id=@User_Id
end
else if(@Actiontype='Select8')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Timing)) as Timing,Id,User_Id,Status,Spend_time,Company_Purpose from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) between cast(@StartDate as Date) and cast(@EndDate as Date)
end
else if(@Actiontype='select7')
begin
select * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) = cast(@ByTime as Date)
end
else if(@Actiontype='select9')
begin
select * from tbl_Spend_Time where cast(Timing as Date) = cast(getdate() as Date)
end
else if(@Actiontype='select10')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Timing)) as Timing,Id,User_Id,Status,Spend_time,Company_Purpose from tbl_Spend_Time where cast(Timing as Date) = cast(@StartDate as Date)
end
end
developer->outsideinside.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Developer/DeveloperMaster.master" AutoEventWireup="true" CodeFile="OutsideInside.aspx.cs" Inherits="Developer_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<table width="400" border="1" cellspacing="2" cellpadding="1" class='tdrow4' align='center'>
<tr align="center">
<td colspan="2" class="txt">Personal Time Calculator (Today Details)</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td width="199" align="right" class="Tab3"><strong><%# Eval("Status")%></strong></td>
<td width="199" align="right" class="Tab3"><strong><%# Eval("Timing", "{0: h:mm tt}")%></strong></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr align="center">
<td colspan="2">
<%--<asp:Button ID="btncmp" OnClick="btncmp_Click" Text="Company Purpose" runat="server" CssClass="Tab2" /> --%>
<asp:Button ID="btnout" runat="server" Text=" Out " ToolTip="Submit"
Style="cursor: pointer;" OnClick="btnout_Click" CssClass="Tab2" />
<%--<asp:TextBox ID="txtcomypor" Width="200" Height="100" TextMode="MultiLine" runat="server" Visible="false"></asp:TextBox>--%>
<%--<asp:Button ID="btnhidetext" OnClick="btnhidetext_Click" Visible="false" Text="close" runat="server" CssClass="Tab2" /> --%>
<asp:Button ID="btnin" runat="server" Text=" In " ToolTip="Submit"
Style="cursor: pointer;" OnClick="btnin_Click" CssClass="Tab2" />
<asp:Label ID="lblmsg" runat="server" ForeColor="Red"></asp:Label>
<asp:Label ID="lblid" runat="server" Visible="false"></asp:Label>
</td>
</tr>
</table>
<table width="400" border="1" cellspacing="2" cellpadding="1" class='tdrow4' align='right'>
<tr>
<td width="199" align="right" class="Tab3"><strong>Personal Outside <%--spend--%> time</strong></td>
<td width="199" align="right" class="Tab3"><strong>(<%=TimeSpend%>) Mins</strong></td>
</tr>
</table>
<br />
<br />
<table width="400" border="1" cellspacing="2" cellpadding="1" class='tdrow4' align='center' style="margin-left:474px;" >
<tr align="center">
<td colspan="2" class="txt">Company Purpose Time Calculator (Today Details)</td>
</tr>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<tr>
<td width="199" align="right" class="Tab3"><strong><%# Eval("Status")%></strong></td>
<td width="199" align="right" class="Tab3"><strong><%# Eval("Timing", "{0: h:mm tt}")%></strong></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr align="center">
<td colspan="2">
<asp:TextBox ID="txtcomypor" Width="200" Height="100" TextMode="MultiLine" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
InitialValue="" ValidationGroup="valgroup" Display="Dynamic" ControlToValidate="txtcomypor"
SetFocusOnError="true" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:Button ID="btnhidetext" OnClick="btnhidetext_Click" Visible="false" Text="close" runat="server" CssClass="Tab2" />
<asp:Button ID="btnComanyOut" runat="server" Text=" Out " ToolTip="Submit"
Style="cursor: pointer;" OnClick="btnCompanyout_Click" CssClass="Tab2" ValidationGroup="valgroup" />
<asp:Button ID="btnComanyIn" runat="server" Text=" In " ToolTip="Submit"
Style="cursor: pointer;" OnClick="btnCompanyin_Click" CssClass="Tab2" />
<asp:Label ID="lblCompanymsg" runat="server" ForeColor="Red"></asp:Label>
<asp:Label ID="lblCompanyid" runat="server" Visible="false"></asp:Label>
</td>
</tr>
</table>
<table width="400" border="1" cellspacing="2" cellpadding="1" class='tdrow4' align='right'>
<tr>
<td width="199" align="right" class="Tab3"><strong>Company Purpose Outside <%--spend--%> time</strong></td>
<td width="199" align="right" class="Tab3"><strong>(<%=CompanyPurposeTimeSpend%>) Mins</strong></td>
</tr>
</table>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js"></script>
<script type="text/javascript">
$(".Tab211").on('click', function()
{
document.getElementById("txtcomypor").style.display = "block";
})
</script>
</asp:Content>
developer-outsideInside.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Developer_Default : System.Web.UI.Page
{
MainClass dut = new MainClass();
DataAccessLayer dal = new DataAccessLayer();
public string TimeSpend = "0", CompanyPurposeTimeSpend = "0";
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["developer_srno"] != null)
{
var value = Request.Cookies["developer_srno"].Value;
if (value == "")
{
Response.Redirect("~/Pr-Admin-Log");
}
Session["developer_srno"] = value;
}
if (Session["developer_srno"] == null)
{
Response.Redirect("~/Pr-Admin-Log");
}
BindSpendTime();
if (!IsPostBack)
{
BindData();
BindCompanyInOutData();
BindSpendTime();
int User_Id = int.Parse(Session["developer_srno"].ToString());
var list = new List<SqlParameter>();
list.Add(new SqlParameter("@Id", "0"));
list.Add(new SqlParameter("@User_Id", User_Id));
list.Add(new SqlParameter("@Actiontype", "lasttime"));
DataTable dt = dal.getdataTable("TimeCalculator", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Timing = Convert.ToDateTime(dr["Timing"].ToString()),
Company_Purpose = dr["Company_Purpose"].ToString(),
Spend_time = dr["Spend_time"].ToString(),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
foreach (var item in listdt1)
{
if(item.Status.ToString().ToLower()=="in")
{
btnout.Visible = true;
btnin.Visible = false;
btnComanyIn.Visible = false;
btnComanyOut.Visible = true;
break;
}
if (item.Company_Purpose!="" && item.Company_Purpose!="Nan")
{
btnout.Visible = false;
txtcomypor.Visible = false;
//btncmp.Visible = false;
btnComanyOut.Visible = false;
btnin.Visible = false;
btnComanyIn.Visible = true;
}
else
{
btnout.Visible = false;
//btncmp.Visible = true;
txtcomypor.Visible = false;
btnComanyOut.Visible = false;
btnin.Visible = true;
btnComanyIn.Visible = false;
}
}
}
else
{
btnout.Visible = true;
btnin.Visible = false;
btnComanyIn.Visible = false;
btnComanyOut.Visible = true;
}
}
}
protected void btnout_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col1 = { "@Id", "@User_Id", "@Timing", "@Status", "@Spend_time", "Company_Purpose", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, "Out", "0", "", "Out" };
int i = dal.execute("TimeCalculator", col1, val1);
if (i == 1)
{
lblmsg.Text = "Data Save Successfuly.";
btnComanyOut.Visible = false;
btnComanyIn.Visible = false;
}
BindData();
Response.Redirect("OutsideInside.aspx");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
protected void btnCompanyout_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col1 = { "@Id", "@User_Id", "@Timing", "@Status", "@Spend_time", "Company_Purpose", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, "Out", "0", ((txtcomypor.Text.Trim()=="Nan")?"No": txtcomypor.Text.Trim()), "Out" };
int i = dal.execute("TimeCalculator", col1, val1);
if (i == 1)
{
lblCompanymsg.Text = "Data Save Successfuly.";
btnout.Visible = false;
btnin.Visible = false;
}
BindData();
Response.Redirect("OutsideInside.aspx");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblCompanymsg.Text = ex.Message.ToString();
}
}
protected void btnCompanyin_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
DateTime OutSideGoingDate;
double totalSec = 0;
int User_Id = int.Parse(Session["developer_srno"].ToString());
var list = new List<SqlParameter>();
list.Add(new SqlParameter("@Id", "0"));
list.Add(new SqlParameter("@User_Id", User_Id));
list.Add(new SqlParameter("@Actiontype", "select1"));
DataTable dt = dal.getdataTable("TimeCalculator", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Timing = Convert.ToDateTime(dr["Timing"].ToString()),
Company_Purpose = dr["Company_Purpose"].ToString(),
Spend_time = dr["Spend_time"].ToString(),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
var LastUpdateDate = (from c in listdt1 where c.Status == "Out" orderby c.Id descending select c).FirstOrDefault();
if (LastUpdateDate != null)
{
OutSideGoingDate = LastUpdateDate.Timing;
totalSec = System.Math.Abs((OutSideGoingDate - DateTime.Now).TotalSeconds);
}
}
string[] col1 = { "@Id", "@User_Id", "@Timing", "@Status", "@Spend_time", "Company_Purpose", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, "In", totalSec, "yes", "In" };
int i = dal.execute("TimeCalculator", col1, val1);
if (i == 1)
{
lblmsg.Text = "Data Save Successfuly.";
}
BindCompanyInOutData();
BindSpendTime();
Response.Redirect("OutsideInside.aspx");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
protected void btnin_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
DateTime OutSideGoingDate;
double totalSec = 0;
int User_Id = int.Parse(Session["developer_srno"].ToString());
var list = new List<SqlParameter>();
list.Add(new SqlParameter("@Id", "0"));
list.Add(new SqlParameter("@User_Id", User_Id));
list.Add(new SqlParameter("@Actiontype", "select1"));
DataTable dt = dal.getdataTable("TimeCalculator", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Timing = Convert.ToDateTime(dr["Timing"].ToString()),
Company_Purpose = dr["Company_Purpose"].ToString(),
Spend_time = dr["Spend_time"].ToString(),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
var LastUpdateDate = (from c in listdt1 where c.Status == "Out" orderby c.Id descending select c).FirstOrDefault();
if (LastUpdateDate != null)
{
OutSideGoingDate = LastUpdateDate.Timing;
totalSec = System.Math.Abs((OutSideGoingDate - DateTime.Now).TotalSeconds);
}
}
string[] col1 = { "@Id", "@User_Id", "@Timing", "@Status", "@Spend_time", "Company_Purpose", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, "In", totalSec, "", "In" };
int i = dal.execute("TimeCalculator", col1, val1);
if (i == 1)
{
lblmsg.Text = "Data Save Successfuly.";
}
BindData();
BindSpendTime();
Response.Redirect("OutsideInside.aspx");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
private void BindData()
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col2 = { "@Id", "@User_Id", "@Actiontype" };
object[] val2 = { "0", User_Id, "Select2" };
DataSet ds2 = dal.getDataSet("TimeCalculator", col2, val2);
if (ds2.Tables[0].Rows.Count > 0)
{
Repeater1.DataSource = ds2.Tables[0];
Repeater1.DataBind();
}
}
private void BindCompanyInOutData()
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col2 = { "@Id", "@User_Id", "@Actiontype" };
object[] val2 = { "0", User_Id, "ctime" };
DataSet ds2 = dal.getDataSet("TimeCalculator", col2, val2);
if (ds2.Tables.Count > 0)
{
Repeater2.DataSource = ds2.Tables[0];
Repeater2.DataBind();
}
}
private void BindSpendTime()
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
double TotalTime = 0;
double TotalTimeCompanyPurpose = 0;
var list = new List<SqlParameter>();
list.Add(new SqlParameter("@Id", "0"));
list.Add(new SqlParameter("@User_Id", User_Id));
list.Add(new SqlParameter("@Actiontype", "select1"));
DataTable dt = dal.getdataTable("TimeCalculator", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Timing = Convert.ToDateTime(dr["Timing"].ToString()),
Company_Purpose = dr["Company_Purpose"].ToString(),
Spend_time = dr["Spend_time"].ToString(),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
foreach (var item in listdt1)
{
if (item.Timing.ToString("MM/dd/yyyy").Equals(DateTime.Now.ToString("MM/dd/yyyy")) && (item.Company_Purpose=="" || item.Company_Purpose=="Nan"))
{
TotalTime = TotalTime + double.Parse(item.Spend_time);
}
else if (item.Timing.ToString("MM/dd/yyyy").Equals(DateTime.Now.ToString("MM/dd/yyyy")) && (item.Company_Purpose != "" || item.Company_Purpose != "Nan"))
{
TotalTimeCompanyPurpose = TotalTimeCompanyPurpose + double.Parse(item.Spend_time);
}
}
TimeSpend = (TotalTime / 60).ToString("N0");
CompanyPurposeTimeSpend = (TotalTimeCompanyPurpose / 60).ToString("N0");
}
}
class MyModelClass
{
public int Id { get; set; }
public int User_Id { get; set; }
public DateTime Timing { get; set; }
public string Status { get; set; }
public string Company_Purpose { get; set; }
public string Spend_time { get; set; }
}
protected void btncmp_Click(object sender, EventArgs e)
{
BindSpendTime();
txtcomypor.Visible = true;
btnhidetext.Visible = true;
}
protected void btnhidetext_Click(object sender, EventArgs e)
{
BindSpendTime();
btnhidetext.Visible = false;
txtcomypor.Visible = false;
}
}
alter proc [dbo].[TimeCalculator]
@Id int,
@User_Id int=null,
@Timing datetime=null,
@ByTime datetime=null,
@StartDate datetime=null,
@EndDate datetime=null,
@Status nvarchar(50)=null,
@Spend_time nvarchar(50)=null,
@Company_Purpose nvarchar(50)=null,
@Actiontype char(10)
as
begin
if(@Actiontype='Out')
begin
insert into tbl_Spend_Time(User_Id,Timing,Status,Spend_time,Company_Purpose) values (@User_Id,@Timing,@Status,@Spend_time,@Company_Purpose)
end
else if(@Actiontype='select1')
begin
select * from tbl_Spend_Time where User_Id=@User_Id
end
else if(@Actiontype='In')
begin
insert into tbl_Spend_Time(User_Id,Timing,Status,Spend_time,Company_Purpose) values (@User_Id,@Timing,@Status,@Spend_time,@Company_Purpose)
end
else if(@Actiontype='Select2')
begin
select * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) = cast(getdate() as Date) and (Company_Purpose='' or Company_Purpose='Nan')
end
else if(@Actiontype='ctime')
begin
select * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) = cast(getdate() as Date) and (Company_Purpose!='' and Company_Purpose!='Nan')
end
else if(@Actiontype='Select4')
begin
select * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) between cast(@StartDate as Date) and cast(@EndDate as Date)
end
else if(@Actiontype='Select5')
begin
select * from tbl_Spend_Time where cast(Timing as Date) between cast(@StartDate as Date) and cast(@EndDate as Date)
end
else if(@Actiontype='Select3')
begin
select * from tbl_Spend_Time where cast(Timing as Date) = cast(getdate() as Date)
end
else if(@Actiontype='lasttime')
begin
select top 1 * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) = cast(getdate() as Date) order by Timing desc
end
else if(@Actiontype='select6')
begin
select Timing, DATEADD(dd, 0, DATEDIFF(dd, 0, Timing)) as Timing,Id,User_Id,Status,Spend_time,Company_Purpose from tbl_Spend_Time where User_Id=@User_Id
end
else if(@Actiontype='Select8')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Timing)) as Timing,Id,User_Id,Status,Spend_time,Company_Purpose from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) between cast(@StartDate as Date) and cast(@EndDate as Date)
end
else if(@Actiontype='select7')
begin
select * from tbl_Spend_Time where User_Id=@User_Id and cast(Timing as Date) = cast(@ByTime as Date)
end
else if(@Actiontype='select9')
begin
select * from tbl_Spend_Time where cast(Timing as Date) = cast(getdate() as Date)
end
else if(@Actiontype='select10')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Timing)) as Timing,Id,User_Id,Status,Spend_time,Company_Purpose from tbl_Spend_Time where cast(Timing as Date) = cast(@StartDate as Date)
end
end
developer->outsideinside.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Developer/DeveloperMaster.master" AutoEventWireup="true" CodeFile="OutsideInside.aspx.cs" Inherits="Developer_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<table width="400" border="1" cellspacing="2" cellpadding="1" class='tdrow4' align='center'>
<tr align="center">
<td colspan="2" class="txt">Personal Time Calculator (Today Details)</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td width="199" align="right" class="Tab3"><strong><%# Eval("Status")%></strong></td>
<td width="199" align="right" class="Tab3"><strong><%# Eval("Timing", "{0: h:mm tt}")%></strong></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr align="center">
<td colspan="2">
<%--<asp:Button ID="btncmp" OnClick="btncmp_Click" Text="Company Purpose" runat="server" CssClass="Tab2" /> --%>
<asp:Button ID="btnout" runat="server" Text=" Out " ToolTip="Submit"
Style="cursor: pointer;" OnClick="btnout_Click" CssClass="Tab2" />
<%--<asp:TextBox ID="txtcomypor" Width="200" Height="100" TextMode="MultiLine" runat="server" Visible="false"></asp:TextBox>--%>
<%--<asp:Button ID="btnhidetext" OnClick="btnhidetext_Click" Visible="false" Text="close" runat="server" CssClass="Tab2" /> --%>
<asp:Button ID="btnin" runat="server" Text=" In " ToolTip="Submit"
Style="cursor: pointer;" OnClick="btnin_Click" CssClass="Tab2" />
<asp:Label ID="lblmsg" runat="server" ForeColor="Red"></asp:Label>
<asp:Label ID="lblid" runat="server" Visible="false"></asp:Label>
</td>
</tr>
</table>
<table width="400" border="1" cellspacing="2" cellpadding="1" class='tdrow4' align='right'>
<tr>
<td width="199" align="right" class="Tab3"><strong>Personal Outside <%--spend--%> time</strong></td>
<td width="199" align="right" class="Tab3"><strong>(<%=TimeSpend%>) Mins</strong></td>
</tr>
</table>
<br />
<br />
<table width="400" border="1" cellspacing="2" cellpadding="1" class='tdrow4' align='center' style="margin-left:474px;" >
<tr align="center">
<td colspan="2" class="txt">Company Purpose Time Calculator (Today Details)</td>
</tr>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<tr>
<td width="199" align="right" class="Tab3"><strong><%# Eval("Status")%></strong></td>
<td width="199" align="right" class="Tab3"><strong><%# Eval("Timing", "{0: h:mm tt}")%></strong></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr align="center">
<td colspan="2">
<asp:TextBox ID="txtcomypor" Width="200" Height="100" TextMode="MultiLine" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
InitialValue="" ValidationGroup="valgroup" Display="Dynamic" ControlToValidate="txtcomypor"
SetFocusOnError="true" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:Button ID="btnhidetext" OnClick="btnhidetext_Click" Visible="false" Text="close" runat="server" CssClass="Tab2" />
<asp:Button ID="btnComanyOut" runat="server" Text=" Out " ToolTip="Submit"
Style="cursor: pointer;" OnClick="btnCompanyout_Click" CssClass="Tab2" ValidationGroup="valgroup" />
<asp:Button ID="btnComanyIn" runat="server" Text=" In " ToolTip="Submit"
Style="cursor: pointer;" OnClick="btnCompanyin_Click" CssClass="Tab2" />
<asp:Label ID="lblCompanymsg" runat="server" ForeColor="Red"></asp:Label>
<asp:Label ID="lblCompanyid" runat="server" Visible="false"></asp:Label>
</td>
</tr>
</table>
<table width="400" border="1" cellspacing="2" cellpadding="1" class='tdrow4' align='right'>
<tr>
<td width="199" align="right" class="Tab3"><strong>Company Purpose Outside <%--spend--%> time</strong></td>
<td width="199" align="right" class="Tab3"><strong>(<%=CompanyPurposeTimeSpend%>) Mins</strong></td>
</tr>
</table>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js"></script>
<script type="text/javascript">
$(".Tab211").on('click', function()
{
document.getElementById("txtcomypor").style.display = "block";
})
</script>
</asp:Content>
developer-outsideInside.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Developer_Default : System.Web.UI.Page
{
MainClass dut = new MainClass();
DataAccessLayer dal = new DataAccessLayer();
public string TimeSpend = "0", CompanyPurposeTimeSpend = "0";
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["developer_srno"] != null)
{
var value = Request.Cookies["developer_srno"].Value;
if (value == "")
{
Response.Redirect("~/Pr-Admin-Log");
}
Session["developer_srno"] = value;
}
if (Session["developer_srno"] == null)
{
Response.Redirect("~/Pr-Admin-Log");
}
BindSpendTime();
if (!IsPostBack)
{
BindData();
BindCompanyInOutData();
BindSpendTime();
int User_Id = int.Parse(Session["developer_srno"].ToString());
var list = new List<SqlParameter>();
list.Add(new SqlParameter("@Id", "0"));
list.Add(new SqlParameter("@User_Id", User_Id));
list.Add(new SqlParameter("@Actiontype", "lasttime"));
DataTable dt = dal.getdataTable("TimeCalculator", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Timing = Convert.ToDateTime(dr["Timing"].ToString()),
Company_Purpose = dr["Company_Purpose"].ToString(),
Spend_time = dr["Spend_time"].ToString(),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
foreach (var item in listdt1)
{
if(item.Status.ToString().ToLower()=="in")
{
btnout.Visible = true;
btnin.Visible = false;
btnComanyIn.Visible = false;
btnComanyOut.Visible = true;
break;
}
if (item.Company_Purpose!="" && item.Company_Purpose!="Nan")
{
btnout.Visible = false;
txtcomypor.Visible = false;
//btncmp.Visible = false;
btnComanyOut.Visible = false;
btnin.Visible = false;
btnComanyIn.Visible = true;
}
else
{
btnout.Visible = false;
//btncmp.Visible = true;
txtcomypor.Visible = false;
btnComanyOut.Visible = false;
btnin.Visible = true;
btnComanyIn.Visible = false;
}
}
}
else
{
btnout.Visible = true;
btnin.Visible = false;
btnComanyIn.Visible = false;
btnComanyOut.Visible = true;
}
}
}
protected void btnout_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col1 = { "@Id", "@User_Id", "@Timing", "@Status", "@Spend_time", "Company_Purpose", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, "Out", "0", "", "Out" };
int i = dal.execute("TimeCalculator", col1, val1);
if (i == 1)
{
lblmsg.Text = "Data Save Successfuly.";
btnComanyOut.Visible = false;
btnComanyIn.Visible = false;
}
BindData();
Response.Redirect("OutsideInside.aspx");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
protected void btnCompanyout_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col1 = { "@Id", "@User_Id", "@Timing", "@Status", "@Spend_time", "Company_Purpose", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, "Out", "0", ((txtcomypor.Text.Trim()=="Nan")?"No": txtcomypor.Text.Trim()), "Out" };
int i = dal.execute("TimeCalculator", col1, val1);
if (i == 1)
{
lblCompanymsg.Text = "Data Save Successfuly.";
btnout.Visible = false;
btnin.Visible = false;
}
BindData();
Response.Redirect("OutsideInside.aspx");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblCompanymsg.Text = ex.Message.ToString();
}
}
protected void btnCompanyin_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
DateTime OutSideGoingDate;
double totalSec = 0;
int User_Id = int.Parse(Session["developer_srno"].ToString());
var list = new List<SqlParameter>();
list.Add(new SqlParameter("@Id", "0"));
list.Add(new SqlParameter("@User_Id", User_Id));
list.Add(new SqlParameter("@Actiontype", "select1"));
DataTable dt = dal.getdataTable("TimeCalculator", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Timing = Convert.ToDateTime(dr["Timing"].ToString()),
Company_Purpose = dr["Company_Purpose"].ToString(),
Spend_time = dr["Spend_time"].ToString(),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
var LastUpdateDate = (from c in listdt1 where c.Status == "Out" orderby c.Id descending select c).FirstOrDefault();
if (LastUpdateDate != null)
{
OutSideGoingDate = LastUpdateDate.Timing;
totalSec = System.Math.Abs((OutSideGoingDate - DateTime.Now).TotalSeconds);
}
}
string[] col1 = { "@Id", "@User_Id", "@Timing", "@Status", "@Spend_time", "Company_Purpose", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, "In", totalSec, "yes", "In" };
int i = dal.execute("TimeCalculator", col1, val1);
if (i == 1)
{
lblmsg.Text = "Data Save Successfuly.";
}
BindCompanyInOutData();
BindSpendTime();
Response.Redirect("OutsideInside.aspx");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
protected void btnin_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
DateTime OutSideGoingDate;
double totalSec = 0;
int User_Id = int.Parse(Session["developer_srno"].ToString());
var list = new List<SqlParameter>();
list.Add(new SqlParameter("@Id", "0"));
list.Add(new SqlParameter("@User_Id", User_Id));
list.Add(new SqlParameter("@Actiontype", "select1"));
DataTable dt = dal.getdataTable("TimeCalculator", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Timing = Convert.ToDateTime(dr["Timing"].ToString()),
Company_Purpose = dr["Company_Purpose"].ToString(),
Spend_time = dr["Spend_time"].ToString(),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
var LastUpdateDate = (from c in listdt1 where c.Status == "Out" orderby c.Id descending select c).FirstOrDefault();
if (LastUpdateDate != null)
{
OutSideGoingDate = LastUpdateDate.Timing;
totalSec = System.Math.Abs((OutSideGoingDate - DateTime.Now).TotalSeconds);
}
}
string[] col1 = { "@Id", "@User_Id", "@Timing", "@Status", "@Spend_time", "Company_Purpose", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, "In", totalSec, "", "In" };
int i = dal.execute("TimeCalculator", col1, val1);
if (i == 1)
{
lblmsg.Text = "Data Save Successfuly.";
}
BindData();
BindSpendTime();
Response.Redirect("OutsideInside.aspx");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
private void BindData()
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col2 = { "@Id", "@User_Id", "@Actiontype" };
object[] val2 = { "0", User_Id, "Select2" };
DataSet ds2 = dal.getDataSet("TimeCalculator", col2, val2);
if (ds2.Tables[0].Rows.Count > 0)
{
Repeater1.DataSource = ds2.Tables[0];
Repeater1.DataBind();
}
}
private void BindCompanyInOutData()
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col2 = { "@Id", "@User_Id", "@Actiontype" };
object[] val2 = { "0", User_Id, "ctime" };
DataSet ds2 = dal.getDataSet("TimeCalculator", col2, val2);
if (ds2.Tables.Count > 0)
{
Repeater2.DataSource = ds2.Tables[0];
Repeater2.DataBind();
}
}
private void BindSpendTime()
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
double TotalTime = 0;
double TotalTimeCompanyPurpose = 0;
var list = new List<SqlParameter>();
list.Add(new SqlParameter("@Id", "0"));
list.Add(new SqlParameter("@User_Id", User_Id));
list.Add(new SqlParameter("@Actiontype", "select1"));
DataTable dt = dal.getdataTable("TimeCalculator", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Timing = Convert.ToDateTime(dr["Timing"].ToString()),
Company_Purpose = dr["Company_Purpose"].ToString(),
Spend_time = dr["Spend_time"].ToString(),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
foreach (var item in listdt1)
{
if (item.Timing.ToString("MM/dd/yyyy").Equals(DateTime.Now.ToString("MM/dd/yyyy")) && (item.Company_Purpose=="" || item.Company_Purpose=="Nan"))
{
TotalTime = TotalTime + double.Parse(item.Spend_time);
}
else if (item.Timing.ToString("MM/dd/yyyy").Equals(DateTime.Now.ToString("MM/dd/yyyy")) && (item.Company_Purpose != "" || item.Company_Purpose != "Nan"))
{
TotalTimeCompanyPurpose = TotalTimeCompanyPurpose + double.Parse(item.Spend_time);
}
}
TimeSpend = (TotalTime / 60).ToString("N0");
CompanyPurposeTimeSpend = (TotalTimeCompanyPurpose / 60).ToString("N0");
}
}
class MyModelClass
{
public int Id { get; set; }
public int User_Id { get; set; }
public DateTime Timing { get; set; }
public string Status { get; set; }
public string Company_Purpose { get; set; }
public string Spend_time { get; set; }
}
protected void btncmp_Click(object sender, EventArgs e)
{
BindSpendTime();
txtcomypor.Visible = true;
btnhidetext.Visible = true;
}
protected void btnhidetext_Click(object sender, EventArgs e)
{
BindSpendTime();
btnhidetext.Visible = false;
txtcomypor.Visible = false;
}
}
Comments
Post a Comment