Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

A Simple Punch Clock Applet

4.71/5 (6 votes)
15 Dec 2012CPOL2 min read 29.3K   496  
A simple punch clock applet

Image 1

Introduction

A couple years ago, I wrote a piece of code that counted down to a particular event - you can read the article here. After my current gig full time ended in September, I ended up getting involved in several different projects, all at the same time, and realized I really need a simple to use punch-clock application that would simply count how much time I'm spending on each project.  It seemed reasonable to use the same code base for the "Countdown Reminders" and modify it slightly to work as a punch clock instead.

Yes, this is a ridiculously short article, but perhaps you'll find the application useful or give me some ideas on what you'd like to see added. I have a few ideas that I discuss at the end.

Under the Hood

This section discusses the changes made to the Countdown Reminder code.

The User Interface

You can read the Countdown Reminders article for how the UI works - I made some minor modifications, eliminating the option to select fields, which resulted in a more brute force way of initializing the counter groups:

C#
protected void CreateCounterGroups()
{
  int pos = 0;
  dayGroup = new Group("Days");
  hourGroup = new Group("Hours");
  minuteGroup = new Group("Minutes");
  secondGroup = new Group("Seconds");

  foreach (Group group in new List<Group>() { dayGroup, hourGroup, minuteGroup, secondGroup })
  {
    group.Location = new Point(pos, 0);
    pos += group.Width;
    Controls.Add(group);
  }

  Width = 6 * Group.GroupWidth;
}

However, everything else is the same with regards to the presentation of the timers.

I did change the popup menu to include a "start" and "stop" option:

Image 2

I also modified the data structure which is reflected in the Setup UI:

Image 3

The Data Structure

The underlying data structure just has a description and time:

C#
private static void CreateTable()
{
  counterTable = new DataTable("Counters");
  counterTable.Columns.Add("Index", typeof(Int32));
  counterTable.Columns.Add("Description", typeof(string));
  counterTable.Columns.Add("Time", typeof(long));

  counterView = new DataView(Program.counterTable);
  counterView.Sort = "Index";
}

Ideally, a DataSet should be used to support a second child table to record the start & stop date-time activity, but that's for a future version.

One Project at a Time

This hard-coded feature...

C#
private void startToolStripMenuItem_Click(object sender, EventArgs e)
{
  Program.StopCounters();
  Program.StartCurrentCounter();
}

...ensures that only one project at a time can be "punched in" - having time charged against it.

What Next?

While there don't appear to be any applications like this on Code Project, there are nifty punch clock apps one can download for the smart phone as well as regular desktop apps, but I don't necessarily have my phone next to me all the time.  That said, there are a few features that are definitely needed:

  • Reports and charts of daily / weekly / monthly activity
  • Summary reports over a period of time for billing purposes
  • Merging data with other devices - for example, if I am working on my laptop on the train, I want to merge that information with the desktop app. Hmmm...cloud based data?

So, it's a start, we'll see where it goes.

License

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