コード例 #1
0
        public static IList <School> Merge(IList <School> l1, IList <School> l2)
        {
            var merged = new List <School>();

            merged.AddRange(l1.ExceptBy(l2, school => school.ID));

            var both = l1.Intersect(l2, new SchoolComparer());

            foreach (var s in both)
            {
                var s1 = l1.First(school => school.ID == s.ID);
                var s2 = l2.First(school => school.ID == s.ID);

                var newSchool = new School(s1.Changed > s2.Changed ? s1.Name : s2.Name, s.ID, s1.Changed > s2.Changed ? s1.Changed : s2.Changed);
                newSchool.Classes.AddRange(SchoolClass.Merge(s1.Classes, s2.Classes));
                merged.Add(newSchool);
            }

            merged.AddRange(l2.ExceptBy(l1, school => school.ID));
            return(merged);
        }
コード例 #2
0
ファイル: SchoolClass.cs プロジェクト: galdiuz/Majblommor
        public static IList <SchoolClass> Merge(IList <SchoolClass> l1, IList <SchoolClass> l2)
        {
            var merged = new List <SchoolClass>();

            merged.AddRange(l1.ExceptBy(l2, schoolClass => schoolClass.ID));

            var both = l1.Intersect(l2, new SchoolClassComparer());

            foreach (var k in both)
            {
                var k1 = l1.First(schoolClass => schoolClass.ID == k.ID);
                var k2 = l2.First(schoolClass => schoolClass.ID == k.ID);

                var newSchoolClass = new SchoolClass(k1.Changed > k2.Changed ? k1.Name : k2.Name, k.ID, k1.Changed > k2.Changed ? k1.Changed : k2.Changed);
                newSchoolClass.Students.AddRange(Student.Merge(k1.Students, k2.Students));
                merged.Add(newSchoolClass);
            }

            merged.AddRange(l2.ExceptBy(l1, schoolClass => schoolClass.ID));
            return(merged);
        }
コード例 #3
0
 private void Edit_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (tv.SelectedItem is School)
     {
         var s      = tv.SelectedItem as School;
         var dialog = new NameDialog("Redigera Skola", s.Name);
         if (dialog.ShowDialog() == true)
         {
             s.Name    = dialog.NewName;
             s.Changed = DateTime.UtcNow.Ticks;
         }
     }
     else if (tv.SelectedItem is SchoolClass)
     {
         SchoolClass k      = tv.SelectedItem as SchoolClass;
         NameDialog  dialog = new NameDialog("Redigera Klass", k.Name);
         if (dialog.ShowDialog() == true)
         {
             k.Name    = dialog.NewName;
             k.Changed = DateTime.UtcNow.Ticks;
         }
     }
 }
コード例 #4
0
        private void Delete_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBoxManager.OK     = "Ta bort";
            MessageBoxManager.Cancel = "Avbryt";
            MessageBoxManager.Register();
            if (tv.SelectedItem is School)
            {
                School s = (School)tv.SelectedItem;
                if (MessageBox.Show("Är du säker att du vill ta bort markerad skola? Alla klasser och elever i skolan kommer försvinna.", "Ta bort skola", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    Schools.Remove(s);
                }
            }
            else
            {
                SchoolClass k = (SchoolClass)tv.SelectedItem;
                if (MessageBox.Show("Är du säker att du vill ta bort markerad klass? Alla elever i klassen kommer försvinna.", "Ta bort klass", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    Schools.First(f => f.Classes.Contains(k)).Classes.Remove(k);
                }
            }

            MessageBoxManager.Unregister();
        }
コード例 #5
0
        private void Merge_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var dialog = new OpenFileDialog {
                Filter = "XML Filer (*.xml)|*.xml|Alla Filer (*.*)|*.*"
            };

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            var file = dialog.FileName;

            var         newschools  = new List <School>();
            School      school      = null;
            SchoolClass schoolClass = null;
            Student     student     = null;

            using (var reader = XmlReader.Create(file))
            {
                while (reader.Read())
                {
                    if (!reader.IsStartElement())
                    {
                        continue;
                    }
                    switch (reader.Name)
                    {
                    case "School":
                        school = new School(reader["Name"], reader["ID"], long.Parse(reader["Changed"]));
                        newschools.Add(school);
                        break;

                    case "SchoolClass":
                        schoolClass = new SchoolClass(reader["Name"], reader["ID"], long.Parse(reader["Changed"]));
                        school?.Classes.Add(schoolClass);
                        break;

                    case "Student":
                        student = new Student(reader["ID"], long.Parse(reader["Changed"]));
                        schoolClass?.Students.Add(student);
                        break;

                    case "Firstname":
                        student.Firstname = reader.ReadElementContentAsString();
                        break;

                    case "Surname":
                        student.Surname = reader.ReadElementContentAsString();
                        break;

                    case "Telephone":
                        student.Telephone = reader.ReadElementContentAsString();
                        break;

                    case "GivSmall":
                        student.Given.Small = reader.ReadElementContentAsInt();
                        break;

                    case "GivWreaths":
                        student.Given.Wreaths = reader.ReadElementContentAsInt();
                        break;

                    case "GivLarge":
                        student.Given.Large = reader.ReadElementContentAsInt();
                        break;

                    case "GivPins":
                        student.Given.Pins = reader.ReadElementContentAsInt();
                        break;

                    case "GivSign":
                        student.GivSign = reader.ReadElementContentAsString();
                        break;

                    case "RetSmall":
                        student.Returned.Small = reader.ReadElementContentAsInt();
                        break;

                    case "RetWreaths":
                        student.Returned.Wreaths = reader.ReadElementContentAsInt();
                        break;

                    case "RetLarge":
                        student.Returned.Large = reader.ReadElementContentAsInt();
                        break;

                    case "RetPins":
                        student.Returned.Pins = reader.ReadElementContentAsInt();
                        break;

                    case "Received":
                        student.Received = reader.ReadElementContentAsInt();
                        break;

                    case "Sign":
                        student.Sign = reader.ReadElementContentAsString();
                        break;

                    case "Note":
                        student.Note = reader.ReadElementContentAsString();
                        break;
                    }
                }
            }

            var mergedschools = School.Merge(Schools, newschools);

            Schools.Clear();
            Schools.AddRange(mergedschools);

            if (Schools.Count > 0)
            {
                CurrentSchool = Schools[0];
            }
        }