public CountdownUserControl() { InitializeComponent(); isRunning = IsCountdownRunning(); CountdownTimesCollection = new ObservableCollection <StopwatchTimes>(); LoadLapAndSplitData(); App.gDefaultCountdown = GetCountdownDefaultTime(); App.gAlarmSetting = GetCountdownAlarmSetting(); lastCountdownValue = GetLastCountdownValue(); if (lastCountdownValue == string.Empty || lastCountdownValue == "00:00:00") { ClockValue = App.gDefaultCountdown; } else { ClockValue = TimeSpan.Parse(lastCountdownValue); } ClockValueString = ClockValue.ToString(@"hh\:mm\:ss"); dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 1); if (isRunning.ToUpper() == "YES") { Mode = AppResources.StartText; Start.Background = new SolidColorBrush(Colors.Green); StartCountdown(); } else { if (lastCountdownValue == string.Empty || lastCountdownValue == "00:00:00" || lastCountdownValue == App.gDefaultCountdown.ToString()) { Mode = AppResources.StartText; Start.Background = new SolidColorBrush(Colors.Green); } else { Mode = AppResources.ResumeText; Start.Background = new SolidColorBrush(Colors.Green); } } this.DataContext = this; }
private void Timer_Tick(object sender, EventArgs e) { if (ClockValue >= new TimeSpan(9, 0, 0)) { if (Mode != AppResources.ExceedText) { MessageBox.Show(AppResources.MaxTimeExceededMessage); Mode = AppResources.ExceedText; } } else if (Mode != AppResources.ExceedText) { ClockValue = App.gStopWatch.Elapsed + _adjustment; ClockValueString = ClockValue.ToString(@"hh\:mm\:ss\.ff"); IS.SaveSetting("Stopwatch-LastValue", ClockValue.ToString()); } }
private void ResetCountdown(bool setClockValueToDefault) { SolidColorBrush mySolidColorBrush = new SolidColorBrush(); dispatcherTimer.Stop(); if (setClockValueToDefault == true) { ClockValue = App.gDefaultCountdown; } // Describes the brush's color using RGB values. Each value has a range of 0-255. mySolidColorBrush.Color = System.Windows.Media.Color.FromArgb(255, 50, 205, 50); ClockValueString = ClockValue.ToString(@"hh\:mm\:ss"); Mode = AppResources.StartText; Start.Background = new SolidColorBrush(Colors.Green); btnCountdownDisplay.Foreground = new SolidColorBrush(mySolidColorBrush.Color); }
private void TimerClickAsync() { try { Dispatcher.BeginInvoke(() => { ClockValue = ClockValue - new TimeSpan(0, 0, 1); ClockValueString = ClockValue.ToString(@"hh\:mm\:ss"); if (ClockValue <= new TimeSpan(0, 0, 5) && ClockValue > new TimeSpan(0, 0, 0)) { btnCountdownDisplay.Foreground = new SolidColorBrush(Colors.Red); PlaySound("Assets/alarm.wav"); } }); if (ClockValue <= new TimeSpan(0, 0, 0)) { Dispatcher.BeginInvoke(() => { PlaySound("Assets/beep.wav"); MessageBoxResult result = MessageBox.Show(AppResources.ElapsedTime + " " + originalCountdownTime, AppResources.CountdownFinished, MessageBoxButton.OK); if (result == MessageBoxResult.OK) { ResetCountdown(true); } }); } IS.SaveSetting("Countdown-LastValue", ClockValue.ToString()); } catch (Exception) { } }
private void countdownTime_ValueChanged(object sender, RoutedPropertyChangedEventArgs <TimeSpan> e) { ClockValue = TimeSpan.Parse(ctlCountdownTime.Value.ToString()); ClockValueString = ClockValue.ToString(@"hh\:mm\:ss"); ResetCountdown(false); }