Ejemplo n.º 1
0
 public Students(Eleve eleve, Action callBack) : this(callBack)
 {
     this.oldEleve     = eleve;
     txtMatricule.Text = eleve.Matricule;
     txtNom.Text       = eleve.Nom;
     txtPrenom.Text    = eleve.Prenom;
     txtNaissance.Text = eleve.Datedenaissance;
     txtVille.Text     = eleve.Ville;
     if (eleve.Photo != null)
     {
         pictureBox1.Image = Image.FromStream(new MemoryStream(eleve.Photo));
     }
 }
Ejemplo n.º 2
0
        private void btnValider_Click(object sender, EventArgs e)
        {
            try
            {
                Eleve newEleve = new Eleve
                                 (
                    txtMatricule.Text.ToUpper(),
                    txtNom.Text,
                    txtPrenom.Text,
                    txtEcole.Text,
                    txtNaissance.Text,
                    txtVille.Text,
                    !string.IsNullOrEmpty(pictureBox1.ImageLocation) ? File.ReadAllBytes(pictureBox1.ImageLocation) : this.oldEleve?.Photo
                                 );

                EleveBLO eleveBLo = new EleveBLO(ConfigurationManager.AppSettings["DbFolder"]);

                if (this.oldEleve == null)
                {
                    eleveBLo.CreateEleve(newEleve);
                }
                else
                {
                    eleveBLo.EditEtudiant(oldEleve, newEleve);
                }

                MessageBox.Show
                (
                    "Save done !",
                    "Confirmation",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                );

                if (callBack != null)
                {
                    callBack();
                }

                if (oldEleve != null)
                {
                    Close();
                }

                txtMatricule.Clear();
                txtNom.Clear();
                txtPrenom.Clear();
                txtNaissance.Clear();
                txtVille.Clear();
                txtEcole.Clear();
            }
            catch (TypingException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Typing error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (DuplicateNameException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Duplicate error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (KeyNotFoundException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Not found error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (Exception ex)
            {
                ex.WriteToFile();
                MessageBox.Show
                (
                    "An error occurred! Please try again later.",
                    "Erreur",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );
            }
        }