1) New change in Developer/attendance.aspx.cs
Developer/attendance.aspx.cs
DataBase Change
alter proc [dbo].[ManageAttendance]
@Id int,
@User_Id int=null,
@Coming_Time datetime=null,
@Going_Time datetime=null,
@ByDate datetime=null,
@StartDate datetime=null,
@EndDate datetime=null,
@Status nvarchar(50)=null,
@Coming_Message nvarchar(max)=null,
@Going_Message nvarchar(max)=null,
@isMeetingGoodMorning int=0,
@Hr_Permission int=0,
@Actiontype char(10)
as
begin
if(@Actiontype='Coming')
begin
insert into tbl_Attendance(User_Id,Coming_Time,Going_Time,Coming_Message,Status,isMeetingGoodMorning)
values (@User_Id,@Coming_Time,@Going_Time,@Coming_Message,@Status,@isMeetingGoodMorning)
end
else if(@Actiontype='select1')
begin
select a.*,datediff(month,b.date,getDate()) as numberOfMonth from tbl_Attendance a inner join tbl_Login b on a.User_Id=b.srno
where a.User_Id=@User_Id
end
else if(@Actiontype='Going')
begin
update tbl_Attendance set
Going_Time=@Going_Time,
Status=@Status,
Going_Message=@Going_Message,
Hr_Permission=@Hr_Permission
where User_Id=@User_Id and Id=@Id
end
else if(@Actiontype='Select2')
begin
select * from tbl_Attendance where User_Id=@User_Id and cast(Coming_Time as Date) = cast(getdate() as Date)
end
else if(@Actiontype='Select3')
begin
select * from tbl_Attendance where User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)
end
else if(@Actiontype='update3')
begin
update tbl_Attendance
SET Coming_Time=@Coming_Time,Going_Time=@Going_Time WHERE User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)
end
else if(@Actiontype='Select4')
begin
select * from tbl_Attendance where User_Id=@User_Id
end
else if(@Actiontype='Select5')
begin
select * from tbl_Attendance where cast(Coming_Time as Date) between cast(@StartDate as Date) and cast(@EndDate as Date) and User_Id=@User_Id
end
else if(@Actiontype='select6')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Coming_Time)) as Coming_Time,User_Id,Id,Status,Coming_Time Coming_Time1,Going_Time as Going_Time1 from tbl_Attendance where User_Id=@User_Id
end
else if(@Actiontype='select7')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Coming_Time)) as Coming_Time,Id,User_Id,Id,Status from tbl_Attendance where User_Id=@User_Id and cast(Coming_Time as Date) between cast(@StartDate as Date) and cast(@EndDate as Date)
end
else if(@Actiontype='select8')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Coming_Time)) as Coming_Time,Id,User_Id,Id,Status from tbl_Attendance where cast(Coming_Time as Date) = cast(@StartDate as Date)
end
else if(@Actiontype='nightU')
begin
if(exists(select 1 from tbl_Attendance where User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)))
begin
update tbl_Attendance
SET Going_Time=@Going_Time WHERE User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)
end
end
else if(@Actiontype='Insert1')
begin
insert into tbl_Attendance(User_Id,Coming_Time,Going_Time,Coming_Message,Going_Message,Status,isMeetingGoodMorning)
values (@User_Id,@Coming_Time,@Going_Time,@Coming_Message,@Going_Message,@Status,@isMeetingGoodMorning)
end
else if(@Actiontype='update4')
begin
update tbl_Attendance
SET Coming_Time=@Coming_Time,Going_Time=@Going_Time,Status=@Status,Coming_Message=@Coming_Message,Going_Message=@Going_Message WHERE User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)
end
else if(@Actiontype='Select11')
begin
select * from tbl_Attendance where cast(Coming_Time as Date) = cast(getdate() as Date)
end
else if(@Actiontype='UpdateHr')
begin
update tbl_Attendance
SET Hr_Permission='1'
WHERE Id=@Id
end
end
Developer/attendance.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 ComingTime = "";
public string GoingTime = "";
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");
}
if (!IsPostBack)
{
txt_date.Text = System.DateTime.Now.ToString("MM/dd/yy H:mm:ss");
comingtime();
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("ManageAttendance", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Going_Time = Convert.ToDateTime(dr["Going_Time"].ToString()),
Coming_Time = Convert.ToDateTime(dr["Coming_Time"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
Hr_Permission = Convert.ToBoolean(dr["Hr_Permission"].ToString())
}).ToList();
foreach (var item in listdt1)
{
if (item.Going_Time.ToString("MM/dd/yyyy").Equals(DateTime.Now.ToString("MM/dd/yyyy")) && item.Status == "Come")
{
btnmorning.Visible = false;
btnnight.Visible = true;
txtmessage.Visible = true;
}
else if (item.Going_Time.ToString("MM/dd/yyyy").Equals(DateTime.Now.ToString("MM/dd/yyyy")) && item.Status == "Go")
{
btnmorning.Visible = false;
btnnight.Visible = false;
txtmessage.Visible = false;
//txt_date.Visible = false;
if(item.Hr_Permission == false)
txtmsg.Text = "Wait for manager's approval ✋";
else
{
txtmsg.Text = "Great ! you my leave now, Good Night 😊";
}
}
else
{
btnmorning.Visible = true;
btnnight.Visible = false;
txtmessage.Visible = true;
//txt_date.Visible = false;
txtmsg.Text = "";
}
}
}
else
{
btnmorning.Visible = true;
btnnight.Visible = false;
txtmessage.Visible = true;
}
}
}
protected void btnmorning_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
comingtime();
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col1 = { "@Id", "@User_Id", "@Coming_Time", "@Going_Time", "@Status", "@Coming_Message", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, DateTime.Now, "Come", txtmessage.Text, "Coming" };
int i = dal.execute("ManageAttendance", col1, val1);
if (i == 1)
lblmsg.Text = "Data Save Successfuly.";
Response.Redirect("attendance.aspx");
txt_date.Text = System.DateTime.Now.ToString("MM/dd/yy H:mm:ss");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
protected void btnnight_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
int Attendance_Id = 0;
bool Hr_Permission = false;
string Status = "";
int numberOfMonth = 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("ManageAttendance", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Going_Time = Convert.ToDateTime(dr["Going_Time"].ToString()),
Coming_Time = Convert.ToDateTime(dr["Coming_Time"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
Hr_Permission = Convert.ToBoolean(dr["Hr_Permission"].ToString()),
numberOfMonth= Convert.ToInt32(dr["numberOfMonth"]),
}).ToList();
if (listdt1.Count > 0)
{
var LastUpdateDate = (from c in listdt1 where c.Status == "Come" select c).FirstOrDefault();
Attendance_Id = LastUpdateDate.Id;
Hr_Permission = LastUpdateDate.Hr_Permission;
numberOfMonth = LastUpdateDate.numberOfMonth;
}
}
//if (Hr_Permission==false)
//{
// lblmsg.Text = "Hr Not Give You Permission";
//}
//else
//{
if (Attendance_Id > 0)
{
var list1 = new List<SqlParameter>();
list1.Add(new SqlParameter("@Id", "0"));
list1.Add(new SqlParameter("@User_Id", User_Id));
list1.Add(new SqlParameter("@Actiontype", "Select2"));
DataTable dt1 = dal.getdataTable("TimeCalculator", list1.ToArray());
if (dt1.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt1.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Going_Time = Convert.ToDateTime(dr["Timing"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
if (listdt1.Count > 0)
{
var LastUpdateDate = (from c in listdt1 select c).LastOrDefault();
Status = LastUpdateDate.Status;
if (Status != "Out")
{
string[] col1 = { "@Id", "@User_Id", "@Coming_Time", "@Going_Time", "@Status", "@Going_Message","@Hr_Permission", "@Actiontype" };
object[] val1 = { Attendance_Id, User_Id, DateTime.Now, DateTime.Now, "Go", txtmessage.Text,((numberOfMonth>=10)?1:0), "Going" };
int i = dal.execute("ManageAttendance", col1, val1);
if (i == 1)
{
btnnight.Visible = false;
lblmsg.Text = "";
txtmessage.Visible = false;
if (numberOfMonth >= 10)
{
txtmsg.Text = "Great ! you my leave now, Good Night 😊";
}
else
{
txtmsg.Text = "Wait for manager's approval ✋";
}
}
txt_date.Text = System.DateTime.Now.ToString("MM/dd/yy H:mm:ss");
}
else
{
lberror.Text = "Please Inside First";
}
}
}
else
{
string[] col1 = { "@Id", "@User_Id", "@Coming_Time", "@Going_Time", "@Status", "@Going_Message", "@Hr_Permission", "@Actiontype" };
object[] val1 = { Attendance_Id, User_Id, DateTime.Now, DateTime.Now, "Go", txtmessage.Text, ((numberOfMonth >= 10) ? 1 : 0), "Going" };
int i = dal.execute("ManageAttendance", col1, val1);
if (i == 1)
{
btnnight.Visible = false;
lblmsg.Text = "";
txtmessage.Visible = false;
if (numberOfMonth >= 10)
{
txtmsg.Text = "Great ! you my leave now, Good Night 😊";
}
else
{
txtmsg.Text = "Wait for manager's approval ✋";
}
}
//Response.Redirect("attendance.aspx");
btnnight.Visible = false;
txt_date.Text = System.DateTime.Now.ToString("MM/dd/yy H:mm:ss");
}
//}
}
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
private void comingtime()
{
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", "Select2"));
DataTable dt = dal.getdataTable("ManageAttendance", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Coming_Time = Convert.ToDateTime(dr["Coming_Time"].ToString()),
Going_Time = Convert.ToDateTime(dr["Going_Time"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
var LastUpdateDate = (from c in listdt1 select c).FirstOrDefault();
ComingTime = LastUpdateDate.Coming_Time.ToString("hh:mm tt");
if (LastUpdateDate.Status == "Go")
{
GoingTime = "(Going Time" + LastUpdateDate.Going_Time.ToString("hh:mm tt") + ")";
}
}
}
class MyModelClass
{
public int Id { get; set; }
public int User_Id { get; set; }
public string Status { get; set; }
public bool Hr_Permission { get; set; }
public DateTime Coming_Time { get; set; }
public DateTime Going_Time { get; set; }
public int numberOfMonth { get; set; }
}
protected void Timer1_Tick(object sender, EventArgs e)
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
int Attendance_Id = 0;
bool Hr_Permission = false;
string Status = "";
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("ManageAttendance", list.ToArray());
DateTime comingTime = new DateTime();
DateTime goingTime = new DateTime();
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Going_Time = Convert.ToDateTime(dr["Going_Time"].ToString()),
Coming_Time = Convert.ToDateTime(dr["Coming_Time"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
Hr_Permission = Convert.ToBoolean(dr["Hr_Permission"].ToString()),
}).ToList();
if (listdt1.Count > 0)
{
var LastUpdateDate = (from c in listdt1 where c.Status == "Go" select c).LastOrDefault();
if (LastUpdateDate != null)
{
Attendance_Id = LastUpdateDate.Id;
Hr_Permission = LastUpdateDate.Hr_Permission;
comingTime = LastUpdateDate.Coming_Time;
goingTime = LastUpdateDate.Going_Time;
}
}
}
string time1 = comingTime.ToString("dd/MM/yy");
string time2 = goingTime.ToString("dd/MM/yy");
string[] times3 = txt_date.Text.ToString().Split('-');
string time3 = times3[1]+"-"+ times3[0]+"-"+ times3[2].Substring(0,2);
if (time1== time2 && time1==time3)
{
if (Hr_Permission == true)
{
lblmsg.Text = "";
txtmsg.Text = "Great ! you my leave now, Good Night 😊";
}
else if (comingTime == goingTime)
{
lblmsg.Text = "";
txtmsg.Text = "";
}
else
{
lblmsg.Text = "";
txtmsg.Text = "Wait for manager's approval ✋";
}
}
else
{
lblmsg.Text = "";
txtmsg.Text = "";
}
}
}
DataBase Change
alter proc [dbo].[ManageAttendance]
@Id int,
@User_Id int=null,
@Coming_Time datetime=null,
@Going_Time datetime=null,
@ByDate datetime=null,
@StartDate datetime=null,
@EndDate datetime=null,
@Status nvarchar(50)=null,
@Coming_Message nvarchar(max)=null,
@Going_Message nvarchar(max)=null,
@isMeetingGoodMorning int=0,
@Hr_Permission int=0,
@Actiontype char(10)
as
begin
if(@Actiontype='Coming')
begin
insert into tbl_Attendance(User_Id,Coming_Time,Going_Time,Coming_Message,Status,isMeetingGoodMorning)
values (@User_Id,@Coming_Time,@Going_Time,@Coming_Message,@Status,@isMeetingGoodMorning)
end
else if(@Actiontype='select1')
begin
select a.*,datediff(month,b.date,getDate()) as numberOfMonth from tbl_Attendance a inner join tbl_Login b on a.User_Id=b.srno
where a.User_Id=@User_Id
end
else if(@Actiontype='Going')
begin
update tbl_Attendance set
Going_Time=@Going_Time,
Status=@Status,
Going_Message=@Going_Message,
Hr_Permission=@Hr_Permission
where User_Id=@User_Id and Id=@Id
end
else if(@Actiontype='Select2')
begin
select * from tbl_Attendance where User_Id=@User_Id and cast(Coming_Time as Date) = cast(getdate() as Date)
end
else if(@Actiontype='Select3')
begin
select * from tbl_Attendance where User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)
end
else if(@Actiontype='update3')
begin
update tbl_Attendance
SET Coming_Time=@Coming_Time,Going_Time=@Going_Time WHERE User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)
end
else if(@Actiontype='Select4')
begin
select * from tbl_Attendance where User_Id=@User_Id
end
else if(@Actiontype='Select5')
begin
select * from tbl_Attendance where cast(Coming_Time as Date) between cast(@StartDate as Date) and cast(@EndDate as Date) and User_Id=@User_Id
end
else if(@Actiontype='select6')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Coming_Time)) as Coming_Time,User_Id,Id,Status,Coming_Time Coming_Time1,Going_Time as Going_Time1 from tbl_Attendance where User_Id=@User_Id
end
else if(@Actiontype='select7')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Coming_Time)) as Coming_Time,Id,User_Id,Id,Status from tbl_Attendance where User_Id=@User_Id and cast(Coming_Time as Date) between cast(@StartDate as Date) and cast(@EndDate as Date)
end
else if(@Actiontype='select8')
begin
select DATEADD(dd, 0, DATEDIFF(dd, 0, Coming_Time)) as Coming_Time,Id,User_Id,Id,Status from tbl_Attendance where cast(Coming_Time as Date) = cast(@StartDate as Date)
end
else if(@Actiontype='nightU')
begin
if(exists(select 1 from tbl_Attendance where User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)))
begin
update tbl_Attendance
SET Going_Time=@Going_Time WHERE User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)
end
end
else if(@Actiontype='Insert1')
begin
insert into tbl_Attendance(User_Id,Coming_Time,Going_Time,Coming_Message,Going_Message,Status,isMeetingGoodMorning)
values (@User_Id,@Coming_Time,@Going_Time,@Coming_Message,@Going_Message,@Status,@isMeetingGoodMorning)
end
else if(@Actiontype='update4')
begin
update tbl_Attendance
SET Coming_Time=@Coming_Time,Going_Time=@Going_Time,Status=@Status,Coming_Message=@Coming_Message,Going_Message=@Going_Message WHERE User_Id=@User_Id and cast(Coming_Time as Date) = cast(@ByDate as Date)
end
else if(@Actiontype='Select11')
begin
select * from tbl_Attendance where cast(Coming_Time as Date) = cast(getdate() as Date)
end
else if(@Actiontype='UpdateHr')
begin
update tbl_Attendance
SET Hr_Permission='1'
WHERE Id=@Id
end
end
Developer/attendance.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 ComingTime = "";
public string GoingTime = "";
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");
}
if (!IsPostBack)
{
txt_date.Text = System.DateTime.Now.ToString("MM/dd/yy H:mm:ss");
comingtime();
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("ManageAttendance", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Going_Time = Convert.ToDateTime(dr["Going_Time"].ToString()),
Coming_Time = Convert.ToDateTime(dr["Coming_Time"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
Hr_Permission = Convert.ToBoolean(dr["Hr_Permission"].ToString())
}).ToList();
foreach (var item in listdt1)
{
if (item.Going_Time.ToString("MM/dd/yyyy").Equals(DateTime.Now.ToString("MM/dd/yyyy")) && item.Status == "Come")
{
btnmorning.Visible = false;
btnnight.Visible = true;
txtmessage.Visible = true;
}
else if (item.Going_Time.ToString("MM/dd/yyyy").Equals(DateTime.Now.ToString("MM/dd/yyyy")) && item.Status == "Go")
{
btnmorning.Visible = false;
btnnight.Visible = false;
txtmessage.Visible = false;
//txt_date.Visible = false;
if(item.Hr_Permission == false)
txtmsg.Text = "Wait for manager's approval ✋";
else
{
txtmsg.Text = "Great ! you my leave now, Good Night 😊";
}
}
else
{
btnmorning.Visible = true;
btnnight.Visible = false;
txtmessage.Visible = true;
//txt_date.Visible = false;
txtmsg.Text = "";
}
}
}
else
{
btnmorning.Visible = true;
btnnight.Visible = false;
txtmessage.Visible = true;
}
}
}
protected void btnmorning_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
comingtime();
int User_Id = int.Parse(Session["developer_srno"].ToString());
string[] col1 = { "@Id", "@User_Id", "@Coming_Time", "@Going_Time", "@Status", "@Coming_Message", "@Actiontype" };
object[] val1 = { "0", User_Id, DateTime.Now, DateTime.Now, "Come", txtmessage.Text, "Coming" };
int i = dal.execute("ManageAttendance", col1, val1);
if (i == 1)
lblmsg.Text = "Data Save Successfuly.";
Response.Redirect("attendance.aspx");
txt_date.Text = System.DateTime.Now.ToString("MM/dd/yy H:mm:ss");
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
protected void btnnight_Click(object sender, EventArgs e)
{
try
{
if (Session["developer_srno"] != null)
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
int Attendance_Id = 0;
bool Hr_Permission = false;
string Status = "";
int numberOfMonth = 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("ManageAttendance", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Going_Time = Convert.ToDateTime(dr["Going_Time"].ToString()),
Coming_Time = Convert.ToDateTime(dr["Coming_Time"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
Hr_Permission = Convert.ToBoolean(dr["Hr_Permission"].ToString()),
numberOfMonth= Convert.ToInt32(dr["numberOfMonth"]),
}).ToList();
if (listdt1.Count > 0)
{
var LastUpdateDate = (from c in listdt1 where c.Status == "Come" select c).FirstOrDefault();
Attendance_Id = LastUpdateDate.Id;
Hr_Permission = LastUpdateDate.Hr_Permission;
numberOfMonth = LastUpdateDate.numberOfMonth;
}
}
//if (Hr_Permission==false)
//{
// lblmsg.Text = "Hr Not Give You Permission";
//}
//else
//{
if (Attendance_Id > 0)
{
var list1 = new List<SqlParameter>();
list1.Add(new SqlParameter("@Id", "0"));
list1.Add(new SqlParameter("@User_Id", User_Id));
list1.Add(new SqlParameter("@Actiontype", "Select2"));
DataTable dt1 = dal.getdataTable("TimeCalculator", list1.ToArray());
if (dt1.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt1.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Going_Time = Convert.ToDateTime(dr["Timing"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
if (listdt1.Count > 0)
{
var LastUpdateDate = (from c in listdt1 select c).LastOrDefault();
Status = LastUpdateDate.Status;
if (Status != "Out")
{
string[] col1 = { "@Id", "@User_Id", "@Coming_Time", "@Going_Time", "@Status", "@Going_Message","@Hr_Permission", "@Actiontype" };
object[] val1 = { Attendance_Id, User_Id, DateTime.Now, DateTime.Now, "Go", txtmessage.Text,((numberOfMonth>=10)?1:0), "Going" };
int i = dal.execute("ManageAttendance", col1, val1);
if (i == 1)
{
btnnight.Visible = false;
lblmsg.Text = "";
txtmessage.Visible = false;
if (numberOfMonth >= 10)
{
txtmsg.Text = "Great ! you my leave now, Good Night 😊";
}
else
{
txtmsg.Text = "Wait for manager's approval ✋";
}
}
txt_date.Text = System.DateTime.Now.ToString("MM/dd/yy H:mm:ss");
}
else
{
lberror.Text = "Please Inside First";
}
}
}
else
{
string[] col1 = { "@Id", "@User_Id", "@Coming_Time", "@Going_Time", "@Status", "@Going_Message", "@Hr_Permission", "@Actiontype" };
object[] val1 = { Attendance_Id, User_Id, DateTime.Now, DateTime.Now, "Go", txtmessage.Text, ((numberOfMonth >= 10) ? 1 : 0), "Going" };
int i = dal.execute("ManageAttendance", col1, val1);
if (i == 1)
{
btnnight.Visible = false;
lblmsg.Text = "";
txtmessage.Visible = false;
if (numberOfMonth >= 10)
{
txtmsg.Text = "Great ! you my leave now, Good Night 😊";
}
else
{
txtmsg.Text = "Wait for manager's approval ✋";
}
}
//Response.Redirect("attendance.aspx");
btnnight.Visible = false;
txt_date.Text = System.DateTime.Now.ToString("MM/dd/yy H:mm:ss");
}
//}
}
}
else
{
Response.Redirect("~/Pr-Admin-Log");
}
}
catch (Exception ex)
{
lblmsg.Text = ex.Message.ToString();
}
}
private void comingtime()
{
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", "Select2"));
DataTable dt = dal.getdataTable("ManageAttendance", list.ToArray());
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Coming_Time = Convert.ToDateTime(dr["Coming_Time"].ToString()),
Going_Time = Convert.ToDateTime(dr["Going_Time"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
}).ToList();
var LastUpdateDate = (from c in listdt1 select c).FirstOrDefault();
ComingTime = LastUpdateDate.Coming_Time.ToString("hh:mm tt");
if (LastUpdateDate.Status == "Go")
{
GoingTime = "(Going Time" + LastUpdateDate.Going_Time.ToString("hh:mm tt") + ")";
}
}
}
class MyModelClass
{
public int Id { get; set; }
public int User_Id { get; set; }
public string Status { get; set; }
public bool Hr_Permission { get; set; }
public DateTime Coming_Time { get; set; }
public DateTime Going_Time { get; set; }
public int numberOfMonth { get; set; }
}
protected void Timer1_Tick(object sender, EventArgs e)
{
int User_Id = int.Parse(Session["developer_srno"].ToString());
int Attendance_Id = 0;
bool Hr_Permission = false;
string Status = "";
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("ManageAttendance", list.ToArray());
DateTime comingTime = new DateTime();
DateTime goingTime = new DateTime();
if (dt.Rows.Count > 0)
{
var listdt1 = (from DataRow dr in dt.Rows
select new MyModelClass()
{
Id = Convert.ToInt32(dr["Id"]),
Going_Time = Convert.ToDateTime(dr["Going_Time"].ToString()),
Coming_Time = Convert.ToDateTime(dr["Coming_Time"].ToString()),
User_Id = Convert.ToInt32(dr["User_Id"]),
Status = dr["Status"].ToString(),
Hr_Permission = Convert.ToBoolean(dr["Hr_Permission"].ToString()),
}).ToList();
if (listdt1.Count > 0)
{
var LastUpdateDate = (from c in listdt1 where c.Status == "Go" select c).LastOrDefault();
if (LastUpdateDate != null)
{
Attendance_Id = LastUpdateDate.Id;
Hr_Permission = LastUpdateDate.Hr_Permission;
comingTime = LastUpdateDate.Coming_Time;
goingTime = LastUpdateDate.Going_Time;
}
}
}
string time1 = comingTime.ToString("dd/MM/yy");
string time2 = goingTime.ToString("dd/MM/yy");
string[] times3 = txt_date.Text.ToString().Split('-');
string time3 = times3[1]+"-"+ times3[0]+"-"+ times3[2].Substring(0,2);
if (time1== time2 && time1==time3)
{
if (Hr_Permission == true)
{
lblmsg.Text = "";
txtmsg.Text = "Great ! you my leave now, Good Night 😊";
}
else if (comingTime == goingTime)
{
lblmsg.Text = "";
txtmsg.Text = "";
}
else
{
lblmsg.Text = "";
txtmsg.Text = "Wait for manager's approval ✋";
}
}
else
{
lblmsg.Text = "";
txtmsg.Text = "";
}
}
}
Comments
Post a Comment