Exemplo n.º 1
0
        private void ShowClasses(Data data, GroupSettings groupSettings, DateTime date)
        {
            List<Class> classes = new List<Class>();

            int currentWeekday = (int)date.DayOfWeek - 1;
            if (currentWeekday == -1)
                currentWeekday = 6;

            int currentWeek = ((date - data.Schedule.SemesterStart).Days) / 7 + 1;

            int currentWeekCode = 2;
            if (currentWeek % 2 == 1)
                currentWeekCode = 1;

            bool zeroClasses = true;

            // Clear classes
            classesStackPanel.Children.Clear();

            ScheduleWeekday weekday = data.Schedule.GetWeekdayByNumber(currentWeekday);
            if (weekday != null)
            {
                emptyImage.Visibility = System.Windows.Visibility.Hidden;

                List<ScheduleClass> scheduleToday = weekday.Classes;

                for (int i = 0; i < scheduleToday.Count; i++)
                {
                    if (scheduleToday[i].Week == 0 || scheduleToday[i].Week == currentWeekCode)
                    {
                        string setting = groupSettings.GetSettingByCode(scheduleToday[i].Code);

                        if (setting == scheduleToday[i].Group)
                        {
                            ClassType type = data.Types.GetTypeById(scheduleToday[i].Type);
                            classesStackPanel.Children.Add((new Class(
                                data.Modules.GetModuleByCode(scheduleToday[i].Code).Name,
                                scheduleToday[i].Location,
                                scheduleToday[i].Hours,
                                scheduleToday[i].Minutes,
                                new SolidColorBrush(Color.FromRgb(type.ColorArray[0], type.ColorArray[1], type.ColorArray[2]))
                            )).Drawable);

                            zeroClasses = false;
                        }
                    }
                }
            }

            if (zeroClasses)
                emptyImage.Visibility = System.Windows.Visibility.Visible;
            else
                emptyImage.Visibility = System.Windows.Visibility.Hidden;
        }
Exemplo n.º 2
0
        private void PrepareSettings(Data data)
        {
            groupSettings = new GroupSettings();
            settingsStackPanel.Children.Clear();

            foreach (GroupContainer i in data.Groups.GroupContainers)
            {
                GroupSetting groupSetting = new GroupSetting(i.AppliesTo, i.Name, i.Items[0].Code);
                groupSetting.PropertyChanged += groupSetting_PropertyChanged;
                groupSettings.Settings.Add(groupSetting);

                List<string> settingNames = new List<string>();

                foreach (Group group in i.Items)
                    settingNames.Add(group.Name);

                Setting setting = new Setting(i.Name, settingNames);
                setting.CurrentSetting = groupSettings.Settings[groupSettings.Settings.Count - 1];

                settingsStackPanel.Children.Add(setting.Drawable);
            }
        }
Exemplo n.º 3
0
        private Data ReadClasses(string fileName)
        {
            XmlTextReader reader = null;
            Data data = null;

            if (File.Exists(fileName))
            {
                reader = new XmlTextReader(fileName);

                data = new Data();

                reader.MoveToContent();
                if (reader.IsEmptyElement) { reader.Read(); return null; }

                if (reader.IsStartElement() && reader.Name == "data")
                {
                    data.ReadFromXml(reader);
                }
                else
                {
                    throw new ArgumentException("\"" + fileName + "\" is not a valid data file");
                }

                reader.Close();
            }

            return data;
        }
Exemplo n.º 4
0
        private void dataReadWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            data = e.Result as Data;

            if (data != null && (!data.Equals(new Data())))
            {
                PrepareSettings(data);
                ShowClasses(data, groupSettings, DateTime.Now);
            }
            else
            {
                MessageBox.Show("Loading schedule failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }