Home.aspx
<html
xmlns="http://www.w3.org/1999/xhtml" >
<head
id="Head1" runat="server">
<title>Attendance System</title>
</head>
<body>
<form id="form1" runat="server">
<div style="text-align:center;">
<div style="font-size:medium; color:Blue; text-align:center;">Today’s Date : <%=strCurrntMonthYear %></div>
<asp:GridView ID="gvCalander" Font-Size="Smaller" Font-Names="verdana, arial" HeaderStyle-HorizontalAlign="Center" RowStyle-HorizontalAlign="Center" RowStyle-BackColor="gray" AlternatingRowStyle-BackColor="Aqua" CellPadding="5" CellSpacing="5"
runat="server" ShowHeader="false" AutoGenerateColumns="false" OnRowDataBound="gvCalander_RowDataBound">
<Columns>
<asp:BoundField DataField="AutoID" HeaderText="Days" />
<asp:BoundField DataField="DaysName" HeaderText="Name" />
<asp:BoundField DataField="Date" HeaderText="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="txtRemarks" runat="server" Text="Remarks" Font-Size="8" onfocus="if(this.value=='Remarks'){this.value=''}" onblur="if(this.value==''){this.value='Remarks'}" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkMark" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="Gray" HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="Aqua" />
</asp:GridView>
</div>
<div style="text-align:center;">
<asp:Button ID="btnAddAttendence" runat="server" Text="Add" OnClick="btnAddAttendence_Click" /> <asp:Button ID="btnReset" runat="server" Text="Reset" />
</div>
</form>
</body>
</html>
Home.aspx.cs Page
using System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Text;
using
System.Data.SqlClient;
public partial class home : System.Web.UI.Page
{
public static string
strCurrntMonthYear = "";
SqlConnection
dbCon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connString"].ToString());
int Year =
0;
int inMonth
= 0;
protected void Page_Load(object
sender, EventArgs e)
{
if
(!IsPostBack)
{
bindAttendance();
}
}
protected void bindAttendance()
{
//get current
Year
Year = DateTime.Now.Year;
//get current
Month
inMonth = DateTime.Now.Month;
//get Day's
in current month
int
Days = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
//Declare
DataTable
DataTable
Dt = new DataTable("dtDays");
//Declare
Data Column
DataColumn
auto = new DataColumn("AutoID", typeof(System.Int32));
Dt.Columns.Add(auto);
DataColumn
DaysName = new DataColumn("DaysName", typeof(string));
Dt.Columns.Add(DaysName);
DataColumn
Date = new DataColumn("Date", typeof(string));
Dt.Columns.Add(Date);
//Declare
Data Row
DataRow
dr = null;
DateTime
days;
DateTime
strDate;
for (int i = 1; i <= Days; i++)
{
//Create
row in DataTable
dr = Dt.NewRow();
days = new
DateTime(Year, inMonth, i); // find days name
strDate = new
DateTime(Year, inMonth, i); // find date w.r.t days
dr["AutoID"]
= i;
dr["DaysName"]
= days.DayOfWeek;
dr["Date"]
= strDate.Date.ToShortDateString();
Dt.Rows.Add(dr); //Add row in
DataTable
}
//Assign
Current Date, Month and Year
strCurrntMonthYear = DateTime.Now.ToString("dd")
+ " " + DateTime.Now.ToString("MMMM") + "
" + Year;
//Assing
DataTable to GridView
gvCalander.DataSource = Dt;
gvCalander.DataBind();
}
protected void gvCalander_RowDataBound(object
sender, GridViewRowEventArgs e)
{
string
currDate = DateTime.Now.ToShortDateString();
if
(e.Row.RowType == DataControlRowType.DataRow)
{
string
rowDate = e.Row.Cells[2].Text; //Date
string
rowDay = e.Row.Cells[1].Text; //Day
CheckBox
chk = (CheckBox)e.Row.FindControl("chkMark");
TextBox
txtRemark = (TextBox)e.Row.FindControl("txtRemarks");
string
strRemarks = "";
bool
boolAttStatus = false;
bindPrevAtt(out boolAttStatus, out strRemarks,
rowDate);
txtRemark.Text = strRemarks;
chk.Checked = boolAttStatus;
if
((Convert.ToDateTime(rowDate) < Convert.ToDateTime(currDate)) || chk.Checked==true)
{
//
CheckBox chk = (CheckBox)e.Row.FindControl("chkMark");
//
TextBox txtRemark = (TextBox)e.Row.FindControl("txtRemarks");
chk.Enabled = false;
txtRemark.Enabled = false;
}
if
(rowDay.Equals("Sunday") ||
rowDay.Equals("Saturday")) //if there is
Sunday make it red colour
{
e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;
}
}
}
protected void btnAddAttendence_Click(object
sender, EventArgs e)
{
string
strRemarks = "";
string
tsCurrHour = DateTime.Now.Hour.ToString();
string
tsCurrMin = DateTime.Now.Minute.ToString();
foreach
(GridViewRow gvr in
gvCalander.Rows)
{
string
strDay = gvr.Cells[1].Text; //Day
string
strDate = gvr.Cells[2].Text; //Date
TextBox
txtRemarks =(TextBox)gvr.FindControl("txtRemarks");
CheckBox
chkMark = (CheckBox)gvr.FindControl("chkMark");
if
(chkMark.Checked == true)
{
if
(Convert.ToInt32(tsCurrHour) > 10 || Convert.ToInt32(tsCurrMin) > 30)
{
strRemarks = "Sorry
you are late";
}
else
{
strRemarks =
txtRemarks.Text.Trim();
}
//strRemarks
= txtRemarks.Text.Trim();
//Save
Data
DateTime
dt = Convert.ToDateTime(strDate);
string
strDateTime = dt.Month+"/"+dt.Day+"/"+dt.Year;
SaveData(1, strRemarks,
strDateTime);
}
}
//bind
Attendance
bindAttendance();
}
protected void SaveData(int
attStatus, string strRemarks, string strDate)
{
//here I am
assuming logged in employee Id as 1
string
strQry = "INSERT INTO AttendanceMaster (empId,
attMonth, attYear, attStatus, remarks, attdate, loggedInDate ) VALUES (1,"
+ DateTime.Now.Month + "," + DateTime.Now.Year
+ "," + attStatus + ", '" + strRemarks + "', '" + strDate + "',getDate())";
SqlCommand
cmd = new SqlCommand(strQry,
dbCon);
dbCon.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
dbCon.Close();
}
protected void bindPrevAtt(out bool attStatus, out string strRemarks, string
strAttDate)
{
attStatus = false;
strRemarks = "Remarks";
string
strQry = "SELECT attStatus, remarks FROM
AttendanceMaster WHERE empId = 1 AND Convert(varchar(12),attDate,103) = '"
+ strAttDate + "'";
SqlCommand
cmd = new SqlCommand(strQry,
dbCon);
dbCon.Open();
SqlDataAdapter
da = new SqlDataAdapter(cmd);
DataTable
dt = new DataTable();
da.Fill(dt);
if
(dt.Rows.Count > 0)
{
strRemarks = dt.Rows[0]["remarks"].ToString();
attStatus = Convert.ToBoolean(dt.Rows[0]["attStatus"]);
}
dt.Dispose();
da.Dispose();
cmd.Dispose();
dbCon.Close();
}
}
Table Scripts
/******
Object: Table
[dbo].[AttendanceMaster] Script Date:
11/21/2011 12:38:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[AttendanceMaster](
[attID] [int] IDENTITY(1,1) NOT NULL,
[empId] [int] NULL,
[attmonth] [int] NULL,
[attYear] [int] NULL,
[attStatus] [bit] NULL,
[remarks] [varchar](200) NULL,
[attdate] [datetime] NULL,
[loggedInDate] [datetime] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[AttendanceMaster]
ADD DEFAULT ((0)) FOR [attStatus]
GO
Note: This is a module of Employee Management
System (Attendance), you can integrate with your existing system using this
Attendance System. Yo need to map your existig employee Id with AttendanceMaster
Table.
Comments
You implement it and if you face any difficulties please let me know.
Koi baat nahi sir, itna hi kafi hai mere liye.
Regards,
ved
Great post..!!!!
I like this Post. It is so nice to read such wonderful blog. Thanks for sharing!
Regards
Time Labs
I am looking forward more feedback/comments on same.
Thank you once again.
Regards,
ved pathak
Great Post...
Always appreciate your suggestions.
Thanks.
Thanks for your suggestion but it is html issues. I tried to post it many times but some tags are always missing while posting.
Please correct after pasting the code in your page. Sorry for Inconvenience.
Regards,
ved
Thanks for your feedback. I am not getting what exactly document you need about. It's very simple step by step explained in blog.
If you face any kind of difficulties, kindly mail me your code so I can send you by resolving it.
Thanks & Regards,
ved pathak
vedrajan@gmail.com
for your appreciation!
Great post.
Sir concerning the html part can you also send it to my mail below?
Am new into programming.
Will really appreciate it if u can send me the html part.
allenteeno@gmail.com
Simply copy and paste the code in aspx and .cs.
Thanks,
ved pathak
We have updated the code, now you are able to copy the aspx part as well without any missing tags.
Thanks for your suggestion.
Cheers,
ved pathak
foreach (GridViewRow gvr in gvCalander.Rows)
{
string strDay = gvr.Cells[1].Text; //Day
string strDate = gvr.Cells[2].Text; //Date
TextBox txtRemarks = (TextBox)gvr.FindControl("txtRemarks");
CheckBox chkMark = (CheckBox)gvr.FindControl("chkMark");
if (chkMark.Checked == true)
{
if (Convert.ToInt32(tsCurrHour) > 10 || Convert.ToInt32(tsCurrMin) > 30)
{
strRemarks = "Sorry you are late";
}
else
{
strRemarks = txtRemarks.Text.Trim();
}
//strRemarks = txtRemarks.Text.Trim();
//Save Data
DateTime dt = Convert.ToDateTime(strDate);
string strDateTime = dt.Month + "/" + dt.Day + "/" + dt.Year;
SaveData(1, strRemarks, strDateTime);
}
I am sorry but I am unable to find exactly what kind of error are you facing? The above code is complete please check it thoroughly and let me know the exact error message which you are getting.
Thanks.
I want to make attendance page like this video on youtube (https://www.youtube.com/watch?v=a0LsniFpDPE). Can you help me in this regard.
Himanshu Goel
himanshu3335@gmail.com
Sure, you can do that way also. You just need to write SQL Query to get month wise day and Student details (RollNo, Name). That way you can just check attendance.
You try it and let me know , by the help of this tutorials you can create the same.
Thanks,
ved pathak
Time and Attendance System
Thank you very much for your appreciation.
Surely, will keep posting useful topics which helps you.
Thank you for visiting.
I copied your code and tried to debug..it shows error at da.Fill(dt);
Can you tell me,how to insert data.
Thanks
Thank your very much for visiting our blog. First of all I would like to know what type of error are you getting?
There could be two reason as per your post:
1. Either you have not declared proper namespace for Data Table, Data Adapter i.e. SQL Data Client OR
2. There might be problem while copying the code.
I suggest you to please write the code instead of copying it and then try to run again and let me know if you are facing the same problem again.
Thanks & Regards,
ved pathak
rfid attendance system with SMS
Keep sending your suggestion.
Thanks again.
Ved Pathak
Compiler Error Message: CS1061: 'ASP.attendancesheet_aspx' does not contain a definition for 'gvCalander_RowDataBound' and no extension method 'gvCalander_RowDataBound' accepting a first argument of type 'ASP.attendancesheet_aspx' could be found (are you missing a using directive or an assembly reference?)
Line 7:
you have not copied the code properly, anyway for you I have modified the code here you can see updated code
http://vedpathak.blogspot.in/2018/02/employee-attendance-system-modified.html
please let me know
For More Information. Click here
need for employee managment system
Thanks.
, please click here.