Exemplo n.º 1
0
        public void FillTabPage(CustomList newTaskData = null)
        {
            /// <summary>
            /// Method that converts all of the items in `this.data` into the page. If `newTaskData` is provided, then `this.data = newTaskData`.
            /// </summary>
            if (newTaskData != null)
            {
                // New tasks have been provided, dispose of the current list items and replace the current data with the new data provided.
                this.data = newTaskData;
                foreach (HomeworkListItem h in this.listItems)
                {
                    h.Dispose();
                }
            }

            int numberOfHomeworks = this.data.GetLength(); // Because this call is O(n), it can be stored as a var

            if (numberOfHomeworks > 0)
            {
                Homework[] homeworkToSort = this.data.ToArray <Homework>();
                Homework[] sortedHomework = Algorithms.Sorts.MergeSort(homeworkToSort, ascending: !this.containsCompletedTasks);

                int y = 0;
                this.listItems = new HomeworkListItem[numberOfHomeworks];
                for (int i = 0; i < numberOfHomeworks; i++)
                {
                    Homework homework = sortedHomework[i];
                    //bool includeBottomBorder = (i != numberOfHomeworks - 1);
                    HomeworkListItem taskListItem = new HomeworkListItem(parent, homework, 2, true);
                    this.listItems[i]     = taskListItem;
                    taskListItem.Location = new Point(0, y);
                    y += taskListItem.Height; // Ensure that the item below is actually underneath the previous item
                    this.Controls.Add(taskListItem);
                }
            }
            this.Text = this.titleText + " (" + numberOfHomeworks.ToString() + ")";
        }
Exemplo n.º 2
0
        public HomeworkListItem(HomeworkTabController tabController, Homework task, int bottomBorderWidth, bool bottomBorder) : base()
        {
            /// <summary>
            /// Constructor method for TaskListItem.
            /// </summary>
            this.tabController     = tabController;
            this.task              = task;
            this.bottomBorder      = bottomBorder;
            this.bottomBorderWidth = bottomBorderWidth;

            // Title Label
            titleLabel           = new LinkLabel();
            titleLabel.AutoSize  = true;
            titleLabel.Font      = new Font("Calibri", 20.0f, FontStyle.Bold);
            titleLabel.Location  = new Point(5, 0);
            titleLabel.Text      = task.title;
            titleLabel.BackColor = Color.Transparent;
            titleLabel.Click    += OnTitleLabelClick;
            this.Controls.Add(titleLabel);

            // Group Label
            groupLabel           = new Label();
            groupLabel.AutoSize  = true;
            groupLabel.Font      = new Font("Calibri", 15.0f);
            groupLabel.Location  = new Point(5, 35);
            groupLabel.Text      = task.group.name;
            groupLabel.BackColor = Color.Transparent;
            this.Controls.Add(groupLabel);

            // Description Label
            descriptionLabel           = new Label();
            descriptionLabel.AutoSize  = true;
            descriptionLabel.Font      = new Font("Calibri", 15.0f);
            descriptionLabel.Location  = new Point(300, 30);
            descriptionLabel.Text      = HomeworkListItem.ReduceText(task.description, 25);
            descriptionLabel.BackColor = Color.Transparent;
            this.Controls.Add(descriptionLabel);

            if (task.dateDue < DateTime.UtcNow && !task.hasCompleted)
            {
                overdueLabel           = new Label();
                overdueLabel.Text      = "Overdue!!!";
                overdueLabel.BackColor = Color.Red;
                overdueLabel.Font      = new Font("Calibri", 15.0f, FontStyle.Bold);
                overdueLabel.Location  = new Point(300, 0);
                overdueLabel.AutoSize  = true;
                overdueLabel.TextAlign = ContentAlignment.TopCenter;
                this.Controls.Add(overdueLabel);
            }

            // DateRepresentationPanel
            date           = new DateRepresentationPanel(task.dateDue, 30.0f, 20.0f, -20);
            date.Location  = new Point(650, 0);
            date.BackColor = Color.White;
            this.Controls.Add(date);

            // Done Checkbox
            doneButton           = new DoneButtonControl("Done?", startingState: this.task.hasCompleted);
            doneButton.AutoSize  = true;
            doneButton.Location  = new Point(550, 20);
            doneButton.BackColor = Color.Transparent;
            doneButton.AddButtonClickAction(this.OnDoneButtonClick);
            this.Controls.Add(doneButton);

            this.Height = date.Location.Y + date.Height + 15; //Height is changed relative to the lowest component to prevent UserControl taking up more space than necessary
        }