Click here to Skip to main content
15,879,348 members
Articles / Programming Languages / C#

A Simple Punch Clock Applet

Rate me:
Please Sign up or sign in to vote.
4.71/5 (6 votes)
15 Dec 2012CPOL2 min read 28.7K   496   18   4
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)


Written By
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions

 
Questionsmall codechange, big result Pin
MrDebug6522-Dec-12 21:20
MrDebug6522-Dec-12 21:20 
AnswerRe: small codechange, big result Pin
Marc Clifton27-Dec-12 3:12
mvaMarc Clifton27-Dec-12 3:12 
BugProcessing the hours Pin
Franz Babener19-Dec-12 23:53
Franz Babener19-Dec-12 23:53 
GeneralRe: Processing the hours Pin
Marc Clifton27-Dec-12 3:13
mvaMarc Clifton27-Dec-12 3:13 

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.