Exemple #1
0
 /**
  * Sélectionne les anciens fichiers
  */
 private void oldFilesButton_Click(object sender, EventArgs e)
 {
     if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
     {
         String oldFilesFolder = folderBrowserDialog.SelectedPath;
         oldAppleClassesFilePath   = ASMTools.createPath(oldFilesFolder, "classes.csv");
         oldAppleCoursesFilePath   = ASMTools.createPath(oldFilesFolder, "courses.csv");
         oldAppleLocationsFilePath = ASMTools.createPath(oldFilesFolder, "locations.csv");
         oldAppleRostersFilePath   = ASMTools.createPath(oldFilesFolder, "rosters.csv");
         oldAppleStaffFilePath     = ASMTools.createPath(oldFilesFolder, "staff.csv");
         oldAppleStudentsFilePath  = ASMTools.createPath(oldFilesFolder, "students.csv");
     }
 }
Exemple #2
0
        /**
         * Charge les fichiers sélectionnés
         */
        private void loadFilesButton_Click(object sender, EventArgs e)
        {
            //Vérifie que tous les fichiers ont bien été sélectionnés avant le début de la conversion
            if (oldAppleClassesFilePath == null || oldAppleCoursesFilePath == null || oldAppleLocationsFilePath == null || oldAppleRostersFilePath == null || oldAppleStaffFilePath == null || oldAppleStudentsFilePath == null || sourceStaffFilePath == null || sourceStudentsFilePath == null || sourceClassesFilePath == null)
            {
                MessageBox.Show("Tous les fichiers n'ont pas été sélectionnés. Vérifiez puis recommencez.", "Fichiers manquants", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //Vérifie la valeur des séparateurs
                oldSeparator = oldSeparatorTextBox.Text[0];
                newSeparator = newSeparatorTextBox.Text[0];

                //Crée les Apple classes
                ArrayList classes = ASMTools.parseCSVFiles(oldAppleClassesFilePath, oldSeparator);
                oldAppleClasses = new List <AppleClasse>();
                try
                {
                    foreach (string[] aClass in classes)
                    {
                        AppleClasse newClass = new AppleClasse(aClass[0].Replace("\"", ""), aClass[1].Replace("\"", ""), aClass[2].Replace("\"", ""));
                        //Ajoute des professeurs
                        if (aClass.Length > 3)
                        {
                            for (int i = 3; i < aClass.Length; i++)
                            {
                                newClass.AddInstructor(aClass[i].Replace("\"", ""));
                            }
                        }

                        oldAppleClasses.Add(newClass);
                    }

                    statusProgressBar.Increment(16);
                    statusLabel.Text = "Classes ajoutées";
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //Crée les Apple courses
                ArrayList courses = ASMTools.parseCSVFiles(oldAppleCoursesFilePath, oldSeparator);
                oldAppleCourses = new List <AppleCourse>();
                try
                {
                    foreach (string[] aCourse in courses)
                    {
                        AppleCourse newCourse = new AppleCourse(aCourse[0].Replace("\"", ""), aCourse[1].Replace("\"", ""), aCourse[2].Replace("\"", ""), aCourse[3].Replace("\"", ""));
                        oldAppleCourses.Add(newCourse);
                    }

                    statusProgressBar.Increment(16);
                    statusLabel.Text = "Cours ajoutés";
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //Crée les Apple locations
                ArrayList locations = ASMTools.parseCSVFiles(oldAppleLocationsFilePath, oldSeparator);
                oldAppleLocations = new List <AppleLocation>();
                try
                {
                    foreach (string[] aLocation in locations)
                    {
                        AppleLocation newLocation = new AppleLocation(aLocation[0].Replace("\"", ""), aLocation[1].Replace("\"", ""));
                        oldAppleLocations.Add(newLocation);
                    }

                    statusProgressBar.Increment(16);
                    statusLabel.Text = "Locations ajoutées";
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //Crée les Apple professeurs
                ArrayList staff = ASMTools.parseCSVFiles(oldAppleStaffFilePath, oldSeparator);
                oldAppleStaff = new List <ApplePerson>();
                try
                {
                    foreach (string[] aStaff in staff)
                    {
                        ApplePerson newStaff = new ApplePerson(aStaff[0].Replace("\"", ""), aStaff[1].Replace("\"", ""), aStaff[2].Replace("\"", ""), aStaff[3].Replace("\"", ""), aStaff[4].Replace("\"", ""), aStaff[5].Replace("\"", ""), aStaff[6].Replace("\"", ""), aStaff[7].Replace("\"", ""));
                        oldAppleStaff.Add(newStaff);
                    }

                    statusProgressBar.Increment(16);
                    statusLabel.Text = "Professeurs ajoutés";
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //Crée les Apple rosters
                ArrayList rosters = ASMTools.parseCSVFiles(oldAppleRostersFilePath, oldSeparator);
                oldAppleRosters = new List <AppleRoster>();
                try
                {
                    foreach (string[] aRoster in rosters)
                    {
                        AppleRoster newRoster = new AppleRoster(aRoster[0].Replace("\"", ""), aRoster[1].Replace("\"", ""), aRoster[2].Replace("\"", ""));
                        oldAppleRosters.Add(newRoster);
                    }

                    statusProgressBar.Increment(16);
                    statusLabel.Text = "Rosters ajoutés";
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //Crée les Apple students
                ArrayList students = ASMTools.parseCSVFiles(oldAppleStudentsFilePath, oldSeparator);
                oldAppleStudents = new List <AppleStudent>();
                try
                {
                    foreach (string[] aStudent in students)
                    {
                        AppleStudent newStudent = new AppleStudent(aStudent[0].Replace("\"", ""), aStudent[1].Replace("\"", ""), aStudent[2].Replace("\"", ""), aStudent[3].Replace("\"", ""), aStudent[4].Replace("\"", ""), aStudent[5].Replace("\"", ""), aStudent[6].Replace("\"", ""), aStudent[7].Replace("\"", ""), aStudent[8].Replace("\"", ""), aStudent[9].Replace("\"", ""));
                        oldAppleStudents.Add(newStudent);
                    }

                    statusProgressBar.Value = 100;
                    statusLabel.Text        = "Fichiers d'origine Apple importés";
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }



                //Crée les classes sources(Saint Jean)
                classes       = ASMTools.parseCSVFiles(sourceClassesFilePath, newSeparator);
                sourceClasses = new List <SourceClasse>();
                try
                {
                    foreach (string[] aClasse in classes)
                    {
                        SourceClasse newClasse = new SourceClasse(aClasse[0].Replace("\"", ""));
                        //Ajoute les professeurs à la classe
                        if (aClasse.Length > 1)
                        {
                            for (int i = 1; i < aClasse.Length; i++)
                            {
                                newClasse.addInstructor(aClasse[i].Replace("\"", ""));
                            }
                        }

                        sourceClasses.Add(newClasse);

                        statusProgressBar.Value = 0;
                        statusProgressBar.Increment(33);
                        statusLabel.Text = "Fichier source des classes importé";
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //Crée les professeurs sources(Saint Jean)
                staff       = ASMTools.parseCSVFiles(sourceStaffFilePath, newSeparator);
                sourceStaff = new List <SourcePerson>();
                try
                {
                    foreach (string[] aStaff in staff)
                    {
                        SourcePerson newStaff = new SourcePerson(aStaff[0].Replace("\"", ""), aStaff[1].Replace("\"", ""), aStaff[2].Replace("\"", ""), aStaff[3].Replace("\"", ""));
                        sourceStaff.Add(newStaff);
                    }

                    statusProgressBar.Increment(33);
                    statusLabel.Text = "Fichier source des professeurs importé";
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //Crée les étudiants source (Saint Jean)
                students       = ASMTools.parseCSVFiles(sourceStudentsFilePath, newSeparator);
                sourceStudents = new List <SourceStudent>();
                try
                {
                    foreach (string[] aStudent in students)
                    {
                        SourceStudent newStudent = new SourceStudent(aStudent[0].Replace("\"", ""), aStudent[1].Replace("\"", ""), aStudent[2].Replace("\"", ""), aStudent[3].Replace("\"", ""), aStudent[4].Replace("\"", ""));
                        sourceStudents.Add(newStudent);
                    }

                    statusProgressBar.Value = 100;
                    statusLabel.Text        = "Fichier source des élèves importé";
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Impossible de lire le fichier. Vérifiez le séparateur", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //===================================================================
                // GENERATION DES NOUVEAUX FICHIERS
                //===================================================================

                statusProgressBar.Value = 0; //Rénitialise la barre de progression
                statusLabel.Text        = "Création des nouveaux fichiers Apple";

                //CREATION DU NOUVEAU FICHIER STAFF APPLE
                //1. N'ajoute que les professeurs présents l'année précédente et cette année
                bool staffHasBeenRemoved;
                int  lastRemovedStaffId;
                newAppleStaff = new List <ApplePerson>();
                foreach (ApplePerson anAppleStaff in oldAppleStaff)
                {
                    if (anAppleStaff.FirstName != "first_name")
                    {
                        staffHasBeenRemoved = true;

                        foreach (SourcePerson aSourceStaff in sourceStaff)
                        {
                            if (anAppleStaff.LastName.ToLower() == aSourceStaff.Name.ToLower() && anAppleStaff.EmailAddress.ToLower() == aSourceStaff.Mail.ToLower())
                            {
                                newAppleStaff.Add(anAppleStaff);
                                staffHasBeenRemoved = false;
                            }
                        }

                        if (staffHasBeenRemoved)
                        {
                            lastRemovedStaffId = Convert.ToInt32(anAppleStaff.PersonNumber.Split('-')[1]);
                            if (lastRemovedStaffId > Properties.Settings.Default.highestRemovedStaffId)
                            {
                                Properties.Settings.Default.highestRemovedStaffId = lastRemovedStaffId;
                            }
                            removedStaff++;
                        }
                    }
                }

                removedStaffValueLabel.Text = removedStaff.ToString(); //Affiche le nombre de professeurs supprimés
                statusProgressBar.Increment(10);                       //Etape terminée incrémente la progresse bar de 10.


                //2. Ajoute les professeurs présents dans le fichier staff source et absents de l'ancien fichier Staff apple
                //2.a Récupère l'identifiant le plus grand
                int personNumber;        //Numéro de l'identifiant de la personne
                int personNumberMax = 0; //Plus grand numéro
                foreach (ApplePerson anAppleStaff in newAppleStaff)
                {
                    personNumber = Convert.ToInt32(anAppleStaff.PersonNumber.Split('-')[1]); //Converti le numéro en entier (int)
                    if (personNumber > personNumberMax)
                    {
                        personNumberMax = personNumber;
                    }
                }

                statusProgressBar.Increment(10); //Première partie de la deuxième étape terminée on incrémente la barre de progression de 10

                //2.b Ajoute les professeurs
                bool notInOldAppleStaff = true;
                //Ici nous recherchons les nouveaux professeurs (présents dans source mais pas dans les fichiers Apple)
                foreach (SourcePerson aSourceStaff in sourceStaff)
                {
                    if (aSourceStaff.FirstName != "Prénom")
                    {
                        foreach (ApplePerson anApplePerson in oldAppleStaff)
                        {
                            if (aSourceStaff.Name == anApplePerson.LastName && aSourceStaff.Mail == anApplePerson.EmailAddress && aSourceStaff.Username == anApplePerson.SisUsername)
                            {
                                notInOldAppleStaff = false;
                            }
                        }

                        //Si le professeur n'est pas dans l'ancien fichier Apple
                        if (notInOldAppleStaff)
                        {
                            //Crée le nouvel identifiant
                            //Vérifier que l'identifiant n'a pas été utilisé précédemment
                            do
                            {
                                personNumberMax++;
                            }while (personNumberMax <= Properties.Settings.Default.highestRemovedStaffId);

                            ApplePerson newStaff = new ApplePerson("ID-Professeur-" + personNumberMax.ToString(), "PROF-" + personNumberMax.ToString(), aSourceStaff.FirstName, "", aSourceStaff.Name, aSourceStaff.Mail, aSourceStaff.Username, "ID-Location-College-Saint_Jean");
                            newAppleStaff.Add(newStaff);
                            addedStaff++;
                        }

                        notInOldAppleStaff = true; //Réinitialise
                    }
                }

                //Affiche les professeurs dans la staffDataGridView
                foreach (ApplePerson anApplePerson in newAppleStaff)
                {
                    staffDataGridView.Rows.Add(anApplePerson.PersonId, anApplePerson.PersonNumber, anApplePerson.FirstName, anApplePerson.MiddleName, anApplePerson.LastName, anApplePerson.EmailAddress, anApplePerson.SisUsername, anApplePerson.LocationId);
                }

                addedStaffValueLabel.Text = addedStaff.ToString(); //On affiche le nombre de professeurs ajoutés
                statusProgressBar.Increment(10);                   //Deuxième étape terminée on incrémente la barre de progression de 10



                //CREATION D'UN NOUVEAU FICHIER STUDENT APPLE
                //1. N'ajoute que les élèves présents l'année précédente et cette année
                bool studentHasBeenRemoved;
                int  lastRemovedStudentId;
                newAppleStudents = new List <AppleStudent>();
                foreach (AppleStudent anAppleStudent in oldAppleStudents)
                {
                    if (anAppleStudent.FirstName != "first_name")
                    {
                        studentHasBeenRemoved = true;

                        foreach (SourceStudent aSourceStudent in sourceStudents)
                        {
                            if (anAppleStudent.LastName.ToLower() == aSourceStudent.Name.ToLower() && anAppleStudent.EmailAddress.ToLower() == aSourceStudent.Mail.ToLower())
                            {
                                anAppleStudent.GradeLevel = aSourceStudent.Classe; //Bug réglé
                                newAppleStudents.Add(anAppleStudent);
                                studentHasBeenRemoved = false;
                            }
                        }

                        if (studentHasBeenRemoved)
                        {
                            try
                            {
                                lastRemovedStudentId = Convert.ToInt32(anAppleStudent.PersonNumber.Split('-')[1]);
                                if (lastRemovedStudentId > Properties.Settings.Default.highestRemovedStudentId)
                                {
                                    Properties.Settings.Default.highestRemovedStudentId = lastRemovedStudentId;
                                }
                                removedStudents++;
                            }
                            catch (IndexOutOfRangeException)
                            {
                                MessageBox.Show("Veuillez vérifier que le person_id et le person_number de l'élève " + anAppleStudent.FirstName + " " + anAppleStudent.LastName + " est au bon format dans le fichier CSV", "IndexOutOfRangeException", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }

                removedStudentsValueLabel.Text = removedStaff.ToString(); //Affiche le nombre de professeurs supprimés
                statusProgressBar.Increment(10);                          //Etape terminée incrémente la progresse bar de 10.


                //2. Ajoute les élèves présents dans le fichier students source et absents de l'ancien fichier Students apple
                //2.a Récupère l'identifiant le plus grand
                personNumber    = 0;
                personNumberMax = 0;
                foreach (AppleStudent anAppleStudent in newAppleStudents)
                {
                    personNumber = Convert.ToInt32(anAppleStudent.PersonNumber.Split('-')[1]);
                    if (personNumber > personNumberMax)
                    {
                        personNumberMax = personNumber;
                    }
                }

                statusProgressBar.Increment(10);

                //2.b Ajoute les professeurs
                bool notInOldAppleStudents = true;

                //Ici nous recherchons les nouveaux élèves (présents dans source mais pas dans les fichiers Apple)
                foreach (SourceStudent aSourceStudent in sourceStudents)
                {
                    if (aSourceStudent.Name != "Nom")
                    {
                        foreach (AppleStudent anAppleStudent in oldAppleStudents)
                        {
                            if (aSourceStudent.Name == anAppleStudent.LastName && aSourceStudent.Mail == anAppleStudent.EmailAddress && aSourceStudent.Username == anAppleStudent.SisUsername)
                            {
                                notInOldAppleStudents = false;
                            }
                        }

                        //Si l'élève n'est pas dans l'ancien fichier Apple
                        if (notInOldAppleStudents)
                        {
                            //Crée le nouvel identifiant
                            //Vérifier que l'identifiant n'a pas été utilisé précédemment
                            do
                            {
                                personNumberMax++;
                            }while (personNumberMax <= Properties.Settings.Default.highestRemovedStudentId);

                            AppleStudent newStudent = new AppleStudent("ID-ELEVE-" + personNumberMax.ToString(), "ELV-" + personNumberMax.ToString(), aSourceStudent.FirstName, "", aSourceStudent.Name, aSourceStudent.Classe, aSourceStudent.Mail, aSourceStudent.Username, "8", "ID-Location-College-Saint_Jean");
                            newAppleStudents.Add(newStudent);
                            addedStudents++;
                        }

                        notInOldAppleStudents = true; //Réinitialise
                    }
                }

                //Affiche les étudiants dans la staffDataGridView
                foreach (AppleStudent anAppleStudent in newAppleStudents)
                {
                    studentsDataGridView.Rows.Add(anAppleStudent.PersonId, anAppleStudent.PersonNumber, anAppleStudent.FirstName, anAppleStudent.MiddleName, anAppleStudent.LastName, anAppleStudent.GradeLevel, anAppleStudent.EmailAddress, anAppleStudent.SisUsername, anAppleStudent.PasswordPolicy, anAppleStudent.LocationId);
                }


                addedStudentsValueLabel.Text = addedStudents.ToString(); //Affiche le nombre d'étudiants ajoutés
                statusProgressBar.Increment(10);                         //Etape terminée incrémente de 10


                //CREATION DU NOUVEAU FICHIER APPLE CLASSES
                newAppleClasses = new List <AppleClasse>();
                foreach (SourceClasse aSourceClasse in sourceClasses)
                {
                    if (aSourceClasse.ClassId != "class_number")
                    {
                        AppleClasse newAppleClasse = new AppleClasse("ID-Classe-" + aSourceClasse.ClassId, aSourceClasse.ClassId, "ID-Cours-" + aSourceClasse.ClassId);
                        foreach (string anInstructor in aSourceClasse.Instructors)
                        {
                            newAppleClasse.AddInstructor(anInstructor);
                        }
                        newAppleClasses.Add(newAppleClasse);
                    }
                }

                statusProgressBar.Increment(10);

                //Affichage des classes dans la classesDataGridView
                int maxInstructors = 1;
                foreach (AppleClasse anAppleClasse in newAppleClasses)
                {
                    if (anAppleClasse.Instructors.Count() > maxInstructors)
                    {
                        maxInstructors = anAppleClasse.Instructors.Count();
                    }
                }

                for (int i = 0; i < maxInstructors; i++)
                {
                    DataGridViewColumn newCol = new DataGridViewColumn();
                    newCol.HeaderText   = "instructor_id_" + i.ToString();
                    newCol.Name         = "InstructorId" + i.ToString();
                    newCol.CellTemplate = new DataGridViewTextBoxCell();
                    classesDataGridView.Columns.Add(newCol);
                }


                foreach (AppleClasse anAppleClasse in newAppleClasses)
                {
                    classesDataGridView.Rows.Add(anAppleClasse.ClassId, anAppleClasse.ClassNumber, anAppleClasse.CourseId, anAppleClasse.Instructors.ToArray());
                }


                //CREATION DU FICHIER COURSES
                newAppleCourses = new List <AppleCourse>();
                foreach (AppleClasse anAppleClasse in newAppleClasses)
                {
                    AppleCourse newAppleCourse = new AppleCourse(anAppleClasse.CourseId, "", "", "ID-Location-College-Saint_Jean");
                    newAppleCourses.Add(newAppleCourse);
                }

                //Affiche les cours dans courseDataGridView
                foreach (AppleCourse anAppleCourse in newAppleCourses)
                {
                    coursesDataGridView.Rows.Add(anAppleCourse.CourseId, anAppleCourse.CourseNumber, anAppleCourse.CourseName, anAppleCourse.LocationId);
                }
                statusProgressBar.Increment(10);


                //CREATION DU FICHIER APPLE ROSTERS
                newAppleRosters = new List <AppleRoster>();
                int rosterNumber = 1; //Numéro du roster
                foreach (SourceStudent aSourceStudent in sourceStudents)
                {
                    foreach (AppleStudent anAppleStudent in newAppleStudents)
                    {
                        if (anAppleStudent.FirstName == aSourceStudent.FirstName && anAppleStudent.LastName == aSourceStudent.Name && anAppleStudent.EmailAddress == aSourceStudent.Mail && anAppleStudent.SisUsername == aSourceStudent.Username)
                        {
                            AppleRoster newAppleRoster = new AppleRoster("SAMPLE-ROSTER-ID-" + rosterNumber, "ID-Classe-" + aSourceStudent.Classe, anAppleStudent.PersonId);
                            newAppleRosters.Add(newAppleRoster);
                            rosterNumber++; //Incrémente
                        }
                    }
                }

                statusProgressBar.Increment(10);

                //Affiches les rosters dans le rostersDataGridView
                foreach (AppleRoster anAppleRoster in newAppleRosters)
                {
                    rostersDataGridView.Rows.Add(anAppleRoster.RosterId, anAppleRoster.ClassId, anAppleRoster.StudentId);
                }


                //CREATION DU NOUVEAU FICHIER APPLE LOCATIONS
                newAppleLocations = new List <AppleLocation>();
                foreach (AppleLocation anOldAppleLocation in oldAppleLocations)
                {
                    if (anOldAppleLocation.LocationId != "location_id")
                    {
                        newAppleLocations.Add(anOldAppleLocation);
                    }
                }
                //Affiche les locations dans la locationsDataGridView
                foreach (AppleLocation anAppleLocation in newAppleLocations)
                {
                    locationsDataGridView.Rows.Add(anAppleLocation.LocationId, anAppleLocation.LocationNumber);
                }

                statusProgressBar.Value = 0;
                statusLabel.Text        = "Fichiers créés. Prêt pour l'exportation";

                //Affiche le nombres d'élèves et de professeurs ajoutés et supprimés
                addedStudentsValueLabel.Text   = addedStudents.ToString();
                removedStudentsValueLabel.Text = removedStudents.ToString();
                addedStaffValueLabel.Text      = addedStaff.ToString();
                removedStaffValueLabel.Text    = removedStaff.ToString();


                loadFilesButton.Enabled = false; //Empêche d'appuyer à nouveau sur le bouton
                exportButton.Enabled    = true;
            }
        }