public void Start() { if (this.state == StopWatchState.Started) { return; } if (this.state == StopWatchState.Stopped) { timer.Tick += timer_Tick; startedTimeSpan = new TimeSpan(DateTime.Now.Ticks); } else if (this.state == StopWatchState.Paused) { startedTimeSpan = new TimeSpan(DateTime.Now.Ticks).Subtract(pausedTimeSpan).Add(startedTimeSpan); pausedTimeSpan = TimeSpan.Zero; } if (timer.Interval.Ticks == 0) { timer.Interval = new TimeSpan(this.Interval * 10000); } timer.Start(); state = StopWatchState.Started; btn_start.BorderBrush = Brushes.Red; btn_pause.BorderBrush = Brushes.Transparent; }
public void Start(TimeSpan input) { if (input.TotalMilliseconds > 0 && _state != StopWatchState.Paused) { _state = StopWatchState.Running; _startTime = DateTime.Now; _curTime = _input = input; } else if (_state == StopWatchState.Paused) { _state = StopWatchState.Running; _pausedEndTime = DateTime.Now; _pausedDuration = _pausedEndTime - _pausedStartTime; input = _input = _curTime; _startTime = _pausedStartTime + _pausedDuration; } else if(_state == StopWatchState.Idle && _curTime < TimeSpan.Zero) { _curTime = input; } else { _curTime = TimeSpan.Zero; _state = StopWatchState.Idle; } }
public ProjectWindow(int _id) { InitializeComponent(); state = StopWatchState.Stopped; timer = new DispatcherTimer(); id = _id; RetrieveData(id); }
public void Start() { if (State == StopWatchState.Paused) { _state = StopWatchState.Running; _pausedEnd = DateTime.Now; _pausedDuration = _pausedEnd - _pausedStartTime; } else _startTime = DateTime.Now; }
private void buttonReset_Click(object sender, EventArgs e) { m_TimeStart = DateTime.Now; m_TimeSpanTotal = TimeSpan.Zero; if (State == StopWatchState.Continue) { labelTimer.Text = m_TimeZero; buttonStartPause.Text = "Start"; State = StopWatchState.Start; } SetNotifyingIcon(); }
public void Pause() { if (this.state != StopWatchState.Started) { return; } timer.Stop(); state = StopWatchState.Paused; pausedTimeSpan = new TimeSpan(DateTime.Now.Ticks); btn_start.BorderBrush = Brushes.Transparent; btn_pause.BorderBrush = Brushes.Red; }
public StopWatchForm() { InitializeComponent(); InitializePanel(); LoadSettings(); labelTimer.Text = m_TimeSpanTotal.ToString(m_TimeFormat); if (labelTimer.Text != m_TimeZero) { buttonStartPause.Text = "Continue"; State = StopWatchState.Continue; } }
public void Reset() { timer.Stop(); timer.Tick -= timer_Tick; timerLabel.Content = "00 : 00 : 00"; state = StopWatchState.Stopped; if (timer != null) { timer.Stop(); timer.Tick -= timer_Tick; } btn_pause.BorderBrush = Brushes.Transparent; btn_start.BorderBrush = Brushes.Transparent; }
private void buttonStartPause_Click(object sender, EventArgs e) { if (State == StopWatchState.Start || State == StopWatchState.Continue) { m_TimeStart = DateTime.Now; timer1.Start(); buttonStartPause.Text = "Pause"; State = StopWatchState.Pause; } else // "Pause". { m_TimeSpanTotal = DateTime.Now - m_TimeStart + m_TimeSpanTotal; timer1.Stop(); buttonStartPause.Text = "Continue"; State = StopWatchState.Continue; } SetNotifyingIcon(); }
public void Save() { Database databaseObject = new Database(); //INSERT INTO DATABASE string query = "UPDATE projects SET h= '" + (hLocal + hGlobal) + "', min='" + (minLocal + minGlobal) + "', sec='" + (secLocal + secGlobal) + "' WHERE id = " + id; hLocal = 0; minLocal = 0; secLocal = 0; SQLiteCommand command = new SQLiteCommand(query, databaseObject.connection); databaseObject.OpenConnection(); var result = command.ExecuteNonQuery(); databaseObject.CloseConnection(); timer.Stop(); timer.Tick -= timer_Tick; timerLabel.Content = "00 : 00 : 00"; if (state == StopWatchState.Started) { timer.Tick += timer_Tick; startedTimeSpan = new TimeSpan(DateTime.Now.Ticks); timer.Start(); state = StopWatchState.Started; btn_pause.BorderBrush = Brushes.Transparent; btn_start.BorderBrush = Brushes.Red; } else { btn_pause.BorderBrush = Brushes.Transparent; btn_start.BorderBrush = Brushes.Transparent; state = StopWatchState.Stopped; } RetrieveData(id); }
public StopWatchItems Stop() { if (_currTime > TimeSpan.Zero) { _count++; var _endTime = _currTime; var ret = new StopWatchItems { RoundTime = _endTime, TimeStamp = DateTime.Now, //Id = 0 }; _state = StopWatchState.Idle; if (ret.RoundTime > TimeSpan.Zero) { _currTime = TimeSpan.Zero; return ret; } } return null; }
public StopWatch() { CurrentState = new StoppedState(this); }
public void Stop() { _state = StopWatchState.Idle; }
public void Paused() { _state = StopWatchState.Paused; _pausedStartTime = DateTime.Now; }