Exemple #1
0
        private void MoveRows(int direction, CalendarNode[] temprow)
        {
            if (direction > 0)
            {
                for (int row = numberOfRows - 1; row >= 0; row--)
                {
                    for (int day = 0; day < numberOfDays; day++)
                    {
                        if (row != numberOfRows - 1)
                        {
                            CalendarNode node  = calendarNodes[row, day];
                            Canvas       _node = node._node;
                            //node._column = day;
                            node._row = row + 1;
                            //Thickness margin = new Thickness(_node.Margin.Left, row * nodeHeight + nodeHeight, _node.Margin.Right, (5 - row) * nodeHeight - nodeHeight);
                            //_node.SetValue(MarginProperty, margin);

                            calendarNodes[row + 1, day] = node;
                        }
                    }
                }
                for (int day = 0; day < numberOfDays; day++)
                {
                    calendarNodes[0, day] = temprow[day];
                }
            }
            else if (direction < 0)
            {
                for (int row = 0; row < numberOfRows; row++)
                {
                    for (int day = 0; day < numberOfDays; day++)
                    {
                        if (row != 0)
                        {
                            CalendarNode node  = calendarNodes[row, day];
                            Canvas       _node = node._node;
                            //node._column = day;
                            node._row = row - 1;
                            //Thickness margin = new Thickness(_node.Margin.Left, row * nodeHeight - nodeHeight, _node.Margin.Right, (5 - row) * nodeHeight + nodeHeight);
                            //_node.SetValue(MarginProperty, margin);

                            calendarNodes[row - 1, day] = calendarNodes[row, day];
                        }
                    }
                }
                for (int day = 0; day < numberOfDays; day++)
                {
                    calendarNodes[numberOfRows - 1, day] = temprow[day];
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemple #2
0
        private void LinkNotificationToCalendarDate(Notification notification, CalendarNode node)
        {
            string   date     = notification.date;
            string   time     = notification.time;
            DateTime dateTime = dateParser.ParseDateTimeFromJSON(date + " " + time);

            TextBlock notificationTitle = new TextBlock();

            notificationTitle.Text  = notification.title;
            notificationTitle.Width = nodeWidth;
            // The constant 20 that is added to the thickness is to accomodate for the dates size and should be changed to that at some point
            notificationTitle.SetValue(MarginProperty, new Thickness(0, node._notifications.IndexOf(notification) * 20 + 20, 0, 0));
            node._node.Children.Add(notificationTitle);
        }
Exemple #3
0
        /// <summary>
        /// This is run when apply is pressed on the notification flyout
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SendNotificationToServer(object sender, RoutedEventArgs e)
        {
            Button send   = sender as Button;
            Grid   parent = (Grid)send.Parent;

            var title = (TextBox)parent.Children[0];
            var date  = (TextBox)parent.Children[1];
            var time  = (TextBox)parent.Children[2];
            var text  = (TextBox)parent.Children[3];

            CalendarNode node         = selectedNodes[0];
            Notification notification = new Notification(date.Text, title.Text, text.Text, time.Text); // dateParser.ParseDateAndTimeForJSON(node._dateTime)

            node._notifications.Add(notification);

            LinkNotificationToCalendarDate(notification, node);
        }
Exemple #4
0
        /// <summary>
        /// Direction should be -1 or 1
        /// </summary>
        /// <param name="direction"></param>
        private void ScrollCalendar(int direction)
        {
            CalendarNode[] temprow = new CalendarNode[7];

            // Down
            if (direction > 0)
            {
                // Make a temporary row from the last row
                temprow = CopyRowToTempRow(numberOfRows - 1);

                // Set new dates for temprow
                SetUpNewRowFromTemprow(direction, temprow);

                // Move all rows down one row
                MoveRows(direction, temprow);

                // Update all node positions
                foreach (var node in calendarNodes)
                {
                    node._node.SetValue(MarginProperty, new Thickness(node._column * nodeWidth, node._row * nodeHeight, (7 - node._column) * nodeWidth, (5 - node._row) * nodeHeight));
                }
            }
            // Up
            else if (direction < 0)
            {
                // Make a temporary row from the first row
                temprow = CopyRowToTempRow(0);

                // Move all rows up one row
                MoveRows(direction, temprow);

                // Set new dates for temprow
                SetUpNewRowFromTemprow(direction, temprow);

                //Update all node positions
                foreach (var node in calendarNodes)
                {
                    node._node.SetValue(MarginProperty, new Thickness(node._column * nodeWidth, node._row * nodeHeight, (6 - node._column) * nodeWidth, (5 - node._row) * nodeHeight));
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemple #5
0
        private void NotificationClicked(object sender, TappedRoutedEventArgs e, Notification _notification, Canvas _canvas)
        {
            TextBlock clickedTextBlock = sender as TextBlock;

            Flyout editNotification = new Flyout();
            Grid   grid             = new Grid();

            editNotification.Content = grid;

            grid.Height = Double.NaN;
            grid.Width  = 300;

            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());

            TextBox titleText = new TextBox();
            TextBox dateText  = new TextBox();
            TextBox timeText  = new TextBox();
            TextBox textText  = new TextBox();

            titleText.Header = "Title";
            dateText.Header  = "Date";
            timeText.Header  = "Time";
            textText.Header  = "Text";

            titleText.Text = _notification.title;
            textText.Text  = _notification.text;
            dateText.Text  = _notification.date;
            timeText.Text  = _notification.time;

            Button applyBtn = new Button();

            applyBtn.Content = "Apply";
            applyBtn.SetValue(VerticalAlignmentProperty, VerticalAlignment.Bottom);
            applyBtn.SetValue(HorizontalContentAlignmentProperty, HorizontalAlignment.Right);
            applyBtn.Click += (sendeer, ee) => SendNotificationEditToServer(sender, e, _canvas, _notification);

            titleText.SetValue(Grid.RowProperty, 0);
            dateText.SetValue(Grid.RowProperty, 1);
            timeText.SetValue(Grid.RowProperty, 1);
            textText.SetValue(Grid.RowProperty, 2);
            applyBtn.SetValue(Grid.RowProperty, 3);

            timeText.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Right);
            dateText.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Left);
            timeText.Width = grid.Width / 2;
            dateText.Width = grid.Width / 2;

            grid.Children.Add(titleText);
            grid.Children.Add(dateText);
            grid.Children.Add(timeText);
            grid.Children.Add(textText);
            grid.Children.Add(applyBtn);

            CalendarNode node = selectedNodes[0];

            dateText.Text         = node._dateTime.Date.ToString("d");
            node._node.Background = new SolidColorBrush(Colors.Red);
            editNotification.ShowAt(node._node);
        }
Exemple #6
0
        /// <summary>
        /// transforms a JToken (json) object to a Notification object and links said object to the corresponding date on the calendar
        /// </summary>
        /// <param name="notificationJSON"></param>



        private void CalendarClicked(object sender, TappedRoutedEventArgs e)
        {
            Canvas       canvas = (Canvas)sender;
            CalendarNode node   = GetCalendarNode(canvas);

            Debug.WriteLine(node._row);
            // If a calendar node is not selected
            // Either create a new notification or show details of existing ones
            if (selectedNodes.Count == 0)
            {
                // If there are no notifications on selected day
                // Show create notification flyout
                if (node._notifications.Count == 0)
                {
                    Flyout notificationFlyout = new Flyout();
                    Grid   notificationGrid   = new Grid();
                    notificationFlyout.Content = notificationGrid;

                    notificationFlyout.Closed += notificationFlyoutClosed;
                    notificationGrid.Height    = Double.NaN;
                    notificationGrid.Width     = 300;

                    notificationGrid.RowDefinitions.Add(new RowDefinition());
                    notificationGrid.RowDefinitions.Add(new RowDefinition());
                    notificationGrid.RowDefinitions.Add(new RowDefinition());
                    notificationGrid.RowDefinitions.Add(new RowDefinition());

                    TextBox titleText = new TextBox();
                    TextBox dateText  = new TextBox();
                    TextBox timeText  = new TextBox();
                    TextBox textText  = new TextBox();

                    titleText.Header = "Title";
                    dateText.Header  = "Date";
                    timeText.Header  = "Time";
                    textText.Header  = "Text";

                    Button applyBtn = new Button();
                    applyBtn.Content = "Apply";
                    applyBtn.SetValue(VerticalAlignmentProperty, VerticalAlignment.Bottom);
                    applyBtn.SetValue(HorizontalContentAlignmentProperty, HorizontalAlignment.Right);
                    applyBtn.Click += SendNotificationToServer;

                    titleText.SetValue(Grid.RowProperty, 0);
                    dateText.SetValue(Grid.RowProperty, 1);
                    timeText.SetValue(Grid.RowProperty, 1);
                    textText.SetValue(Grid.RowProperty, 2);
                    applyBtn.SetValue(Grid.RowProperty, 3);

                    timeText.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Right);
                    dateText.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Left);
                    timeText.Width = notificationGrid.Width / 2;
                    dateText.Width = notificationGrid.Width / 2;

                    notificationGrid.Children.Add(titleText);
                    notificationGrid.Children.Add(dateText);
                    notificationGrid.Children.Add(timeText);
                    notificationGrid.Children.Add(textText);
                    notificationGrid.Children.Add(applyBtn);

                    selectedNodes.Add(node);
                    dateText.Text         = node._dateTime.Date.ToString("d");
                    node._node.Background = new SolidColorBrush(Colors.Red);
                    notificationFlyout.ShowAt(canvas);
                }
                // If There are notifications on the selected day
                // Show Details of said notifications
                else
                {
                    Flyout notificationFlyout = new Flyout();
                    Grid   notificationGrid   = new Grid();
                    notificationFlyout.Content = notificationGrid;

                    notificationFlyout.Closed += notificationFlyoutClosed;
                    notificationGrid.Height    = Double.NaN;
                    notificationGrid.Width     = 300;

                    notificationGrid.RowDefinitions.Add(new RowDefinition());
                    Button addNotification = new Button();
                    addNotification.SetValue(Grid.RowProperty, 0);

                    addNotification.Content = "+ Add new notification";
                    notificationGrid.Children.Add(addNotification);

                    notificationGrid.RowDefinitions.Add(new RowDefinition());
                    TextBlock date = new TextBlock();
                    date.Text  = node._dateTime.Date.ToString("d");
                    date.Width = 300;
                    date.SetValue(Grid.RowProperty, 1);
                    date.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Right);
                    notificationGrid.Children.Add(date);

                    for (int i = 0; i < node._notifications.Count; i++)
                    {
                        notificationGrid.RowDefinitions.Add(new RowDefinition());
                        Notification notification = node._notifications[i];
                        TextBlock    title        = new TextBlock();
                        TextBlock    text         = new TextBlock();

                        title.Text = notification.title;
                        text.Text  = notification.text;

                        title.Width = 300;
                        text.Width  = 300;

                        title.SetValue(Grid.RowProperty, i + 2);
                        text.SetValue(Grid.RowProperty, i + 2);

                        title.SetValue(MarginProperty, new Thickness(0, 0, 0, 0));
                        text.SetValue(MarginProperty, new Thickness(0, 20, 0, 0));

                        notificationGrid.Children.Add(title);
                        notificationGrid.Children.Add(text);

                        title.Tapped += new TappedEventHandler((sendeer, ee) => NotificationClicked(sender, e, notification, canvas));
                    }

                    selectedNodes.Add(node);
                    node._node.Background = new SolidColorBrush(Colors.Red);
                    notificationFlyout.ShowAt(canvas);
                }
            }
            // If calendar node is selected
            // Clear the selected nodes
            else
            {
                ClearSelectedNodes();
            }
        }
