Example #1
0
        /// <summary>
        /// Creates an object that contains a list with all planned takings for a drug, based on the start- and endtime and the day times where the drug needs to be taken
        /// author: Florian Schnyder
        /// </summary>
        /// <param name="drug">Contanis the drug object for which the taking plan has been created</param>
        /// <param name="takingStart">Startpoint for drug reminder</param>
        /// <param name="takingEnd">Endpoint for a drug reminder, if the enddate is alredy known</param>
        /// <param name="takingDayTime">Contanis the information at which points of the day (morning, lunch, evening, night) the drug should be taken</param>
        /// <param name="takingTime">Contanis the information at what time i have to take the drug</param>
        public TakingPlan(Drug drug, DateTime takingStart, DateTime takingEnd, DayTime takingDayTime, Dictionary<DayTime, DateTime> takingTime)
        {
            this.drug = drug;
            this.takingStart = takingStart;
            this.takingEnd = takingEnd;
            this.takingDayTime = takingDayTime;
            this.takingTime = takingTime;

            //create an XML file with the implemented method
            XmlDocument file = createXML();
            DateTime time = DateTime.Now.AddMinutes(1);

            //add the notificaction to the operating system
            ScheduledToastNotification noti = new ScheduledToastNotification(file, time);
            noti.Id = drug.ToString();
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(noti); 

            //creates daily notifications for the drug if the flag in DayTime is set. At the moment only for one week and without checking the takingEndDate....
            if (drug != null && this.takingStart != null && this.takingStart >= DateTime.Now)
            {
                Settings settings = Settings.Instance;

                //checks if the flag at the specified position is set. If yes, the durg will be added to the realted list
                if (takingDayTime.HasFlag(DayTime.Morning))
                {
                    //create an XML file with the implemented method
                    XmlDocument xml = createXML();

                    //add temporary variable to count one week
                    int temp = 0;

                    //Get the current year, month and day, afterwards, get the needed data form the settings class (just for prototype, afterwards, it will check the drugs own daily taking times)
                    DateTime plannedTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, settings.DefaultMorningTakingTime.Hours, settings.DefaultMorningTakingTime.Minutes, 0);

                    while (temp < 7)
                    {
                        plannedTime = plannedTime.AddDays(1);
                        // add the notification to the operating system
                        ScheduledToastNotification toast = new ScheduledToastNotification(xml, plannedTime);
                        toast.Id = drug.ToString() + temp;
                        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
                        temp++;
                    }

                }

                if (takingDayTime.HasFlag(DayTime.Lunch))
                {
                    //create an XML file with the implemented method
                    XmlDocument xml = createXML();

                    //add temporary variable to count one week
                    int temp = 0;

                    //Get the current year, month and day, afterwards, get the needed data form the settings class (just for prototype, afterwards, it will check the drugs own daily taking times)
                    DateTime plannedTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, settings.DefaultLunchTakingTime.Hours, settings.DefaultLunchTakingTime.Minutes, 0);

                    while (temp < 7)
                    {
                        plannedTime = plannedTime.AddDays(1);
                        // add the notification to the operating system
                        ScheduledToastNotification toast = new ScheduledToastNotification(xml, plannedTime);
                        toast.Id = drug.ToString() + temp;
                        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
                        temp++;
                    }

                }

                if (takingDayTime.HasFlag(DayTime.Evening))
                {
                    //create an XML file with the implemented method
                    XmlDocument xml = createXML();

                    //add temporary variable to count one week
                    int temp = 0;

                    //Get the current year, month and day, afterwards, get the needed data form the settings class (just for prototype, afterwards, it will check the drugs own daily taking times)
                    DateTime plannedTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, settings.DefaultEveningTakingTime.Hours, settings.DefaultEveningTakingTime.Minutes, 0);

                    while (temp < 7)
                    {
                        plannedTime = plannedTime.AddDays(1);
                        // add the notification to the operating system
                        ScheduledToastNotification toast = new ScheduledToastNotification(xml, plannedTime);
                        toast.Id = drug.ToString() + temp;
                        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
                        temp++;
                    }

                }

                if (takingDayTime.HasFlag(DayTime.Night))
                {
                   
                    XmlDocument xml = createXML();

                    //add temporary variable to count one week
                    int temp = 0;

                    //Get the current year, month and day, afterwards, get the needed data form the settings class (just for prototype, afterwards, it will check the drugs own daily taking times)
                    DateTime plannedTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, settings.DefaultNightTakingTime.Hours, settings.DefaultNightTakingTime.Minutes, 0);

                    while (temp < 7)
                    {
                        plannedTime = plannedTime.AddDays(1);
                        // add the notification to the operating system
                        ScheduledToastNotification toast = new ScheduledToastNotification(xml, plannedTime);
                        toast.Id = drug.ToString() + temp;
                        ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
                        temp++;
                    }
                }
            }
        }