Tiny app to track working time on Jira tickets

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I'm a .NET intern. For my project management we work with Jira and we have to track real working time on a ticket to log the work and compare it to the original estimate. For this purpose I have written a tiny WPF app that shows a timer, because I have difficulties to track the time manually.
I was just wanting to get some comments on my code for educational purpose and self-improvement.
Example

Code
using System;
using System.Windows;
using System.Windows.Threading;
namespace Timer
public partial class MainWindow : Window
private int counter = 20000;
private bool IsTimerPaused = false; // used to switch the text of the button (pause - resume) timer
private bool IsTimerStarted = false;
private readonly DispatcherTimer timer = new DispatcherTimer();
private const int SECONDS_IN_MINUTE = 60;
private const int SECONDS_IN_HOUR = 3600;
public MainWindow()
InitializeComponent();
StartButton.Click += StartTimer;
ResetButton.Click += ResetTimer;
PauseButton.Click += PauseTimer;
private void PauseTimer(object sender, RoutedEventArgs e)
if (!IsTimerPaused)
timer.IsEnabled = false;
PauseButton.Content = "Resume";
else
timer.IsEnabled = true;
PauseButton.Content = "Pause";
IsTimerPaused = !IsTimerPaused;
private void ResetTimer(object sender, RoutedEventArgs e)
timer.Stop();
ToggleStartButton();
counter = 0;
DisplayTimer();
private void StartTimer(object sender, EventArgs e)
if (IsTimerStarted) return;
ToggleStartButton();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick -= IncreaseCounter; // prevents double call when start has been pressed multiple times
timer.Tick += IncreaseCounter;
timer.Start();
private void ToggleStartButton()
StartButton.IsEnabled = !StartButton.IsEnabled;
IsTimerStarted = !IsTimerStarted;
private void IncreaseCounter(object sender, EventArgs e)
counter++;
DisplayTimer();
private void DisplayTimer()
string timeEllapsed;
int seconds;
int minutes;
if (counter <= 60)
seconds = counter;
timeEllapsed = seconds + "s";
else if (counter <= 3600)
minutes = counter / SECONDS_IN_MINUTE;
seconds = counter % SECONDS_IN_MINUTE;
timeEllapsed = minutes + "m " + seconds + "s";
else
var hours = counter / SECONDS_IN_HOUR;
minutes = (counter - (hours * SECONDS_IN_HOUR)) / SECONDS_IN_MINUTE;
seconds = ((counter - (hours * SECONDS_IN_HOUR)) - (minutes * SECONDS_IN_MINUTE)) % SECONDS_IN_MINUTE;
timeEllapsed = hours + "h " + minutes + "m " + seconds + "s";
TimerTextBox.Text = timeEllapsed;
c# .net wpf
add a comment |Â
up vote
1
down vote
favorite
I'm a .NET intern. For my project management we work with Jira and we have to track real working time on a ticket to log the work and compare it to the original estimate. For this purpose I have written a tiny WPF app that shows a timer, because I have difficulties to track the time manually.
I was just wanting to get some comments on my code for educational purpose and self-improvement.
Example

