Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am referring to the article:
[Calendar.NET]

This is my code
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 21-Sep-12 0:39am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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. Smile | :)

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 Smile | :)

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

Hope it has helped you.
Regards
Tushar Srivastava
  Permalink  
Comments
Member 9446578 at 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!
Tushar Sriv at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 229
1 OriginalGriff 225
2 Suvendu Shekhar Giri 205
3 PIEBALDconsult 180
4 Peter Leow 135
0 Sergey Alexandrovich Kryukov 6,434
1 OriginalGriff 6,033
2 Peter Leow 2,534
3 Maciej Los 2,268
4 Abhinav S 2,264


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100