Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am referring to the article:
[Calendar.NET]

This is my code
C#
public viewCalendar(String firstIntake, String nextIntake, String lastIntake, String days, String medName, String dosageCount)
        {
            InitializeComponent();
            calendar1.CalendarDate = DateTime.Now;
            calendar1.CalendarView = CalendarViews.Month;

            lblHiddenDays.Text = days;

                var takeMed1 = new CustomEvent
                {
                    Date = DateTime.Parse(firstIntake),
                    EventText = "Take " + dosageCount + " of " + medName,
                    EventFont = new Font("Verdana", 8, FontStyle.Regular),
                    EventColor = Color.LightBlue,
                    EventTextColor = Color.Black,
                    Rank = 1,
                    ThisDayForwardOnly= true,
                    RecurringFrequency = RecurringFrequencies.EveryTueThurs
                    //CustomRecurringFunction = IntakeDays
                };

                var takeMed2 = new CustomEvent
                {
                    Date = DateTime.Parse(nextIntake),
                    EventText = "Take " + dosageCount + " of " + medName,
                    EventFont = new Font("Verdana", 8, FontStyle.Regular),
                    EventColor = Color.LightGoldenrodYellow,
                    EventTextColor = Color.Black,
                    Rank = 2,
                    ThisDayForwardOnly = true,
                    RecurringFrequency = RecurringFrequencies.EveryTueThurs
                    //CustomRecurringFunction = IntakeDays
                };

                var takeMed3 = new CustomEvent
                {
                    Date = DateTime.Parse(lastIntake),
                    EventText = "Take " + dosageCount + " of " + medName,
                    EventFont = new Font("Verdana", 8, FontStyle.Regular),
                    EventColor = Color.LightPink,
                    EventTextColor = Color.Black,
                    Rank = 3,
                    ThisDayForwardOnly = true,
                    RecurringFrequency = RecurringFrequencies.EveryTueThurs
                    //CustomRecurringFunction = IntakeDays
                };

                calendar1.AddEvent(takeMed1);
                calendar1.AddEvent(takeMed2);
                calendar1.AddEvent(takeMed3); 
        }

     /*   [CustomRecurringFunction("IntakeDays", "Calculates how many days the medicine has to be taken for")]
        private bool IntakeDays(IEvent evnt, DateTime day)
        {
            for (int i =+ 0; i<int.Parse(lblHiddenDays.Text); i++)
            {
                return true;
            }
            return false;
        }
        */


The calendar creates a schedule on when i should take the medicine.
It is first passed in from another form.
So for instance, my firstIntake is 10AM, nextIntake is 4pm and lastIntake is 10pm
I have no problem displaying that with the code above.

However, I passed in "days" from my previous form and that variable stores the number of days these events has to span across. Let's say "days" = 7

The takeMed1 event will be at 9/21/2012, 10AM
The takeMed2 event will be at 9/21/2012, 4PM
the takeMed3 event will be at 9/21/2012, 10PM

So if "days" = 7, each event will span from 9/21/2012 to 9/28/2012

I have no idea how to do this for the recurring function. Anyone help?
Posted

I would suggest you address the author of the article you referenced in this question. Load the article text, locate the section "Comments and Discussions" at the end and click "Add a Comment or Question" to add your question. The author get the notification of your post and a chance to reply.

Good luck,
—SA
 
Share this answer
 
Hi Friend,
I seriously have no idea about how you are going to approach this, but I have few points that can be followed in order to do so.. I am sure it can help you a lot.

1. Since you want a recurring function that can recur every day at specific time, you can simply make an external thread. This thread will continuously monitor the current time and date and compare it with the time provided by you. (But it is very poor method since it will continuously run in background and waste CPU memory, can it be possible to use some user interrupt?) Byt the way it is the only method that I can think of right now. :-)

2. Now whenever this thread found that event can occur, ie the time set by you matches, it will invoke the function to handle it :-)

3. Now if you need any help regarding how to implement these two steps, you can ask me :-)

Hope it has helped you.
Regards
Tushar Srivastava
 
Share this answer
 
Comments
Member 9446578 22-Sep-12 2:53am    
<pre lang="c#"> [CustomRecurringFunction("IntakeDays", "Calculates how many days the medicine has to be taken for")]
private bool IntakeDays(IEvent evnt, DateTime day)
{

DateTime firstCondition = DateTime.Parse(lblHiddenFirstIntake.Text);
DateTime secondCondition = DateTime.Parse(lblHiddenFirstIntake.Text).AddDays(double.Parse(lblHiddenDays.Text));

while (firstCondition < secondCondition)
{
firstCondition = firstCondition.AddDays(1);
return true;
}
return false;
}</pre>

I tried doing this but the date keeps looping back to the original date. I believe this will work!
Er. Tushar Srivastava 22-Sep-12 10:00am    
The function seems to be good, I tried this
<pre lang="C#">
private void mytest()
{
DateTime myday = DateTime.Parse(label1.Text);
DateTime myevent = DateTime.Parse(label1.Text).AddDays(double.Parse(label2.Text));
if(myday < myevent)
MessageBox.Show(myevent.ToString());
}
</pre>

The result was, from today, 29-09-2012 PM 05:00:00 when I set the value of days equals 7 in label2 and 22-09-2012 PM 05:00 in label1.
Now this means that the function is working fine.
So, the code must work correctly, now if it is looping back to it's initial date then you can use this code and test it also,
<pre lang="c#">
private void mytest()
{
DateTime currday = DateTime.Now;
DateTime myday = DateTime.Parse(label1.Text);
DateTime myevent = DateTime.Parse(label1.Text).AddDays(double.Parse(label2.Text));

if (currday < myevent)
MessageBox.Show(myevent.ToString());
}
</pre>

ie. Instead of comparing it to the date already saved inside label, compare it with current date :-) Hope it helped you.

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