Ejemplo n.º 1
0
        /// <summary>
        /// Update the begin cell to make a selection.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void canvas_PointerPressed(object sender, Windows.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
        {
            beginCell = (Canvas)sender;
            beginCell.Background = new SolidColorBrush(new Color() { A = 100, R = 70, B = 180, G = 130 });
            lastColored = beginCell;
            int beginPos = (Grid.GetColumn(beginCell) - 1) * 24 + (Grid.GetRow(beginCell) - 1);
            DateTime begin;
            DateTime end;

            int row = Grid.GetRow(beginCell);
            if (row == 24) row = 23;

            //  begin = Date.AddDays(Grid.GetColumn(beginCell) - 1).AddHours(Grid.GetRow(beginCell));
            // begin= Date.AddDays(Grid.GetColumn(beginCell) - 1);
            begin = Date.AddDays(Grid.GetColumn(beginCell) - 1).AddMinutes(-(Date.Minute)).AddSeconds(-(Date.Second)).AddHours(-(Date.Hour) + row);
            begin.AddHours(Grid.GetRow(beginCell));

            //end = Date.AddDays(Grid.GetColumn(beginCell) - 1).AddHours(Grid.GetRow(beginCell)+1);
            end = Date.AddDays(Grid.GetColumn(beginCell) - 1).AddMinutes(-(Date.Minute)).AddSeconds(-(Date.Second)).AddHours(-(Date.Hour) + row + 1);
            end.AddHours(Grid.GetRow(beginCell));

            GoogleCalendar.Data.Event events = new GoogleCalendar.Data.Event();
            events.Location = "";
            events.Description = "";
            events.Summary = "";
            events.Start = new EventDateTime() { DateTime = begin.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssK") };
            events.End = new EventDateTime() { DateTime = end.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssK") };


            WeekEvent we = new WeekEvent(events);

            AddEvent evtDetail = new AddEvent(we.Evt, Controler, this);
            pop = new Popup()
            {
                Child = evtDetail,
                VerticalOffset = (Window.Current.Bounds.Height - 394) / 2,
                HorizontalOffset = (Window.Current.Bounds.Width - 596) / 2,
                Visibility = Windows.UI.Xaml.Visibility.Visible,
                IsLightDismissEnabled = true,
                IsOpen = true
            };


        }
Ejemplo n.º 2
0
        /// <summary>
        /// Methode qui crée les évènements et les place dans les stackpanel correspondants
        /// </summary>
        /// <param name="e"></param>
        private void createEvent(GoogleCalendar.Data.Event e)
        {
            DateTime time, timeEnd;

            if (!String.IsNullOrEmpty(e.Start.DateTime))
                time = DateTime.Parse(e.Start.DateTime);
            else
                time = DateTime.Parse(e.Start.Date);

            if (!String.IsNullOrEmpty(e.Start.DateTime))
                timeEnd = DateTime.Parse(e.End.DateTime);
            else
                timeEnd = DateTime.Parse(e.End.Date);// format : 2011-11-02T07:00:00+01:00

            //on récupère la colonne de l'evenement
            int col = getCol(time);

            int hour = time.Hour;

            int n = timeEnd.DayOfYear - time.DayOfYear;

            for (int i = 0; i <= n; i++)
            {
                //On créer un user Control et on lui donne l'evenement comme contexte
                WeekEvent we = new WeekEvent(e);

                //on définit l'action a effectuer lors d'un double tap 
                we.DoubleTapped += new Windows.UI.Xaml.Input.DoubleTappedEventHandler(EventDoubleTapped);

                //retourne le stackpanel à l'index spécifié
                StackPanel pan = GetStackPanel(hour, col + i);


                // on définit la ligne où l'on doit ajouter le userControl
                Grid.SetRow(pan, hour);

                //on définit la colonne ou l'on doit ajouter le userControl
                Grid.SetColumn(pan, col + i);

                // si i est différent de n
                if (i != n)
                {
                    // on précise que l'évenement doit prendre plusieurs lignes
                    Grid.SetRowSpan(pan, (24 - hour));
                    hour = 0;
                }
                else
                {   // si l'heure de fin est égale à l'heure de début
                    if (timeEnd.Hour == hour && timeEnd.Minute == time.Minute)
                    {
                        Grid.SetRowSpan(pan, 24);
                    }
                    else if (timeEnd.Hour == hour && timeEnd.Minute != time.Minute)
                    {
                        Grid.SetRowSpan(pan, (timeEnd.Hour - hour + 1));
                    }
                    else
                    {
                        Grid.SetRowSpan(pan, (timeEnd.Hour - hour));
                    }
                }
                Events.Add(we);


                IEnumerable<WeekEvent> collection = pan.Children.OfType<WeekEvent>();

                double width = pan.ActualWidth;

                if (collection.Count() == 1)
                {
                    we.Width = width / 2;
                    foreach (WeekEvent old in collection)
                    {
                        pan.Orientation = Orientation.Horizontal;
                        old.Width = width / 2;
                    }
                }
                else if (collection.Count() == 2)
                {
                    we.Width = width / 3;
                    pan.Orientation = Orientation.Horizontal;
                    foreach (WeekEvent old in collection)
                    {
                        old.Width = width / 3;
                    }
                }
                else if (collection.Count() == 3)
                {
                    we.Width = width / 4;
                    pan.Orientation = Orientation.Horizontal;
                    foreach (WeekEvent old in collection)
                    {
                        old.Width = width / 4;
                    }
                }
                else
                {

                    we.Width = width;
                }
                pan.Children.Add(we);
                LayoutWeek.UpdateLayout();
                layout = this.LayoutWeek;
            }
        }