Project/SMI

[C#] DateTime을 이용한 알람 설정

빡썽 2010. 12. 6. 13:07

//설정된 시간에서 30분후에 알람을 울리게 해보자

private void AfterSettingProc()
        {
            int CompareMinute = 60;
            int AfterNum = 30;
            int temphour;
            int tempmin;
            temphour = SettingHour; //SettingHour은 TextBox에 입력 받은 값
            tempmin = SettingMin; //SettingMin은 TextBox에 입력 받은 값
            tempmin += AfterNum;
            if (tempmin > 60) // 입력 시간이 50분이라면 80분이 되기 때문에 20분으로 변경을 해주자
            {
                tempmin -= CompareMinute;  
            }
            SettingTime = new DateTime(2010, 12, dt.Day, temphour, tempmin, dt.Second);
            DateTime end = SettingTime;
            TimeSpan t3 = end.Subtract(DateTime.Now);
            TimeSpan t2 = DateTime.Now.Subtract(DateTime.Now);
            if (t3.CompareTo(t2) > 0)//현재 시간 이후로되어 있다면 남는 시간 출력
            {
                if (t3.Hours == 0)//시간이 0이면 출력에서 제회
                {
                    MessageBox.Show(t3.Minutes + ": Minutes  Call" + "♪");
                }
                else
                {
                    MessageBox.Show(t3.Hours + ": Hours - " + t3.Minutes + ": Minutes  Call" + "♪");
                }
               
            }
            else
            {
                MessageBox.Show("Timer over");
            }
        }