Esempio 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);
                }
            }
        }
        public HomeworkItem(HomeworkTask task, Windows.UI.Color c, UIElementCollection container = null, Module module = null)
        {
            this.InitializeComponent();
            self = task;

            //initial values
            root.Background      = new SolidColorBrush(c);
            _description.Text    = self.Notes;
            completedSwitch.IsOn = self.Completed;
            dateButton.Content   = CoreTime.FormatTime(task.DueOn);



            deleteButton.Tapped += (e, ev) =>
            {
                //OnDelete(this);
                container.Remove(this);
                module.Homeworks.Remove(self);
            };
            completedSwitch.Toggled += (e, ev) =>
            {
                self.Completed = completedSwitch.IsOn;
                // OnChange();
            };
            _description.TextChanged += (e, ev) =>
            {
                Validator.isStringValid(
                    target: _description.Text, scope: "description", allowDigits: true, allowEmpty: true, max: Validator.HomeworkDescriptionMax,
                    autoFix: true, fixTarget: _description, autoNotify: true);
                self.Notes = _description.Text;
                //OnChange();
            };

            dateButton.Click += (e, ev) =>
            {
                introDate.Begin();
            };
            datePicker.BackPressed += (time) =>
            {
                exitDate.Begin();
                dateButton.Content = CoreTime.FormatTime(time);
                self.DueOn         = time;
                //OnChange();
            };
        }
Esempio n. 3
0
        async void changedEvent(object sender, SelectionChangedEventArgs e)
        {
            self.StartTime.Hours   = int.Parse(((start1.SelectedItem as ComboBoxItem).Content as string));
            self.StartTime.Minutes = int.Parse(((start2.SelectedItem as ComboBoxItem).Content as string));

            self.EndTime.Hours   = int.Parse(((end1.SelectedItem as ComboBoxItem).Content as string));
            self.EndTime.Minutes = int.Parse(((end2.SelectedItem as ComboBoxItem).Content as string));

            self.Day = day.SelectedIndex;
            try
            {
                InstanceChanged();
            }
            catch { }

            if (int.Parse((start1.SelectedValue as ComboBoxItem).Content as string) * 60 + int.Parse((start2.SelectedValue as ComboBoxItem).Content as string) >= int.Parse((end1.SelectedValue as ComboBoxItem).Content as string) * 60 + int.Parse((end2.SelectedValue as ComboBoxItem).Content as string))
            {
                MessageDialog error_dialog = new MessageDialog("The class start time must be before the end time", "We have a problem , Watson");
                error_dialog.Commands.Add(new UICommand("Okay"));
                await error_dialog.ShowAsync();

                error_flag.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                error_flag.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }

            TimeOverlapData result = CoreTime.isOverlapping(self, selfParent);

            if (result.isOverlapping)
            {
                MessageDialog error_dialog = new MessageDialog("Classes cannot overlap.Please choose another time.", "This class time overlaps with your " + result.OverlappingEventName + " class");
                error_dialog.Commands.Add(new UICommand("Okay"));
                await error_dialog.ShowAsync();

                isValid = false;
            }
            else
            {
                isValid = true;
            }
        }