Ejemplo n.º 1
0
 internal static void RestoreCurrentValuesOfAllControls(Control ParentControl, string PathAndFile)
 {
     try
     {
         string[,] NamesAndValues = TextFile.FileToMatrix(PathAndFile, '\t');
         int index = 0;
         RestoreControlsValuesOfLevel(ParentControl, NamesAndValues, ref index);
     }
     catch (Exception ex)
     {
         Console.Beep(200, 300);
     }
 }
Ejemplo n.º 2
0
        private void BtnImportStudentsOfClass_Click(object sender, EventArgs e)
        {
            // give warning to avoid modifying existing class instead of making a new one
            if (Commons.bl.GetClass(currentSchool.IdSchool, idSchoolYear, CmbClasses.Text).Abbreviation != null)
            {
                MessageBox.Show("Esiste già una classe con il nome \"" + CmbClasses.Text + "\" in questo anno!", "Avviso",
                                MessageBoxButtons.OK);
                return;
            }
            if (CmbClasses.Text.Contains(" "))
            {
                DialogResult d = MessageBox.Show("E' meglio non mettere spazi nella sigla della classe." +
                                                 "\r\nDevo metterli lo stesso?",
                                                 "Informazione", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                if (d != DialogResult.Yes)
                {
                    return;
                }
            }
            if (!File.Exists(TxtFileOfStudentsImport.Text) ||
                TxtFileOfStudentsImport.Text.Substring(TxtFileOfStudentsImport.Text.Length - 1, 1) == "\\")
            {
                MessageBox.Show("Il file \"" + TxtFileOfStudentsImport.Text + "\" non esiste!", "Avviso",
                                MessageBoxButtons.OK);
                return;
            }
            string[,] datiAllievi = TextFile.FileToMatrix(TxtFileOfStudentsImport.Text, '\t');

            int   idClass;
            Class newClass = new Class(0, CmbClasses.Text, CmbSchoolYear.Text, TxtOfficialSchoolAbbreviation.Text);

            if (!RdbPhotoUserChoosen.Checked)
            {
                newClass.IdClass = Commons.bl.CreateClassAndStudents(datiAllievi, CmbClasses.Text, TxtClassDescription.Text,
                                                                     CmbSchoolYear.Text, TxtOfficialSchoolAbbreviation.Text, RdbPhotoAlreadyPresent.Checked);
            }
            else
            {
                idClass = Commons.bl.CreateClass(CmbClasses.Text, TxtClassDescription.Text,
                                                 CmbSchoolYear.Text, TxtOfficialSchoolAbbreviation.Text);
                for (int riga = 1; riga < datiAllievi.GetLength(0); riga++)
                {
                    Student s = Commons.bl.CreateStudentFromStringMatrix(datiAllievi, riga);
                    if (s.IdStudent > 0)
                    {
                        Commons.bl.PutStudentInClass(s.IdStudent, idClass);
                        if (rdbChooseStudentsPhotoWhileImporting.Checked)
                        {
                            using (OpenFileDialog dlg = new OpenFileDialog())
                            {
                                dlg.Title = "Scegli una foto dello studente " + datiAllievi[riga, 1] + " " +
                                            datiAllievi[riga, 2] + ", " + CmbClasses.Text + " " + CmbSchoolYear.Text;
                                dlg.Filter           = "jpg files (*.jpg)|*.jpg";
                                dlg.InitialDirectory = TxtPathImages.Text;
                                if (dlg.ShowDialog() == DialogResult.OK)
                                {
                                    Student s1 = new Student();
                                    s1.IdStudent = s.IdStudent;
                                    s1.LastName  = datiAllievi[riga, 1];
                                    s1.FirstName = datiAllievi[riga, 2];
                                    Commons.bl.CopyAndLinkOnePhoto(s1, newClass, dlg.FileName);
                                }
                            }
                        }
                    }
                }
            }
            MessageBox.Show("Importazione terminata");
            this.Close();
        }