Code
using System;
using System.Windows;
using System.Windows.Threading;
namespace Timer
public partial class MainWindow : Window
private int counter = 20000;
private bool IsTimerPaused = false; // used to switch the text of the button (pause - resume) timer
private bool IsTimerStarted = false;
private readonly DispatcherTimer timer = new DispatcherTimer();
private const int SECONDS_IN_MINUTE = 60;
private const int SECONDS_IN_HOUR = 3600;
public MainWindow()
InitializeComponent();
StartButton.Click += StartTimer;
ResetButton.Click += ResetTimer;
PauseButton.Click += PauseTimer;
private void PauseTimer(object sender, RoutedEventArgs e)
if (!IsTimerPaused)
timer.IsEnabled = false;
PauseButton.Content = "Resume";
else
timer.IsEnabled = true;
PauseButton.Content = "Pause";
IsTimerPaused = !IsTimerPaused;
private void ResetTimer(object sender, RoutedEventArgs e)
timer.Stop();
ToggleStartButton();
counter = 0;
DisplayTimer();
private void StartTimer(object sender, EventArgs e)
if (IsTimerStarted) return;
ToggleStartButton();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick -= IncreaseCounter; // prevents double call when start has been pressed multiple times
timer.Tick += IncreaseCounter;
timer.Start();
private void ToggleStartButton()
StartButton.IsEnabled = !StartButton.IsEnabled;
IsTimerStarted = !IsTimerStarted;
private void IncreaseCounter(object sender, EventArgs e)
counter++;
DisplayTimer();
private void DisplayTimer()
string timeEllapsed;
int seconds;
int minutes;
if (counter <= 60)
seconds = counter;
timeEllapsed = seconds + "s";
else if (counter <= 3600)
minutes = counter / SECONDS_IN_MINUTE;
seconds = counter % SECONDS_IN_MINUTE;
timeEllapsed = minutes + "m " + seconds + "s";
else
var hours = counter / SECONDS_IN_HOUR;
minutes = (counter - (hours * SECONDS_IN_HOUR)) / SECONDS_IN_MINUTE;
seconds = ((counter - (hours * SECONDS_IN_HOUR)) - (minutes * SECONDS_IN_MINUTE)) % SECONDS_IN_MINUTE;
timeEllapsed = hours + "h " + minutes + "m " + seconds + "s";
TimerTextBox.Text = timeEllapsed;
c# .net wpf
Why not use Stopwatch?
â paparazzo
Feb 12 at 12:39
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm a .NET intern. For my project management we work with Jira and we have to track real working time on a ticket to log the work and compare it to the original estimate. For this purpose I have written a tiny WPF app that shows a timer, because I have difficulties to track the time manually.
I was just wanting to get some comments on my code for educational purpose and self-improvement.
Example

Code
using System;
using System.Windows;
using System.Windows.Threading;
namespace Timer
public partial class MainWindow : Window
private int counter = 20000;
private bool IsTimerPaused = false; // used to switch the text of the button (pause - resume) timer
private bool IsTimerStarted = false;
private readonly DispatcherTimer timer = new DispatcherTimer();
private const int SECONDS_IN_MINUTE = 60;
private const int SECONDS_IN_HOUR = 3600;
public MainWindow()
InitializeComponent();
StartButton.Click += StartTimer;
ResetButton.Click += ResetTimer;
PauseButton.Click += PauseTimer;
private void PauseTimer(object sender, RoutedEventArgs e)
if (!IsTimerPaused)
timer.IsEnabled = false;
PauseButton.Content = "Resume";
else
timer.IsEnabled = true;
PauseButton.Content = "Pause";
IsTimerPaused = !IsTimerPaused;
private void ResetTimer(object sender, RoutedEventArgs e)
timer.Stop();
ToggleStartButton();
counter = 0;
DisplayTimer();
private void StartTimer(object sender, EventArgs e)
if (IsTimerStarted) return;
ToggleStartButton();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick -= IncreaseCounter; // prevents double call when start has been pressed multiple times
timer.Tick += IncreaseCounter;
timer.Start();
private void ToggleStartButton()
StartButton.IsEnabled = !StartButton.IsEnabled;
IsTimerStarted = !IsTimerStarted;
private void IncreaseCounter(object sender, EventArgs e)
counter++;
DisplayTimer();
private void DisplayTimer()
string timeEllapsed;
int seconds;
int minutes;
if (counter <= 60)
seconds = counter;
timeEllapsed = seconds + "s";
else if (counter <= 3600)
minutes = counter / SECONDS_IN_MINUTE;
seconds = counter % SECONDS_IN_MINUTE;
timeEllapsed = minutes + "m " + seconds + "s";
else
var hours = counter / SECONDS_IN_HOUR;
minutes = (counter - (hours * SECONDS_IN_HOUR)) / SECONDS_IN_MINUTE;
seconds = ((counter - (hours * SECONDS_IN_HOUR)) - (minutes * SECONDS_IN_MINUTE)) % SECONDS_IN_MINUTE;
timeEllapsed = hours + "h " + minutes + "m " + seconds + "s";
TimerTextBox.Text = timeEllapsed;
c# .net wpf
I'm a .NET intern. For my project management we work with Jira and we have to track real working time on a ticket to log the work and compare it to the original estimate. For this purpose I have written a tiny WPF app that shows a timer, because I have difficulties to track the time manually.
I was just wanting to get some comments on my code for educational purpose and self-improvement.
Example

