protected override ViewItemHomework CreateItem(DataItemMegaItem dataItem, ViewItemClass c)
 {
     return(new ViewItemHomework(dataItem)
     {
         Class = c
     });
 }
 protected override ViewItemExam CreateItem(DataItemMegaItem dataItem, ViewItemClass c)
 {
     return(new ViewItemExam(dataItem)
     {
         Class = c
     });
 }
Beispiel #3
0
        public static BaseArguments CreateArgumentsForView(DataItemMegaItem item, Guid localAccountId, LaunchSurface launchSurface = LaunchSurface.Normal)
        {
            BaseArgumentsWithAccountAndItem args;

            if (item.MegaItemType == PowerPlannerSending.MegaItemType.Homework)
            {
                args = new ViewHomeworkArguments();
            }

            else if (item.MegaItemType == PowerPlannerSending.MegaItemType.Exam)
            {
                args = new ViewExamArguments();
            }

            else
            {
                return new OpenAccountArguments()
                       {
                           LocalAccountId = localAccountId
                       }
            };

            args.LocalAccountId = localAccountId;
            args.ItemId         = item.Identifier;
            args.LaunchSurface  = launchSurface;

            return(args);
        }
Beispiel #4
0
 /// <summary>
 /// Assumes item has already been filtered (date and class)
 /// </summary>
 /// <param name="i"></param>
 private void Add(DataItemMegaItem i)
 {
     if (i.MegaItemType == PowerPlannerSending.MegaItemType.Homework)
     {
         var viewItem = CreateHomework(i);
         AssignClass(i, viewItem);
         if (viewItem.Class == null)
         {
             TelemetryExtension.Current?.TrackException(new NullReferenceException("CalendarViewItemsGroup: Class for homework couldn't be found"));
             return;
         }
         Items.InsertSorted(viewItem);
     }
     else if (i.MegaItemType == PowerPlannerSending.MegaItemType.Exam)
     {
         var viewItem = CreateExam(i);
         AssignClass(i, viewItem);
         if (viewItem.Class == null)
         {
             TelemetryExtension.Current?.TrackException(new NullReferenceException("CalendarViewItemsGroup: Class for exam couldn't be found"));
             return;
         }
         Items.InsertSorted(viewItem);
     }
     else if (i.MegaItemType == PowerPlannerSending.MegaItemType.Task)
     {
         var viewItem = CreateTask(i);
         AssignClass(i, viewItem);
         Items.InsertSorted(viewItem);
     }
 }
 protected override ViewItemTaskOrEvent CreateItem(DataItemMegaItem dataItem, ViewItemClass c)
 {
     return(new ViewItemTaskOrEvent(dataItem)
     {
         Class = c
     });
 }
Beispiel #6
0
        protected override void PopulateFromDataItemOverride(BaseDataItem dataItem)
        {
            base.PopulateFromDataItemOverride(dataItem);

            DataItemMegaItem i = dataItem as DataItemMegaItem;

            PercentComplete = i.PercentComplete;
        }
        /// <summary>
        /// Assumes item has already been filtered (date and class)
        /// </summary>
        /// <param name="h"></param>
        private void Add(DataItemMegaItem i)
        {
            BaseViewItemHomeworkExam viewItem = i.CreateViewItemTaskOrEvent(_semester);

            if (viewItem != null && !viewItem.IsComplete())
            {
                Add(viewItem);
            }
        }
