Beispiel #1
0
        public void AddEvent(Event evnt)
        {
            Names.Add(evnt.Name);
            Guids.Add(evnt.Guid);
            List <YearEvents> collection = evnt.IsPast ? CallendarPast : CallendarActive;
            YearEvents        year       = collection.Where(i => i.Year == evnt.Date.Year).FirstOrDefault();

            if (year == null)
            {
                var last = collection.LastOrDefault();
                if (last == null)
                {
                    collection.Add(new YearEvents(evnt));
                    return;
                }
                foreach (var y in collection)
                {
                    if (evnt.Date.Year < y.Year)
                    {
                        collection.Insert(collection.IndexOf(y), new YearEvents(evnt));
                        return;
                    }
                    else if (last == y)
                    {
                        collection.Add(new YearEvents(evnt));
                        break;
                    }
                }
            }
            else
            {
                year.AddSorted(evnt);
            }
        }
Beispiel #2
0
        public static Page GetActivePage(Event evnt = null)
        {
            List <YearEvents> years;
            State             state;

            if (State.MenuSelected == MenuSelection.Scheduled)
            {
                years = Storage.CallendarActive;
                state = State.ActiveEvents;
            }
            else
            {
                years = Storage.CallendarPast;
                state = State.PastEvents;
            }
            switch (state.Page)
            {
            case PageActive.Years:
                return(new YearList(years));

            case PageActive.Months:
                YearEvents year = years.Where(i => i.Year == state.Year).FirstOrDefault();
                if (year == null)
                {
                    State.ActivePage = PageActive.Years;
                    return(new YearList(years));
                }
                else
                {
                    return(new MonthList(year));
                }

            case PageActive.Events:
                YearEvents y = years.Where(i => i.Year == state.Year).FirstOrDefault();
                if (y == null)
                {
                    State.ActivePage = PageActive.Years;
                    return(new YearList(years));
                }
                else
                {
                    MonthEvents month = y.Months.Where(i => i.Month == state.Month).FirstOrDefault();
                    if (month == null)
                    {
                        State.ActivePage = PageActive.Months;
                        return(new MonthList(y));
                    }
                    else
                    {
                        return(evnt == null ? new EventList(month) : new EventList(month, evnt));
                    }
                }

            default: return(null);
            }
        }
        private void List_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            YearEvents sel = e.AddedItems.FirstOrDefault() as YearEvents;

            if (sel != null)
            {
                App.State.Year       = sel.Year;
                App.State.ActivePage = PageActive.Months;
                App.Cont.Content     = new MonthList(sel);
            }
        }
Beispiel #4
0
        public async Task <bool> RemoveAsync(params Event[] evnts)
        {
            StorageFile xml = await ApplicationData.Current.LocalFolder.GetFileAsync("data.xml");

            XmlDocument doc = await XmlDocument.LoadFromFileAsync(xml);

            List <YearEvents> collection = evnts[0].IsPast ? CallendarPast : CallendarActive;
            YearEvents        year       = collection.Where(i => i.Year == evnts[0].Date.Year).FirstOrDefault();
            MonthEvents       month      = year.Months.Where(i => i.Month == evnts[0].Date.Month).FirstOrDefault();

            foreach (Event evnt in evnts)
            {
                if (!evnt.IconPath.AbsoluteUri.StartsWith("ms-appx"))
                {
                    await(await StorageFile.GetFileFromApplicationUriAsync(evnt.IconPath)).DeleteAsync();
                }
                if (evnt.MediaMessageType != MediaMessageType.None)
                {
                    await(await StorageFile.GetFileFromApplicationUriAsync(evnt.MediaMessageUri)).DeleteAsync();
                }
                if (evnt.HasStroke)
                {
                    await(await(await ApplicationData.Current.LocalFolder.
                                GetFolderAsync("Inks")).GetFileAsync(evnt.Guid.ToString() + ".gif")).DeleteAsync();
                }
                var root = doc.FirstChild;
                foreach (var enode in root.ChildNodes)
                {
                    if (enode.FirstChild.InnerText == evnt.Guid.ToString())
                    {
                        root.RemoveChild(enode);
                        break;
                    }
                }
                Names.Remove(evnt.Name);
                Guids.Remove(evnt.Guid);
                if (evnt.Alarm != null)
                {
                    var notifier = ToastNotificationManager.CreateToastNotifier();
                    var notifs   = notifier.GetScheduledToastNotifications();
                    var notif    = notifs.Where(i => i.DeliveryTime == evnt.Alarm.Value).FirstOrDefault();
                    if (notif != null)
                    {
                        notifier.RemoveFromSchedule(notif);
                    }
                }
                month.Events.Remove(evnt);
            }
            await doc.SaveToFileAsync(xml);

            if (month.Events.Count > 0)
            {
                return(false);
            }
            else
            {
                year.Months.Remove(month);
                if (year.Months.Count > 0)
                {
                    App.State.ActivePage = PageActive.Months;
                    return(true);
                }
                else
                {
                    collection.Remove(year);
                    App.State.ActivePage = PageActive.Years;
                    return(true);
                }
            }
        }
Beispiel #5
0
 public MonthList(YearEvents evnt)
 {
     Year = evnt;
     this.InitializeComponent();
 }