Code
using System;
using System.Windows;
using System.Windows.Threading;
namespace Timer
public partial class MainWindow : Window
private int counter = 20000;
private bool IsTimerPaused = false; // used to switch the text of the button (pause - resume) timer
private bool IsTimerStarted = false;
private readonly DispatcherTimer timer = new DispatcherTimer();
private const int SECONDS_IN_MINUTE = 60;
private const int SECONDS_IN_HOUR = 3600;
public MainWindow()
InitializeComponent();
StartButton.Click += StartTimer;
ResetButton.Click += ResetTimer;
PauseButton.Click += PauseTimer;
private void PauseTimer(object sender, RoutedEventArgs e)
if (!IsTimerPaused)
timer.IsEnabled = false;
PauseButton.Content = "Resume";
else
timer.IsEnabled = true;
PauseButton.Content = "Pause";
IsTimerPaused = !IsTimerPaused;
private void ResetTimer(object sender, RoutedEventArgs e)
timer.Stop();
ToggleStartButton();
counter = 0;
DisplayTimer();
private void StartTimer(object sender, EventArgs e)
if (IsTimerStarted) return;
ToggleStartButton();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick -= IncreaseCounter; // prevents double call when start has been pressed multiple times
timer.Tick += IncreaseCounter;
timer.Start();
private void ToggleStartButton()
StartButton.IsEnabled = !StartButton.IsEnabled;
IsTimerStarted = !IsTimerStarted;
private void IncreaseCounter(object sender, EventArgs e)
counter++;
DisplayTimer();
private void DisplayTimer()
string timeEllapsed;
int seconds;
int minutes;
if (counter <= 60)
seconds = counter;
timeEllapsed = seconds + "s";
else if (counter <= 3600)
minutes = counter / SECONDS_IN_MINUTE;
seconds = counter % SECONDS_IN_MINUTE;
timeEllapsed = minutes + "m " + seconds + "s";
else
var hours = counter / SECONDS_IN_HOUR;
minutes = (counter - (hours * SECONDS_IN_HOUR)) / SECONDS_IN_MINUTE;
seconds = ((counter - (hours * SECONDS_IN_HOUR)) - (minutes * SECONDS_IN_MINUTE)) % SECONDS_IN_MINUTE;
timeEllapsed = hours + "h " + minutes + "m " + seconds + "s";
TimerTextBox.Text = timeEllapsed;
c# .net wpf
edited Feb 10 at 20:20
Jamalâ¦
30.1k11114225
30.1k11114225
asked Feb 10 at 18:14
Chingiz Mizambekov
62
62
Why not use Stopwatch?
â paparazzo
Feb 12 at 12:39
add a comment |Â
Why not use Stopwatch?
â paparazzo
Feb 12 at 12:39
Why not use Stopwatch?
â paparazzo
Feb 12 at 12:39
Why not use Stopwatch?
â paparazzo
Feb 12 at 12:39
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187269%2ftiny-app-to-track-working-time-on-jira-tickets%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Why not use Stopwatch?
â paparazzo
Feb 12 at 12:39