Beispiel #8
0
 private bool IsUnassignedChild(DataItemMegaItem item)
 {
     // It's a child if it's a child of this class and weight category is unassiged OR weight category not found
     return(item.UpperIdentifier == _classId &&
            (item.MegaItemType == PowerPlannerSending.MegaItemType.Exam || item.MegaItemType == PowerPlannerSending.MegaItemType.Homework) &&
            item.WeightCategoryIdentifier != PowerPlannerSending.BaseHomeworkExam.WEIGHT_CATEGORY_EXCLUDED &&
            (item.WeightCategoryIdentifier == PowerPlannerSending.BaseHomeworkExam.WEIGHT_CATEGORY_UNASSIGNED ||
             !this.Class.WeightCategories.Any(i => i.Identifier == item.WeightCategoryIdentifier)));
 }
        /// <summary>
        /// Assumes item has already been filtered (date and class)
        /// </summary>
        /// <param name="h"></param>
        private void Add(DataItemMegaItem i)
        {
            ViewItemTaskOrEvent viewItem = i.CreateViewItemTaskOrEvent(_semester);

            if (viewItem != null && !viewItem.IsComplete)
            {
                Add(viewItem);
            }
        }
 private ViewItemTaskOrEvent CreateItem(DataItemMegaItem dataItem)
 {
     if (dataItem.IsTaskOrEvent())
     {
         return(new ViewItemTaskOrEvent(dataItem));
     }
     else
     {
         throw new NotImplementedException("Wasn't any of expected types");
     }
 }
 private void AssignClass(DataItemMegaItem data, ViewItemTaskOrEvent view)
 {
     if (data.MegaItemType == PowerPlannerSending.MegaItemType.Task || data.MegaItemType == PowerPlannerSending.MegaItemType.Event)
     {
         view.Class = _semester.NoClassClass;
     }
     else
     {
         view.Class = _semester.Classes.First(i => i.Identifier == data.UpperIdentifier);
     }
 }
        /// <summary>
        /// Assumes item has already been filtered (date and class)
        /// </summary>
        /// <param name="i"></param>
        private void Add(DataItemMegaItem i)
        {
            var viewItem = new ViewItemTaskOrEvent(i);

            AssignClass(i, viewItem);
            if (viewItem.Class == null)
            {
                TelemetryExtension.Current?.TrackException(new NullReferenceException("CalendarViewItemsGroup: Class for TaskOrEvent couldn't be found"));
                return;
            }
            Items.InsertSorted(viewItem);
        }
        /// <summary>
        /// Assumes item has already been filtered
        /// </summary>
        /// <param name="h"></param>
        private void Add(DataItemMegaItem i)
        {
            ViewItemTaskOrEvent taskOrExam = i.CreateViewItemTaskOrEvent(Semester);

            if (taskOrExam != null)
            {
                Items.Add(taskOrExam);
            }
            else if (i.MegaItemType == PowerPlannerSending.MegaItemType.Holiday)
            {
                var viewItem = CreateHoliday(i);
                Items.Add(viewItem);
            }
        }
Beispiel #14
0
 private BaseViewItemHomeworkExam CreateHomeworkOrExam(DataItemMegaItem dataHomework)
 {
     if (dataHomework.MegaItemType == PowerPlannerSending.MegaItemType.Homework)
     {
         return(new ViewItemHomework(dataHomework));
     }
     else if (dataHomework.MegaItemType == PowerPlannerSending.MegaItemType.Exam)
     {
         return(new ViewItemExam(dataHomework));
     }
     else
     {
         throw new NotImplementedException("Unknown type: " + dataHomework.MegaItemType);
     }
 }
Beispiel #15
0
 private BaseViewItemHomeworkExam CreateItem(DataItemMegaItem dataItem)
 {
     if (dataItem.MegaItemType == PowerPlannerSending.MegaItemType.Homework)
     {
         return(CreateHomework(dataItem));
     }
     else if (dataItem.MegaItemType == PowerPlannerSending.MegaItemType.Exam)
     {
         return(CreateExam(dataItem));
     }
     else if (dataItem.MegaItemType == PowerPlannerSending.MegaItemType.Task)
     {
         return(CreateTask(dataItem));
     }
     else
     {
         throw new NotImplementedException("Wasn't any of expected types");
     }
 }