Exemple #7
0
        private void FillCalendarWithDates(DateTime _date)
        {
            dateTimeInCalendar = _date;
            DateTime firstDay = new DateTime(_date.Year, _date.Month, 1);
            // LastMonthDays is used to sync the visible last months days to the calendar
            // Almost like temprow that is explained below
            int lastMonthDays = 0;

            // Looping 6 rows in a month
            for (int row = 0; row < numberOfRows; row++)
            {
                // Temprow is used to sync days to their proper rows
                // Each Sunday if there has not been 7 days since we changed rows
                // Increment temprow by one so the next day (Monday) goes to the next row
                // And does not override this rows monday
                int tempRow = 0;

                if (row == 0)
                {
                    lastMonthDays = helper.HowManyDaysFromMonthBefore(firstDay);
                }
                for (int day = 0; day < 7; day++)
                {
                    int          daysToAdd = row * 7 + day;
                    DateTime     date      = firstDay.AddDays(daysToAdd - lastMonthDays);
                    CalendarNode node      = calendarNodes[row + tempRow, day];
                    TextBlock    label     = new TextBlock();

                    if (row == numberOfRows - 1)
                    {
                        tempRow = 0;
                    }
                    if (row == 1 && day == 0)
                    {
                        //firstDayInCalendar = date;
                    }
                    if (date.Date.ToString("dddd", new CultureInfo("en-US")) == "Monday")
                    {
                        label.Text = date.Day.ToString();
                        node._node.Children.Add(label);
                        node._dateTime = date;
                    }
                    if (date.Date.ToString("dddd", new CultureInfo("en-US")) == "Tuesday")
                    {
                        label.Text = date.Day.ToString();
                        node._node.Children.Add(label);
                        node._dateTime = date;
                    }
                    if (date.Date.ToString("dddd", new CultureInfo("en-US")) == "Wednesday")
                    {
                        label.Text = date.Day.ToString();
                        node._node.Children.Add(label);
                        node._dateTime = date;
                    }
                    if (date.Date.ToString("dddd", new CultureInfo("en-US")) == "Thursday")
                    {
                        label.Text = date.Day.ToString();
                        node._node.Children.Add(label);
                        node._dateTime = date;
                    }
                    if (date.Date.ToString("dddd", new CultureInfo("en-US")) == "Friday")
                    {
                        label.Text = date.Day.ToString();
                        node._node.Children.Add(label);
                        node._dateTime = date;
                    }
                    if (date.Date.ToString("dddd", new CultureInfo("en-US")) == "Saturday")
                    {
                        label.Text = date.Day.ToString();
                        node._node.Children.Add(label);
                        node._dateTime = date;
                    }
                    if (date.Date.ToString("dddd", new CultureInfo("en-US")) == "Sunday")
                    {
                        label.Text = date.Day.ToString();
                        node._node.Children.Add(label);
                        node._dateTime = date;
                        tempRow++;
                    }
                }
            }
            //string notificationJSON = serverHelper.SendGETRequest(localsettings.Values["webroot"] + "/api/notifications/", "");
            //var json = JArray.Parse(notificationJSON);
            //foreach (var item in json)
            //{
            //LinkNotificationToCalendarDate(item);
            //}
        }