Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the last step which i have to make alarm sound every match with current time and the current day (not date), the data of time will be taken from database which i have created before with entity framework below are models which i created , there are two table , the first is AlarmModel
C#
public int id { get; set;  }


public int dayId {get;set;}
[ForeignKey("dayId")]
public virtual Day day { get; set; }

public int sessionId { get; set; }
[ForeignKey("sessionId")]
public virtual Session session { get; set; }

public DateTime time { get; set; }
public int repeatTime { get; set; }

public String path { get; set; }
public String keterangan { get; set; }

and this is the second class DayModel
C#
public class Day
{
    public int id { get; set; }
    public String nameDay { get; set; }        
}

Below is the image of my alarm table enter image description here

So i just focus to the time and the day id example i set time to 08:00 and day is Sunday so 08:00 on sunday there will be sound ring that is path

I have tried this code , but I get nothing

What I have tried:

C#
public class AlarmClock
    {
        public AmanContext repo { get; set; }
        public AlarmClock()
        {
            repo = new AmanContext();
        }
        public DateTime GetAlarm(DateTime time)
        {
            DateTime alarm = DateTime.Now;
            foreach (var item in repo.alarms.ToList())
            {
                if (time > item.time)
                {
                    alarm = item.time;
                }

            }

            return alarm;
        }



    DispatcherTimer timer = new DispatcherTimer();
        public ViewAlarm()
                {
                    this.alarmService = new AlarmService();
                    InitializeComponent();

                    timer.Interval = TimeSpan.FromSeconds(1);
                    timer.Tick += timer_tick;
                    timer.Start();



                }
                AlarmClock ac = new AlarmClock();
                private void timer_tick(object sender, EventArgs e)
                {
                    DateTime timeNow = DateTime.Now;

                    DateTime alarms = ac.GetAlarm(timeNow);
                    alarmlbl.Content = timeNow.ToLongTimeString();

                    if (timeNow > alarms)
                    {
                        //Sound Something

                    }
                }
Posted
v2
Comments
Did you debug? Where is the exact issue?

1 solution

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
Quote:
I have tried this code , but I get nothing
The debugger will show you what your code is doing and thus help you spot where the problem is.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900