Beispiel #16
0
        protected override void PopulateFromDataItemOverride(BaseDataItem dataItem)
        {
            base.PopulateFromDataItemOverride(dataItem);

            DataItemMegaItem i = dataItem as DataItemMegaItem;

            if (i.EndTime == PowerPlannerSending.DateValues.UNASSIGNED)
            {
                EndTime = i.EndTime;
            }
            else
            {
                EndTime = DateTime.SpecifyKind(i.EndTime, DateTimeKind.Local);
            }

            // TODO: I probably need to do a similar local conversion for Reminder too when I start using it
            Reminder = i.Reminder;
            WeightCategoryIdentifier = i.WeightCategoryIdentifier;

#if ANDROID
            HasSentReminder = i.HasSentReminder;
#endif
        }
        public async Task HandleViewHolidayActivation(Guid localAccountId, Guid holidayId)
        {
            DataItemMegaItem holiday = await Task.Run(async delegate
            {
                using (await Locks.LockDataForReadAsync("HandleViewHolidayActivation"))
                {
                    var dataStore = await AccountDataStore.Get(localAccountId);
                    if (dataStore == null)
                    {
                        return(null);
                    }

                    return(dataStore.TableMegaItems.FirstOrDefault(i =>
                                                                   i.MegaItemType == PowerPlannerSending.MegaItemType.Holiday &&
                                                                   i.Identifier == holidayId));
                }
            });

            if (holiday != null)
            {
                var holidayDate         = DateTime.SpecifyKind(holiday.Date, DateTimeKind.Local);
                var desiredDisplayMonth = holidayDate;
                var mainScreen          = GetMainScreenViewModel();
                if (mainScreen != null && mainScreen.CurrentAccount != null && mainScreen.CurrentAccount.LocalAccountId == localAccountId && mainScreen.Content is CalendarViewModel)
                {
                    (mainScreen.Content as CalendarViewModel).DisplayMonth = desiredDisplayMonth;
                    (mainScreen.Content as CalendarViewModel).SelectedDate = holidayDate;
                }
                else
                {
                    NavigationManager.SetDisplayMonth(desiredDisplayMonth);
                    NavigationManager.SetSelectedDate(holidayDate);
                    await HandleSelectMenuItemActivation(localAccountId, NavigationManager.MainMenuSelections.Calendar);
                }
            }
        }
 protected abstract ViewItemTaskOrEvent CreateItem(DataItemMegaItem dataItem, ViewItemClass c);
 private bool ShouldIncludeItem(DataItemMegaItem i, Guid[] classIdentifiers, DateTime todayAsUtc)
 {
     return(ShouldIncludeItemFunction(classIdentifiers, todayAsUtc).Invoke(i));
 }
Beispiel #20
0
 private ViewItemHomework CreateHomework(DataItemMegaItem h)
 {
     return(new ViewItemHomework(h));
 }
Beispiel #21
0
 private ViewItemExam CreateExam(DataItemMegaItem e)
 {
     return(new ViewItemExam(e));
 }
Beispiel #22
0
        private DataItemMegaItem CreateDataItem(DateTime date)
        {
            DataItemMegaItem dataItem = new DataItemMegaItem();

            switch (Type)
            {
            case TaskOrEventType.Event:
                if (Class.IsNoClassClass)
                {
                    dataItem.MegaItemType = PowerPlannerSending.MegaItemType.Event;
                }
                else
                {
                    dataItem.MegaItemType = PowerPlannerSending.MegaItemType.Exam;
                }
                break;

            case TaskOrEventType.Task:
                if (Class.IsNoClassClass)
                {
                    dataItem.MegaItemType = PowerPlannerSending.MegaItemType.Task;
                }
                else
                {
                    dataItem.MegaItemType = PowerPlannerSending.MegaItemType.Homework;
                }
                break;

            default:
                throw new NotImplementedException("Unknown type");
            }

            if (AddParams != null)
            {
                dataItem.Identifier = Guid.NewGuid();
            }

            else
            {
                dataItem.Identifier = EditParams.Item.Identifier;
            }

            dataItem.Name    = Name;
            dataItem.Date    = DateTime.SpecifyKind(date, DateTimeKind.Utc).Date;
            dataItem.Details = Details.Trim();

            dataItem.UpperIdentifier = Class.Identifier;
            if (Class.IsNoClassClass)
            {
                dataItem.WeightCategoryIdentifier = Guid.Empty;
            }
            else
            {
                dataItem.WeightCategoryIdentifier = SelectedWeightCategory.Identifier;
            }

            // 00 seconds represents default
            // - Task: Start of class
            // - Event
            //   - If no end time: During class
            //   - Otherwise
            //     - If end time is 23:59:59: All day
            //     - Else: Custom time

            // 01 seconds represents
            // - Task: Before class

            // 02 seconds represents
            // - Task: During class (currently not supported, might add in future)

            // 03 seconds represents
            // - Task: End of class

            // 04 seconds represents
            // - Task: Custom time

            // 23:59:59 represents
            // - Task: End of day

            switch (Type)
            {
            case TaskOrEventType.Task:
                if (SelectedTimeOption == TimeOption_BeforeClass)
                {
                    dataItem.Date = dataItem.Date.AddSeconds(1);
                }
                else if (SelectedTimeOption == TimeOption_DuringClass)
                {
                    dataItem.Date = dataItem.Date.AddSeconds(2);
                }
                else if (SelectedTimeOption == TimeOption_EndOfClass)
                {
                    dataItem.Date = dataItem.Date.AddSeconds(3);
                }
                else if (SelectedTimeOption == TimeOption_Custom)
                {
                    dataItem.Date = dataItem.Date.Add(StartTime).AddSeconds(4);
                }
                else if (SelectedTimeOption == TimeOption_AllDay)
                {
                    dataItem.Date = dataItem.Date.AddDays(1).AddSeconds(-1);
                }
                else     /* Start of class */
                {
                }
                break;

            case TaskOrEventType.Event:
                if (SelectedTimeOption == TimeOption_Custom)
                {
                    dataItem.Date    = dataItem.Date.Add(StartTime);
                    dataItem.EndTime = dataItem.Date.Date.Add(EndTime);
                }
                else if (SelectedTimeOption == TimeOption_AllDay)
                {
                    dataItem.EndTime = dataItem.Date.AddDays(1).AddSeconds(-1);
                }
                else     /* during class */
                {
                    dataItem.EndTime = PowerPlannerSending.DateValues.UNASSIGNED;
                }
                break;
            }

            dataItem.ImageNames = ImageNames;

            return(dataItem);
        }
