Click here to Skip to main content
12,748,904 members (40,113 online)
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 30 Jan 2012

Employee Attendance Tracking

, 31 Jan 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Program to track employee work time


The above screen shot shows Adam checked-in, worked 17 seconds, took a 10 seconds break then checked-in again. Chirs worked 61 seconds and Mary worked 16 seconds. Currently, Adam is the only one still in office.

Last Friday, I was casually browsing codeproject site and was entertained by a question and answer that were posted a long time ago. Seeker looked for an attendance tracking program and got one replied that “no, we do not do your home work.” and I totally agreed with the replier.

But by Sunday, I woke up to a delicious morning, when the whole body is one sense, and imbibes delight through every pore(Walden Pond), with the add of a cup of hot coffee (Walden Pond author despised), I found myself coded away the employee attendance tracker project.

I coded to demonstrate following features (Microsoft C# 2010 Express) I learned recently:

  • connect datagrideview with xml data source.
  • call a form within an active form
  • save persistent data to sqlite database
  • organize code into a class to ease programming
  • use a timer object to control the programming flow
  • run batch job interactively or in background

The design scenarios for EAT

I designed program with the following two scenarios in mind.

scenario 1, a small shop only has one computer used by everyone to check in and out.

scenario 2, an office that everyone have their own computer and can check-in and out from their own desktop.

How does the program work?

EAT records employee work time in seconds and displays to user as HH:MM:SS.

The employee can check in out several times a day. The work time will be accumulated.

Once the employee checks-in, the work time will start to increase; once checked-out, the time stopped.

The time of check-in, check-out will be recorded and displayed.

Program enforced a security of passcode with four letters as the ATM passcode.

If passcode is enforced, user needs to enter the right passcode to Check-in, out and view report.

employee can click on IN, OUT, NAME column to indicate Check-in, Check-out and obtains a history report.

For the simplicity and this demo, program displays the history on the bottom view immediately.

A Timer object

A timer can simplify the flow of program execution and make program more responsive to user’s command. Without timer, programmer needs to introduce some artificial delay, such as sleep for a few micro seconds or doing some looping which can cause problem.

I use one timer in the following fashion:

Every second, timer will do the increment of the employee’s work time if an employee has checked in. It checks if user has done typing in Enter Passcode form. Without timer, the flow of control is difficult to coordinate between two forms because Windows does not wait for the Child form to finish.

Three SortedDictionary Objects

dTimeWorked and dTimeSection use employee name as a key to store the accumulate total seconds worked and each check-in out total seconds worked.

dCheckedIn uses employee name as a key to store the true or false value to indicate if an employee is check-in or check-out.

SortedDictionary<string, int> dTimeWorked = new SortedDictionary<string, int>();//name, second
SortedDictionary<string, int> dTimeSection = new SortedDictionary<string, int>();//name,second 
SortedDictionary<string, bool> dCheckedIn = new SortedDictionary<string, bool>();//name,true 

XML Datasource

It is effortless to maintain employee's name and passcode in employees.xml file, just edit it with a notepad. "EXT." is for employee's phone extension.

The following code loadDGViewFromXML reads employees.xml and assigns to dataGridView1, connecting data with the ROW tag in employees.xml.

private void Form1_Load(object sender, EventArgs e)
    attendance = new DBAttendance();
    dataGridView2.DataSource = attendance.atbl;
    chkBoxViewBatch.Checked = true; // default to true
    chkBoxSecurity.Checked = false;       // default to true; enforece security

public void loadDGViewFromXML(string filePath)
    DataSet dsRows = new DataSet("ROW");
    dataGridView1.DataSource = dsRows;
    dataGridView1.DataMember = "ROW";

Enforced Security Mode

When program runs in the security mode, following prompt will pop up when employee tries to check-in or check-out.


Switching value between two columns

// switch value between two columns when user click on either column
private void swapValue(int row, int col1, int col2)  //'X' between in/out
    string temp = dataGridView1.Rows[row].Cells[col1].Value.ToString();
    dataGridView1.Rows[row].Cells[col1].Value = dataGridView1.Rows[row].Cells[col2].Value;
    dataGridView1.Rows[row].Cells[col2].Value = temp;

Call another form within the main form

There are three steps to make this happening:
//step1 - in Form1.cs[Design], Properties, Modifiers, changes value to Public
//step2 - Add the following module in Form1

private void checkPassCode()
{   // lblPassCode.Text will hold the value pass back from form2
    lblPassCode.Text = "";  
    Form2 subForm = new Form2(this);

//step3 - Add the following module in Form2
Form1 mainForm;
public Form2(Form1 mainForm)
    this.mainForm = mainForm;

// return the value to form1 and close form2
private void textBox1_KeyUp(object sender, KeyEventArgs e)
    if (textBox1.Text.Length == 4)
        mainForm.lblPassCode.Text = textBox1.Text;

Save log to sqlite database

If program is in interactive mode, the following screen will appear. Press a key to go on. Use d.bat, debug.sql to debug the sqllite.



sqlite3 employeeattendance.db <  debug.sql 
SELECT * FROM sqlite_master;
SELECT * FROM worklog order by ename;





30-Jan-2012 - First version.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

C Yang
United States United States
A program analyst specialize in XML/HTML/CSS, Office Automation and Oracle Database.

A hobbyist of computer science. My favorite languages are C# and C++, but I also like to code in Ruby, Perl, Java, Python, Basic and SQL script.

You may also be interested in...


Comments and Discussions

Questiongood work Pin
Cimak6664-Sep-15 1:57
memberCimak6664-Sep-15 1:57 
QuestionIn web Application Pin
Abhilask kumar9-May-13 22:52
professionalAbhilask kumar9-May-13 22:52 
QuestionGood initiative, but... Pin
Paulo Zemek31-Jan-12 4:09
mvpPaulo Zemek31-Jan-12 4:09 
AnswerRe: Good initiative, but... Pin
johny1015198131-Jan-12 4:21
memberjohny1015198131-Jan-12 4:21 
AnswerRe: Good initiative, but... Pin
planetjim6-Feb-12 15:17
memberplanetjim6-Feb-12 15:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 31 Jan 2012
Article Copyright 2012 by C Yang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid