コード例 #1
0
ファイル: EditPage.xaml.cs プロジェクト: PPalac/Reminder_beta
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var indeks = e.Parameter as string;

            App.indeks1 = indeks;

            ReminderData Data = new ReminderData();

            Data = App.ListOfData[int.Parse(indeks)];
            WhatToRemind.Text     = Data.Name;
            Quantity.Text         = Data.Quantity.ToString();
            UnitBox.SelectedIndex = Data.Unit;      //     TODO: Unitbox selected item when on edit page!!
            TimePicker.Time       = Data.Time;
            if (Data.afterMeal == true)
            {
                AfterMeal.IsChecked = true;
            }
            if (Data.beforeMeal == true)
            {
                BeforeMeal.IsChecked = true;
            }

            foreach (DayOfWeek element in Data.WeekDays)
            {
                switch (element)
                {
                case DayOfWeek.Monday:
                    Monday.IsChecked = true;
                    break;

                case DayOfWeek.Tuesday:
                    Tuesday.IsChecked = true;
                    break;

                case DayOfWeek.Wednesday:
                    Wednesday.IsChecked = true;
                    break;

                case DayOfWeek.Thursday:
                    Thursday.IsChecked = true;
                    break;

                case DayOfWeek.Friday:
                    Friday.IsChecked = true;
                    break;

                case DayOfWeek.Saturday:
                    Saturday.IsChecked = true;
                    break;

                case DayOfWeek.Sunday:
                    Sunday.IsChecked = true;
                    break;
                }
            }
        }
コード例 #2
0
        public void setEverything(ReminderData DataFromList)
        {
            DateTime  now = DateTime.Now;
            DayOfWeek day = now.DayOfWeek;

            Data = DataFromList;
            foreach (DayOfWeek element in DataFromList.WeekDays)
            {
                DateAndTime = DateTimeOffset.Now;
                DateAndTime = DateAndTime.AddSeconds(-DateAndTime.Second);
                int i = day.CompareTo(element);
                if (i == -1)
                {
                    DateAndTime = DateAndTime.AddDays(element - day);
                }
                else
                {
                    if (i == 1)
                    {
                        DateAndTime = DateAndTime.AddDays(7 - (day - element));
                    }
                    else
                    {
                        if (DataFromList.Time.Hours <= now.Hour && DataFromList.Time.Minutes <= now.Minute)
                        {
                            DateAndTime = DateAndTime.AddDays(7);
                        }
                    }
                }
                if (DataFromList.Time.Hours.CompareTo(now.Hour) == -1)
                {
                    DateAndTime = DateAndTime.AddHours(DataFromList.Time.Hours - now.Hour);
                }
                else
                {
                    if (DataFromList.Time.Hours.CompareTo(now.Hour) == 1)
                    {
                        DateAndTime = DateAndTime.AddHours(DataFromList.Time.Hours - now.Hour);
                    }
                    //  else
                    //   {
                    //     DateAndTime = DateAndTime.AddHours(DataFromList.Time.Hours);
                    //  }
                }

                if (DataFromList.Time.Minutes.CompareTo(now.Minute) == -1)
                {
                    DateAndTime = DateAndTime.AddMinutes(DataFromList.Time.Minutes - now.Minute);
                }
                else
                {
                    if (DataFromList.Time.Minutes.CompareTo(now.Minute) == 1)
                    {
                        DateAndTime = DateAndTime.AddMinutes(DataFromList.Time.Minutes - now.Minute);
                    }
                    else
                    {
                        DateAndTime = DateAndTime.AddMinutes(DataFromList.Time.Minutes);
                    }
                }
                CreateScheduledNotification();
            }
        }
コード例 #3
0
        private async void button_Click(object sender, RoutedEventArgs e)

        {
            Frame            rootFrame    = Window.Current.Content as Frame;
            List <DayOfWeek> weekdays     = new List <DayOfWeek>();
            TimeSpan         SelectedTime = new TimeSpan();

            weekdays = selectedDays();
            bool beforemeal;
            bool aftermeal;

            if (AfterMeal.IsChecked == true)
            {
                aftermeal = true;
            }
            else
            {
                aftermeal = false;
            }
            if (BeforeMeal.IsChecked == true)
            {
                beforemeal = true;
            }
            else
            {
                beforemeal = false;
            }
            SelectedTime = SelectedTime.Add(TimePicker.Time);

            try
            {
                if (weekdays.Count() == 0)
                {
                    throw new CustomException();
                }
                else
                {
                    ReminderData Data = new ReminderData(WhatToRemind.Text, beforemeal, aftermeal, int.Parse(Quantity.Text), UnitBox.SelectedIndex, SelectedTime, weekdays);

                    App.ListOfData.Add(Data);
                    bool check = await SaveMyData(App.ListOfData);



                    ScheduledNotification toast = new ScheduledNotification();
                    toast.setEverything(Data);

                    this.Frame.Navigate(typeof(Reminders));
                    rootFrame.BackStack.Remove(rootFrame.BackStack.Last());
                    rootFrame.BackStack.Remove(rootFrame.BackStack.Last());
                }
            }
            catch (CustomException ex)
            {
                var dialog = new MessageDialog("Select Day", "Error!");
                await dialog.ShowAsync();
            }
            catch
            {
                var dialog = new MessageDialog("Enter Quantity", "Error!");
                await dialog.ShowAsync();
            }
        }
コード例 #4
0
ファイル: EditPage.xaml.cs プロジェクト: PPalac/Reminder_beta
        private async void SetReminderData()
        {
            int indeks = int.Parse(App.indeks1);
            List <DayOfWeek> weekdays     = new List <DayOfWeek>();
            TimeSpan         SelectedTime = new TimeSpan();

            weekdays = selectedDays();
            bool beforemeal;
            bool aftermeal;

            if (AfterMeal.IsChecked == true)
            {
                aftermeal = true;
            }
            else
            {
                aftermeal = false;
            }
            if (BeforeMeal.IsChecked == true)
            {
                beforemeal = true;
            }
            else
            {
                beforemeal = false;
            }
            SelectedTime = SelectedTime.Add(TimePicker.Time);

            // ReminderData Data = new ReminderData(WhatToRemind.Text, beforemeal, aftermeal, int.Parse(Quantity.Text), UnitBox.SelectedIndex, SelectedTime/*TimePicker.Time.Hours, TimePicker.Time.Minutes*/, weekdays);
            //  App.ListOfData[indeks] = Data;
            //   ScheduledNotification toast = new ScheduledNotification();
            //   toast.setEverything(Data);
            try
            {
                if (weekdays.Count() == 0)
                {
                    throw new CustomException();
                }
                else
                {
                    ReminderData Data = new ReminderData(WhatToRemind.Text, beforemeal, aftermeal, int.Parse(Quantity.Text), UnitBox.SelectedIndex, SelectedTime /*TimePicker.Time.Hours, TimePicker.Time.Minutes*/, weekdays);

                    App.ListOfData[indeks] = Data;



                    ScheduledNotification toast = new ScheduledNotification();
                    toast.setEverything(Data);

                    this.Frame.Navigate(typeof(Reminders));
                }
            }
            catch (CustomException ex)
            {
                var dialog = new MessageDialog("Select Day", "Error!");
                await dialog.ShowAsync();
            }
            catch
            {
                var dialog = new MessageDialog("Enter Quantity", "Error!");
                await dialog.ShowAsync();
            }
        }