Beispiel #23
0
 private ViewItemHomework CreateTask(DataItemMegaItem i)
 {
     return(new ViewItemHomework(i));
 }
 private bool IsHomeworkOrExamChild(DataItemMegaItem dataChild)
 {
     return((dataChild.MegaItemType == MegaItemType.Homework || dataChild.MegaItemType == MegaItemType.Homework) &&
            dataChild.UpperIdentifier == Identifier);
 }
 protected abstract TViewItem CreateItem(DataItemMegaItem dataItem, ViewItemClass c);
Beispiel #26
0
 public BaseViewItemHomeworkExam(DataItemMegaItem dataItem) : base(dataItem)
 {
 }
Beispiel #27
0
        public async void Save()
        {
            try
            {
                if (!AreWeightsValid())
                {
                    await new PortableMessageDialog(PowerPlannerResources.GetString("String_InvalidWeightCategoriesMessageBody"), PowerPlannerResources.GetString("String_InvalidWeightCategoriesMessageHeader")).ShowAsync();
                    return;
                }

                DataChanges changes = new DataChanges();

                // Process weight category changes
                List <EditingWeightCategoryViewModel> newWeights = new List <EditingWeightCategoryViewModel>(WeightCategories);

                List <BaseViewItemMegaItem> lostGrades = new List <BaseViewItemMegaItem>();

                //handle weights that were deleted
                foreach (ViewItemWeightCategory existing in Class.WeightCategories)
                {
                    //if that existing weight isn't in the new weights list
                    if (!newWeights.Any(i => i.Identifier == existing.Identifier))
                    {
                        //mark it for deletion
                        changes.DeleteItem(existing.Identifier);

                        //add all of its grades to the lost grades
                        lostGrades.AddRange(existing.Grades);
                    }
                }

                //if there aren't any weights, need to add the default All Grades
                if (newWeights.Count == 0)
                {
                    newWeights.Add(new EditingWeightCategoryViewModel()
                    {
                        Name   = PowerPlannerResources.GetString("WeightCategory_AllGrades"),
                        Weight = 100
                    });
                }

                Guid firstCategory = newWeights.First().Identifier;

                //strip away any existing weight categories that didn't change
                foreach (EditingWeightCategoryViewModel newWeight in newWeights.ToArray())
                {
                    ViewItemWeightCategory existing = Class.WeightCategories.FirstOrDefault(i => i.Identifier == newWeight.Identifier);

                    if (existing != null)
                    {
                        //if the name and/or value didn't change, we'll remove it from the main list
                        if (existing.Name.Equals(newWeight.Name) && existing.WeightValue == newWeight.Weight)
                        {
                            newWeights.Remove(newWeight);
                        }
                    }
                }

                //and now process the new/changed weights
                foreach (EditingWeightCategoryViewModel changed in newWeights)
                {
                    DataItemWeightCategory w;

                    ViewItemWeightCategory existing = Class.WeightCategories.FirstOrDefault(i => i.Identifier == changed.Identifier);

                    //if existing, serialize
                    if (existing != null)
                    {
                        w = new DataItemWeightCategory()
                        {
                            Identifier = existing.Identifier
                        }
                    }
                    ;

                    else
                    {
                        w = new DataItemWeightCategory()
                        {
                            Identifier      = Guid.NewGuid(),
                            UpperIdentifier = Class.Identifier
                        };

                        //if we didn't have a first category yet
                        if (firstCategory == Guid.Empty)
                        {
                            firstCategory = w.Identifier;
                        }
                    }

                    w.Name        = changed.Name;
                    w.WeightValue = changed.Weight;

                    changes.Add(w);
                }

                // And then move the lost grades into the first available weight category
                foreach (var lostGrade in lostGrades.OfType <ViewItemGrade>())
                {
                    DataItemGrade g = new DataItemGrade()
                    {
                        Identifier = lostGrade.Identifier
                    };

                    g.UpperIdentifier = firstCategory;

                    changes.Add(g);
                }
                foreach (var lostGrade in lostGrades.OfType <ViewItemTaskOrEvent>())
                {
                    DataItemMegaItem g = new DataItemMegaItem()
                    {
                        Identifier = lostGrade.Identifier
                    };

                    g.WeightCategoryIdentifier = firstCategory;

                    changes.Add(g);
                }

                TryStartDataOperationAndThenNavigate(delegate
                {
                    return(PowerPlannerApp.Current.SaveChanges(changes));
                }, delegate
                {
                    this.RemoveViewModel();
                });
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
                await new PortableMessageDialog("Error encountered while saving. Your error report has been sent to the developer.", "Error").ShowAsync();
            }
        }
