Beispiel #1
0
        public static bool TryParse(string hour, string minute, string second, out CountdownTime countdownTime)
        {
            bool parsed = false;

            int tempHour   = 0;
            int tempMinute = 0;
            int tempSecond = 0;

            if (hour == string.Empty)
            {
                hour = "0";
            }
            if (minute == string.Empty)
            {
                minute = "0";
            }
            if (second == string.Empty)
            {
                second = "0";
            }

            parsed = (int.TryParse(hour, out tempHour) && int.TryParse(minute, out tempMinute) && int.TryParse(second, out tempSecond));

            countdownTime = new CountdownTime(tempHour, tempMinute, tempSecond);

            return(parsed);
        }
Beispiel #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (!timer.IsRunning)
            {
                if (paused)
                {
                    timer.Start();
                    btnStart.Text = "Pause";
                }
                else
                {
                    string[]      strTime = mtxtTime.Text.Split(':');
                    CountdownTime time    = new CountdownTime();

                    string strHours = strTime[0].Trim();
                    string strMin   = strTime[1].Trim();
                    string strSec   = strTime[2].Trim();

                    if (CountdownTime.TryParse(strHours, strMin, strSec, out time))
                    {
                        if (time < (new CountdownTime(0, 0, 0)))
                        {
                            MessageBox.Show("Time cant be less than 1 minute");
                        }
                        else
                        {
                            EnableTextBoxes(false);
                            btnStart.Text = "Pause";
                            timer.SetTimes(time);
                            timer.Start();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong syntax");
                    }
                }
            }
            else
            {
                timer.Stop();
                btnStart.Text = "Start";
                paused        = true;
            }
        }
Beispiel #3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            CountdownTime otherCDT = obj as CountdownTime;

            if (Hour == otherCDT.Hour && Minute == otherCDT.Minute && Second == otherCDT.Second)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            CountdownTime otherCDT = obj as CountdownTime;

            if (otherCDT != null)
            {
                if (Hour > otherCDT.Hour)
                {
                    return(1);
                }
                else if (Hour == otherCDT.Hour)
                {
                    if (Minute > otherCDT.Minute)
                    {
                        return(1);
                    }
                    else if (Minute == otherCDT.Minute)
                    {
                        if (Second > otherCDT.Second)
                        {
                            return(1);
                        }
                        else if (Second == otherCDT.Second)
                        {
                            return(0);
                        }
                    }
                }

                return(-1);
            }
            else
            {
                throw new ArgumentException("Object is not a valid CountdownTime");
            }
        }
Beispiel #5
0
 /// <summary>
 /// Sets times
 /// </summary>
 /// <param name="time">The countdown time</param>
 public void SetTimes(CountdownTime time)
 {
     Hour   = time.Hour;
     Minute = time.Minute;
     Second = time.Second;
 }
Beispiel #6
0
 /// <summary>
 /// Creates a new instance of DetailedTimer
 /// </summary>
 public DetailedTimer()
 {
     timerSecond.Interval = 1000;
     timerSecond.Tick    += timerSecond_Tick;
     WarningTime          = new CountdownTime(0, 1, 0);
 }