Ejemplo n.º 1
0
        public void FillWith(StudentDataBundle studentDataBundle)
        {
            timeLabels.Children.Clear();
            root.Children.Clear();
            if (studentDataBundle.Courses.Count > 0 && studentDataBundle.GetTotalInstances() > 0)
            {
                lowerBound = CoreTime.GetEarliest(studentDataBundle);
                upperBound = CoreTime.GetLatest(studentDataBundle);

                //set size based on whether there is a weekedend or not
                labelContainer.Width = ((studentDataBundle.hasWeekend()) ? 7 : 5) * Constants.EventControlWidth;
                this.Width           = Constants.EventControlWidth * ((studentDataBundle.hasWeekend()) ? 7 : 5) + 43;

                this.Height = (upperBound.TotalMinutes - lowerBound.TotalMinutes) / 60 * Constants.EventControlHeight + 43;


                for (int x = 0; x < studentDataBundle.Courses.Count; x++)
                {
                    Course model = studentDataBundle.Courses[x];
                    foreach (Instance instance in model.Instances)
                    {
                        //foreach instance we
                        EventControl cont = new EventControl(model);                                                                              //create a control
                        cont.setTime(instance.StartTime, instance.EndTime);                                                                       //set the text
                        instances[instance.Day].Add(cont);                                                                                        //add it to the appropiate list
                        root.Children.Add(cont);                                                                                                  //add it to the view
                        Canvas.SetLeft(cont, Constants.EventControlWidth * instance.Day);                                                         //set it at the x coord and y coord
                        Canvas.SetTop(cont, ((instance.StartTime.TotalMinutes - lowerBound.TotalMinutes) / 60.0) * Constants.EventControlHeight); //take lenght in account (i.e 2 hour lesson)
                        double dt     = (instance.EndTime.TotalMinutes - instance.StartTime.TotalMinutes);
                        double height = dt / 60;
                        cont.Height = height * Constants.EventControlHeight; //set the height proportionately to the duration
                    }
                }

                //create the time labels and the outline lines
                for (int x = lowerBound.TotalMinutes; x <= upperBound.TotalMinutes; x += 30)
                {
                    TextBlock block = new TextBlock {
                        FontSize = (x % 60 == 0) ? 12 : 10
                    };
                    //block.Text = string.Format("{0}:{1}", ((int)x / 60).ToString(), ((x % 60)).ToString());
                    // block.Text = (x / 60).ToString() + ":00";
                    double hours = x / 60.0;
                    block.Text = Math.Truncate(hours).ToString() + ":" + ((hours - Math.Truncate(hours)) * 60).ToString();
                    timeLabels.Children.Add(block);
                    Canvas.SetLeft(block, 0);
                    Canvas.SetTop(block, Constants.EventControlHeight * ((x - lowerBound.TotalMinutes) / 60.0) - block.ActualHeight);

                    Line indicator = new Line {
                        Stroke = new SolidColorBrush(Colors.DarkGray), StrokeThickness = 1
                    };
                    root.Children.Add(indicator);
                    indicator.X1 = 0;
                    indicator.Y1 = Constants.EventControlHeight * ((x - lowerBound.TotalMinutes) / 60.0);
                    indicator.X2 = Constants.EventControlWidth * ((studentDataBundle.hasWeekend()) ? 7 : 5) + timeLabels.ActualWidth;
                    indicator.Y2 = indicator.Y1;
                    Canvas.SetZIndex(indicator, -1);
                }
            }
        }
Ejemplo n.º 2
0
        public void FillWith(StudentDataBundle table)
        {
            nextPanel.Visibility = Windows.UI.Xaml.Visibility.Visible;
            description.Text     = table.Description;
            Course earliest = new Course {
                Name = "null"
            };
            Instance earliestInstance = new Instance {
                StartTime = Time.MaximumTime, EndTime = Time.MaximumTime
            };

            foreach (Course model in table.Courses)
            {
                EventControl control = new EventControl(model);
                control.Margin = new Thickness(5, 0, 5, 0);
                eventHolder.Children.Add(control);
                foreach (Instance instance in model.Instances)
                {
                    if (instance.Day == (int)DateTime.Now.DayOfWeek - 1)
                    {
                        Time now = new Time {
                            Hours = DateTime.Now.Hour, Minutes = DateTime.Now.Minute
                        };
                        if (now < instance.StartTime)
                        {
                            if (earliestInstance.StartTime < now)
                            {
                                earliestInstance = instance;
                                earliest         = model;
                            }
                            else
                            {
                                if (instance.StartTime - now < earliestInstance.StartTime - now)
                                {
                                    earliestInstance = instance;
                                    earliest         = model;
                                }
                            }
                        }
                    }
                }
            }
            if (earliest.Name != "null")
            {
                eventControl.FillWith(earliest);
                eventControl.setTime(earliestInstance.StartTime, earliestInstance.EndTime);
            }
            else
            {
                nextPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
        }