Beispiel #28
0
 internal ViewItemHomework(DataItemMegaItem dataItem) : base(dataItem)
 {
     base.PropertyChanged += ViewItemHomework_PropertyChanged;
 }
        public async void Save()
        {
            try
            {
                string name = Name;

                if (string.IsNullOrWhiteSpace(name))
                {
                    await new PortableMessageDialog(PowerPlannerResources.GetStringNoNameMessageBody(), PowerPlannerResources.GetStringNoNameMessageHeader()).ShowAsync();
                    return;
                }

                DataItemMegaItem holiday;

                if (HolidayToEdit != null)
                {
                    holiday = new DataItemMegaItem()
                    {
                        Identifier = HolidayToEdit.Identifier
                    }
                }
                ;

                else if (AddParams != null)
                {
                    holiday = new DataItemMegaItem()
                    {
                        Identifier      = Guid.NewGuid(),
                        UpperIdentifier = AddParams.SemesterIdentifier,
                        MegaItemType    = PowerPlannerSending.MegaItemType.Holiday
                    }
                }
                ;

                else
                {
                    throw new NullReferenceException("Either editing holiday or add holiday param must be initialized.");
                }

                holiday.Name = name;

                holiday.Date = DateTime.SpecifyKind(StartDate.Date, DateTimeKind.Utc);

                if (!SqlDate.IsValid(holiday.Date))
                {
                    holiday.Date = DateTime.Today;
                }

                holiday.EndTime = DateTime.SpecifyKind(EndDate.Date, DateTimeKind.Utc);
                holiday.EndTime = holiday.EndTime.AddDays(1).AddSeconds(-1);

                if (!SqlDate.IsValid(holiday.EndTime))
                {
                    holiday.EndTime = DateTime.Today;
                }



                if (holiday.Date > holiday.EndTime)
                {
                    await new PortableMessageDialog(PowerPlannerResources.GetString("EditSemesterPage_String_StartDateGreaterThanEndExplanation"), PowerPlannerResources.GetString("EditSemesterPage_String_InvalidStartDate")).ShowAsync();
                    return;
                }

                DataChanges changes = new DataChanges();
                changes.Add(holiday);

                TryStartDataOperationAndThenNavigate(async delegate
                {
                    await PowerPlannerApp.Current.SaveChanges(changes);
                }, delegate
                {
                    this.RemoveViewModel();
                });
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);
            }
        }
 private bool ShouldIncludeItem(DataItemMegaItem i, Guid[] classIdentifiers, DateTime start, DateTime end)
 {
     return(ShouldIncludeItemFunction(classIdentifiers, start, end).Invoke(i));
 }