Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying but no use, Can anyone help me solve this?
I have given a facility to user to select the reminder type (such as daily, weekly[user will be asked to select a day], on a special day)
and when the user add an event after filling such fields (event name, event description, reminder type, date and time) and the app should remind him the events on specific time.
Please help me to do with this task?

My code - A method that will be called into the main form

C#
public void Reminders()
        {
            SqlCeConnection conn = new SqlCeConnection("Data Source=E:\\Project Final_Year\\Project Final\\MyProject\\ERU Implementation\\VirtualPetedit\\VirtualPet\\MyDB.sdf");
            string query = "SELECT time FROM Events";
            SqlCeDataReader r;
            DateTime thisDay = DateTime.Today;
            

            
            try
            {
                conn.Open();
                SqlCeCommand command = new SqlCeCommand(query, conn);
                r  = command.ExecuteReader();
                //if (r.HasRows)
                       // {
                DateTime tag = r.GetDateTime(0);
                            while (r.Read())
                            {
                                int result = DateTime.Compare(thisDay, tag);
                                if (result == 0)
                                    MessageBox.Show("You have a reminder at this moment");

                                /*
                                DateTime tag = r.GetDateTime(0);
                                if (r.GetDateTime(0)  == thisDay )
                                {
                                    
                                    VirtualPet.Popup popup = new VirtualPet.Popup();
                                    popup.Reminder();
                                }*/
                            }
                       // }
                       /* else
                        {
                            MessageBox.Show("No Reminder times currently");                          
                        }*/
                conn.Close(); 
            }
            catch (Exception ex)
            { 
              //  MessageBox.Show(ex.Message.ToString());
            }
        }
Posted
Updated 25-May-15 0:16am
v3

1 solution

The problem with that approach is that the reminder time has to be accurate: to the microsecond or the comparison will fail.
Instead of looking for equality, add a column to your DB which indicates that a reminder has been issued and acknowledged. Then change your SQL SELECT to only return "unused" reminders.
And move the usage of the SqlReader inside the loop!
Then, change your comparison code to:
C#
try
    {
    conn.Open();
    using (SqlCeCommand command = new SqlCeCommand(query, conn))
        {
        r = command.ExecuteReader();
        DateTime now = DateTime.Now;
        while (r.Read())
            {
            DateTime tag = r.GetDateTime(0);
            if (tag <= now)
                }
                MessageBox.Show("You have a reminder at this moment");
                }
            }
        }
    conn.Close(); 
    }
catch (Exception ex)
    { 
    MessageBox.Show(ex.Message.ToString());
    }
 
Share this answer
 
Comments
Abdul Rahman BCS 4-Jun-15 23:40pm    
I have created a column in my table named popup(data type : bit)
After reminding an event how can i mark the event reminded so that it does not retrieved again to chck for events?
please help me. I am still stuck.

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